EIP-4895: add withdrawal processing in txpool

This commit is contained in:
jangko 2023-08-16 20:05:43 +07:00
parent a19168dcef
commit 0c1236756d
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
4 changed files with 16 additions and 14 deletions

View File

@ -9,7 +9,7 @@
# according to those terms.
import
math,
../../utils/utils,
../../common/common,
../../constants,
../../db/accounts_cache,
@ -28,13 +28,6 @@ import
{.push raises: [].}
# ------------------------------------------------------------------------------
# Private functions
# ------------------------------------------------------------------------------
func gwei(n: uint64): UInt256 =
n.u256 * (10 ^ 9).u256
# Factored this out of procBlkPreamble so that it can be used directly for
# stateless execution of specific transactions.
proc processTransactions*(vmState: BaseVMState;

View File

@ -311,7 +311,7 @@ proc vmState*(dh: TxChainRef): BaseVMState =
proc withdrawals*(dh: TxChainRef): seq[Withdrawal] =
## Getter, `BaseVmState` descriptor based on the current insertion point.
result = system.move(dh.withdrawals)
dh.withdrawals
# ------------------------------------------------------------------------------
# Public functions, setters

View File

@ -20,6 +20,7 @@ import
stew/sorted_set,
../../../db/[accounts_cache, core_db],
../../../common/common,
../../../utils/utils,
"../.."/[dao, executor, validate, eip4844],
../../../transaction/call_evm,
../../../transaction,
@ -92,7 +93,6 @@ proc runTx(pst: TxPackerStateRef; item: TxItemRef): GasInt
pst.cleanState = false
doAssert 0 <= result
proc runTxCommit(pst: TxPackerStateRef; item: TxItemRef; gasBurned: GasInt)
{.gcsafe,raises: [CatchableError].} =
## Book keeping after executing argument `item` transaction in the VM. The
@ -219,6 +219,11 @@ proc vmExecCommit(pst: TxPackerStateRef)
xp = pst.xp
vmState = xp.chain.vmState
# EIP-4895
if xp.chain.nextFork >= FkShanghai:
for withdrawal in xp.chain.withdrawals:
vmState.stateDB.addBalance(withdrawal.address, withdrawal.amount.gwei)
# EIP-3675: no reward for miner in POA/POS
if vmState.com.consensus == ConsensusType.POW:
let

View File

@ -1,4 +1,5 @@
import
std/math,
eth/[rlp, common/eth_types_rlp],
stew/byteutils,
../db/core_db
@ -79,3 +80,6 @@ proc decompose*(rlpBytes: openArray[byte],
body: var BlockBody) {.gcsafe, raises: [RlpError].} =
var rlp = rlpFromBytes(rlpBytes)
rlp.decompose(header, body)
func gwei*(n: uint64): UInt256 =
n.u256 * (10 ^ 9).u256