Prepare Portal bridge for Capella by adding withdrawalsRoot (#1543)
This commit is contained in:
parent
c58d83efd5
commit
9fde5c96e8
|
@ -204,10 +204,35 @@ proc asPortalBlockData*(
|
||||||
|
|
||||||
return tr.rootHash()
|
return tr.rootHash()
|
||||||
|
|
||||||
|
# TODO: Since Capella we can also access ExecutionPayloadHeader and thus
|
||||||
|
# could get the Roots through there instead.
|
||||||
|
proc calculateWithdrawalsRoot(
|
||||||
|
items: openArray[WithdrawalV1]):
|
||||||
|
Hash256 {.raises: [].} =
|
||||||
|
|
||||||
|
var tr = initHexaryTrie(newMemoryDB())
|
||||||
|
for i, w in items:
|
||||||
|
try:
|
||||||
|
let withdrawal = Withdrawal(
|
||||||
|
index: distinctBase(w.index),
|
||||||
|
validatorIndex: distinctBase(w.validatorIndex),
|
||||||
|
address: distinctBase(w.address),
|
||||||
|
amount: distinctBase(w.amount)
|
||||||
|
)
|
||||||
|
tr.put(rlp.encode(i), rlp.encode(withdrawal))
|
||||||
|
except RlpError as e:
|
||||||
|
raiseAssert(e.msg)
|
||||||
|
|
||||||
|
return tr.rootHash()
|
||||||
|
|
||||||
let
|
let
|
||||||
txRoot = calculateTransactionData(payload.transactions)
|
txRoot = calculateTransactionData(payload.transactions)
|
||||||
|
withdrawalsRoot =
|
||||||
|
when type(payload) is ExecutionPayloadV1:
|
||||||
|
options.none(Hash256)
|
||||||
|
else:
|
||||||
|
some(calculateWithdrawalsRoot(payload.withdrawals))
|
||||||
|
|
||||||
# TODO: update according to payload type
|
|
||||||
header = etypes.BlockHeader(
|
header = etypes.BlockHeader(
|
||||||
parentHash: payload.parentHash.asEthHash,
|
parentHash: payload.parentHash.asEthHash,
|
||||||
ommersHash: EMPTY_UNCLE_HASH,
|
ommersHash: EMPTY_UNCLE_HASH,
|
||||||
|
@ -225,8 +250,8 @@ proc asPortalBlockData*(
|
||||||
mixDigest: payload.prevRandao.asEthHash,
|
mixDigest: payload.prevRandao.asEthHash,
|
||||||
nonce: default(BlockNonce),
|
nonce: default(BlockNonce),
|
||||||
fee: some(payload.baseFeePerGas),
|
fee: some(payload.baseFeePerGas),
|
||||||
withdrawalsRoot: options.none(Hash256), # TODO: Update later
|
withdrawalsRoot: withdrawalsRoot,
|
||||||
excessDataGas: options.none(UInt256) # TODO: Update later
|
excessDataGas: options.none(UInt256) # TODO: Update later according to fork
|
||||||
)
|
)
|
||||||
|
|
||||||
headerWithProof = BlockHeaderWithProof(
|
headerWithProof = BlockHeaderWithProof(
|
||||||
|
@ -237,6 +262,8 @@ proc asPortalBlockData*(
|
||||||
for tx in payload.transactions:
|
for tx in payload.transactions:
|
||||||
discard transactions.add(TransactionByteList(distinctBase(tx)))
|
discard transactions.add(TransactionByteList(distinctBase(tx)))
|
||||||
|
|
||||||
|
# TODO: Specifications are not ready for Shanghai/Capella on how to add the
|
||||||
|
# withdrawals here.
|
||||||
let body = BlockBodySSZ(
|
let body = BlockBodySSZ(
|
||||||
transactions: transactions,
|
transactions: transactions,
|
||||||
uncles: Uncles(@[byte 0xc0]))
|
uncles: Uncles(@[byte 0xc0]))
|
||||||
|
|
Loading…
Reference in New Issue