Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synapse required hash field refactoring and imports #1927

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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