mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
Simplify BeaconEngineRef (#2812)
This commit is contained in:
parent
430611d3bc
commit
c88c1911c9
@ -185,23 +185,19 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
||||
let attrs = attrsOpt.get()
|
||||
validateVersion(attrs, com, apiVersion)
|
||||
|
||||
let bundle = ben.generatePayload(attrs).valueOr:
|
||||
let bundle = ben.generateExecutionBundle(attrs).valueOr:
|
||||
error "Failed to create sealing payload", err = error
|
||||
raise invalidAttr(error)
|
||||
|
||||
let id = computePayloadId(blockHash, attrs)
|
||||
ben.put(id,
|
||||
bundle.blockValue,
|
||||
bundle.executionPayload,
|
||||
bundle.blobsBundle,
|
||||
bundle.executionRequests)
|
||||
ben.put(id, bundle)
|
||||
|
||||
info "Created payload for block proposal",
|
||||
number = bundle.executionPayload.blockNumber,
|
||||
hash = bundle.executionPayload.blockHash.short,
|
||||
txs = bundle.executionPayload.transactions.len,
|
||||
gasUsed = bundle.executionPayload.gasUsed,
|
||||
blobGasUsed = bundle.executionPayload.blobGasUsed.get(Quantity(0)),
|
||||
number = bundle.payload.blockNumber,
|
||||
hash = bundle.payload.blockHash.short,
|
||||
txs = bundle.payload.transactions.len,
|
||||
gasUsed = bundle.payload.gasUsed,
|
||||
blobGasUsed = bundle.payload.blobGasUsed.get(Quantity(0)),
|
||||
id = id.toHex,
|
||||
attrs = attrs
|
||||
|
||||
|
@ -23,51 +23,46 @@ proc getPayload*(ben: BeaconEngineRef,
|
||||
trace "Engine API request received",
|
||||
meth = "GetPayload", id
|
||||
|
||||
var payloadGeneric: ExecutionPayload
|
||||
var blockValue: UInt256
|
||||
var blobsBundle: Opt[BlobsBundleV1]
|
||||
if not ben.get(id, blockValue, payloadGeneric, blobsBundle):
|
||||
raise unknownPayload("Unknown payload")
|
||||
var bundle: ExecutionBundle
|
||||
if not ben.get(id, bundle):
|
||||
raise unknownPayload("Unknown bundle")
|
||||
|
||||
let version = payloadGeneric.version
|
||||
let version = bundle.payload.version
|
||||
if version > expectedVersion:
|
||||
raise unsupportedFork("getPayload" & $expectedVersion &
|
||||
" expect ExecutionPayload" & $expectedVersion &
|
||||
" but get ExecutionPayload" & $version)
|
||||
if blobsBundle.isSome:
|
||||
" expect payload" & $expectedVersion &
|
||||
" but get payload" & $version)
|
||||
if bundle.blobsBundle.isSome:
|
||||
raise unsupportedFork("getPayload" & $expectedVersion &
|
||||
" contains unsupported BlobsBundleV1")
|
||||
|
||||
GetPayloadV2Response(
|
||||
executionPayload: payloadGeneric.V1V2,
|
||||
blockValue: blockValue
|
||||
executionPayload: bundle.payload.V1V2,
|
||||
blockValue: bundle.blockValue
|
||||
)
|
||||
|
||||
proc getPayloadV3*(ben: BeaconEngineRef, id: Bytes8): GetPayloadV3Response =
|
||||
trace "Engine API request received",
|
||||
meth = "GetPayload", id
|
||||
|
||||
var payloadGeneric: ExecutionPayload
|
||||
var blockValue: UInt256
|
||||
var blobsBundle: Opt[BlobsBundleV1]
|
||||
if not ben.get(id, blockValue, payloadGeneric, blobsBundle):
|
||||
raise unknownPayload("Unknown payload")
|
||||
var bundle: ExecutionBundle
|
||||
if not ben.get(id, bundle):
|
||||
raise unknownPayload("Unknown bundle")
|
||||
|
||||
let version = payloadGeneric.version
|
||||
let version = bundle.payload.version
|
||||
if version != Version.V3:
|
||||
raise unsupportedFork("getPayloadV3 expect ExecutionPayloadV3 but get ExecutionPayload" & $version)
|
||||
if blobsBundle.isNone:
|
||||
raise unsupportedFork("getPayloadV3 expect payloadV3 but get payload" & $version)
|
||||
if bundle.blobsBundle.isNone:
|
||||
raise unsupportedFork("getPayloadV3 is missing BlobsBundleV1")
|
||||
|
||||
let payload = payloadGeneric.V3
|
||||
let com = ben.com
|
||||
if not com.isCancunOrLater(ethTime payload.timestamp):
|
||||
raise unsupportedFork("payload timestamp is less than Cancun activation")
|
||||
if not com.isCancunOrLater(ethTime bundle.payload.timestamp):
|
||||
raise unsupportedFork("bundle timestamp is less than Cancun activation")
|
||||
|
||||
GetPayloadV3Response(
|
||||
executionPayload: payload,
|
||||
blockValue: blockValue,
|
||||
blobsBundle: blobsBundle.get,
|
||||
executionPayload: bundle.payload.V3,
|
||||
blockValue: bundle.blockValue,
|
||||
blobsBundle: bundle.blobsBundle.get,
|
||||
shouldOverrideBuilder: false
|
||||
)
|
||||
|
||||
@ -75,30 +70,26 @@ proc getPayloadV4*(ben: BeaconEngineRef, id: Bytes8): GetPayloadV4Response =
|
||||
trace "Engine API request received",
|
||||
meth = "GetPayload", id
|
||||
|
||||
var payloadGeneric: ExecutionPayload
|
||||
var blockValue: UInt256
|
||||
var blobsBundle: Opt[BlobsBundleV1]
|
||||
var executionRequests: Opt[array[3, seq[byte]]]
|
||||
if not ben.get(id, blockValue, payloadGeneric, blobsBundle, executionRequests):
|
||||
raise unknownPayload("Unknown payload")
|
||||
var bundle: ExecutionBundle
|
||||
if not ben.get(id, bundle):
|
||||
raise unknownPayload("Unknown bundle")
|
||||
|
||||
let version = payloadGeneric.version
|
||||
let version = bundle.payload.version
|
||||
if version != Version.V3:
|
||||
raise unsupportedFork("getPayloadV4 expect ExecutionPayloadV3 but get ExecutionPayload" & $version)
|
||||
if blobsBundle.isNone:
|
||||
raise unsupportedFork("getPayloadV4 expect payloadV3 but get payload" & $version)
|
||||
if bundle.blobsBundle.isNone:
|
||||
raise unsupportedFork("getPayloadV4 is missing BlobsBundleV1")
|
||||
if executionRequests.isNone:
|
||||
if bundle.executionRequests.isNone:
|
||||
raise unsupportedFork("getPayloadV4 is missing executionRequests")
|
||||
|
||||
let payload = payloadGeneric.V3
|
||||
let com = ben.com
|
||||
if not com.isPragueOrLater(ethTime payload.timestamp):
|
||||
raise unsupportedFork("payload timestamp is less than Prague activation")
|
||||
if not com.isPragueOrLater(ethTime bundle.payload.timestamp):
|
||||
raise unsupportedFork("bundle timestamp is less than Prague activation")
|
||||
|
||||
GetPayloadV4Response(
|
||||
executionPayload: payload,
|
||||
blockValue: blockValue,
|
||||
blobsBundle: blobsBundle.get,
|
||||
executionPayload: bundle.payload.V3,
|
||||
blockValue: bundle.blockValue,
|
||||
blobsBundle: bundle.blobsBundle.get,
|
||||
shouldOverrideBuilder: false,
|
||||
executionRequests: executionRequests.get,
|
||||
executionRequests: bundle.executionRequests.get,
|
||||
)
|
||||
|
@ -20,7 +20,8 @@ import
|
||||
eth/common/[hashes, headers]
|
||||
|
||||
export
|
||||
chain
|
||||
chain,
|
||||
ExecutionBundle
|
||||
|
||||
type
|
||||
BeaconEngineRef* = ref object
|
||||
@ -117,28 +118,8 @@ func put*(ben: BeaconEngineRef,
|
||||
ben.queue.put(hash, header)
|
||||
|
||||
func put*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: UInt256, payload: ExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
ben.queue.put(id, blockValue, payload, blobsBundle)
|
||||
|
||||
func put*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: UInt256, payload: ExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1],
|
||||
executionRequests: Opt[array[3, seq[byte]]]) =
|
||||
ben.queue.put(id, blockValue, payload, blobsBundle, executionRequests)
|
||||
|
||||
func put*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: UInt256, payload: SomeExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
doAssert blobsBundle.isNone == (payload is
|
||||
ExecutionPayloadV1 | ExecutionPayloadV2)
|
||||
ben.queue.put(id, blockValue, payload, blobsBundle)
|
||||
|
||||
func put*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: UInt256,
|
||||
payload: ExecutionPayloadV1 | ExecutionPayloadV2) =
|
||||
ben.queue.put(
|
||||
id, blockValue, payload, blobsBundle = Opt.none(BlobsBundleV1))
|
||||
payload: ExecutionBundle) =
|
||||
ben.queue.put(id, payload)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions, getters
|
||||
@ -154,52 +135,15 @@ func get*(ben: BeaconEngineRef, hash: Hash32,
|
||||
ben.queue.get(hash, header)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload,
|
||||
blobsBundle: var Opt[BlobsBundleV1]): bool =
|
||||
ben.queue.get(id, blockValue, payload, blobsBundle)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload,
|
||||
blobsBundle: var Opt[BlobsBundleV1],
|
||||
executionRequests: var Opt[array[3, seq[byte]]]): bool =
|
||||
ben.queue.get(id, blockValue, payload, blobsBundle, executionRequests)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV2): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV3,
|
||||
blobsBundle: var BlobsBundleV1): bool =
|
||||
ben.queue.get(id, blockValue, payload, blobsBundle)
|
||||
|
||||
func get*(ben: BeaconEngineRef, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1OrV2): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
payload: var ExecutionBundle): bool =
|
||||
ben.queue.get(id, payload)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
type AssembledExecutionPayload* = object
|
||||
executionPayload*: ExecutionPayload
|
||||
blobsBundle*: Opt[BlobsBundleV1]
|
||||
blockValue*: UInt256
|
||||
executionRequests*: Opt[array[3, seq[byte]]]
|
||||
|
||||
proc generatePayload*(ben: BeaconEngineRef,
|
||||
proc generateExecutionBundle*(ben: BeaconEngineRef,
|
||||
attrs: PayloadAttributes):
|
||||
Result[AssembledExecutionPayload, string] =
|
||||
Result[ExecutionBundle, string] =
|
||||
wrapException:
|
||||
let
|
||||
xp = ben.txPool
|
||||
@ -238,8 +182,8 @@ proc generatePayload*(ben: BeaconEngineRef,
|
||||
proofs: blobData.proofs.mapIt it.Web3KZGProof,
|
||||
blobs: blobData.blobs.mapIt it.Web3Blob)
|
||||
|
||||
ok AssembledExecutionPayload(
|
||||
executionPayload: executionPayload(bundle.blk),
|
||||
ok ExecutionBundle(
|
||||
payload: executionPayload(bundle.blk),
|
||||
blobsBundle: blobsBundle,
|
||||
blockValue: bundle.blockValue,
|
||||
executionRequests: bundle.executionRequests)
|
||||
|
@ -31,12 +31,16 @@ type
|
||||
SimpleQueue[M: static[int]; T] = object
|
||||
list: array[M, QueueItem[T]]
|
||||
|
||||
ExecutionBundle* = object
|
||||
payload*: ExecutionPayload
|
||||
blockValue*: UInt256
|
||||
blobsBundle*: Opt[BlobsBundleV1]
|
||||
executionRequests*: Opt[array[3, seq[byte]]]
|
||||
targetBlobsPerBlock*: Opt[Quantity]
|
||||
|
||||
PayloadItem = object
|
||||
id: Bytes8
|
||||
payload: ExecutionPayload
|
||||
blockValue: UInt256
|
||||
blobsBundle: Opt[BlobsBundleV1]
|
||||
executionRequests: Opt[array[3, seq[byte]]]
|
||||
payload: ExecutionBundle
|
||||
|
||||
HeaderItem = object
|
||||
hash: Hash32
|
||||
@ -73,30 +77,8 @@ proc put*(api: var PayloadQueue,
|
||||
api.headerQueue.put(HeaderItem(hash: hash, header: header))
|
||||
|
||||
proc put*(api: var PayloadQueue, id: Bytes8,
|
||||
blockValue: UInt256, payload: ExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
api.payloadQueue.put(PayloadItem(id: id,
|
||||
payload: payload, blockValue: blockValue, blobsBundle: blobsBundle))
|
||||
|
||||
proc put*(api: var PayloadQueue, id: Bytes8,
|
||||
blockValue: UInt256, payload: ExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1],
|
||||
executionRequests: Opt[array[3, seq[byte]]]) =
|
||||
api.payloadQueue.put(PayloadItem(id: id,
|
||||
payload: payload, blockValue: blockValue,
|
||||
blobsBundle: blobsBundle, executionRequests: executionRequests))
|
||||
|
||||
proc put*(api: var PayloadQueue, id: Bytes8,
|
||||
blockValue: UInt256, payload: SomeExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
doAssert blobsBundle.isNone == (payload is
|
||||
ExecutionPayloadV1 | ExecutionPayloadV2)
|
||||
api.put(id, blockValue, payload.executionPayload, blobsBundle = blobsBundle)
|
||||
|
||||
proc put*(api: var PayloadQueue, id: Bytes8,
|
||||
blockValue: UInt256,
|
||||
payload: ExecutionPayloadV1 | ExecutionPayloadV2) =
|
||||
api.put(id, blockValue, payload, blobsBundle = Opt.none(BlobsBundleV1))
|
||||
payload: ExecutionBundle) =
|
||||
api.payloadQueue.put(PayloadItem(id: id, payload: payload))
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions, getters
|
||||
@ -111,81 +93,9 @@ proc get*(api: PayloadQueue, hash: Hash32,
|
||||
false
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload,
|
||||
blobsBundle: var Opt[BlobsBundleV1]): bool =
|
||||
payload: var ExecutionBundle): bool =
|
||||
for x in api.payloadQueue:
|
||||
if x.id == id:
|
||||
payload = x.payload
|
||||
blockValue = x.blockValue
|
||||
blobsBundle = x.blobsBundle
|
||||
return true
|
||||
false
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload,
|
||||
blobsBundle: var Opt[BlobsBundleV1],
|
||||
executionRequests: var Opt[array[3, seq[byte]]]): bool =
|
||||
for x in api.payloadQueue:
|
||||
if x.id == id:
|
||||
payload = x.payload
|
||||
blockValue = x.blockValue
|
||||
blobsBundle = x.blobsBundle
|
||||
executionRequests = x.executionRequests
|
||||
return true
|
||||
false
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1): bool =
|
||||
var
|
||||
p: ExecutionPayload
|
||||
blobsBundleOpt: Opt[BlobsBundleV1]
|
||||
let found = api.get(id, blockValue, p, blobsBundleOpt)
|
||||
if found:
|
||||
doAssert(p.version == Version.V1)
|
||||
payload = p.V1
|
||||
doAssert(blobsBundleOpt.isNone)
|
||||
return found
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV2): bool =
|
||||
var
|
||||
p: ExecutionPayload
|
||||
blobsBundleOpt: Opt[BlobsBundleV1]
|
||||
let found = api.get(id, blockValue, p, blobsBundleOpt)
|
||||
if found:
|
||||
doAssert(p.version == Version.V2)
|
||||
payload = p.V2
|
||||
doAssert(blobsBundleOpt.isNone)
|
||||
return found
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV3,
|
||||
blobsBundle: var BlobsBundleV1): bool =
|
||||
var
|
||||
p: ExecutionPayload
|
||||
blobsBundleOpt: Opt[BlobsBundleV1]
|
||||
let found = api.get(id, blockValue, p, blobsBundleOpt)
|
||||
if found:
|
||||
doAssert(p.version == Version.V3)
|
||||
payload = p.V3
|
||||
doAssert(blobsBundleOpt.isSome)
|
||||
blobsBundle = blobsBundleOpt.unsafeGet
|
||||
return found
|
||||
|
||||
proc get*(api: PayloadQueue, id: Bytes8,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1OrV2): bool =
|
||||
var
|
||||
p: ExecutionPayload
|
||||
blobsBundleOpt: Opt[BlobsBundleV1]
|
||||
let found = api.get(id, blockValue, p, blobsBundleOpt)
|
||||
if found:
|
||||
doAssert(p.version in {Version.V1, Version.V2})
|
||||
payload = p.V1V2
|
||||
doAssert(blobsBundleOpt.isNone)
|
||||
return found
|
||||
|
Loading…
x
Reference in New Issue
Block a user