mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-02-02 23:35:31 +00:00
fix withdrawals problem in tx-pool
This commit is contained in:
parent
27393e9420
commit
9868eceed1
@ -11,9 +11,9 @@ import
|
|||||||
|
|
||||||
type
|
type
|
||||||
CasperRef* = ref object
|
CasperRef* = ref object
|
||||||
feeRecipient* : EthAddress
|
feeRecipient : EthAddress
|
||||||
timestamp* : EthTime
|
timestamp : EthTime
|
||||||
prevRandao* : Hash256
|
prevRandao : Hash256
|
||||||
|
|
||||||
proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
||||||
header.coinbase = ctx.feeRecipient
|
header.coinbase = ctx.feeRecipient
|
||||||
@ -21,7 +21,7 @@ proc prepare*(ctx: CasperRef, header: var BlockHeader) =
|
|||||||
header.prevRandao = ctx.prevRandao
|
header.prevRandao = ctx.prevRandao
|
||||||
header.difficulty = DifficultyInt.zero
|
header.difficulty = DifficultyInt.zero
|
||||||
|
|
||||||
proc prepareForSeal*(ctx: CasperRef, header: var BlockHeader) =
|
proc prepareForSeal*(ctx: CasperRef, header: var BlockHeader) {.gcsafe, raises:[RlpError].} =
|
||||||
header.nonce = default(BlockNonce)
|
header.nonce = default(BlockNonce)
|
||||||
header.extraData = @[] # TODO: probably this should be configurable by user?
|
header.extraData = @[] # TODO: probably this should be configurable by user?
|
||||||
# this repetition, assigning prevRandao is because how txpool works
|
# this repetition, assigning prevRandao is because how txpool works
|
||||||
|
@ -33,6 +33,10 @@ import
|
|||||||
from web3/ethtypes as web3types import nil, TypedTransaction, WithdrawalV1, ExecutionPayloadV1OrV2, toExecutionPayloadV1OrV2, toExecutionPayloadV1
|
from web3/ethtypes as web3types import nil, TypedTransaction, WithdrawalV1, ExecutionPayloadV1OrV2, toExecutionPayloadV1OrV2, toExecutionPayloadV1
|
||||||
from web3/engine_api_types import PayloadAttributesV1, ExecutionPayloadV1, PayloadAttributesV2, ExecutionPayloadV2
|
from web3/engine_api_types import PayloadAttributesV1, ExecutionPayloadV1, PayloadAttributesV2, ExecutionPayloadV2
|
||||||
|
|
||||||
|
export
|
||||||
|
# generateExecutionPayload caller will need this
|
||||||
|
casper
|
||||||
|
|
||||||
type
|
type
|
||||||
EngineState* = enum
|
EngineState* = enum
|
||||||
EngineStopped,
|
EngineStopped,
|
||||||
@ -142,6 +146,17 @@ template unsafeQuantityToInt64(q: web3types.Quantity): int64 =
|
|||||||
proc toTypedTransaction(tx: Transaction): TypedTransaction =
|
proc toTypedTransaction(tx: Transaction): TypedTransaction =
|
||||||
web3types.TypedTransaction(rlp.encode(tx))
|
web3types.TypedTransaction(rlp.encode(tx))
|
||||||
|
|
||||||
|
func toWithdrawal(x: WithdrawalV1): Withdrawal =
|
||||||
|
result.index = x.index.uint64
|
||||||
|
result.validatorIndex = x.validatorIndex.uint64
|
||||||
|
result.address = x.address.EthAddress
|
||||||
|
result.amount = x.amount.uint64
|
||||||
|
|
||||||
|
func toWithdrawals(list: openArray[WithdrawalV1]): seq[Withdrawal] =
|
||||||
|
result = newSeqOfCap[Withdrawal](list.len)
|
||||||
|
for x in list:
|
||||||
|
result.add toWithdrawal(x)
|
||||||
|
|
||||||
proc generateExecutionPayload*(engine: SealingEngineRef,
|
proc generateExecutionPayload*(engine: SealingEngineRef,
|
||||||
payloadAttrs: PayloadAttributesV1 | PayloadAttributesV2): Result[ExecutionPayloadV1OrV2, string] =
|
payloadAttrs: PayloadAttributesV1 | PayloadAttributesV2): Result[ExecutionPayloadV1OrV2, string] =
|
||||||
let
|
let
|
||||||
@ -153,6 +168,11 @@ proc generateExecutionPayload*(engine: SealingEngineRef,
|
|||||||
pos.timestamp = fromUnix(payloadAttrs.timestamp.unsafeQuantityToInt64)
|
pos.timestamp = fromUnix(payloadAttrs.timestamp.unsafeQuantityToInt64)
|
||||||
pos.feeRecipient = EthAddress payloadAttrs.suggestedFeeRecipient
|
pos.feeRecipient = EthAddress payloadAttrs.suggestedFeeRecipient
|
||||||
|
|
||||||
|
when payloadAttrs is PayloadAttributesV2:
|
||||||
|
engine.txPool.withdrawals = payloadAttrs.withdrawals.toWithdrawals
|
||||||
|
else:
|
||||||
|
engine.txPool.withdrawals = @[]
|
||||||
|
|
||||||
if headBlock.blockHash != engine.txPool.head.blockHash:
|
if headBlock.blockHash != engine.txPool.head.blockHash:
|
||||||
# reorg
|
# reorg
|
||||||
discard engine.txPool.smartHead(headBlock)
|
discard engine.txPool.smartHead(headBlock)
|
||||||
|
@ -436,7 +436,8 @@ import
|
|||||||
chronicles,
|
chronicles,
|
||||||
eth/keys,
|
eth/keys,
|
||||||
stew/[keyed_queue, results],
|
stew/[keyed_queue, results],
|
||||||
../common/common
|
../common/common,
|
||||||
|
./casper
|
||||||
|
|
||||||
export
|
export
|
||||||
TxItemRef,
|
TxItemRef,
|
||||||
@ -621,6 +622,10 @@ proc ethBlock*(xp: TxPoolRef): EthBlock
|
|||||||
for (_,nonceList) in xp.txDB.packingOrderAccounts(txItemPacked):
|
for (_,nonceList) in xp.txDB.packingOrderAccounts(txItemPacked):
|
||||||
result.txs.add toSeq(nonceList.incNonce).mapIt(it.tx)
|
result.txs.add toSeq(nonceList.incNonce).mapIt(it.tx)
|
||||||
|
|
||||||
|
let com = xp.chain.com
|
||||||
|
if com.consensus == ConsensusType.POS:
|
||||||
|
result.withdrawals = some(xp.chain.withdrawals)
|
||||||
|
|
||||||
proc gasCumulative*(xp: TxPoolRef): GasInt =
|
proc gasCumulative*(xp: TxPoolRef): GasInt =
|
||||||
## Getter, retrieves the gas that will be burned in the block after
|
## Getter, retrieves the gas that will be burned in the block after
|
||||||
## retrieving it via `ethBlock`.
|
## retrieving it via `ethBlock`.
|
||||||
@ -766,6 +771,9 @@ proc `minTipPrice=`*(xp: TxPoolRef; val: GasPrice) =
|
|||||||
xp.pMinTipPrice = val
|
xp.pMinTipPrice = val
|
||||||
xp.pDirtyBuckets = true
|
xp.pDirtyBuckets = true
|
||||||
|
|
||||||
|
proc `withdrawals=`*(xp: TxPoolRef, val: sink seq[Withdrawal]) =
|
||||||
|
xp.chain.withdrawals = system.move(val)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, per-tx-item operations
|
# Public functions, per-tx-item operations
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
@ -66,6 +66,7 @@ type
|
|||||||
limits: TxChainGasLimits ## Gas limits for packer and next header
|
limits: TxChainGasLimits ## Gas limits for packer and next header
|
||||||
txEnv: TxChainPackerEnv ## Assorted parameters, tx packer environment
|
txEnv: TxChainPackerEnv ## Assorted parameters, tx packer environment
|
||||||
prepHeader: BlockHeader ## Prepared Header from Consensus Engine
|
prepHeader: BlockHeader ## Prepared Header from Consensus Engine
|
||||||
|
withdrawals: seq[Withdrawal]
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Private functions
|
# Private functions
|
||||||
@ -90,7 +91,7 @@ proc prepareHeader(dh: TxChainRef; parent: BlockHeader)
|
|||||||
of ConsensusType.POS:
|
of ConsensusType.POS:
|
||||||
dh.com.pos.prepare(dh.prepHeader)
|
dh.com.pos.prepare(dh.prepHeader)
|
||||||
|
|
||||||
proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [].} =
|
proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [RlpError].} =
|
||||||
case dh.com.consensus
|
case dh.com.consensus
|
||||||
of ConsensusType.POW:
|
of ConsensusType.POW:
|
||||||
# do nothing, tx pool was designed with POW in mind
|
# do nothing, tx pool was designed with POW in mind
|
||||||
@ -201,6 +202,9 @@ proc getHeader*(dh: TxChainRef): BlockHeader
|
|||||||
# nonce: BlockNonce # mining free vaiable
|
# nonce: BlockNonce # mining free vaiable
|
||||||
fee: dh.txEnv.vmState.fee)
|
fee: dh.txEnv.vmState.fee)
|
||||||
|
|
||||||
|
if dh.com.forkGTE(Shanghai):
|
||||||
|
result.withdrawalsRoot = some(calcWithdrawalsRoot(dh.withdrawals))
|
||||||
|
|
||||||
dh.prepareForSeal(result)
|
dh.prepareForSeal(result)
|
||||||
|
|
||||||
proc clearAccounts*(dh: TxChainRef)
|
proc clearAccounts*(dh: TxChainRef)
|
||||||
@ -280,6 +284,10 @@ proc vmState*(dh: TxChainRef): BaseVMState =
|
|||||||
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
||||||
dh.txEnv.vmState
|
dh.txEnv.vmState
|
||||||
|
|
||||||
|
proc withdrawals*(dh: TxChainRef): seq[Withdrawal] =
|
||||||
|
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
||||||
|
result = system.move(dh.withdrawals)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, setters
|
# Public functions, setters
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -342,6 +350,9 @@ proc `txRoot=`*(dh: TxChainRef; val: Hash256) =
|
|||||||
## Setter
|
## Setter
|
||||||
dh.txEnv.txRoot = val
|
dh.txEnv.txRoot = val
|
||||||
|
|
||||||
|
proc `withdrawals=`*(dh: TxChainRef, val: sink seq[Withdrawal]) =
|
||||||
|
dh.withdrawals = system.move(val)
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
|||||||
Subproject commit d57a1094b1c0d6faa6b3b70ae653948299266fa3
|
Subproject commit e639dc1e145722ec137639ee040eddc524f853dd
|
Loading…
x
Reference in New Issue
Block a user