Skip to content

Commit 247a98c

Browse files
committed
review
1 parent 6f5f959 commit 247a98c

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

nimbus_verified_proxy/rpc/blocks.nim

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import
1313
chronicles,
1414
web3/[eth_api_types, eth_api],
1515
json_rpc/[rpcproxy, rpcserver, rpcclient],
16-
eth/common/addresses,
1716
eth/common/eth_types_rlp,
17+
eth/rlp,
1818
eth/trie/[ordered_trie, trie_defs],
1919
../../execution_chain/beacon/web3_eth_conv,
2020
../types,
@@ -99,7 +99,12 @@ proc walkBlocks(
9999
number = blk.number,
100100
remaining = distinctBase(blk.number) - targetNum
101101

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
103108

104109
if nextHeader.parentHash == targetHash:
105110
return ok()
@@ -112,18 +117,19 @@ proc verifyHeader(
112117
vp: VerifiedRpcProxy, header: Header, hash: Hash32
113118
): Future[Result[void, string]] {.async.} =
114119
# verify calculated hash with the requested hash
115-
if header.rlpHash != hash:
120+
if header.computeBlockHash != hash:
116121
return err("hashed block header doesn't match with blk.hash(downloaded)")
117122

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")
120126

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+
)
125132
)
126-
)
127133

128134
ok()
129135

@@ -139,9 +145,12 @@ proc verifyBlock(
139145
?verifyTransactions(header.transactionsRoot, blk.transactions)
140146

141147
# 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")
145154

146155
ok()
147156

nimbus_verified_proxy/rpc/rpc_eth_api.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
7878
(await vp.getBlock(blockHash, fullTransactions)).valueOr:
7979
raise newException(ValueError, error)
8080

81+
vp.proxy.rpc("eth_getBlockByNumber") do(
82+
blockTag: BlockTag, fullTransactions: bool
83+
) -> BlockObject:
84+
(await vp.getBlock(blockTag, fullTransactions)).valueOr:
85+
raise newException(ValueError, error)
86+
8187
vp.proxy.rpc("eth_getUncleCountByBlockNumber") do(blockTag: BlockTag) -> Quantity:
8288
let blk = (await vp.getBlock(blockTag, false)).valueOr:
8389
raise newException(ValueError, error)

0 commit comments

Comments
 (0)