Giuliano Mega
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee
  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    [TOC] ## Building the Geth Network #### Step 1.1: Get Geth. Just follow [the official install guide](https://geth.ethereum.org/docs/getting-started/installing-geth) 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): ```bash= geth account new --datadir data1 ``` the account generator will ask you to set a password (you can leave blank), and then will print the account ID: ```text INFO [03-22|12:58:05.637] Maximum peer count ETH=50 total=50 INFO [03-22|12:58:05.638] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory" Your new account is locked with a password. Please give a password. Do not forget this password. Password: Repeat password: Your new key was generated Public address of the key: 0x93976895c4939d99837C8e0E1779787718EF8368 ... ``` 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: * the type of consensus algorithm used in the network; * the historical version of Ethereum you want to run and when, including the hability to pre-program historical hard forks and toggle new features as certain block heights are reached; * the initial set of accounts in the network, and the initial amount of ETH for each account; * transaction gas limits. 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: ```json! { "config": { "chainId": 12345, "homesteadBlock": 0, "eip150Block": 0, "eip155Block": 0, "eip158Block": 0, "byzantiumBlock": 0, "constantinopleBlock": 0, "petersburgBlock": 0, "istanbulBlock": 0, "berlinBlock": 0, "londonBlock": 0, "arrowGlacierBlock": 0, "grayGlacierBlock": 0, "clique": { "period": 1, "epoch": 30000 } }, "difficulty": "1", "gasLimit": "8000000", "extradata": "0x000000000000000000000000000000000000000000000000000000000000000093976895c4939d99837C8e0E1779787718EF83680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "alloc": { "93976895c4939d99837C8e0E1779787718EF8368": { "balance": "10000000000000000000000" } } } ``` 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 the `extradata` string, as well as assigned a balance under `alloc` -- 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 in `alloc`. Also note the configuration for the PoA consensus algorithm, Clique: ```json "clique": { "period": 1, "epoch": 30000 } ``` 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](#Step-22-Wait-for-256-blocks-to-be-mined)), 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: ```bash= geth init --datadir data1 network.json ``` #### Step 1.5: Launch the initial node. To launch the initial node, run: ```bash= geth\ --datadir data1\ --networkid 12345\ --unlock 0x93976895c4939d99837C8e0E1779787718EF8368\ --password <your-accounts-password>\ --nat extip:127.0.0.1\ --netrestrict 127.0.0.0/24\ --mine\ --miner.etherbase 0x93976895c4939d99837C8e0E1779787718EF8368\ --http\ --allow-insecure-unlock ``` This will launch a `geth` node using account `0x93976895c4939d99837C8e0E1779787718EF8368` 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: ```bash= geth init --datadir data2 network.json ``` 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: ```bash! ➜ geth geth attach --exec admin.nodeInfo.enr ./data1/geth.ipc "enr:-KO4QF8ztLpqqery6xLqcL8bvsQqTQPi4Si07Hg3mascRl0LLUIAPLBM3aF-LHnAyjWO4M-g44gzJ715Wg30kTKuDVmGAY5n3QuLg2V0aMfGhBpX1EaAgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQMtJholIyJHLn9atGa5ECgyLdlJ5bVfDJwxowUvtDza24RzbmFwwIN0Y3CCdl-DdWRwgnZf" ``` we can then use that ENR to boostrap our node: ```bash= geth\ --datadir data2\ --networkid 12345\ --bootnodes "enr:-KO4QF8ztLpqqery6xLqcL8bvsQqTQPi4Si07Hg3mascRl0LLUIAPLBM3aF-LHnAyjWO4M-g44gzJ715Wg30kTKuDVmGAY5n3QuLg2V0aMfGhBpX1EaAgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQMtJholIyJHLn9atGa5ECgyLdlJ5bVfDJwxowUvtDza24RzbmFwwIN0Y3CCdl-DdWRwgnZf"\ --port 30305\ --authrpc.port 8036\ --http\ --http.port 8546 ``` 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. ```bash= git clone https://github.com/codex-storage/codex-contracts-eth cd codex-contracts-eth npm install ``` #### 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: ```bash= geth attach --exec web3.eth.blockNumber ./data2/geth.ipc ``` 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](https://github.com/codex-storage/codex-contracts-eth/blob/master/hardhat.config.js#L29) 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]. ```bash= export DISTTEST_NETWORK_URL=http://localhost:8545 # bootstrap node npx hardhat --network codexdisttestnetwork deploy ``` Once the command returns, you're done. ## Github Repo I have put together the code for this tutorial in a [github repo](https://github.com/gmega/geth-net-fun) for reference. It includes [a script](https://github.com/gmega/geth-net-fun/blob/main/run.sh) to launch it all on Linux. [^1]: 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](https://github.com/ethereum/go-ethereum/issues/28449#issuecomment-1790164924) 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. [^3]: 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. [^2]: [Clique PoA protocol & Rinkeby PoA testnet](https://github.com/ethereum/EIPs/issues/225)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    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.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully