add payloadId; add merge vector test script; remove consensusValidated (#2982)
This commit is contained in:
parent
1da4192f3f
commit
2eb9a608a4
|
@ -474,9 +474,8 @@ proc init*(T: type ChainDAGRef, cfg: RuntimeConfig, db: BeaconChainDB,
|
||||||
)
|
)
|
||||||
|
|
||||||
doAssert cfg.GENESIS_FORK_VERSION != cfg.ALTAIR_FORK_VERSION
|
doAssert cfg.GENESIS_FORK_VERSION != cfg.ALTAIR_FORK_VERSION
|
||||||
when true:
|
doAssert cfg.GENESIS_FORK_VERSION != cfg.MERGE_FORK_VERSION
|
||||||
doAssert cfg.GENESIS_FORK_VERSION != cfg.MERGE_FORK_VERSION
|
doAssert cfg.ALTAIR_FORK_VERSION != cfg.MERGE_FORK_VERSION
|
||||||
doAssert cfg.ALTAIR_FORK_VERSION != cfg.MERGE_FORK_VERSION
|
|
||||||
doAssert cfg.ALTAIR_FORK_EPOCH <= cfg.MERGE_FORK_EPOCH
|
doAssert cfg.ALTAIR_FORK_EPOCH <= cfg.MERGE_FORK_EPOCH
|
||||||
doAssert dag.updateFlags in [{}, {verifyFinalization}]
|
doAssert dag.updateFlags in [{}, {verifyFinalization}]
|
||||||
|
|
||||||
|
|
|
@ -422,13 +422,6 @@ proc executePayload*(p: Web3DataProviderRef,
|
||||||
payload: engine_api.ExecutionPayload): Future[ExecutePayloadResponse] =
|
payload: engine_api.ExecutionPayload): Future[ExecutePayloadResponse] =
|
||||||
p.web3.provider.engine_executePayload(payload)
|
p.web3.provider.engine_executePayload(payload)
|
||||||
|
|
||||||
proc consensusValidated*(p: Web3DataProviderRef,
|
|
||||||
blockHash: BlockHash,
|
|
||||||
status: BlockValidationStatus): Future[JsonNode] =
|
|
||||||
p.web3.provider.engine_consensusValidated(BlockValidationResult(
|
|
||||||
blockHash: blockHash,
|
|
||||||
status: $status))
|
|
||||||
|
|
||||||
proc forkchoiceUpdated*(p: Web3DataProviderRef,
|
proc forkchoiceUpdated*(p: Web3DataProviderRef,
|
||||||
headBlock, finalizedBlock: Eth2Digest): Future[JsonNode] =
|
headBlock, finalizedBlock: Eth2Digest): Future[JsonNode] =
|
||||||
p.web3.provider.engine_forkchoiceUpdated(ForkChoiceUpdate(
|
p.web3.provider.engine_forkchoiceUpdated(ForkChoiceUpdate(
|
||||||
|
@ -770,9 +763,9 @@ template getBlockProposalData*(m: Eth1Monitor,
|
||||||
finalizedStateDepositIndex: uint64): BlockProposalEth1Data =
|
finalizedStateDepositIndex: uint64): BlockProposalEth1Data =
|
||||||
getBlockProposalData(m.eth1Chain, state, finalizedEth1Data, finalizedStateDepositIndex)
|
getBlockProposalData(m.eth1Chain, state, finalizedEth1Data, finalizedStateDepositIndex)
|
||||||
|
|
||||||
proc new(T: type Web3DataProvider,
|
proc new*(T: type Web3DataProvider,
|
||||||
depositContractAddress: Eth1Address,
|
depositContractAddress: Eth1Address,
|
||||||
web3Url: string): Future[Result[Web3DataProviderRef, string]] {.async.} =
|
web3Url: string): Future[Result[Web3DataProviderRef, string]] {.async.} =
|
||||||
let web3Fut = newWeb3(web3Url)
|
let web3Fut = newWeb3(web3Url)
|
||||||
yield web3Fut or sleepAsync(chronos.seconds(10))
|
yield web3Fut or sleepAsync(chronos.seconds(10))
|
||||||
if (not web3Fut.finished) or web3Fut.failed:
|
if (not web3Fut.finished) or web3Fut.failed:
|
||||||
|
|
|
@ -42,6 +42,9 @@ type
|
||||||
BloomLogs* = object
|
BloomLogs* = object
|
||||||
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/execution-apis/blob/v1.0.0-alpha.2/src/engine/interop/specification.md#returns
|
||||||
|
PayloadId* = uint64
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.4/specs/merge/beacon-chain.md#executionpayload
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-beta.4/specs/merge/beacon-chain.md#executionpayload
|
||||||
ExecutionPayload* = object
|
ExecutionPayload* = object
|
||||||
parent_hash*: Eth2Digest
|
parent_hash*: Eth2Digest
|
||||||
|
|
|
@ -384,25 +384,6 @@ proc getBlockProposalEth1Data*(node: BeaconNode,
|
||||||
state, finalizedEpochRef.eth1_data,
|
state, finalizedEpochRef.eth1_data,
|
||||||
finalizedEpochRef.eth1_deposit_index)
|
finalizedEpochRef.eth1_deposit_index)
|
||||||
|
|
||||||
func getOpaqueTransaction(s: string): OpaqueTransaction =
|
|
||||||
try:
|
|
||||||
# Effectively an internal logic error in the Eth1/Eth2 client system, as
|
|
||||||
# it's not possible to just omit a malformatted transaction: it would be
|
|
||||||
# the wrong ExecutionPayload blockHash overall, and rejected by newBlock
|
|
||||||
# when one attempted to reinsert it into Geth (which, while not all Eth2
|
|
||||||
# clients might connect to, some will). It's also not possible to skip a
|
|
||||||
# whole ExecutionPayload being that it's an integral part of BeaconBlock
|
|
||||||
# construction. So not much better to do than bail if an incoming string
|
|
||||||
# representation of the OpaqueTransaction is invalid. init() could catch
|
|
||||||
# this, but it'd make its interface clumsier in a way it doesn't .add().
|
|
||||||
let opaqueTransactionSeq = hexToSeqByte(s)
|
|
||||||
if opaqueTransactionSeq.len > MAX_BYTES_PER_OPAQUE_TRANSACTION:
|
|
||||||
raiseAssert "Execution engine returned too-long opaque transaction"
|
|
||||||
OpaqueTransaction(List[byte, MAX_BYTES_PER_OPAQUE_TRANSACTION].init(
|
|
||||||
opaqueTransactionSeq))
|
|
||||||
except ValueError:
|
|
||||||
raiseAssert "Execution engine returned invalidly formatted transaction"
|
|
||||||
|
|
||||||
proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
|
proc makeBeaconBlockForHeadAndSlot*(node: BeaconNode,
|
||||||
randao_reveal: ValidatorSig,
|
randao_reveal: ValidatorSig,
|
||||||
validator_index: ValidatorIndex,
|
validator_index: ValidatorIndex,
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
{.used.}
|
||||||
|
|
||||||
|
# https://notes.ethereum.org/@9AeMAlpyQYaAAyuj47BzRw/rkwW3ceVY
|
||||||
|
# Monitor traffic: socat -v TCP-LISTEN:9545,fork TCP-CONNECT:127.0.0.1:8545
|
||||||
|
|
||||||
|
import
|
||||||
|
unittest2,
|
||||||
|
chronos, web3/[engine_api_types, ethtypes],
|
||||||
|
../beacon_chain/eth1/eth1_monitor,
|
||||||
|
../beacon_chain/spec/[digest, presets],
|
||||||
|
./testutil
|
||||||
|
|
||||||
|
suite "Merge test vectors":
|
||||||
|
let web3Provider = (waitFor Web3DataProvider.new(
|
||||||
|
default(Eth1Address), "ws://127.0.0.1:8546")).get
|
||||||
|
|
||||||
|
test "preparePayload, getPayload, executePayload, and forkchoiceUpdated":
|
||||||
|
let
|
||||||
|
existingBlock = waitFor web3Provider.getBlockByNumber(5)
|
||||||
|
payloadId = waitFor web3Provider.preparePayload(
|
||||||
|
existingBlock.hash.asEth2Digest,
|
||||||
|
existingBlock.timestamp.uint64 + 12,
|
||||||
|
default(Eth2Digest).data, # Random
|
||||||
|
Eth1Address.fromHex("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) # Fee recipient
|
||||||
|
payload = waitFor web3Provider.getPayload(
|
||||||
|
Quantity(payloadId.payloadId))
|
||||||
|
payloadStatus = waitFor web3Provider.executePayload(payload)
|
||||||
|
fcupdatedStatus = waitFor web3Provider.forkchoiceUpdated(
|
||||||
|
payload.blockHash.asEth2Digest, payload.blockHash.asEth2Digest)
|
||||||
|
|
||||||
|
payloadId2 = waitFor web3Provider.preparePayload(
|
||||||
|
payload.blockHash.asEth2Digest,
|
||||||
|
existingBlock.timestamp.uint64 + 24,
|
||||||
|
default(Eth2Digest).data, # Random
|
||||||
|
Eth1Address.fromHex("0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b")) # Fee recipient
|
||||||
|
payload2 = waitFor web3Provider.getPayload(
|
||||||
|
Quantity(payloadId2.payloadId))
|
||||||
|
payloadStatus2 = waitFor web3Provider.executePayload(payload2)
|
||||||
|
fcupdatedStatus2 = waitFor web3Provider.forkchoiceUpdated(
|
||||||
|
payload2.blockHash.asEth2Digest, payload2.blockHash.asEth2Digest)
|
||||||
|
|
||||||
|
check: payloadStatus.status == "VALID"
|
||||||
|
|
||||||
|
test "getPayload unknown payload":
|
||||||
|
try:
|
||||||
|
let res = waitFor web3Provider.getPayload(Quantity(100000))
|
||||||
|
doAssert false
|
||||||
|
except ValueError as e:
|
||||||
|
# expected outcome
|
||||||
|
echo e.msg
|
Loading…
Reference in New Issue