13
13
chronicles,
14
14
web3/ [eth_api_types, eth_api],
15
15
json_rpc/ [rpcproxy, rpcserver, rpcclient],
16
- eth/ common/ addresses,
17
16
eth/ common/ eth_types_rlp,
17
+ eth/ rlp,
18
18
eth/ trie/ [ordered_trie, trie_defs],
19
19
../../ execution_chain/ beacon/ web3_eth_conv,
20
20
../ types,
@@ -99,7 +99,12 @@ proc walkBlocks(
99
99
number = blk.number,
100
100
remaining = distinctBase(blk.number) - targetNum
101
101
102
- convHeader(blk)
102
+ let header = convHeader(blk)
103
+
104
+ if header.computeBlockHash != nextHash:
105
+ return err(" Encountered an invalid block header while walking the chain" )
106
+
107
+ header
103
108
104
109
if nextHeader.parentHash == targetHash:
105
110
return ok()
@@ -112,18 +117,19 @@ proc verifyHeader(
112
117
vp: VerifiedRpcProxy, header: Header, hash: Hash32
113
118
): Future[Result[void , string ]] {.async.} =
114
119
# verify calculated hash with the requested hash
115
- if header.rlpHash != hash:
120
+ if header.computeBlockHash != hash:
116
121
return err(" hashed block header doesn't match with blk.hash(downloaded)" )
117
122
118
- let latestHeader = vp.headerStore.latest.valueOr:
119
- return err(" syncing" )
123
+ if not vp.headerStore.contains(hash):
124
+ let latestHeader = vp.headerStore.latest.valueOr:
125
+ return err(" Couldn't get the latest header, syncing in progress" )
120
126
121
- # walk blocks backwards(time) from source to target
122
- ? (
123
- await vp.walkBlocks(
124
- latestHeader.number, header.number, latestHeader.parentHash, hash
127
+ # walk blocks backwards(time) from source to target
128
+ ? (
129
+ await vp.walkBlocks(
130
+ latestHeader.number, header.number, latestHeader.parentHash, hash
131
+ )
125
132
)
126
- )
127
133
128
134
ok()
129
135
@@ -139,9 +145,12 @@ proc verifyBlock(
139
145
? verifyTransactions(header.transactionsRoot, blk.transactions)
140
146
141
147
# verify withdrawals
142
- if blk.withdrawals.isSome():
143
- if blk.withdrawalsRoot.get() != orderedTrieRoot(blk.withdrawals.get()):
144
- return err(" withdrawals within the block do not yield the same withdrawals root" )
148
+ if blk.withdrawalsRoot.isSome():
149
+ if blk.withdrawalsRoot.get() != orderedTrieRoot(blk.withdrawals.get(@ [])):
150
+ return err(" Withdrawals within the block do not yield the same withdrawals root" )
151
+ else :
152
+ if blk.withdrawals.isSome():
153
+ return err(" Block contains withdrawals but no withdrawalsRoot" )
145
154
146
155
ok()
147
156
0 commit comments