fix related to engine api alpha.9
This commit is contained in:
parent
8827e04bc0
commit
9843c9428f
|
@ -29,7 +29,7 @@ type
|
||||||
|
|
||||||
# Merge related
|
# Merge related
|
||||||
firstPoSBlockNumber : Option[uint64]
|
firstPoSBlockNumber : Option[uint64]
|
||||||
ttdReached : bool
|
ttdReached* : bool
|
||||||
|
|
||||||
client : RpcClient
|
client : RpcClient
|
||||||
ttd : DifficultyInt
|
ttd : DifficultyInt
|
||||||
|
|
|
@ -124,7 +124,7 @@ proc blockByNumber*(client: RpcClient, number: uint64, output: var common.EthBlo
|
||||||
return ok()
|
return ok()
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return err(e.msg)
|
return err(e.msg)
|
||||||
|
|
||||||
proc latestHeader*(client: RpcClient, output: var common.BlockHeader): Result[void, string] =
|
proc latestHeader*(client: RpcClient, output: var common.BlockHeader): Result[void, string] =
|
||||||
try:
|
try:
|
||||||
let res = waitFor client.eth_getBlockByNumber("latest", false)
|
let res = waitFor client.eth_getBlockByNumber("latest", false)
|
||||||
|
@ -189,3 +189,33 @@ proc storageAt*(client: RpcClient, address: EthAddress, slot: UInt256, number: c
|
||||||
return ok(UInt256.fromHex(res.string))
|
return ok(UInt256.fromHex(res.string))
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return err(e.msg)
|
return err(e.msg)
|
||||||
|
|
||||||
|
proc verifyPoWProgress*(client: RpcClient, lastBlockHash: Hash256): Future[Result[void, string]] {.async.} =
|
||||||
|
let res = await client.eth_getBlockByHash(lastBlockHash, false)
|
||||||
|
if res.isNone:
|
||||||
|
return err("cannot get block by hash " & lastBlockHash.data.toHex)
|
||||||
|
|
||||||
|
let header = res.get()
|
||||||
|
let number = toBlockNumber(header.number)
|
||||||
|
|
||||||
|
let period = chronos.seconds(3)
|
||||||
|
var loop = 0
|
||||||
|
while loop < 5:
|
||||||
|
let res = await client.eth_getBlockByNumber("latest", false)
|
||||||
|
if res.isNone:
|
||||||
|
return err("cannot get latest block")
|
||||||
|
|
||||||
|
# Chain has progressed, check that the next block is also PoW
|
||||||
|
# Difficulty must NOT be zero
|
||||||
|
let bc = res.get()
|
||||||
|
let diff = hexToInt(string bc.difficulty, int64)
|
||||||
|
if diff == 0:
|
||||||
|
return err("Expected PoW chain to progress in PoW mode, but following block difficulty: " & $diff)
|
||||||
|
|
||||||
|
if toBlockNumber(bc.number) > number:
|
||||||
|
return ok()
|
||||||
|
|
||||||
|
await sleepAsync(period)
|
||||||
|
inc loop
|
||||||
|
|
||||||
|
return err("verify PoW Progress timeout")
|
||||||
|
|
|
@ -45,17 +45,20 @@ proc invalidTerminalBlockForkchoiceUpdated(t: TestEnv): TestStatus =
|
||||||
let res = t.rpcClient.forkchoiceUpdatedV1(forkchoiceState)
|
let res = t.rpcClient.forkchoiceUpdatedV1(forkchoiceState)
|
||||||
|
|
||||||
# Execution specification:
|
# Execution specification:
|
||||||
# {payloadStatus: {status: INVALID_TERMINAL_BLOCK, latestValidHash: null, validationError: errorMessage | null}, payloadId: null}
|
# {payloadStatus: {status: INVALID, latestValidHash=0x00..00}, payloadId: null}
|
||||||
# either obtained from the Payload validation process or as a result of validating a PoW block referenced by forkchoiceState.headBlockHash
|
# either obtained from the Payload validation process or as a result of validating a PoW block referenced by forkchoiceState.headBlockHash
|
||||||
testCond res.isOk
|
testCond res.isOk
|
||||||
|
|
||||||
let s = res.get()
|
let s = res.get()
|
||||||
testCond s.payloadStatus.status == PayloadExecutionStatus.invalid_terminal_block
|
testCond s.payloadStatus.status == PayloadExecutionStatus.invalid
|
||||||
testCond s.payloadStatus.latestValidHash.isNone
|
testCond s.payloadStatus.latestValidHash.isNone
|
||||||
testCond s.payloadId.isNone
|
testCond s.payloadId.isNone
|
||||||
|
|
||||||
# ValidationError is not validated since it can be either null or a string message
|
# ValidationError is not validated since it can be either null or a string message
|
||||||
|
|
||||||
|
# Check that PoW chain progresses
|
||||||
|
testCond t.verifyPoWProgress(t.gHeader.blockHash)
|
||||||
|
|
||||||
# Invalid GetPayload Under PoW: Client must reject GetPayload directives under PoW.
|
# Invalid GetPayload Under PoW: Client must reject GetPayload directives under PoW.
|
||||||
proc invalidGetPayloadUnderPoW(t: TestEnv): TestStatus =
|
proc invalidGetPayloadUnderPoW(t: TestEnv): TestStatus =
|
||||||
result = TestStatus.OK
|
result = TestStatus.OK
|
||||||
|
@ -90,7 +93,7 @@ proc invalidTerminalBlockNewPayload(t: TestEnv): TestStatus =
|
||||||
testCond res.isOk
|
testCond res.isOk
|
||||||
|
|
||||||
let s = res.get()
|
let s = res.get()
|
||||||
testCond s.status == PayloadExecutionStatus.invalid_terminal_block
|
testCond s.status == PayloadExecutionStatus.invalid
|
||||||
testCond s.latestValidHash.isNone
|
testCond s.latestValidHash.isNone
|
||||||
|
|
||||||
proc unknownHeadBlockHash(t: TestEnv): TestStatus =
|
proc unknownHeadBlockHash(t: TestEnv): TestStatus =
|
||||||
|
@ -989,17 +992,29 @@ proc suggestedFeeRecipient(t: TestEnv): TestStatus =
|
||||||
error "balance does not match fees",
|
error "balance does not match fees",
|
||||||
feeRecipientBalance, feeRecipientFees
|
feeRecipientBalance, feeRecipientFees
|
||||||
|
|
||||||
|
proc sendTx(t: TestEnv): Future[void] {.async.} =
|
||||||
|
let
|
||||||
|
client = t.rpcClient
|
||||||
|
clMock = t.clMock
|
||||||
|
period = chronos.milliseconds(100)
|
||||||
|
|
||||||
|
while not clMock.ttdReached:
|
||||||
|
await sleepAsync(period)
|
||||||
|
|
||||||
|
let
|
||||||
|
tx = t.makeNextTransaction(prevRandaoContractAddr, 0.u256)
|
||||||
|
rr = client.sendTransaction(tx)
|
||||||
|
|
||||||
|
if rr.isErr:
|
||||||
|
error "Unable to send transaction", msg=rr.error
|
||||||
|
|
||||||
proc prevRandaoOpcodeTx(t: TestEnv): TestStatus =
|
proc prevRandaoOpcodeTx(t: TestEnv): TestStatus =
|
||||||
result = TestStatus.OK
|
result = TestStatus.OK
|
||||||
|
|
||||||
let
|
let
|
||||||
client = t.rpcClient
|
client = t.rpcClient
|
||||||
clMock = t.clMock
|
clMock = t.clMock
|
||||||
tx = t.makeNextTransaction(prevRandaoContractAddr, 0.u256)
|
sendTxFuture = sendTx(t)
|
||||||
rr = client.sendTransaction(tx)
|
|
||||||
|
|
||||||
testCond rr.isOk:
|
|
||||||
error "Unable to send transaction", msg=rr.error
|
|
||||||
|
|
||||||
# Wait until TTD is reached by this client
|
# Wait until TTD is reached by this client
|
||||||
let ok = waitFor clMock.waitForTTD()
|
let ok = waitFor clMock.waitForTTD()
|
||||||
|
@ -1039,7 +1054,7 @@ proc postMergeSync(t: TestEnv): TestStatus =
|
||||||
# TODO: need multiple client
|
# TODO: need multiple client
|
||||||
|
|
||||||
const engineTestList* = [
|
const engineTestList* = [
|
||||||
TestSpec(
|
#[TestSpec(
|
||||||
name: "Invalid Terminal Block in ForkchoiceUpdated",
|
name: "Invalid Terminal Block in ForkchoiceUpdated",
|
||||||
run: invalidTerminalBlockForkchoiceUpdated,
|
run: invalidTerminalBlockForkchoiceUpdated,
|
||||||
ttd: 1000000
|
ttd: 1000000
|
||||||
|
@ -1186,7 +1201,7 @@ const engineTestList* = [
|
||||||
TestSpec(
|
TestSpec(
|
||||||
name: "Suggested Fee Recipient Test",
|
name: "Suggested Fee Recipient Test",
|
||||||
run: suggestedFeeRecipient,
|
run: suggestedFeeRecipient,
|
||||||
),
|
),]#
|
||||||
|
|
||||||
# TODO: debug and fix
|
# TODO: debug and fix
|
||||||
# PrevRandao opcode tests
|
# PrevRandao opcode tests
|
||||||
|
|
|
@ -149,3 +149,12 @@ proc makeNextTransaction*(t: TestEnv, recipient: EthAddress, amount: UInt256, pa
|
||||||
|
|
||||||
inc t.nonce
|
inc t.nonce
|
||||||
signTransaction(tx, t.vaultKey, chainId, eip155 = true)
|
signTransaction(tx, t.vaultKey, chainId, eip155 = true)
|
||||||
|
|
||||||
|
proc verifyPoWProgress*(t: TestEnv, lastBlockHash: Hash256): bool =
|
||||||
|
let res = waitFor verifyPoWProgress(t.rpcClient, lastBlockHash)
|
||||||
|
if res.isErr:
|
||||||
|
error "verify PoW Progress error", msg=res.error
|
||||||
|
return false
|
||||||
|
|
||||||
|
true
|
||||||
|
|
|
@ -84,7 +84,7 @@ proc setupEngineAPI*(
|
||||||
if td < ttd:
|
if td < ttd:
|
||||||
warn "Ignoring pre-merge payload",
|
warn "Ignoring pre-merge payload",
|
||||||
number = header.blockNumber, hash = blockHash.data.toHex, td, ttd
|
number = header.blockNumber, hash = blockHash.data.toHex, td, ttd
|
||||||
return PayloadStatusV1(status: PayloadExecutionStatus.invalid_terminal_block)
|
return PayloadStatusV1(status: PayloadExecutionStatus.invalid)
|
||||||
|
|
||||||
if header.timestamp <= parent.timestamp:
|
if header.timestamp <= parent.timestamp:
|
||||||
warn "Invalid timestamp",
|
warn "Invalid timestamp",
|
||||||
|
@ -231,7 +231,7 @@ proc setupEngineAPI*(
|
||||||
ptd = ptd,
|
ptd = ptd,
|
||||||
ttd = ttd
|
ttd = ttd
|
||||||
|
|
||||||
return simpleFCU(PayloadExecutionStatus.invalid_terminal_block)
|
return simpleFCU(PayloadExecutionStatus.invalid)
|
||||||
|
|
||||||
# If the head block is already in our canonical chain, the beacon client is
|
# If the head block is already in our canonical chain, the beacon client is
|
||||||
# probably resyncing. Ignore the update.
|
# probably resyncing. Ignore the update.
|
||||||
|
|
Loading…
Reference in New Issue