Skip to content

Commit 3badaf9

Browse files
committed
review
1 parent 6f5f959 commit 3badaf9

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

nimbus_verified_proxy/rpc/blocks.nim

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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.computRlpHash != 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,20 @@ 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.computeRlpHash != 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")
120123

121-
# walk blocks backwards(time) from source to target
122-
?(
123-
await vp.walkBlocks(
124-
latestHeader.number, header.number, latestHeader.parentHash, hash
124+
if not vp.headerStore.contains(blockHash):
125+
let latestHeader = vp.headerStore.latest.valueOr:
126+
return err("Couldn't get the latest header, syncing in progress")
127+
128+
# walk blocks backwards(time) from source to target
129+
?(
130+
await vp.walkBlocks(
131+
latestHeader.number, header.number, latestHeader.parentHash, hash
132+
)
125133
)
126-
)
127134

128135
ok()
129136

@@ -139,9 +146,12 @@ proc verifyBlock(
139146
?verifyTransactions(header.transactionsRoot, blk.transactions)
140147

141148
# 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")
149+
if blk.withdrawalsRoot.isSome():
150+
if blk.withdrawalsRoot.get() != orderedTrieRoot(blk.withdrawals.get(@[])):
151+
return err("Withdrawals within the block do not yield the same withdrawals root")
152+
else:
153+
if blk.withdrawals.isSome():
154+
return err("Block contains withdrawals but no withdrawalsRoot")
145155

146156
ok()
147157

nimbus_verified_proxy/rpc/rpc_eth_api.nim

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ proc installEthApiHandlers*(vp: VerifiedRpcProxy) =
7777
) -> BlockObject:
7878
(await vp.getBlock(blockHash, fullTransactions)).valueOr:
7979
raise newException(ValueError, error)
80+
81+
vp.proxy.rpc("eth_getBlockByNumber") do(
82+
blockTag: BockTag, fullTransactions: bool
83+
) -> BlockObject:
84+
(await vp.getBlock(blockTag, fullTransactions)).valueOr:
85+
raise newException(ValueError, error)
8086

8187
vp.proxy.rpc("eth_getUncleCountByBlockNumber") do(blockTag: BlockTag) -> Quantity:
8288
let blk = (await vp.getBlock(blockTag, false)).valueOr:

0 commit comments

Comments
 (0)