Fix engine api: getPayload V2 and V3 now returns correct blockValue
This commit is contained in:
parent
467e6fffa6
commit
4fd53156f5
|
@ -232,6 +232,11 @@ proc generateExecutionPayload*(engine: SealingEngineRef,
|
|||
excessBlobGas: excessBlobGas
|
||||
))
|
||||
|
||||
proc blockValue*(engine: SealingEngineRef): UInt256 =
|
||||
# return sum of reward for feeRecipient for each
|
||||
# tx included in a block
|
||||
engine.txPool.blockValue
|
||||
|
||||
proc new*(_: type SealingEngineRef,
|
||||
chain: ChainRef,
|
||||
ctx: EthContext,
|
||||
|
|
|
@ -97,6 +97,7 @@ 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
|
||||
|
||||
param: TxPoolParam ## Getter/Setter parameters
|
||||
|
||||
|
|
|
@ -108,6 +108,7 @@ proc runTxCommit(pst: TxPackerStateRef; item: TxItemRef; gasBurned: GasInt)
|
|||
assert 0 <= gasTip
|
||||
let reward = gasBurned.u256 * gasTip.uint64.u256
|
||||
vmState.stateDB.addBalance(xp.chain.feeRecipient, reward)
|
||||
xp.blockValue += reward
|
||||
|
||||
if vmState.generateWitness:
|
||||
vmState.stateDB.collectWitnessData()
|
||||
|
@ -153,6 +154,9 @@ proc vmExecInit(xp: TxPoolRef): TxPackerStateRef
|
|||
# Flush `packed` bucket
|
||||
xp.bucketFlushPacked
|
||||
|
||||
# reset blockValue before adding any tx
|
||||
xp.blockValue = 0.u256
|
||||
|
||||
xp.chain.maxMode = (packItemsMaxGasLimit in xp.pFlags)
|
||||
|
||||
if xp.chain.com.daoForkSupport and
|
||||
|
|
|
@ -58,17 +58,6 @@ proc invalidFCU(com: CommonRef, header: EthBlockHeader): ForkchoiceUpdatedRespon
|
|||
let blockHash = latestValidHash(com.db, parent, com.ttd.get(high(common.BlockNumber)))
|
||||
invalidFCU(blockHash)
|
||||
|
||||
proc txPriorityFee(ttx: TypedTransaction): UInt256 =
|
||||
try:
|
||||
let tx = rlp.decode(distinctBase(ttx), Transaction)
|
||||
return u256(tx.gasPrice * tx.maxPriorityFee)
|
||||
except RlpError:
|
||||
doAssert(false, "found TypedTransaction that RLP failed to decode")
|
||||
|
||||
# AARDVARK: make sure I have the right units (wei/gwei)
|
||||
proc sumOfBlockPriorityFees(payload: ExecutionPayloadV1OrV2): UInt256 =
|
||||
payload.transactions.foldl(a + txPriorityFee(b), UInt256.zero)
|
||||
|
||||
template unsafeQuantityToInt64(q: Quantity): int64 =
|
||||
int64 q
|
||||
|
||||
|
@ -201,11 +190,10 @@ proc handle_getPayload(api: EngineApiRef, payloadId: PayloadID): GetPayloadV2Res
|
|||
meth = "GetPayload", id = payloadId.toHex
|
||||
|
||||
var payload: ExecutionPayloadV1OrV2
|
||||
if not api.get(payloadId, payload):
|
||||
var blockValue: UInt256
|
||||
if not api.get(payloadId, blockValue, payload):
|
||||
raise unknownPayload("Unknown payload")
|
||||
|
||||
let blockValue = sumOfBlockPriorityFees(payload)
|
||||
|
||||
return GetPayloadV2Response(
|
||||
executionPayload: payload,
|
||||
blockValue: blockValue
|
||||
|
@ -216,20 +204,19 @@ proc handle_getPayloadV3(api: EngineApiRef, com: CommonRef, payloadId: PayloadID
|
|||
meth = "GetPayload", id = payloadId.toHex
|
||||
|
||||
var payload: ExecutionPayloadV3
|
||||
if not api.get(payloadId, payload):
|
||||
var blockValue: UInt256
|
||||
if not api.get(payloadId, blockValue, payload):
|
||||
raise unknownPayload("Unknown payload")
|
||||
|
||||
if not com.isCancunOrLater(fromUnix(payload.timestamp.unsafeQuantityToInt64)):
|
||||
raise unsupportedFork("payload timestamp is less than Cancun activation")
|
||||
|
||||
var
|
||||
blockValue: UInt256
|
||||
blobsBundle: BlobsBundleV1
|
||||
|
||||
try:
|
||||
for ttx in payload.transactions:
|
||||
let tx = rlp.decode(distinctBase(ttx), Transaction)
|
||||
blockValue += u256(tx.gasPrice * tx.maxPriorityFee)
|
||||
if tx.networkPayload.isNil.not:
|
||||
for blob in tx.networkPayload.blobs:
|
||||
blobsBundle.blobs.add Web3Blob(blob)
|
||||
|
@ -462,7 +449,7 @@ proc handle_forkchoiceUpdated(sealingEngine: SealingEngineRef,
|
|||
let payload = res.get
|
||||
|
||||
let id = computePayloadId(blockHash, payloadAttrs)
|
||||
api.put(id, payload)
|
||||
api.put(id, sealingEngine.blockValue, payload)
|
||||
|
||||
info "Created payload for sealing",
|
||||
id = id.toHex,
|
||||
|
|
|
@ -43,6 +43,7 @@ type
|
|||
PayloadItem = object
|
||||
id: PayloadID
|
||||
payload: ExecutionPayload
|
||||
blockValue: UInt256
|
||||
|
||||
HeaderItem = object
|
||||
hash: Hash256
|
||||
|
@ -83,43 +84,57 @@ proc get*(api: EngineApiRef, hash: Hash256, header: var EthBlockHeader): bool =
|
|||
return true
|
||||
false
|
||||
|
||||
proc put*(api: EngineApiRef, id: PayloadID, payload: ExecutionPayload) =
|
||||
api.payloadQueue.put(PayloadItem(id: id, payload: payload))
|
||||
proc put*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: UInt256, payload: ExecutionPayload) =
|
||||
api.payloadQueue.put(PayloadItem(id: id,
|
||||
payload: payload, blockValue: blockValue))
|
||||
|
||||
proc put*(api: EngineApiRef, id: PayloadID, payload: SomeExecutionPayload) =
|
||||
api.put(id, payload.executionPayload)
|
||||
proc put*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: UInt256, payload: SomeExecutionPayload) =
|
||||
api.put(id, blockValue, payload.executionPayload)
|
||||
|
||||
proc get*(api: EngineApiRef, id: PayloadID, payload: var ExecutionPayload): bool =
|
||||
proc get*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload): bool =
|
||||
for x in api.payloadQueue:
|
||||
if x.id == id:
|
||||
payload = x.payload
|
||||
blockValue = x.blockValue
|
||||
return true
|
||||
false
|
||||
|
||||
proc get*(api: EngineApiRef, id: PayloadID, payload: var ExecutionPayloadV1): bool =
|
||||
proc get*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1): bool =
|
||||
var p: ExecutionPayload
|
||||
let found = api.get(id, p)
|
||||
let found = api.get(id, blockValue, p)
|
||||
doAssert(p.version == Version.V1)
|
||||
payload = p.V1
|
||||
return found
|
||||
|
||||
proc get*(api: EngineApiRef, id: PayloadID, payload: var ExecutionPayloadV2): bool =
|
||||
proc get*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV2): bool =
|
||||
var p: ExecutionPayload
|
||||
let found = api.get(id, p)
|
||||
let found = api.get(id, blockValue, p)
|
||||
doAssert(p.version == Version.V2)
|
||||
payload = p.V2
|
||||
return found
|
||||
|
||||
proc get*(api: EngineApiRef, id: PayloadID, payload: var ExecutionPayloadV3): bool =
|
||||
proc get*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV3): bool =
|
||||
var p: ExecutionPayload
|
||||
let found = api.get(id, p)
|
||||
let found = api.get(id, blockValue, p)
|
||||
doAssert(p.version == Version.V3)
|
||||
payload = p.V3
|
||||
return found
|
||||
|
||||
proc get*(api: EngineApiRef, id: PayloadID, payload: var ExecutionPayloadV1OrV2): bool =
|
||||
proc get*(api: EngineApiRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1OrV2): bool =
|
||||
var p: ExecutionPayload
|
||||
let found = api.get(id, p)
|
||||
let found = api.get(id, blockValue, p)
|
||||
doAssert(p.version in {Version.V1, Version.V2})
|
||||
payload = p.V1V2
|
||||
return found
|
||||
|
|
Loading…
Reference in New Issue