Skip to content

Commit 0a5ffa8

Browse files
authored
Merge pull request #994 from gsalgado/persist_block-uncles
ChainDB.persist_block() now only persists uncles when not empty
2 parents 68a8abb + b62650d commit 0a5ffa8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

evm/db/chain.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@
3232
from eth_hash.auto import keccak
3333

3434
from evm.constants import (
35+
EMPTY_UNCLE_HASH,
3536
GENESIS_PARENT_HASH,
3637
)
3738
from evm.exceptions import (
3839
CanonicalHeadNotFound,
3940
HeaderNotFound,
4041
ParentNotFound,
4142
TransactionNotFound,
43+
ValidationError,
4244
)
4345
from evm.db.header import BaseHeaderDB, HeaderDB
4446
from evm.db.backends.base import (
@@ -171,6 +173,8 @@ def get_block_uncles(self, uncles_hash: Hash32) -> List[BlockHeader]:
171173
Returns an iterable of uncle headers specified by the given uncles_hash
172174
"""
173175
validate_word(uncles_hash, title="Uncles Hash")
176+
if uncles_hash == EMPTY_UNCLE_HASH:
177+
return []
174178
try:
175179
encoded_uncles = self.db[uncles_hash]
176180
except KeyError:
@@ -268,9 +272,14 @@ def persist_block(self, block: 'BaseBlock') -> None:
268272
for index, transaction_hash in enumerate(self.get_block_transaction_hashes(header)):
269273
self._add_transaction_to_canonical_chain(transaction_hash, header, index)
270274

271-
if hasattr(block, "uncles"):
275+
if block.uncles:
272276
uncles_hash = self.persist_uncles(block.uncles)
273-
assert uncles_hash == block.header.uncles_hash
277+
else:
278+
uncles_hash = EMPTY_UNCLE_HASH
279+
if uncles_hash != block.header.uncles_hash:
280+
raise ValidationError(
281+
"Block's uncles_hash (%s) does not match actual uncles' hash (%s)",
282+
block.header.uncles_hash, uncles_hash)
274283

275284
def persist_uncles(self, uncles: Tuple[BlockHeader]) -> Hash32:
276285
"""

0 commit comments

Comments
 (0)