Skip to content

Latest commit

 

History

History
165 lines (101 loc) · 6 KB

devnet.md

File metadata and controls

165 lines (101 loc) · 6 KB

Devnet Environment

This document was written with reference to the devnet.md of the Magi and has been adapted for Hildr-node.

The devnet environment is built on the foundation of the locally available Optimism Bedrock devnet. Essentially, this environment runs op-geth and geth node in development mode, excluding the PoS client, and without finality. This is why the --devnet flag for Hildr node is necessary. This flag allows for the acceptance of any block as finalized. Otherwise, the Hildr node would operate exclusively with finalized blocks.

The devnet environment for Hildr node connects to the initiated OP L1 devnet node and launches its own corresponding op-geth node from the Hildr node docker.

Get started

Configuring the OP Stack

Begin by cloning the Optimism repository:

git clone [email protected]:ethereum-optimism/optimism.git

The develop branch is typically suitable. However, if issues arise, consider using the specific revision 18bcfb0dcc16de4287cb614f0a0b7bb3c276cbd3.

To launch the OP devnet, ensure you have Docker, Golang v1.20.11, [python3]:

    cd optimism
    git submodule update --init --recursive
    make install-geth
    make cannon-prestate
    make devnet-up

If building action has failed, could try to repeat executing make build command until it is success.

For troubleshooting, please refer to the official documentation.

Configure OP-Geth for Hildr

Once you have successfully started the OP devnet docker containers, proceed to the next step: launching an op-geth L2 instance for Hildr node.

Navigate to the hildr/docker directory and copy the configuration:

cp .env.default .env

Edit the .env file located within the directory:

# Set the network value to `devnet` in the configuration.
NETWORK=devnet

# To avoid potential conflicts with the default ports in the OP devnet, it's recommended to modify the RPC ports.

# The exeuction client Auth RPC port.
EXECUTION_CLIENT_AUTH_RPC_PORT=5551

# The execution client RPC port.
EXECUTION_CLIENT_RPC_PORT=5545

# The execution client WebSocket port.
EXECUTION_CLIENT_WS_PORT=5546

# Only for `custom` or `devnet` network.
# Specify the path to the `genesis-l2.json` file generated by `op-node`.
# For the devnet configuration, this file should be located in the `.devnet` folder within the Optimism directory.
OP_GENESIS_JSON_FILEPATH=<genesis-l2.json file path>

To initiate, start the op-geth node:

    docker-compose up op-geth

Launch Hildr node

Build Hildr:

    ./gradlew build -x test

Launch Hildr node:

    java \
        --enable-preview \
        -cp hildr-node/build/libs/hildr-node-0.1.0.jar io.optimism.Hildr \
        --network <rollup.json file path> \ # Specify the path to the `rollup.json` file, akin to `OP_ROLLUP_JSON_FILEPATH`
        --jwt-secret bf549f5188556ce0951048ef467ec93067bc4ea21acebe46ef675cd4e8e015ff \ # Replace only if altered in `.env`.
        --l1-rpc-url http://127.0.0.1:8545 \ # This depends on the OP devnet configuration.
        --l1-ws-rpc-url ws://127.0.0.1:8546 \ # This depends on the OP devnet configuration.
        --l2-rpc-url http://127.0.0.1:5545 \ # As per the Hildr `op-geth` configuration (refer to devnet profile).
        --l2-engine-url http://127.0.0.1:5551 \ # As per the Hildr `op-geth` configuration (see devnet profile).
        --rpc-port 11545 \ # Choose any available port.
        --devnet \ # Indicates it's a devnet.
        --sync-mode full # Other modes haven't been tested.

Remember to adjust the parameters as necessary based on your setup and configurations.

If everything is set up successfully, the Hildr node should log a message similar to:

[Tue, 29 Aug 2023 20:12:10] INFO: safe head updated: 312 0xd3c43585a005b6ae5e5fb70eb4bd408a707751a19f2b2fd1def29b36e633f0cc

Query node

Let's query our Hildr op-geth:

cast block latest --rpc-url localhost:5545

Compare the results with from OP devnet L2:

cast block latest --rpc-url localhost:9545

The responses should show approximately equal block heights. A difference of around 10-20 blocks is acceptable.

Additionally, you can retrieve a block hash from the Hildr op-geth and query this hash in OP L2:

cast block <block hash> --rpc-url localhost:9545

Test deposits/withdrawal

Navigate to the directory optimism/packages/sdk.

If you have previously built the TypeScript components within packages/, there's no need to rebuild the SDK. If not, execute the following commands:

pnpm install
pnpm all

Occasionally, you may also need to build packages/core-utils. If required, follow the same procedure as above for this package.

Deposit

Depositing ETH to your L2 Account:

    cast wallet new # Generate a Random Account (for example purposes).
    cast balance <address> --rpc-url localhost:5545 # Query the ETH Balance (it should be zero initially)
    npx hardhat deposit-eth --amount 1 --to <address> --network devnetL1 --withdraw false # Replace `<address>` with your own address.

Deposit & Withdraw

To simultaneously deposit ETH and initiate a withdrawal:

    npx hardhat deposit-eth --amount 1 --to <address> --network devnetL1

Note: This command will withdraw some ETH from pre-deposited accounts on L2. However, it will not withdraw from the provided address as the private key is required for that operation.

To test withdrawal from your account refer to this tutorial.

Troubleshooting

If the Hildr node stops syncing, you can reset the devnet.

To do this, navigate to the Optimism root directory and run the following command: make devnet-clean.

Afterward, start again both the devnet and Hildr node.

If the issue continues, please create a new issue on GitHub providing detailed information about the problem.