Skip to content

Commit

Permalink
Merge pull request #42 from pontem-network/steph-s/devnet-run
Browse files Browse the repository at this point in the history
feat: devnet launch
  • Loading branch information
refcell authored Oct 11, 2023
2 parents f160592 + bfc66eb commit c5e121d
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 148 deletions.
3 changes: 3 additions & 0 deletions crates/primitives/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub static GENESIS_DEV_ACCOUNTS: Lazy<Vec<H160>> = Lazy::new(|| {
H160::from_slice(&hex!("70997970c51812dc3a010c7d01b50e0d17dc79c8")),
H160::from_slice(&hex!("f39fd6e51aad88f6f4ce6ab8827279cfffb92266")),
H160::from_slice(&hex!("9d14A1992b81dfD355AE83b0b54Dd51582f62db2")),
H160::from_slice(&hex!("3fab184622dc19b6109349b94811493bf2a45362")),
]
});

Expand Down Expand Up @@ -98,6 +99,8 @@ pub fn dev_accounts() -> GenesisAlloc {
pub fn genesis_template(timestamp: u64) -> Option<Genesis> {
let mut genesis_allocations = genesis_allocations();
genesis_allocations.extend(dev_accounts());
// It's neccesary here, something wrong with the lazy_static initialization
Lazy::<Genesis>::force(&GENESIS_TEMPLATE);
let genesis = Lazy::get(&GENESIS_TEMPLATE);
genesis.map(|genesis| {
let mut genesis = genesis.clone();
Expand Down
224 changes: 91 additions & 133 deletions crates/stages/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::path::Path;
use std::process::Command;

use op_config::Config;
use op_contracts::AddressManager;
use op_primitives::genesis;

mod commands;
Expand All @@ -38,10 +37,10 @@ pub const L2_URL: &str = "http://localhost:9545";
pub const L2_PORT: u16 = 9545;

/// Rollup node url.
pub const ROLLUP_URL: &str = "http://localhost:7545";
pub const OP_NODE_URL: &str = "http://localhost:7545";

/// Rollup node port.
pub const ROLLUP_PORT: u16 = 7545;
pub const OP_NODE_PORT: u16 = 7545;

/// Testing deployer private key.
pub const DEPLOYER_PRIVATE_KEY: &str =
Expand Down Expand Up @@ -77,8 +76,8 @@ impl Stages<'_> {
let genesis_l1_file = devnet_dir.join("genesis-l1.json");
let genesis_l2_file = devnet_dir.join("genesis-l2.json");
let genesis_rollup_file = devnet_dir.join("rollup.json");
let allocs_file = devnet_dir.join("allocs-l1.json");
let addresses_json_file = devnet_dir.join("addresses.json");
let addresses_sdk_json_file = devnet_dir.join("addresses-sdk.json");
let deploy_config_file = deploy_config_dir.join("devnetL1.json");

// Check if the optimism and optimism-rs paths exist in the project root dir.
Expand All @@ -97,24 +96,78 @@ impl Stages<'_> {
tracing::info!(target: "opup", "Building devnet...");
self.config.create_artifacts_dir()?;
let curr_timestamp = genesis::current_timestamp();
let genesis_template = genesis::genesis_template_string(curr_timestamp)
.ok_or_else(|| eyre::eyre!("Could not create genesis template"))?;
if !devnet_dir.exists() {
std::fs::create_dir_all(&devnet_dir)?;
}

// Step 1.
// Create prestate and allocs

if !genesis_l2_file.exists() {
tracing::info!(target: "opup", "Making prestate and allocs...");
let bin_dir = op_monorepo_dir.join("op-program/bin");
if std::fs::metadata(bin_dir).is_err() {
let make_command = Command::new("make")
.args(["cannon-prestate"])
.current_dir(&op_monorepo_dir)
.output()?;
check_command(make_command, "Failed to do cannon prestate")?;
}

let allocs = Command::new("make")
.args(["devnet-allocs"])
.current_dir(&op_monorepo_dir)
.output()?;
check_command(allocs, "Failed to do allocs")?;
let copy_addr = Command::new("cp")
.args([".devnet/addresses.json", "../.devnet/"])
.current_dir(&op_monorepo_dir)
.output()?;
check_command(copy_addr, "Failed to do copy of addresses.json")?;
let copy_allocs = Command::new("cp")
.args([".devnet/allocs-l1.json", "../.devnet/"])
.current_dir(&op_monorepo_dir)
.output()?;
check_command(copy_allocs, "Failed to do copy of allocs.json")?;
}

// Step 2.
// Generate deploy config

tracing::info!(target: "opup", "Generating deploy config...");
let mut deploy_config = json::read_json(&deploy_config_file)?;
let hex_timestamp = format!("{:#x}", curr_timestamp);
json::set_json_property(&mut deploy_config, "l1GenesisBlockTimestamp", hex_timestamp);
json::set_json_property(&mut deploy_config, "l1StartingBlockTag", "earliest");
json::write_json(&deploy_config_file, &deploy_config)?;

// Step 3.
// Create L1 genesis

if !genesis_l1_file.exists() {
tracing::info!(target: "opup", "Creating L1 genesis...");
std::fs::write(genesis_l1_file, genesis_template)?;
let genesis_template = genesis::genesis_template_string(curr_timestamp)
.ok_or_else(|| eyre::eyre!("Could not create genesis template"))?;
std::fs::write(genesis_l1_file.clone(), genesis_template)?;
let l1_genesis = Command::new("go")
.args(["run", "cmd/main.go", "genesis", "l1"])
.args(["--deploy-config", deploy_config_file.to_str().unwrap()])
.args(["--l1-allocs", allocs_file.to_str().unwrap()])
.args(["--l1-deployments", addresses_json_file.to_str().unwrap()])
.args(["--outfile.l1", genesis_l1_file.to_str().unwrap()])
.current_dir(&op_node_dir)
.output()?;
check_command(l1_genesis, "Failed to create L1 genesis")?;
} else {
tracing::info!(target: "opup", "L1 genesis already found.");
}

// Step 2.
// Step 4.
// Start L1 execution client

tracing::info!(target: "opup", "Starting L1 execution client...");
let start_l1 = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "l1"])
.args(["up", "-d", "l1"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L1_CLIENT_CHOICE", self.config.l1_client.to_string())
.current_dir(&docker_dir)
Expand All @@ -123,59 +176,15 @@ impl Stages<'_> {
check_command(start_l1, "Failed to start L1 execution client")?;
net::wait_up(L1_PORT, 10, 1)?;

if !genesis_l2_file.exists() {
tracing::info!(target: "opup", "Creating L2 and rollup genesis...");
let l2_genesis = Command::new("make")
.args(["devnet-allocs"])
.current_dir(&op_monorepo_dir)
.output()?;
check_command(l2_genesis, "Failed to create L2 genesis")?;
}
// block entire thread, because we don't have tokio, or any similar dependency
std::thread::sleep(std::time::Duration::from_secs(10));

// Step 3.
// Generate network configs
tracing::info!(target: "opup", "Generating network configs...");
let mut deploy_config = json::read_json(&deploy_config_file)?;
json::set_json_property(
&mut deploy_config,
"l1GenesisBlockTimestamp",
curr_timestamp,
);
json::set_json_property(&mut deploy_config, "l1StartingBlockTag", "earliest");
json::write_json(&deploy_config_file, &deploy_config)?;

// Step 4.
// Deploy contracts
let addresses = if !addresses_json_file.exists() {
println!("Deploying contracts...");
let install_deps = Command::new("yarn")
.args(["install"])
.current_dir(&contracts_bedrock_dir)
.output()?;
check_command(install_deps, "Failed to install dependencies")?;

let deploy_contracts = Command::new("yarn")
.args(["hardhat", "--network", "devnetL1", "deploy", "--tags", "l1"])
.env("CHAIN_ID", "900")
.env("L1_RPC", L1_URL)
.env("PRIVATE_KEY_DEPLOYER", DEPLOYER_PRIVATE_KEY)
.current_dir(&contracts_bedrock_dir)
.output()?;

check_command(deploy_contracts, "Failed to deploy contracts")?;

// Write the addresses to json
let (addresses, sdk_addresses) = AddressManager::set_addresses(&deployment_dir)?;
json::write_json(&addresses_json_file, &addresses)?;
json::write_json(&addresses_sdk_json_file, &sdk_addresses)?;
// Step 5.
// Bind the addresses (contracts already deployed by "allocs" step)

addresses
} else {
tracing::info!(target: "opup", "Contracts already deployed.");
json::read_json(&addresses_json_file)?
};
let addresses = json::read_json(&addresses_json_file)?;

// Step 5.
// Step 6.
// Create L2 genesis

if !genesis_l2_file.exists() {
Expand All @@ -194,102 +203,51 @@ impl Stages<'_> {
tracing::info!(target: "opup", "L2 genesis already found.");
}

// Step 6.
// Step 7.
// Start L2 execution client

println!("Starting L2 execution client...");
tracing::info!(target: "opup", "Starting L2 execution client...");
let start_l2 = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "l2"])
.args(["up", "-d", "l2"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L2_CLIENT_CHOICE", self.config.l2_client.to_string())
.current_dir(&docker_dir)
.output()?;
check_command(start_l2, "Failed to start L2 execution client")?;
net::wait_up(L2_PORT, 10, 1)?;

// Step 7.
// Start rollup client

println!("Starting rollup client...");
let start_rollup = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "rollup-client"])
.env("PWD", docker_dir.to_str().unwrap())
.env(
"ROLLUP_CLIENT_CHOICE",
self.config.rollup_client.to_string(),
)
.current_dir(&docker_dir)
.output()?;
check_command(start_rollup, "Failed to start rollup client")?;
net::wait_up(ROLLUP_PORT, 30, 1)?;

// Step 8.
// Start proposer
// Start other services

println!("Starting proposer...");
let start_proposer = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "proposer"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L2OO_ADDRESS", addresses["L2OutputOracleProxy"].to_string())
.current_dir(&docker_dir)
.output()?;
check_command(start_proposer, "Failed to start proposer")?;

// Step 9.
// Start batcher

println!("Starting batcher...");
tracing::info!(target: "opup", "Bringing up everything else...");
let rollup_config = json::read_json(&genesis_rollup_file)?;
let start_batcher = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "batcher"])
let l2oo_address = addresses["L2OutputOracleProxy"]
.as_str()
.unwrap_or_default();
let sequencer_batch_inbox_address = rollup_config["batch_inbox_address"]
.as_str()
.unwrap_or_default();
let start_rollup = Command::new("docker-compose")
.args(["up", "-d", "node", "proposer", "batcher"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L2OO_ADDRESS", addresses["L2OutputOracleProxy"].to_string())
.env("L2OO_ADDRESS", l2oo_address)
.env(
"SEQUENCER_BATCH_INBOX_ADDRESS",
rollup_config["batch_inbox_address"].to_string(),
sequencer_batch_inbox_address,
)
.current_dir(&docker_dir)
.output()?;
check_command(start_batcher, "Failed to start batcher")?;

// Step 10.
// Start challenger

// TODO: Deploy the mock dispute game contract
let dgf_address = "0x0000000000000000000000000000000000000000";

println!("Starting challenger...");
let start_challenger = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "challenger"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L2OO_ADDRESS", addresses["L2OutputOracleProxy"].to_string())
.env("DGF_ADDRESS", dgf_address)
.env(
"CHALLENGER_AGENT_CHOICE",
self.config.challenger.to_string(),
)
.current_dir(&docker_dir)
.output()?;
check_command(start_challenger, "Failed to start challenger")?;

// Step 11.
// Start stateviz
let start_stateviz = Command::new("docker-compose")
.args(["up", "-d", "--no-deps", "--build", "stateviz"])
.env("PWD", docker_dir.to_str().unwrap())
.env("L2OO_ADDRESS", addresses["L2OutputOracleProxy"].to_string())
.current_dir(&docker_dir)
.output()?;
check_command(start_stateviz, "Failed to start stateviz")?;
check_command(start_rollup, "Failed to start rollup client")?;
net::wait_up(OP_NODE_PORT, 30, 1)?;

// Done!

println!("\n--------------------------");
println!("Devnet built successfully!");
println!("L1 endpoint: {}", L1_URL);
println!("L2 endpoint: {}", L2_URL);
println!("Rollup node endpoint: {}", ROLLUP_URL);
println!("--------------------------\n");
tracing::info!(target: "opup", "--------------------------");
tracing::info!(target: "opup", "Devnet built successfully!");
tracing::info!(target: "opup", "L1 endpoint: {}", L1_URL);
tracing::info!(target: "opup", "L2 endpoint: {}", L2_URL);
tracing::info!(target: "opup", "op-node endpoint: {}", OP_NODE_URL);
tracing::info!(target: "opup", "--------------------------\n");

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.l1-geth
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ethereum/client-go:v1.11.2
FROM ethereum/client-go:v1.12.2

RUN apk add --no-cache jq

Expand Down
30 changes: 30 additions & 0 deletions docker/Dockerfile.op-node
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM --platform=$BUILDPLATFORM golang:1.21.1-alpine3.18 as builder

ARG VERSION=v0.0.0

RUN apk add --no-cache make gcc musl-dev linux-headers git jq bash

COPY ./go.mod /app/go.mod
COPY ./go.sum /app/go.sum

WORKDIR /app

RUN go mod download

# build op-node with the shared go.mod & go.sum files
COPY ./op-node /app/op-node
COPY ./op-chain-ops /app/op-chain-ops
COPY ./op-service /app/op-service
COPY ./op-bindings /app/op-bindings

WORKDIR /app/op-node

ARG TARGETOS TARGETARCH

RUN make op-node VERSION="$VERSION" GOOS=$TARGETOS GOARCH=$TARGETARCH

FROM alpine:3.18

COPY --from=builder /app/op-node/bin/op-node /usr/local/bin

CMD ["op-node"]
Loading

0 comments on commit c5e121d

Please sign in to comment.