or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Building the Geth Network
Step 1.1: Get Geth.
Just follow the official install guide for your OS.
Step 1.2: Create a signer account.
We'll be using PoA, so you need an authorized signer node to mint and sign the blocks. The first step is creating a signer account which the signing node will use to sign blocks (the PoW equivalent of PoA):
the account generator will ask you to set a password (you can leave blank), and then will print the account ID:
the keys will be stored under
./data1/keystore
. You should keep the account ID stored somewhere as you will need it later. It is also probably a good idea to create a few more accounts to use with the Codex clients. You can repeat the command above a few more times; make sure to write down the account ids.Step 1.3: Create the configuration for the network.
With a few accounts in hands, we are ready to create the configuration file for our network. This configuration file defines things like:
Note that this can get confusing pretty quickly. In particular, the fact that you can replay Ethereum upgrades at specific block heights (or timestamps, in case of Shanghai) can be very confusing, as can the fact that certain features will work only with certain Ethereum versions and not with others, and the only indication you will get that something stopped working is a message that gets quickly buried in logs. Missing parameters will furthermore often simply cause a feature not to work and will not generate errors [1]. All of this can contribute to puzzling and surprising behavior.
With that in mind, we create a configuration file named
network.json
which specifies a pre-merge PoA network based on Gray Glacier, which was the last Ethereum upgrade before the merge:Note that the
*Block
parameters are all set to zero, which means we will be at Gray Glacier at block heights \(\geq\) 0. Also note that the account we created in Step 2 (0x93976895c4939d99837C8e0E1779787718EF8368
) is embedded in theextradata
string, as well as assigned a balance underalloc
– make sure to replace it with the signer account ID you created before. Any other accounts you may have created can also have balances assigned to them here under separate entries inalloc
.Also note the configuration for the PoA consensus algorithm, Clique:
this tells that the network should pump out a block at every \(1\) seconds (you will undertsand why we want such a short period in Step 2.2), and that the maximum window for a running signer membership ballot (which we do not really care about as our signer network is static) is \(30\,000\) blocks[2].
Step 1.4: Initialize the network.
We can now create the genesis block for the network and set up geth. We initialize this under
data1
as the first node in our network will also be the signer:Step 1.5: Launch the initial node.
To launch the initial node, run:
This will launch a
geth
node using account0x93976895c4939d99837C8e0E1779787718EF8368
to sign blocks (--miner.etherbase
). This means we need to allow geth to unlock the account; i.e., read its private key, which we do through--unlock
and--password
. Note that we are also enabling JSON-RPC access in this node (with--http
), which means any transactions submitted to it will be automatically signed. Since this is highly unsafe (it could allow one to drain the balance of the unlocked account), we also need to pass--allow-insecure-unlock
[3].Finally, we set
--nat extip:127.0.0.1
so that the node allows other nodes to boostrap from it. By default, geth will try to connect to peers in every network it knows about, so it is probably a good idea to constrain connections to the local network only. This is done with the--netrestrict 127.0.0.0/24
option.Step 1.6: Launch the second node.
As before, we need to initialize the second node so it knows about our network:
Now recall that the first node will be our bootstrap node. We therefore first need to obtain its ENR (Ethereum Name Record), which is similar to libp2p SPRs. To do that, we can use the geth console. This will go something like:
we can then use that ENR to boostrap our node:
where
--port
,--authrpc.port
, and--http.port
are specified to avoid clashes with the first node use of the default ports. Since this is not a miner node, it does not need to unlock any accounts.Deploying Codex Contracts
We are finally ready to deploy Codex's contracts.
Step 2.1. Clone the Codex ETH contracts repo and install deps.
Step 2.2. Wait for \(256\) blocks to be mined.
You need to wait for a block height of \(256\) to be reached in the network before you can deploy the contracts. You can inspect that in node 2, for fun:
once that prints something \(\geq 256\), you are good to go.
Step 2.3. Deploy contracts.
To deploy contracts, we can simply reuse the deploy configuration for the distributed tests and set the URL to the bootstrap node. Note that although the non-bootstrap node should also in theory allow contracts to be deployed, I was not able to make that work[3:1].
Once the command returns, you're done.
Github Repo
I have put together the code for this tutorial in a github repo for reference. It includes a script to launch it all on Linux.
One such example is trying to run the Shanghai EVM with Proof-of-Authority (PoA) consensus, which is a geth-specific consensus implementation. Because Shanghai networks have moved consensus into a separate consensus client, geth will simply cease to run consensus once the Shanghai timestamp is reached and expect a beacon client to be present. This is confusing because PoA has always been a geth-only construct, and yet they decided to drop support for it in epochs after the beacon chain split on the basis that having consensus built in would then become too much of a deviation from how "real Ethereum" works, and too much of a maintenance burden. ↩︎
Clique PoA protocol & Rinkeby PoA testnet ↩︎
Ideally we would not enable JSON-HTTP access in this node and have it enabled in the non-signer node instead. I could not get that to work, however – contract deploy transactions would simply get stuck in the txpool. We therefore keep it simple here, but feel free to try a better setup if you feel like it. ↩︎ ↩︎