mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-23 18:49:57 +00:00
Engine API: rearrange version and fork validation in fcU and newPayload (#1848)
This commit is contained in:
parent
77289c7795
commit
5bfdcd0d27
@ -211,9 +211,9 @@ method execute*(step: NewPayloads, ctx: CancunTestContext): bool =
|
|||||||
expectedError = step.fcUOnPayloadRequest.getExpectedError()
|
expectedError = step.fcUOnPayloadRequest.getExpectedError()
|
||||||
expectedStatus = PayloadExecutionStatus.valid
|
expectedStatus = PayloadExecutionStatus.valid
|
||||||
timestamp = env.clMock.latestHeader.timestamp.uint64
|
timestamp = env.clMock.latestHeader.timestamp.uint64
|
||||||
version = step.fcUOnPayloadRequest.forkchoiceUpdatedVersion(timestamp)
|
|
||||||
|
|
||||||
payloadAttributes = step.fcUOnPayloadRequest.getPayloadAttributes(payloadAttributes)
|
payloadAttributes = step.fcUOnPayloadRequest.getPayloadAttributes(payloadAttributes)
|
||||||
|
let version = step.fcUOnPayloadRequest.forkchoiceUpdatedVersion(timestamp, some(payloadAttributes.timestamp.uint64))
|
||||||
|
|
||||||
if step.fcUOnPayloadRequest.getExpectInvalidStatus():
|
if step.fcUOnPayloadRequest.getExpectInvalidStatus():
|
||||||
expectedStatus = PayloadExecutionStatus.invalid
|
expectedStatus = PayloadExecutionStatus.invalid
|
||||||
|
@ -238,6 +238,7 @@ let cancunTestList* = [
|
|||||||
]
|
]
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
TestDesc(
|
TestDesc(
|
||||||
name: "Blob Transaction Ordering, Single Account 2",
|
name: "Blob Transaction Ordering, Single Account 2",
|
||||||
about: """
|
about: """
|
||||||
@ -619,7 +620,7 @@ let cancunTestList* = [
|
|||||||
run: specExecute,
|
run: specExecute,
|
||||||
spec: CancunSpec(
|
spec: CancunSpec(
|
||||||
mainFork: ForkCancun,
|
mainFork: ForkCancun,
|
||||||
forkHeight: 1,
|
forkHeight: 2,
|
||||||
testSequence: @[
|
testSequence: @[
|
||||||
NewPayloads(
|
NewPayloads(
|
||||||
fcUOnPayloadRequest: DowngradeForkchoiceUpdatedVersion(
|
fcUOnPayloadRequest: DowngradeForkchoiceUpdatedVersion(
|
||||||
@ -651,11 +652,12 @@ let cancunTestList* = [
|
|||||||
testSequence: @[
|
testSequence: @[
|
||||||
NewPayloads(
|
NewPayloads(
|
||||||
fcUOnPayloadRequest: DowngradeForkchoiceUpdatedVersion(
|
fcUOnPayloadRequest: DowngradeForkchoiceUpdatedVersion(
|
||||||
|
beaconRoot: some(common.Hash256()),
|
||||||
expectedError: engineApiInvalidParams,
|
expectedError: engineApiInvalidParams,
|
||||||
),
|
),
|
||||||
expectationDescription: """
|
expectationDescription: """
|
||||||
ForkchoiceUpdatedV2 after Cancun with beacon root field must return INVALID_PARAMS_ERROR (code $1)
|
ForkchoiceUpdatedV2 after Cancun with beacon root field must return INVALID_PARAMS_ERROR (code $1)
|
||||||
"""% [$engineApiInvalidParams],
|
""" % [$engineApiInvalidParams],
|
||||||
).TestStep,
|
).TestStep,
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
@ -163,7 +163,7 @@ template expectErrorCode*(res: untyped, errCode: int, expectedDesc: string) =
|
|||||||
testCond res.isErr:
|
testCond res.isErr:
|
||||||
error "unexpected result, want error, get ok"
|
error "unexpected result, want error, get ok"
|
||||||
testCond res.error.find($errCode) != -1:
|
testCond res.error.find($errCode) != -1:
|
||||||
fatal "DEBUG", msg=expectedDesc
|
fatal "DEBUG", msg=expectedDesc, got=res.error
|
||||||
|
|
||||||
template expectNoError*(res: untyped, expectedDesc: string) =
|
template expectNoError*(res: untyped, expectedDesc: string) =
|
||||||
testCond res.isOk:
|
testCond res.isOk:
|
||||||
|
@ -19,33 +19,39 @@ import
|
|||||||
|
|
||||||
{.push gcsafe, raises:[CatchableError].}
|
{.push gcsafe, raises:[CatchableError].}
|
||||||
|
|
||||||
template validateVersion(attrsOpt, com, expectedVersion) =
|
template validateVersion(attrsOpt, com, apiVersion) =
|
||||||
if attrsOpt.isSome:
|
if attrsOpt.isSome:
|
||||||
let
|
let
|
||||||
attr = attrsOpt.get
|
attr = attrsOpt.get
|
||||||
version = attr.version
|
version = attr.version
|
||||||
timestamp = ethTime attr.timestamp
|
timestamp = ethTime attr.timestamp
|
||||||
|
|
||||||
if com.isCancunOrLater(timestamp):
|
if apiVersion == Version.V3:
|
||||||
if version != Version.V3:
|
if version != apiVersion:
|
||||||
raise invalidParams("if timestamp is Cancun or later," &
|
raise invalidParams("forkChoiceUpdatedV3 expect PayloadAttributesV3" &
|
||||||
" payloadAttributes must be PayloadAttributesV3")
|
" but got PayloadAttributes" & $version)
|
||||||
elif com.isShanghaiOrLater(timestamp):
|
if not com.isCancunOrLater(timestamp):
|
||||||
if version != Version.V2:
|
raise unsupportedFork(
|
||||||
raise invalidParams("if timestamp is Shanghai or later," &
|
"forkchoiceUpdatedV3 get invalid payloadAttributes timestamp")
|
||||||
" payloadAttributes must be PayloadAttributesV2")
|
|
||||||
else:
|
else:
|
||||||
if version != Version.V1:
|
if com.isCancunOrLater(timestamp):
|
||||||
raise invalidParams("if timestamp is earlier than Shanghai," &
|
if version < Version.V3:
|
||||||
" payloadAttributes must be PayloadAttributesV1")
|
raise unsupportedFork("forkChoiceUpdated" & $apiVersion &
|
||||||
|
" doesn't support payloadAttributes with Cancun timestamp")
|
||||||
if expectedVersion == Version.V3 and version != expectedVersion:
|
if version >= Version.V3:
|
||||||
raise invalidParams("forkChoiceUpdated" & $expectedVersion &
|
raise invalidParams("forkChoiceUpdated" & $apiVersion &
|
||||||
" expect PayloadAttributes" & $expectedVersion &
|
" doesn't support PayloadAttributes" & $version)
|
||||||
" but got PayloadAttributes" & $version)
|
elif com.isShanghaiOrLater(timestamp):
|
||||||
|
if version != Version.V2:
|
||||||
|
raise invalidParams("if timestamp is Shanghai or later," &
|
||||||
|
" payloadAttributes must be PayloadAttributesV2")
|
||||||
|
else:
|
||||||
|
if version != Version.V1:
|
||||||
|
raise invalidParams("if timestamp is earlier than Shanghai," &
|
||||||
|
" payloadAttributes must be PayloadAttributesV1")
|
||||||
|
|
||||||
proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
||||||
expectedVersion: Version,
|
apiVersion: Version,
|
||||||
update: ForkchoiceStateV1,
|
update: ForkchoiceStateV1,
|
||||||
attrsOpt: Option[PayloadAttributes]):
|
attrsOpt: Option[PayloadAttributes]):
|
||||||
ForkchoiceUpdatedResponse =
|
ForkchoiceUpdatedResponse =
|
||||||
@ -55,7 +61,7 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
|||||||
chain = ben.chain
|
chain = ben.chain
|
||||||
blockHash = ethHash update.headBlockHash
|
blockHash = ethHash update.headBlockHash
|
||||||
|
|
||||||
validateVersion(attrsOpt, com, expectedVersion)
|
validateVersion(attrsOpt, com, apiVersion)
|
||||||
|
|
||||||
if blockHash == common.Hash256():
|
if blockHash == common.Hash256():
|
||||||
warn "Forkchoice requested update to zero hash"
|
warn "Forkchoice requested update to zero hash"
|
||||||
|
@ -19,7 +19,11 @@ import
|
|||||||
|
|
||||||
{.push gcsafe, raises:[CatchableError].}
|
{.push gcsafe, raises:[CatchableError].}
|
||||||
|
|
||||||
template validateVersion(com, timestamp, version, expectedVersion) =
|
template validateVersion(com, timestamp, version, apiVersion) =
|
||||||
|
if apiVersion == Version.V3:
|
||||||
|
if not com.isCancunOrLater(timestamp):
|
||||||
|
raise unsupportedFork("newPayloadV3 expect payload timestamp fall within Cancun")
|
||||||
|
|
||||||
if com.isCancunOrLater(timestamp):
|
if com.isCancunOrLater(timestamp):
|
||||||
if version != Version.V3:
|
if version != Version.V3:
|
||||||
raise invalidParams("if timestamp is Cancun or later, " &
|
raise invalidParams("if timestamp is Cancun or later, " &
|
||||||
@ -38,14 +42,15 @@ template validateVersion(com, timestamp, version, expectedVersion) =
|
|||||||
raise invalidParams("if timestamp is earlier than Shanghai, " &
|
raise invalidParams("if timestamp is earlier than Shanghai, " &
|
||||||
"payload must be ExecutionPayloadV1")
|
"payload must be ExecutionPayloadV1")
|
||||||
|
|
||||||
if expectedVersion == Version.V3 and version != expectedVersion:
|
if apiVersion == Version.V3:
|
||||||
raise invalidParams("newPayload" & $expectedVersion &
|
if version != apiVersion:
|
||||||
" expect ExecutionPayload" & $expectedVersion &
|
raise invalidParams("newPayload" & $apiVersion &
|
||||||
" but got ExecutionPayload" & $version)
|
" expect ExecutionPayload" & $apiVersion &
|
||||||
|
" but got ExecutionPayload" & $version)
|
||||||
|
|
||||||
|
|
||||||
proc newPayload*(ben: BeaconEngineRef,
|
proc newPayload*(ben: BeaconEngineRef,
|
||||||
expectedVersion: Version,
|
apiVersion: Version,
|
||||||
payload: ExecutionPayload,
|
payload: ExecutionPayload,
|
||||||
beaconRoot = none(Web3Hash)): PayloadStatusV1 =
|
beaconRoot = none(Web3Hash)): PayloadStatusV1 =
|
||||||
|
|
||||||
@ -54,7 +59,7 @@ proc newPayload*(ben: BeaconEngineRef,
|
|||||||
number = payload.blockNumber,
|
number = payload.blockNumber,
|
||||||
hash = payload.blockHash
|
hash = payload.blockHash
|
||||||
|
|
||||||
if expectedVersion == Version.V3:
|
if apiVersion == Version.V3:
|
||||||
if beaconRoot.isNone:
|
if beaconRoot.isNone:
|
||||||
raise invalidParams("newPayloadV3 expect beaconRoot but got none")
|
raise invalidParams("newPayloadV3 expect beaconRoot but got none")
|
||||||
|
|
||||||
@ -64,7 +69,7 @@ proc newPayload*(ben: BeaconEngineRef,
|
|||||||
timestamp = ethTime payload.timestamp
|
timestamp = ethTime payload.timestamp
|
||||||
version = payload.version
|
version = payload.version
|
||||||
|
|
||||||
validateVersion(com, timestamp, version, expectedVersion)
|
validateVersion(com, timestamp, version, apiVersion)
|
||||||
|
|
||||||
var header = blockHeader(payload, ethHash beaconRoot)
|
var header = blockHeader(payload, ethHash beaconRoot)
|
||||||
let blockHash = ethHash payload.blockHash
|
let blockHash = ethHash payload.blockHash
|
||||||
|
@ -115,7 +115,7 @@ func V3*(attr: PayloadAttributes): PayloadAttributesV3 =
|
|||||||
timestamp: attr.timestamp,
|
timestamp: attr.timestamp,
|
||||||
prevRandao: attr.prevRandao,
|
prevRandao: attr.prevRandao,
|
||||||
suggestedFeeRecipient: attr.suggestedFeeRecipient,
|
suggestedFeeRecipient: attr.suggestedFeeRecipient,
|
||||||
withdrawals: attr.withdrawals.get,
|
withdrawals: attr.withdrawals.get(newSeq[WithdrawalV1]()),
|
||||||
parentBeaconBlockRoot: attr.parentBeaconBlockRoot.get
|
parentBeaconBlockRoot: attr.parentBeaconBlockRoot.get
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user