Rewire blockValue from Txpool to EngineAPI (#2554)

This commit is contained in:
andri lim 2024-08-09 06:05:18 +07:00 committed by GitHub
parent 3dc30195ad
commit b8e128203f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 23 additions and 14 deletions

View File

@ -224,7 +224,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
raise invalidAttr(error)
let id = computePayloadId(blockHash, attrs)
ben.put(id, ben.blockValue, bundle.executionPayload, bundle.blobsBundle)
ben.put(id, bundle.blockValue, bundle.executionPayload, bundle.blobsBundle)
info "Created payload for sealing",
id = id.toHex,

View File

@ -165,11 +165,6 @@ func posFinalized*(ben: BeaconEngineRef): bool =
## PoSFinalized reports whether the chain has entered the PoS stage.
ben.merge.posFinalized
func blockValue*(ben: BeaconEngineRef): UInt256 =
## return sum of reward for feeRecipient for each
## tx included in a block
ben.txPool.blockValue
proc get*(ben: BeaconEngineRef, hash: common.Hash256,
header: var common.BlockHeader): bool =
ben.queue.get(hash, header)
@ -208,6 +203,7 @@ proc get*(ben: BeaconEngineRef, id: PayloadID,
type ExecutionPayloadAndBlobsBundle* = object
executionPayload*: ExecutionPayload
blobsBundle*: Opt[BlobsBundleV1]
blockValue*: UInt256
proc generatePayload*(ben: BeaconEngineRef,
attrs: PayloadAttributes):
@ -253,7 +249,8 @@ proc generatePayload*(ben: BeaconEngineRef,
ok ExecutionPayloadAndBlobsBundle(
executionPayload: executionPayload(bundle.blk),
blobsBundle: blobsBundle)
blobsBundle: blobsBundle,
blockValue: bundle.blockValue)
proc setInvalidAncestor*(ben: BeaconEngineRef, header: common.BlockHeader, blockHash: common.Hash256) =
ben.invalidBlocksHits[blockHash] = 1

View File

@ -472,6 +472,7 @@ func com*(xp: TxPoolRef): CommonRef =
type EthBlockAndBlobsBundle* = object
blk*: EthBlock
blobsBundle*: Opt[BlobsBundle]
blockValue*: UInt256
proc assembleBlock*(
xp: TxPoolRef,
@ -529,7 +530,8 @@ proc assembleBlock*(
ok EthBlockAndBlobsBundle(
blk: blk,
blobsBundle: blobsBundleOpt)
blobsBundle: blobsBundleOpt,
blockValue: pst.blockValue)
# core/tx_pool.go(474): func (pool SetGasPrice,*TxPool) Stats() (int, int) {
# core/tx_pool.go(1728): func (t *txLookup) Count() int {

View File

@ -56,7 +56,6 @@ type
lifeTime*: times.Duration ## Maximum life time of a tx in the system
priceBump*: uint ## Min precentage price when superseding
blockValue*: UInt256 ## Sum of reward received by feeRecipient
const
txItemLifeTime = ##\

View File

@ -181,9 +181,6 @@ proc vmExecInit(xp: TxPoolRef): Result[TxPacker, string]
# Flush `packed` bucket
xp.bucketFlushPacked
# reset blockValue before adding any tx
xp.blockValue = 0.u256
let packer = TxPacker(
vmState: xp.vmState,
txDB: xp.txDB,
@ -341,6 +338,9 @@ proc assembleHeader*(pst: TxPacker): BlockHeader =
result.blobGasUsed = Opt.some vmState.blobGasUsed
result.excessBlobGas = Opt.some vmState.blockCtx.excessBlobGas
func blockValue*(pst: TxPacker): UInt256 =
pst.blockValue
# ------------------------------------------------------------------------------
# End
# ------------------------------------------------------------------------------

View File

@ -16,9 +16,11 @@ import
../nimbus/core/chain,
../nimbus/[config, transaction, constants],
../nimbus/core/tx_pool,
../nimbus/core/tx_pool/tx_desc,
../nimbus/core/casper,
../nimbus/common/common,
../nimbus/utils/utils,
../nimbus/evm/types,
./test_txpool/helpers,
./macro_assembler
@ -38,7 +40,7 @@ type
xp : TxPoolRef
const
signerKeyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"
# signerKeyHex = "9c647b8b7c4e7c3490668fb6c11473619db80c93704c70893d3813af4090c39c"
vaultKeyHex = "63b508a03c3b5937ceb903af8b1b0c191012ef6eb7e9c3fb7afa94e5d214d376"
recipient = hexToByteArray[20]("0000000000000000000000000000000000000318")
feeRecipient = hexToByteArray[20]("0000000000000000000000000000000000000212")
@ -210,7 +212,8 @@ proc runTxPoolBlobhashTest() =
check false
return
blk = r.get.blk
let bundle = r.get
blk = bundle.blk
check com.isBlockAfterTtd(blk.header)
body = BlockBody(
@ -220,6 +223,14 @@ proc runTxPoolBlobhashTest() =
)
check blk.txs.len == 2
let
gasUsed1 = xp.vmState.receipts[0].cumulativeGasUsed
gasUsed2 = xp.vmState.receipts[1].cumulativeGasUsed - gasUsed1
blockValue = gasUsed1.u256 * tx1.effectiveGasTip(blk.header.baseFeePerGas).u256 +
gasUsed2.u256 * tx2.effectiveGasTip(blk.header.baseFeePerGas).u256
check blockValue == bundle.blockValue
test "Blobhash persistBlocks":
let rr = chain.persistBlocks([EthBlock.init(blk.header, body)])
check rr.isOk()