mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-18 17:37:33 +00:00
non-intrusive, novel portions of merge (#2535)
This commit is contained in:
parent
e0f4d28116
commit
290b889ce6
14
beacon_chain/rpc/eth_merge_sigs.nim
Normal file
14
beacon_chain/rpc/eth_merge_sigs.nim
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
## 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
|
9
beacon_chain/rpc/eth_merge_web3.nim
Normal file
9
beacon_chain/rpc/eth_merge_web3.nim
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
import
|
||||||
|
strutils,
|
||||||
|
json_serialization/std/[sets, net], serialization/errors,
|
||||||
|
./spec/[datatypes, digest, crypto, eth2_apis/beacon_rpc_client],
|
||||||
|
json_rpc/[client, jsonmarshal]
|
||||||
|
|
||||||
|
from os import DirSep, AltSep
|
||||||
|
template sourceDir: string = currentSourcePath.rsplit({DirSep, AltSep}, 1)[0]
|
||||||
|
createRpcSigs(RpcClient, sourceDir & "/rpc/eth_merge_sigs.nim")
|
102
beacon_chain/spec/datatypes/merge.nim
Normal file
102
beacon_chain/spec/datatypes/merge.nim
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2021 Status Research & Development GmbH
|
||||||
|
# Licensed and distributed under either of
|
||||||
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
||||||
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
||||||
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
# TODO Careful, not nil analysis is broken / incomplete and the semantics will
|
||||||
|
# likely change in future versions of the language:
|
||||||
|
# https://github.com/nim-lang/RFCs/issues/250
|
||||||
|
{.experimental: "notnil".}
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
|
import
|
||||||
|
std/macros,
|
||||||
|
stew/assign2,
|
||||||
|
json_serialization,
|
||||||
|
json_serialization/types as jsonTypes,
|
||||||
|
../../ssz/types as sszTypes, ../digest,
|
||||||
|
#web3/ethtypes,
|
||||||
|
nimcrypto/utils
|
||||||
|
|
||||||
|
const
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/e895c29f3f42382a0c913f3d0fd33522d7db9e87/specs/merge/beacon-chain.md#execution
|
||||||
|
MAX_BYTES_PER_OPAQUE_TRANSACTION* = 1048576
|
||||||
|
MAX_EXECUTION_TRANSACTIONS* = 16384
|
||||||
|
BYTES_PER_LOGS_BLOOM* = 256
|
||||||
|
|
||||||
|
EVM_BLOCK_ROOTS_SIZE* = 8
|
||||||
|
|
||||||
|
type
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/eca6bd7d622a0cfb7343bff742da046ed25b3825/specs/merge/beacon-chain.md#custom-types
|
||||||
|
# TODO is this maneuver sizeof()/memcpy()/SSZ-equivalent? Pretty sure, but not 100% certain
|
||||||
|
OpaqueTransaction* = object
|
||||||
|
data*: List[byte, MAX_BYTES_PER_OPAQUE_TRANSACTION]
|
||||||
|
|
||||||
|
EthAddress* = object
|
||||||
|
data*: array[20, byte] # TODO there's a network_metadata type, but the import hierarchy's inconvenient without splitting out aspects of this module
|
||||||
|
|
||||||
|
BloomLogs* = object
|
||||||
|
data*: array[BYTES_PER_LOGS_BLOOM, byte]
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/merge/beacon-chain.md#executionpayload
|
||||||
|
ExecutionPayload* = object
|
||||||
|
block_hash*: Eth2Digest # Hash of execution block
|
||||||
|
parent_hash*: Eth2Digest
|
||||||
|
coinbase*: EthAddress
|
||||||
|
state_root*: Eth2Digest
|
||||||
|
number*: uint64
|
||||||
|
gas_limit*: uint64
|
||||||
|
gas_used*: uint64
|
||||||
|
timestamp*: uint64
|
||||||
|
receipt_root*: Eth2Digest
|
||||||
|
logs_bloom*: BloomLogs
|
||||||
|
transactions*: List[OpaqueTransaction, MAX_EXECUTION_TRANSACTIONS]
|
||||||
|
|
||||||
|
# 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_EXECUTION_TRANSACTIONS]
|
||||||
|
|
||||||
|
BlockParams* = object
|
||||||
|
parentHash*: string
|
||||||
|
timestamp*: string
|
||||||
|
|
||||||
|
BoolReturnValidRPC* = object
|
||||||
|
valid*: bool
|
||||||
|
|
||||||
|
BoolReturnSuccessRPC* = object
|
||||||
|
success*: bool
|
||||||
|
|
||||||
|
proc fromHex*(T: typedesc[BloomLogs], s: string): T =
|
||||||
|
hexToBytes(s, result.data)
|
||||||
|
|
||||||
|
proc fromHex*(T: typedesc[EthAddress], s: string): T =
|
||||||
|
hexToBytes(s, result.data)
|
||||||
|
|
||||||
|
proc writeValue*(w: var JsonWriter, a: EthAddress) {.raises: [Defect, IOError, SerializationError].} =
|
||||||
|
w.writeValue $a
|
||||||
|
|
||||||
|
proc readValue*(r: var JsonReader, a: var EthAddress) {.raises: [Defect, IOError, SerializationError].} =
|
||||||
|
try:
|
||||||
|
a = fromHex(type(a), r.readValue(string))
|
||||||
|
except ValueError:
|
||||||
|
raiseUnexpectedValue(r, "Hex string expected")
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/dev/specs/merge/beacon-chain.md#is_transition_completed
|
||||||
|
func is_transition_completed*(state: auto): bool =
|
||||||
|
# Rayonism starts post-merge
|
||||||
|
true
|
BIN
docs/rayonism_catalyst_logs.png
Normal file
BIN
docs/rayonism_catalyst_logs.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 122 KiB |
29
docs/rayonism_merge.md
Normal file
29
docs/rayonism_merge.md
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
# How to run Catalyst
|
||||||
|
|
||||||
|
- Clone Geth master into ~/client/catalyst: `git clone https://github.com/ethereum/go-ethereum ~/client/catalyst`
|
||||||
|
- Build Geth and Catalyst with `go build -o ./build/bin/catalyst ./cmd/geth`
|
||||||
|
- Run `scripts/run-catalyst.sh` to run Catalyst. It listens on port 8545.
|
||||||
|
|
||||||
|
# Verify Catalyst is working
|
||||||
|
|
||||||
|
- Clone https://github.com/protolambda/mergenet-tutorial
|
||||||
|
- Navigate to `rpc_examples` and run `consensus_assembleBlock.sh`, `consensus_newBlock.sh`, `consensus_setHead.sh`, and `
|
||||||
|
get_genesis_hash.sh` to verify that Catalyst is properly configured.
|
||||||
|
- If issues present themselves here, or when Nimbus attempts to use the API, one can `debug.verbosity(4)` console command in Catalyst.
|
||||||
|
|
||||||
|
# How to run Nimbus
|
||||||
|
|
||||||
|
- Check out branch `quick-merge-v1`
|
||||||
|
- Run `./scripts/launch_local_testnet.sh --testnet 0 --nodes 4 --disable-htop --stop-at-epoch 8 -- --verify-finalization --discv5:no`
|
||||||
|
|
||||||
|
![./rayonism_catalyst_logs.png](./rayonism_catalyst_logs.png)
|
||||||
|
|
||||||
|
# How to post a transaction
|
||||||
|
|
||||||
|
- Set up the MetaMask Chrome extension and use the seed phrase corresponding to an address with funds at genesis.
|
||||||
|
- Configure the localhost:8545 network to use the Chain ID corresponding to the Catalyst chain configuration.
|
||||||
|
![./rayonism_metamask_network_setup.png](./rayonism_metamask_network_setup.png)
|
||||||
|
- Create a transaction from that address to another address.
|
||||||
|
![./rayonism_metamask_send_eth.png](./rayonism_metamask_send_eth.png)
|
||||||
|
- Run the local testnet to confirm the transaction.
|
||||||
|
![./rayonism_metamask_transaction_confirmation.png](./rayonism_metamask_transaction_confirmation.png)
|
BIN
docs/rayonism_metamask_network_setup.png
Normal file
BIN
docs/rayonism_metamask_network_setup.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
docs/rayonism_metamask_send_eth.png
Normal file
BIN
docs/rayonism_metamask_send_eth.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
BIN
docs/rayonism_metamask_transaction_confirmation.png
Normal file
BIN
docs/rayonism_metamask_transaction_confirmation.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
36
scripts/run-catalyst.sh
Executable file
36
scripts/run-catalyst.sh
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# set -Eeuo pipefail
|
||||||
|
# https://github.com/prysmaticlabs/bazel-go-ethereum/blob/catalyst/run-catalyst.sh
|
||||||
|
|
||||||
|
# To increase verbosity: debug.verbosity(5) or debug.verbosity(6)
|
||||||
|
# MetaMask seed phrase for account with balance is
|
||||||
|
# lecture manual soon title cloth uncle gesture cereal common fruit tooth crater
|
||||||
|
|
||||||
|
echo \{ \
|
||||||
|
\"config\": \{ \
|
||||||
|
\"chainId\": 220720, \
|
||||||
|
\"homesteadBlock\": 0, \
|
||||||
|
\"eip150Block\": 0, \
|
||||||
|
\"eip155Block\": 0, \
|
||||||
|
\"eip158Block\": 0, \
|
||||||
|
\"byzantiumBlock\": 0, \
|
||||||
|
\"constantinopleBlock\": 0, \
|
||||||
|
\"petersburgBlock\": 0, \
|
||||||
|
\"istanbulBlock\": 0, \
|
||||||
|
\"catalystBlock\": 0 \
|
||||||
|
\}, \
|
||||||
|
\"alloc\": \{\"0x4A55eF8869af149aea4E07874cd8598044Eea2cb\": \{\"balance\": \"1000000000000000000\"\}\}, \
|
||||||
|
\"coinbase\": \"0x0000000000000000000000000000000000000000\", \
|
||||||
|
\"difficulty\": \"0x20000\", \
|
||||||
|
\"extraData\": \"\", \
|
||||||
|
\"gasLimit\": \"0x2fefd8\", \
|
||||||
|
\"nonce\": \"0x0000000000220720\", \
|
||||||
|
\"mixhash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", \
|
||||||
|
\"parentHash\": \"0x0000000000000000000000000000000000000000000000000000000000000000\", \
|
||||||
|
\"timestamp\": \"0x00\" \
|
||||||
|
\} > /tmp/catalystgenesis.json
|
||||||
|
|
||||||
|
# TODO these paths need to be generalized
|
||||||
|
rm /tmp/catalystchaindata -rvf
|
||||||
|
~/clients/catalyst/build/bin/catalyst --catalyst --datadir /tmp/catalystchaindata init /tmp/catalystgenesis.json
|
||||||
|
~/clients/catalyst/build/bin/catalyst --catalyst --rpc --rpcapi net,eth,eth2,consensus,catalyst --nodiscover --miner.etherbase 0x1000000000000000000000000000000000000000 --datadir /tmp/catalystchaindata console
|
Loading…
x
Reference in New Issue
Block a user