mirror of https://github.com/status-im/nim-eth.git
extend `BlockHeader` for EIP-4844 (#570)
Extends `BlockHeader` with `excessDataGas` according to EIP-4844 (used by Nimbus-CL in empty block prod fallback).
This commit is contained in:
parent
5c46220e72
commit
c9fcab8052
|
@ -121,6 +121,7 @@ type
|
|||
# `baseFee` is the get/set of `fee`
|
||||
fee*: Option[UInt256] # EIP-1559
|
||||
withdrawalsRoot*: Option[Hash256] # EIP-4895
|
||||
excessDataGas*: Option[GasInt] # EIP-4844
|
||||
|
||||
BlockBody* = object
|
||||
transactions*: seq[Transaction]
|
||||
|
|
|
@ -318,25 +318,28 @@ proc append*(w: var RlpWriter, h: BlockHeader) =
|
|||
var len = 15
|
||||
if h.fee.isSome: inc len
|
||||
if h.withdrawalsRoot.isSome: inc len
|
||||
if h.excessDataGas.isSome: inc len
|
||||
w.startList(len)
|
||||
for k, v in fieldPairs(h):
|
||||
when k notin ["fee", "withdrawalsRoot"]:
|
||||
when v isnot Option:
|
||||
w.append(v)
|
||||
if h.fee.isSome:
|
||||
w.append(h.fee.get())
|
||||
if h.withdrawalsRoot.isSome:
|
||||
w.append(h.withdrawalsRoot.get())
|
||||
if h.excessDataGas.isSome:
|
||||
w.append(h.excessDataGas.get())
|
||||
|
||||
proc read*(rlp: var Rlp, T: type BlockHeader): T =
|
||||
let len = rlp.listLen
|
||||
|
||||
if len notin {15, 16, 17}:
|
||||
if len notin {15, 16, 17, 18}:
|
||||
raise newException(UnsupportedRlpError,
|
||||
"BlockHeader elems should be 15, 16, or 17 got " & $len)
|
||||
"BlockHeader elems should be 15, 16, 17, or 18 got " & $len)
|
||||
|
||||
rlp.tryEnterList()
|
||||
for k, v in fieldPairs(result):
|
||||
when k notin ["fee", "withdrawalsRoot"]:
|
||||
when v isnot Option:
|
||||
v = rlp.read(type v)
|
||||
|
||||
if len >= 16:
|
||||
|
@ -345,6 +348,9 @@ proc read*(rlp: var Rlp, T: type BlockHeader): T =
|
|||
if len >= 17:
|
||||
# EIP-4895
|
||||
result.withdrawalsRoot = some rlp.read(Hash256)
|
||||
if len >= 18:
|
||||
# EIP-4844
|
||||
result.excessDataGas = some rlp.read(GasInt)
|
||||
|
||||
proc rlpHash*[T](v: T): Hash256 =
|
||||
keccakHash(rlp.encode(v))
|
||||
|
|
|
@ -97,11 +97,27 @@ proc suite2() =
|
|||
for i in 0..<10:
|
||||
loadFile(i)
|
||||
|
||||
test "rlp roundtrip EIP1559":
|
||||
test "rlp roundtrip EIP1559 / EIP4895 / EIP4844":
|
||||
proc doTest(h: BlockHeader) =
|
||||
let xy = rlp.encode(h)
|
||||
let hh = rlp.decode(xy, BlockHeader)
|
||||
check h == hh
|
||||
|
||||
var h: BlockHeader
|
||||
let xy = rlp.encode(h)
|
||||
let hh = rlp.decode(xy, BlockHeader)
|
||||
check h == hh
|
||||
doTest h
|
||||
|
||||
# EIP-1559
|
||||
h.fee = some 1234.u256
|
||||
doTest h
|
||||
|
||||
# EIP-4895
|
||||
h.withdrawalsRoot = some Hash256.fromHex(
|
||||
"0x7a64245f7f95164f6176d90bd4903dbdd3e5433d555dd1385e81787f9672c588")
|
||||
doTest h
|
||||
|
||||
# EIP-4844
|
||||
h.excessDataGas = some GasInt(1337)
|
||||
doTest h
|
||||
|
||||
suite1()
|
||||
suite2()
|
||||
|
|
Loading…
Reference in New Issue