|
32 | 32 | from eth_hash.auto import keccak
|
33 | 33 |
|
34 | 34 | from evm.constants import (
|
| 35 | + EMPTY_UNCLE_HASH, |
35 | 36 | GENESIS_PARENT_HASH,
|
36 | 37 | )
|
37 | 38 | from evm.exceptions import (
|
38 | 39 | CanonicalHeadNotFound,
|
39 | 40 | HeaderNotFound,
|
40 | 41 | ParentNotFound,
|
41 | 42 | TransactionNotFound,
|
| 43 | + ValidationError, |
42 | 44 | )
|
43 | 45 | from evm.db.header import BaseHeaderDB, HeaderDB
|
44 | 46 | from evm.db.backends.base import (
|
@@ -171,6 +173,8 @@ def get_block_uncles(self, uncles_hash: Hash32) -> List[BlockHeader]:
|
171 | 173 | Returns an iterable of uncle headers specified by the given uncles_hash
|
172 | 174 | """
|
173 | 175 | validate_word(uncles_hash, title="Uncles Hash")
|
| 176 | + if uncles_hash == EMPTY_UNCLE_HASH: |
| 177 | + return [] |
174 | 178 | try:
|
175 | 179 | encoded_uncles = self.db[uncles_hash]
|
176 | 180 | except KeyError:
|
@@ -268,9 +272,14 @@ def persist_block(self, block: 'BaseBlock') -> None:
|
268 | 272 | for index, transaction_hash in enumerate(self.get_block_transaction_hashes(header)):
|
269 | 273 | self._add_transaction_to_canonical_chain(transaction_hash, header, index)
|
270 | 274 |
|
271 |
| - if hasattr(block, "uncles"): |
| 275 | + if block.uncles: |
272 | 276 | 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) |
274 | 283 |
|
275 | 284 | def persist_uncles(self, uncles: Tuple[BlockHeader]) -> Hash32:
|
276 | 285 | """
|
|
0 commit comments