Skip to content

Commit

Permalink
dev: change type of branch node subnodes
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Dec 20, 2024
1 parent 1adcc1b commit 6783252
Show file tree
Hide file tree
Showing 16 changed files with 80 additions and 64 deletions.
9 changes: 5 additions & 4 deletions src/ethereum/arrow_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/berlin/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/byzantium/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/cancun/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -100,7 +101,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -140,7 +141,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -462,9 +463,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/constantinople/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/dao_fork/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/frontier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -96,7 +97,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -136,7 +137,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -460,9 +461,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/gray_glacier/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/homestead/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
9 changes: 5 additions & 4 deletions src/ethereum/istanbul/trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MutableMapping,
Optional,
Sequence,
Tuple,
TypeVar,
Union,
)
Expand Down Expand Up @@ -97,7 +98,7 @@ class ExtensionNode:
class BranchNode:
"""Branch node in the Merkle Trie"""

subnodes: List[rlp.Extended]
subnodes: Tuple[rlp.Extended, ...]
value: rlp.Extended


Expand Down Expand Up @@ -137,7 +138,7 @@ def encode_internal_node(node: Optional[InternalNode]) -> rlp.Extended:
node.subnode,
)
elif isinstance(node, BranchNode):
unencoded = node.subnodes + [node.value]
unencoded = list(node.subnodes) + [node.value]
else:
raise AssertionError(f"Invalid internal node type {type(node)}!")

Expand Down Expand Up @@ -459,9 +460,9 @@ def patricialize(
branches[key[level]][key] = obj[key]

return BranchNode(
[
(
encode_internal_node(patricialize(branches[k], level + Uint(1)))
for k in range(16)
],
),
value,
)
Loading

0 comments on commit 6783252

Please sign in to comment.