mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 05:14:14 +00:00
Implement EIP-2935: Serve historical block hashes from state (#2606)
* Implement EIP-2935: Serve historical block hashes from state * Fix EIP-2935 in t8n
This commit is contained in:
parent
5464f8e5f1
commit
38c58c4feb
@ -107,4 +107,5 @@ const
|
|||||||
result[19] = x.byte
|
result[19] = x.byte
|
||||||
initAddress(3)
|
initAddress(3)
|
||||||
|
|
||||||
|
HISTORY_STORAGE_ADDRESS* = hexToByteArray[20]("0x0aae40965e6800cd9b1f4b05ff21581047e3f91e")
|
||||||
# End
|
# End
|
||||||
|
@ -66,6 +66,9 @@ proc procBlkPreamble(
|
|||||||
if blk.transactions.calcTxRoot != header.txRoot:
|
if blk.transactions.calcTxRoot != header.txRoot:
|
||||||
return err("Mismatched txRoot")
|
return err("Mismatched txRoot")
|
||||||
|
|
||||||
|
if com.isPragueOrLater(header.timestamp):
|
||||||
|
?vmState.processParentBlockHash(header.parentHash)
|
||||||
|
|
||||||
if com.isCancunOrLater(header.timestamp):
|
if com.isCancunOrLater(header.timestamp):
|
||||||
if header.parentBeaconBlockRoot.isNone:
|
if header.parentBeaconBlockRoot.isNone:
|
||||||
return err("Post-Cancun block header must have parentBeaconBlockRoot")
|
return err("Post-Cancun block header must have parentBeaconBlockRoot")
|
||||||
@ -144,10 +147,10 @@ proc procBlkEpilogue(
|
|||||||
|
|
||||||
if not skipReceipts:
|
if not skipReceipts:
|
||||||
let bloom = createBloom(vmState.receipts)
|
let bloom = createBloom(vmState.receipts)
|
||||||
|
|
||||||
if header.logsBloom != bloom:
|
if header.logsBloom != bloom:
|
||||||
return err("bloom mismatch")
|
return err("bloom mismatch")
|
||||||
|
|
||||||
let receiptsRoot = calcReceiptsRoot(vmState.receipts)
|
let receiptsRoot = calcReceiptsRoot(vmState.receipts)
|
||||||
if header.receiptsRoot != receiptsRoot:
|
if header.receiptsRoot != receiptsRoot:
|
||||||
# TODO replace logging with better error
|
# TODO replace logging with better error
|
||||||
|
@ -157,6 +157,36 @@ proc processBeaconBlockRoot*(vmState: BaseVMState, beaconRoot: Hash256):
|
|||||||
statedb.persist(clearEmptyAccount = true)
|
statedb.persist(clearEmptyAccount = true)
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
|
proc processParentBlockHash*(vmState: BaseVMState, prevHash: Hash256):
|
||||||
|
Result[void, string] =
|
||||||
|
## processParentBlockHash stores the parent block hash in the
|
||||||
|
## history storage contract as per EIP-2935.
|
||||||
|
let
|
||||||
|
statedb = vmState.stateDB
|
||||||
|
call = CallParams(
|
||||||
|
vmState : vmState,
|
||||||
|
sender : SYSTEM_ADDRESS,
|
||||||
|
gasLimit : 30_000_000.GasInt,
|
||||||
|
gasPrice : 0.GasInt,
|
||||||
|
to : HISTORY_STORAGE_ADDRESS,
|
||||||
|
input : @(prevHash.data),
|
||||||
|
|
||||||
|
# It's a systemCall, no need for other knicks knacks
|
||||||
|
sysCall : true,
|
||||||
|
noAccessList: true,
|
||||||
|
noIntrinsic : true,
|
||||||
|
noGasCharge : true,
|
||||||
|
noRefund : true,
|
||||||
|
)
|
||||||
|
|
||||||
|
# runComputation a.k.a syscall/evm.call
|
||||||
|
let res = call.runComputation(string)
|
||||||
|
if res.len > 0:
|
||||||
|
return err("processParentBlockHash: " & res)
|
||||||
|
|
||||||
|
statedb.persist(clearEmptyAccount = true)
|
||||||
|
ok()
|
||||||
|
|
||||||
proc processTransaction*(
|
proc processTransaction*(
|
||||||
vmState: BaseVMState; ## Parent accounts environment for transaction
|
vmState: BaseVMState; ## Parent accounts environment for transaction
|
||||||
tx: Transaction; ## Transaction to validate
|
tx: Transaction; ## Transaction to validate
|
||||||
|
@ -234,6 +234,18 @@ proc exec(ctx: var TransContext,
|
|||||||
vmState.processBeaconBlockRoot(ctx.env.parentBeaconBlockRoot.get).isOkOr:
|
vmState.processBeaconBlockRoot(ctx.env.parentBeaconBlockRoot.get).isOkOr:
|
||||||
raise newError(ErrorConfig, error)
|
raise newError(ErrorConfig, error)
|
||||||
|
|
||||||
|
if vmState.com.isPragueOrLater(ctx.env.currentTimestamp) and
|
||||||
|
ctx.env.blockHashes.len > 0:
|
||||||
|
let
|
||||||
|
prevNumber = ctx.env.currentNumber - 1
|
||||||
|
prevHash = ctx.env.blockHashes.getOrDefault(prevNumber)
|
||||||
|
|
||||||
|
if prevHash == static(Hash256()):
|
||||||
|
raise newError(ErrorConfig, "previous block hash not found for block number: " & $prevNumber)
|
||||||
|
|
||||||
|
vmState.processParentBlockHash(prevHash).isOkOr:
|
||||||
|
raise newError(ErrorConfig, error)
|
||||||
|
|
||||||
for txIndex, txRes in txList:
|
for txIndex, txRes in txList:
|
||||||
if txRes.isErr:
|
if txRes.isErr:
|
||||||
rejected.add RejectedTx(
|
rejected.add RejectedTx(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user