Skip to content

Commit

Permalink
narrow to bytes32 hinting in DataStore.insert_batch() (#19178)
Browse files Browse the repository at this point in the history
<!-- Merging Requirements:
- Please give your PR a title that is release-note friendly
- In order to be merged, you must add the most appropriate category
Label (Added, Changed, Fixed) to your PR
-->
<!-- Explain why this is an improvement (Does this add missing
functionality, improve performance, or reduce complexity?) -->

### Purpose:

<!-- Does this PR introduce a breaking change? -->

### Current Behavior:

### New Behavior:

<!-- As we aim for complete code coverage, please include details
regarding unit, and regression tests -->

### Testing Notes:

<!-- Attach any visual examples, or supporting evidence (attach any
.gif/video/console output below) -->
  • Loading branch information
altendky authored Jan 24, 2025
2 parents 38694fe + 96fd8ec commit b484368
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions chia/_tests/core/data_layer/test_merkle_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,10 @@ def generate_kvid(seed: int) -> tuple[KVId, KVId]:
return kv_ids[0], kv_ids[1]


def generate_hash(seed: int) -> bytes:
def generate_hash(seed: int) -> bytes32:
seed_bytes = seed.to_bytes(8, byteorder="big", signed=True)
hash_obj = hashlib.sha256(seed_bytes)
return hash_obj.digest()
return bytes32(hash_obj.digest())


def test_insert_delete_loads_all_keys() -> None:
Expand Down Expand Up @@ -337,7 +337,7 @@ def test_proof_of_inclusion_merkle_blob() -> None:
num_deletes = 1 + repeats * 10

kv_ids: list[tuple[KVId, KVId]] = []
hashes: list[bytes] = []
hashes: list[bytes32] = []
for _ in range(num_inserts):
seed += 1
key, value = generate_kvid(seed)
Expand Down
2 changes: 1 addition & 1 deletion chia/data_layer/data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ async def insert_batch(
last_action[hash] = change["action"]

batch_keys_values: list[tuple[KVId, KVId]] = []
batch_hashes: list[bytes] = []
batch_hashes: list[bytes32] = []

for change in changelist:
if change["action"] == "insert":
Expand Down
2 changes: 1 addition & 1 deletion chia/data_layer/util/merkle_blob.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ def get_nodes_with_indexes(self, index: TreeIndex = TreeIndex(0)) -> list[tuple[

return this + left_nodes + right_nodes

def batch_insert(self, keys_values: list[tuple[KVId, KVId]], hashes: list[bytes]) -> None:
def batch_insert(self, keys_values: list[tuple[KVId, KVId]], hashes: list[bytes32]) -> None:
indexes: list[TreeIndex] = []

if len(self.key_to_index) <= 1:
Expand Down

0 comments on commit b484368

Please sign in to comment.