EIP-4895: add withdrawal processing in txpool
This commit is contained in:
parent
a19168dcef
commit
0c1236756d
|
@ -9,7 +9,7 @@
|
||||||
# according to those terms.
|
# according to those terms.
|
||||||
|
|
||||||
import
|
import
|
||||||
math,
|
../../utils/utils,
|
||||||
../../common/common,
|
../../common/common,
|
||||||
../../constants,
|
../../constants,
|
||||||
../../db/accounts_cache,
|
../../db/accounts_cache,
|
||||||
|
@ -28,13 +28,6 @@ import
|
||||||
|
|
||||||
{.push raises: [].}
|
{.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
|
# Factored this out of procBlkPreamble so that it can be used directly for
|
||||||
# stateless execution of specific transactions.
|
# stateless execution of specific transactions.
|
||||||
proc processTransactions*(vmState: BaseVMState;
|
proc processTransactions*(vmState: BaseVMState;
|
||||||
|
|
|
@ -311,7 +311,7 @@ proc vmState*(dh: TxChainRef): BaseVMState =
|
||||||
|
|
||||||
proc withdrawals*(dh: TxChainRef): seq[Withdrawal] =
|
proc withdrawals*(dh: TxChainRef): seq[Withdrawal] =
|
||||||
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
## Getter, `BaseVmState` descriptor based on the current insertion point.
|
||||||
result = system.move(dh.withdrawals)
|
dh.withdrawals
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# Public functions, setters
|
# Public functions, setters
|
||||||
|
|
|
@ -20,6 +20,7 @@ import
|
||||||
stew/sorted_set,
|
stew/sorted_set,
|
||||||
../../../db/[accounts_cache, core_db],
|
../../../db/[accounts_cache, core_db],
|
||||||
../../../common/common,
|
../../../common/common,
|
||||||
|
../../../utils/utils,
|
||||||
"../.."/[dao, executor, validate, eip4844],
|
"../.."/[dao, executor, validate, eip4844],
|
||||||
../../../transaction/call_evm,
|
../../../transaction/call_evm,
|
||||||
../../../transaction,
|
../../../transaction,
|
||||||
|
@ -92,7 +93,6 @@ proc runTx(pst: TxPackerStateRef; item: TxItemRef): GasInt
|
||||||
pst.cleanState = false
|
pst.cleanState = false
|
||||||
doAssert 0 <= result
|
doAssert 0 <= result
|
||||||
|
|
||||||
|
|
||||||
proc runTxCommit(pst: TxPackerStateRef; item: TxItemRef; gasBurned: GasInt)
|
proc runTxCommit(pst: TxPackerStateRef; item: TxItemRef; gasBurned: GasInt)
|
||||||
{.gcsafe,raises: [CatchableError].} =
|
{.gcsafe,raises: [CatchableError].} =
|
||||||
## Book keeping after executing argument `item` transaction in the VM. The
|
## Book keeping after executing argument `item` transaction in the VM. The
|
||||||
|
@ -219,6 +219,11 @@ proc vmExecCommit(pst: TxPackerStateRef)
|
||||||
xp = pst.xp
|
xp = pst.xp
|
||||||
vmState = xp.chain.vmState
|
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
|
# EIP-3675: no reward for miner in POA/POS
|
||||||
if vmState.com.consensus == ConsensusType.POW:
|
if vmState.com.consensus == ConsensusType.POW:
|
||||||
let
|
let
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import
|
import
|
||||||
|
std/math,
|
||||||
eth/[rlp, common/eth_types_rlp],
|
eth/[rlp, common/eth_types_rlp],
|
||||||
stew/byteutils,
|
stew/byteutils,
|
||||||
../db/core_db
|
../db/core_db
|
||||||
|
@ -65,8 +66,8 @@ proc short*(h: Hash256): string =
|
||||||
bytes[^3..^1] = h.data[^3..^1]
|
bytes[^3..^1] = h.data[^3..^1]
|
||||||
bytes.toHex
|
bytes.toHex
|
||||||
|
|
||||||
proc decompose*(rlp: var Rlp,
|
proc decompose*(rlp: var Rlp,
|
||||||
header: var BlockHeader,
|
header: var BlockHeader,
|
||||||
body: var BlockBody) {.gcsafe, raises: [RlpError].} =
|
body: var BlockBody) {.gcsafe, raises: [RlpError].} =
|
||||||
var blk = rlp.read(EthBlock)
|
var blk = rlp.read(EthBlock)
|
||||||
header = system.move(blk.header)
|
header = system.move(blk.header)
|
||||||
|
@ -74,8 +75,11 @@ proc decompose*(rlp: var Rlp,
|
||||||
body.uncles = system.move(blk.uncles)
|
body.uncles = system.move(blk.uncles)
|
||||||
body.withdrawals = system.move(blk.withdrawals)
|
body.withdrawals = system.move(blk.withdrawals)
|
||||||
|
|
||||||
proc decompose*(rlpBytes: openArray[byte],
|
proc decompose*(rlpBytes: openArray[byte],
|
||||||
header: var BlockHeader,
|
header: var BlockHeader,
|
||||||
body: var BlockBody) {.gcsafe, raises: [RlpError].} =
|
body: var BlockBody) {.gcsafe, raises: [RlpError].} =
|
||||||
var rlp = rlpFromBytes(rlpBytes)
|
var rlp = rlpFromBytes(rlpBytes)
|
||||||
rlp.decompose(header, body)
|
rlp.decompose(header, body)
|
||||||
|
|
||||||
|
func gwei*(n: uint64): UInt256 =
|
||||||
|
n.u256 * (10 ^ 9).u256
|
||||||
|
|
Loading…
Reference in New Issue