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