Skip to content

Commit

Permalink
Merge pull request #1927 from opentensor/refactoring/opendansor/synap…
Browse files Browse the repository at this point in the history
…se-required-hash-field-refactoring

Refactor: Fix naming in Synapse comment for required hash field
  • Loading branch information
opendansor committed May 23, 2024
2 parents c5dc22f + 3489ee6 commit 948720e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
7 changes: 3 additions & 4 deletions bittensor/synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import base64
import json
import sys
import typing
import warnings

from pydantic import (
Expand All @@ -31,7 +30,7 @@
model_validator,
)
import bittensor
from typing import Optional, Any, Dict
from typing import Optional, Any, Dict, ClassVar, Tuple


def get_size(obj, seen=None) -> int:
Expand Down Expand Up @@ -482,7 +481,7 @@ def set_name_type(cls, values) -> dict:
repr=False,
)

required_hash_fields: typing.ClassVar[typing.Tuple[str, ...]] = ()
required_hash_fields: ClassVar[Tuple[str, ...]] = ()

_extract_total_size = field_validator("total_size", mode="before")(cast_int)

Expand Down Expand Up @@ -676,7 +675,7 @@ def body_hash(self) -> str:
Process:
1. Iterates over each required field as specified in ``required_fields_hash``.
1. Iterates over each required field as specified in ``required_hash_fields``.
2. Concatenates the string representation of these fields.
3. Applies SHA3-256 hashing to the concatenated string to produce a unique fingerprint of the data.
Expand Down
6 changes: 2 additions & 4 deletions tests/unit_tests/test_synapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
# DEALINGS IN THE SOFTWARE.
import json
import base64
import typing
from typing import Optional

import pytest
import bittensor
from typing import Optional, ClassVar


def test_parse_headers_to_inputs():
Expand Down Expand Up @@ -239,7 +237,7 @@ class HashedSynapse(bittensor.Synapse):
b: int
c: Optional[int] = None
d: Optional[list[str]] = None
required_hash_fields: typing.ClassVar[tuple[str, ...]] = ("a", "b", "d")
required_hash_fields: ClassVar[tuple[str, ...]] = ("a", "b", "d")


@pytest.mark.parametrize("synapse_cls", [LegacyHashedSynapse, HashedSynapse])
Expand Down

0 comments on commit 948720e

Please sign in to comment.