This commit is contained in:
tersec 2023-06-03 18:47:55 +00:00 committed by GitHub
parent 55b9da0bea
commit c608426d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 9 deletions

View File

@ -99,6 +99,7 @@ type
address* : EthAddress address* : EthAddress
amount* : uint64 amount* : uint64
# https://eips.ethereum.org/EIPS/eip-4844#header-extension
BlockHeader* = object BlockHeader* = object
parentHash*: Hash256 parentHash*: Hash256
ommersHash*: Hash256 ommersHash*: Hash256
@ -118,7 +119,8 @@ type
# `baseFee` is the get/set of `fee` # `baseFee` is the get/set of `fee`
fee*: Option[UInt256] # EIP-1559 fee*: Option[UInt256] # EIP-1559
withdrawalsRoot*: Option[Hash256] # EIP-4895 withdrawalsRoot*: Option[Hash256] # EIP-4895
excessDataGas*: Option[UInt256] # EIP-4844 dataGasUsed*: Option[uint64] # EIP-4844
excessDataGas*: Option[uint64] # EIP-4844
BlockBody* = object BlockBody* = object
transactions*: seq[Transaction] transactions*: seq[Transaction]

View File

@ -87,7 +87,7 @@ proc recoverMsgPublicKey(msg: openArray[byte]): DiscResult[PublicKey] =
proc unpack(msg: openArray[byte]): tuple[cmdId: CommandId, payload: seq[byte]] proc unpack(msg: openArray[byte]): tuple[cmdId: CommandId, payload: seq[byte]]
{.raises: [DiscProtocolError].} = {.raises: [DiscProtocolError].} =
# Check against possible RangeError # Check against possible RangeDefect
if msg[HEAD_SIZE].int < CommandId.low.ord or if msg[HEAD_SIZE].int < CommandId.low.ord or
msg[HEAD_SIZE].int > CommandId.high.ord: msg[HEAD_SIZE].int > CommandId.high.ord:
raise newException(DiscProtocolError, "Unsupported packet id") raise newException(DiscProtocolError, "Unsupported packet id")

View File

@ -11,7 +11,7 @@ proc initNibbleRange*(bytes: openArray[byte]): NibblesSeq =
proc `{}`(r: NibblesSeq, pos: int): byte {.inline.} = proc `{}`(r: NibblesSeq, pos: int): byte {.inline.} =
## This is a helper for a more raw access to the nibbles. ## This is a helper for a more raw access to the nibbles.
## It works with absolute positions. ## It works with absolute positions.
if pos > r.iend: raise newException(RangeError, "index out of range") if pos > r.iend: raise newException(RangeDefect, "index out of range")
return if (pos and 1) != 0: (r.bytes[pos div 2] and 0xf) return if (pos and 1) != 0: (r.bytes[pos div 2] and 0xf)
else: (r.bytes[pos div 2] shr 4) else: (r.bytes[pos div 2] shr 4)

View File

@ -116,7 +116,8 @@ proc suite2() =
doTest h doTest h
# EIP-4844 # EIP-4844
h.excessDataGas = some 1234.u256 h.dataGasUsed = some 1234'u64
h.excessDataGas = some 1234'u64
doTest h doTest h
suite1() suite1()

View File

@ -64,14 +64,16 @@ suite "BlockHeader roundtrip test":
test "Header + none(baseFee) + some(withdrawalsRoot) + some(excessDataGas)": test "Header + none(baseFee) + some(withdrawalsRoot) + some(excessDataGas)":
let h = BlockHeader( let h = BlockHeader(
withdrawalsRoot: some(Hash256()), withdrawalsRoot: some(Hash256()),
excessDataGas: some(1.u256) dataGasUsed: some(1'u64),
excessDataGas: some(1'u64)
) )
expect AssertionDefect: expect AssertionDefect:
roundTrip(h) roundTrip(h)
test "Header + none(baseFee) + none(withdrawalsRoot) + some(excessDataGas)": test "Header + none(baseFee) + none(withdrawalsRoot) + some(excessDataGas)":
let h = BlockHeader( let h = BlockHeader(
excessDataGas: some(1.u256) dataGasUsed: some(1'u64),
excessDataGas: some(1'u64)
) )
expect AssertionDefect: expect AssertionDefect:
roundTrip(h) roundTrip(h)
@ -79,7 +81,8 @@ suite "BlockHeader roundtrip test":
test "Header + some(baseFee) + none(withdrawalsRoot) + some(excessDataGas)": test "Header + some(baseFee) + none(withdrawalsRoot) + some(excessDataGas)":
let h = BlockHeader( let h = BlockHeader(
fee: some(2.u256), fee: some(2.u256),
excessDataGas: some(1.u256) dataGasUsed: some(1'u64),
excessDataGas: some(1'u64)
) )
expect AssertionDefect: expect AssertionDefect:
roundTrip(h) roundTrip(h)
@ -95,7 +98,8 @@ suite "BlockHeader roundtrip test":
let h = BlockHeader( let h = BlockHeader(
fee: some(2.u256), fee: some(2.u256),
withdrawalsRoot: some(Hash256()), withdrawalsRoot: some(Hash256()),
excessDataGas: some(1.u256) dataGasUsed: some(1'u64),
excessDataGas: some(1'u64)
) )
roundTrip(h) roundTrip(h)
@ -173,7 +177,8 @@ type
nonce*: BlockNonce nonce*: BlockNonce
fee*: Opt[UInt256] fee*: Opt[UInt256]
withdrawalsRoot*: Opt[Hash256] withdrawalsRoot*: Opt[Hash256]
excessDataGas*: Opt[UInt256] dataGasUsed*: Opt[GasInt]
excessDataGas*: Opt[GasInt]
BlockBodyOpt* = object BlockBodyOpt* = object
transactions*: seq[Transaction] transactions*: seq[Transaction]