Definitions related to the new execution engine JSON-RPC API

This commit is contained in:
Zahary Karadjov 2021-09-29 22:26:27 +03:00 committed by zah
parent 933879e298
commit 66b9f33edd
5 changed files with 32 additions and 72 deletions

View File

@ -9,17 +9,17 @@
import
std/[deques, hashes, options, strformat, strutils, sequtils, tables,
typetraits, uri],
typetraits, uri, json],
# Nimble packages:
chronos, json, metrics, chronicles/timings,
web3, web3/ethtypes as web3Types, web3/ethhexstrings, eth/common/eth_types,
web3, web3/ethtypes as web3Types, web3/ethhexstrings, web3/engine_api,
eth/common/eth_types,
eth/async_utils, stew/byteutils,
# Local modules:
../spec/[eth2_merkleization, forks, helpers],
../spec/datatypes/[base, merge],
../networking/network_metadata,
../consensus_object_pools/block_pools_types,
../rpc/eth_merge_web3,
".."/[beacon_chain_db, beacon_node_status],
./merkle_minimal
@ -403,37 +403,37 @@ proc getBlockByNumber*(p: Web3DataProviderRef,
except ValueError as exc: raiseAssert exc.msg # Never fails
p.web3.provider.eth_getBlockByNumber(hexNumber, false)
proc setHead*(p: Web3DataProviderRef, hash: Eth2Digest):
Future[BoolReturnSuccessRPC] =
p.web3.provider.consensus_setHead(hash.data.encodeQuantityHex)
proc preparePayload*(p: Web3DataProviderRef,
parentHash: Eth2Digest,
timestamp: uint64,
randomData: array[32, byte],
feeRecipient: Eth1Address): Future[PreparePayloadResponse] =
p.web3.provider.engine_preparePayload(PayloadAttributes(
parentHash: parentHash.asBlockHash,
timestamp: Quantity timestamp,
random: FixedBytes[32] randomData,
feeRecipient: feeRecipient))
proc assembleBlock*(p: Web3DataProviderRef, parentHash: Eth2Digest,
timestamp: uint64): Future[ExecutionPayloadRPC] =
p.web3.provider.consensus_assembleBlock(BlockParams(
parentHash: parentHash.data.encodeQuantityHex,
timestamp: encodeQuantity(timestamp)))
proc getPayload*(p: Web3DataProviderRef,
payloadId: Quantity): Future[engine_api.ExecutionPayload] =
p.web3.provider.engine_getPayload(payloadId)
func encodeOpaqueTransaction(ot: OpaqueTransaction): string =
var res = "0x"
for b in ot:
res &= b.toHex
res
proc executePayload*(p: Web3DataProviderRef,
payload: engine_api.ExecutionPayload): Future[ExecutePayloadResponse] =
p.web3.provider.engine_executePayload(payload)
proc newBlock*(p: Web3DataProviderRef,
executableData: ExecutionPayload): Future[BoolReturnValidRPC] =
p.web3.provider.consensus_newBlock(ExecutionPayloadRPC(
parentHash: executableData.parent_hash.data.encodeQuantityHex,
miner: executableData.coinbase.data.encodeQuantityHex,
stateRoot: executableData.state_root.data.encodeQuantityHex,
number: executableData.block_number.encodeQuantity,
gasLimit: executableData.gas_limit.encodeQuantity,
gasUsed: executableData.gas_used.encodeQuantity,
timestamp: executableData.timestamp.encodeQuantity,
receiptsRoot: executableData.receipt_root.data.encodeQuantityHex,
logsBloom: executableData.logs_bloom.data.encodeQuantityHex,
blockHash: executableData.block_hash.data.encodeQuantityHex,
transactions: List[string, MAX_TRANSACTIONS_PER_PAYLOAD].init(
mapIt(executableData.transactions, it.value.encodeOpaqueTransaction))))
proc consensusValidated*(p: Web3DataProviderRef,
blockHash: BlockHash,
status: BlockValidationStatus): Future[JsonNode] =
p.web3.provider.engine_consensusValidated(BlockValidationResult(
blockHash: blockHash,
status: $status))
proc forkchoiceUpdated*(p: Web3DataProviderRef,
headBlock, finalizedBlock: Eth2Digest): Future[JsonNode] =
p.web3.provider.engine_forkchoiceUpdated(ForkChoiceUpdate(
headBlockHash: headBlock.asBlockHash,
finalizedBlockHash: finalizedBlock.asBlockHash))
template readJsonField(j: JsonNode, fieldName: string, ValueType: type): untyped =
var res: ValueType

View File

@ -1,14 +0,0 @@
## This module contains signatures for the Ethereum merge RPCs.
## The signatures are not imported directly, but read and processed with parseStmt,
## then a procedure body is generated to marshal native Nim parameters to json and visa versa.
import json, options, stint, ethtypes
# https://hackmd.io/@n0ble/ethereum_consensus_upgrade_mainnet_perspective
# https://notes.ethereum.org/@n0ble/rayonism-the-merge-spec
# https://github.com/gballet/go-ethereum/blob/catalyst-for-rayonism/eth/catalyst/api.go
# https://github.com/gballet/go-ethereum/blob/catalyst-for-rayonism/eth/catalyst/api_test.go
proc consensus_assembleBlock(blockParams: BlockParams): ExecutionPayloadRPC
proc consensus_newBlock(executableData: ExecutionPayloadRPC): BoolReturnValidRPC
proc consensus_finalizeBlock(blockHash: Eth2Digest): BoolReturnValidRPC
proc consensus_setHead(newHead: string): BoolReturnSuccessRPC

View File

@ -1,10 +0,0 @@
import
strutils,
json_serialization/std/[sets, net], serialization/errors,
../spec/datatypes/[base, merge],
../spec/eth2_apis/rpc_beacon_client,
json_rpc/[client, jsonmarshal]
from os import DirSep, AltSep
template sourceDir: string = currentSourcePath.rsplit({DirSep, AltSep}, 1)[0]
createRpcSigs(RpcClient, sourceDir & "/eth_merge_sigs.nim")

View File

@ -334,22 +334,6 @@ type
SomeSomeSignedBeaconBlock* = SomeSignedBeaconBlock | altair.SomeSignedBeaconBlock | phase0.SomeSignedBeaconBlock
# Empirically derived from Catalyst responses; doesn't seem to match merge
# spec per commit 1fb9a6dd32b581c912d672634882d7e2eb2775cd from 2021-04-22
# {"jsonrpc":"2.0","id":1,"result":{"blockHash":"0x35139e42d930c640eee446944f7f8b345771b69dfa10120895057f48680ea27d","parentHash":"0x3a3fdfc9ab6e17ff530b57bc21494da3848ebbeaf9343545fded7a18d221ffec","miner":"0x1000000000000000000000000000000000000000","stateRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","number":"0x1","gasLimit":"0x2fefd8","gasUsed":"0x0","timestamp":"0x6087e796","receiptsRoot":"0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421","logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","transactions":[]}}
ExecutionPayloadRPC* = object
blockHash*: string # Hash of execution block
parentHash*: string
miner*: string
stateRoot*: string
number*: string
gasLimit*: string
gasUsed*: string
timestamp*: string
receiptsRoot*: string
logsBloom*: string
transactions*: List[string, MAX_TRANSACTIONS_PER_PAYLOAD]
BlockParams* = object
parentHash*: string
timestamp*: string

2
vendor/nim-web3 vendored

@ -1 +1 @@
Subproject commit 97e05aea6573d2630e318e7777a54d95db6ec40e
Subproject commit 9a23474afb7e2a14798ec0bf0e69e96cd5895e55