Skip to content

Commit

Permalink
Merge pull request #1262 from EspressoSystems/feat/deploy-script
Browse files Browse the repository at this point in the history
Overhaul contract deployment and configuration for local demo
  • Loading branch information
jbearer authored Mar 20, 2024
2 parents c1b2986 + e5c8e40 commit 060cd76
Show file tree
Hide file tree
Showing 19 changed files with 487 additions and 242 deletions.
26 changes: 16 additions & 10 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

RUST_LOG=info,libp2p=off
RUST_LOG_FORMAT=full

# Parallelism config
# Since we have many processes using async-std, limit them to one thread each to keep the CPU
# requirements for the local demo down.
ASYNC_STD_THREAD_COUNT=1
# Rayon is only used occasionally when generating a light client proof. Allow it to use 2 threads to
# speed up proof generation, but still don't use every available core or else the demo is too
# heavyweight.
RAYON_NUM_THREADS=2

# Internal port inside container
ESPRESSO_WEB_SERVER_PORT=40000
Expand All @@ -30,21 +38,21 @@ ESPRESSO_SEQUENCER_L1_PORT=8545
ESPRESSO_SEQUENCER_L1_WS_PORT=8546
ESPRESSO_SEQUENCER_L1_PROVIDER=http://demo-l1-network:$ESPRESSO_SEQUENCER_L1_PORT
ESPRESSO_SEQUENCER_ETH_MNEMONIC="test test test test test test test test test test test junk"
ESPRESSO_SEQUENCER_HOTSHOT_ACCOUNT_INDEX=5
ESPRESSO_SEQUENCER_HOTSHOT_NUM_BLOCKS_PER_EPOCH=4294967295 # u32::MAX for now as we do not handle epochs
ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS=0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f
ESPRESSO_COMMITMENT_TASK_PORT=60000
ESPRESSO_SEQUENCER_DB_PORT=5432
ESPRESSO_STATE_RELAY_SERVER_PORT=40004
ESPRESSO_STATE_RELAY_SERVER_URL=http://state-relay-server:$ESPRESSO_STATE_RELAY_SERVER_PORT

# Ethereum accounts (note 11-15 are used by the sequencer nodes)
ESPRESSO_SEQUENCER_HOTSHOT_ACCOUNT_INDEX=5
ESPRESSO_SEQUENCER_STATE_PROVER_ACCOUNT_INDEX=7
ESPRESSO_DEPLOYER_ACCOUNT_INDEX=9

# Example rollup demo variables
ESPRESSO_DEMO_ROLLUP_PORT=8084
ESPRESSO_DEMO_L1_HTTP_PROVIDER=$ESPRESSO_SEQUENCER_L1_PROVIDER
ESPRESSO_DEMO_HOTSHOT_ADDRESS=$ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS
ESPRESSO_DEMO_ROLLUP_MNEMONIC="test test test test test test test test test test test junk"
ESPRESSO_DEMO_ROLLUP_ACCOUNT_INDEX=7
# Contracts
ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS=0x700b6a60ce7eaaea56f065753d8dcb9653dbad35
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xe1aa25618fa0c7a1cfdab5d6b456af611873b629
ESPRESSO_SEQUENCER_LIGHTCLIENT_ADDRESS=$ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS

# Example sequencer demo private keys
ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_0=BLS_SIGNING_KEY~lNDh4Pn-pTAyzyprOAFdXHwhrKhEwqwtMtkD3CZF4x3o
Expand Down Expand Up @@ -74,8 +82,6 @@ ESPRESSO_STATE_SIGNATURE_WEIGHT_THRESHOLD=3
# Prover service
ESPRESSO_PROVER_SERVICE_PORT=60001
ESPRESSO_STATE_PROVER_UPDATE_INTERVAL=10m
# will deploy a light client contract if the address is not provided before launching prover service
ESPRESSO_SEQUENCER_DEPLOY_LIGHTCLIENT_CONTRACT=yes

# Load generator
ESPRESSO_SUBMIT_TRANSACTIONS_DELAY=1s
Expand Down
23 changes: 18 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ jobs:
target/release/web-server
target/release/state-relay-server
target/release/state-prover
target/release/gen-demo-genesis
target/release/sequencer
target/release/cli
target/release/commitment-task
target/release/submit-transactions
target/release/reset-storage
target/release/deploy
build-arm:
runs-on: [self-hosted, ARM64]
Expand Down Expand Up @@ -101,12 +101,12 @@ jobs:
target/release/web-server
target/release/state-relay-server
target/release/state-prover
target/release/gen-demo-genesis
target/release/sequencer
target/release/cli
target/release/commitment-task
target/release/submit-transactions
target/release/reset-storage
target/release/deploy
build-dockers:
runs-on: ubuntu-latest
Expand All @@ -119,6 +119,7 @@ jobs:
orchestrator-tag: ${{ steps.orchestrator.outputs.tags }}
commitment-task-tag: ${{ steps.commitment-task.outputs.tags }}
submit-transactions-tag: ${{ steps.submit-transactions.outputs.tags }}
deploy-tag: ${{ steps.deploy.outputs.tags }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -190,11 +191,11 @@ jobs:
with:
images: ghcr.io/espressosystems/espresso-sequencer/submit-transactions

- name: Generate example rollup metadata
- name: Generate deploy metadata
uses: docker/metadata-action@v5
id: example-rollup
id: deploy
with:
images: ghcr.io/espressosystems/espresso-sequencer/example-rollup
images: ghcr.io/espressosystems/espresso-sequencer/deploy

- name: Build and push sequencer docker
uses: docker/build-push-action@v5
Expand Down Expand Up @@ -266,6 +267,16 @@ jobs:
tags: ${{ steps.submit-transactions.outputs.tags }}
labels: ${{ steps.submit-transactions.outputs.labels }}

- name: Build and push deploy docker
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/deploy.Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.deploy.outputs.tags }}
labels: ${{ steps.deploy.outputs.labels }}

test-demo:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
Expand All @@ -288,6 +299,7 @@ jobs:
docker pull ${{ needs.build-dockers.outputs.orchestrator-tag }}
docker pull ${{ needs.build-dockers.outputs.commitment-task-tag }}
docker pull ${{ needs.build-dockers.outputs.submit-transactions-tag }}
docker pull ${{ needs.build-dockers.outputs.deploy-tag }}
- name: Tag new docker images
run: |
docker tag ${{ needs.build-dockers.outputs.sequencer-tag }} ghcr.io/espressosystems/espresso-sequencer/sequencer:main
Expand All @@ -297,6 +309,7 @@ jobs:
docker tag ${{ needs.build-dockers.outputs.orchestrator-tag }} ghcr.io/espressosystems/espresso-sequencer/orchestrator:main
docker tag ${{ needs.build-dockers.outputs.commitment-task-tag }} ghcr.io/espressosystems/espresso-sequencer/commitment-task:main
docker tag ${{ needs.build-dockers.outputs.submit-transactions-tag }} ghcr.io/espressosystems/espresso-sequencer/submit-transactions:main
docker tag ${{ needs.build-dockers.outputs.deploy-tag }} ghcr.io/espressosystems/espresso-sequencer/deploy:main
- name: Test docker demo
run: |
Expand Down
18 changes: 14 additions & 4 deletions .github/workflows/build_static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ jobs:
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/web-server
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/state-relay-server
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/state-prover
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/gen-demo-genesis
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/sequencer
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/cli
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/commitment-task
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/submit-transactions
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/reset-storage
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/deploy
static-dockers:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -167,11 +167,11 @@ jobs:
images: ghcr.io/espressosystems/espresso-sequencer/submit-transactions
flavor: suffix=musl

- name: Generate example rollup metadata
- name: Generate deploy rollup metadata
uses: docker/metadata-action@v5
id: example-rollup
id: deploy
with:
images: ghcr.io/espressosystems/espresso-sequencer/example-rollup
images: ghcr.io/espressosystems/espresso-sequencer/deploy
flavor: suffix=musl

- name: Build and push sequencer docker
Expand Down Expand Up @@ -243,3 +243,13 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.submit-transactions.outputs.tags }}
labels: ${{ steps.submit-transactions.outputs.labels }}

- name: Build and push deploy docker
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/deploy.Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.deploy.outputs.tags }}
labels: ${{ steps.deploy.outputs.labels }}
2 changes: 1 addition & 1 deletion .github/workflows/contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ env:

jobs:
contracts:
timeout-minutes: 20
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Install Nix
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ async-std = { version = "1.12.0", features = ["attributes", "tokio1"] }
async-trait = "0.1.77"
base64 = "0.22"
base64-bytes = "0.1"
clap = { version = "4.4", features = ["derive", "env"] }
clap = { version = "4.4", features = ["derive", "env", "string"] }
cld = "0.5"
derive_more = "0.99.17"
ethers = { version = "2.0" }
ethers = { version = "2.0", features = ["solc"] }
futures = "0.3"
hotshot = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.24" }
hotshot-orchestrator = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.24" }
hotshot-stake-table = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.24" }
hotshot-state-prover = { version = "0.1.0", path = "hotshot-state-prover" }
hotshot-task = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.24" }
hotshot-types = { git = "https://github.com/EspressoSystems/hotshot-types", tag = "0.1.1" }
hotshot-web-server = { git = "https://github.com/EspressoSystems/hotshot", tag = "0.5.24" }
Expand Down
27 changes: 23 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ networks:

services:
demo-l1-network:
# TODO: update image: https://github.com/EspressoSystems/espresso-geth/issues/12
image: ghcr.io/espressosystems/geth-l1:main
command: --dev --dev.period=1
ports:
Expand All @@ -16,6 +15,21 @@ services:
- "./geth-config/genesis-default.json:/genesis.json"
- "./geth-config/test-jwt-secret.txt:/config/test-jwt-secret.txt"

deploy-contracts:
image: ghcr.io/espressosystems/deploy:main
environment:
- ESPRESSO_SEQUENCER_ORCHESTRATOR_URL
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_DEPLOYER_ACCOUNT_INDEX
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
depends_on:
demo-l1-network:
condition: service_healthy
orchestrator:
condition: service_healthy

orchestrator:
image: ghcr.io/espressosystems/espresso-sequencer/orchestrator:main
ports:
Expand Down Expand Up @@ -79,19 +93,22 @@ services:
- ESPRESSO_STATE_PROVER_UPDATE_INTERVAL
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_DEPLOY_LIGHTCLIENT_CONTRACT
- ESPRESSO_SEQUENCER_HOTSHOT_NUM_BLOCKS_PER_EPOCH
- ESPRESSO_SEQUENCER_LIGHTCLIENT_ADDRESS
- MNEMONIC=$ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_STATE_PROVER_ACCOUNT_INDEX
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
- RAYON_NUM_THREADS
depends_on:
orchestrator:
condition: service_healthy
state-relay-server:
condition: service_healthy
demo-l1-network:
condition: service_healthy
deploy-contracts:
condition: service_completed_successfully

sequencer0:
image: ghcr.io/espressosystems/espresso-sequencer/sequencer:main
Expand Down Expand Up @@ -255,13 +272,13 @@ services:
image: ghcr.io/espressosystems/espresso-sequencer/commitment-task:main
ports:
- "$ESPRESSO_COMMITMENT_TASK_PORT:$ESPRESSO_COMMITMENT_TASK_PORT"
command: commitment-task --deploy
environment:
- ESPRESSO_SEQUENCER_ETH_MNEMONIC
- ESPRESSO_SEQUENCER_HOTSHOT_ACCOUNT_INDEX
- ESPRESSO_COMMITMENT_TASK_PORT
- ESPRESSO_SEQUENCER_URL
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS
- RUST_LOG
- RUST_LOG_FORMAT
- ASYNC_STD_THREAD_COUNT
Expand All @@ -270,6 +287,8 @@ services:
condition: service_healthy
demo-l1-network:
condition: service_healthy
deploy-contracts:
condition: service_completed_successfully

submit-transactions:
image: ghcr.io/espressosystems/espresso-sequencer/submit-transactions:main
Expand Down
13 changes: 13 additions & 0 deletions docker/deploy.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ubuntu:jammy

ARG TARGETARCH

RUN apt-get update \
&& apt-get install -y curl libcurl4 wait-for-it tini \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["tini", "--"]

COPY target/$TARGETARCH/release/deploy /bin/deploy
RUN chmod +x /bin/deploy

CMD [ "/bin/deploy"]
21 changes: 1 addition & 20 deletions docker/prover-service.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,13 @@ RUN apt-get update \
&& rm -rf /var/lib/apt/lists/*
ENTRYPOINT ["tini", "--"]

# install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
ENV PATH "$PATH:/root/.cargo/bin"

# install foundry toolchain
RUN curl -L https://foundry.paradigm.xyz | bash
ENV PATH "$PATH:/root/.foundry/bin"
RUN foundryup

# copy the contracts
RUN mkdir /work
WORKDIR /work
COPY foundry.toml /work/foundry.toml
COPY contracts/ /work/contracts/

# copy the binaries
COPY target/$TARGETARCH/release/state-prover /usr/local/bin/state-prover
COPY target/$TARGETARCH/release/gen-demo-genesis /usr/local/bin/gen-demo-genesis
COPY scripts/launch-prover-service /usr/local/bin/launch-prover-service
RUN chmod +x /usr/local/bin/state-prover
RUN chmod +x /usr/local/bin/launch-prover-service
RUN chmod +x /usr/local/bin/gen-demo-genesis

# When running as a Docker service, we always want a healthcheck endpoint, so set a default for the
# port that the HTTP server will run on. This can be overridden in any given deployment environment.
ENV ESPRESSO_COMMITMENT_TASK_PORT=80
HEALTHCHECK --interval=1s --timeout=1s --retries=100 CMD curl --fail http://localhost:${ESPRESSO_COMMITMENT_TASK_PORT}/healthcheck || exit 1

CMD [ "launch-prover-service" ]
CMD [ "state-prover", "-d" ]
31 changes: 2 additions & 29 deletions hotshot-state-prover/src/bin/gen-demo-genesis.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
use clap::Parser;
use ethers::abi::AbiEncode;
use hotshot_contract_adapter::jellyfish::u256_to_field;
use hotshot_contract_adapter::light_client::ParsedLightClientState;
use hotshot_state_prover::service::init_stake_table_from_orchestrator;
use hotshot_types::light_client::GenericPublicInput;
use hotshot_types::traits::stake_table::SnapshotVersion;
use hotshot_types::traits::stake_table::StakeTableScheme as _;
use hotshot_state_prover::service::light_client_genesis;
use url::Url;

type F = ark_ed_on_bn254::Fq;

#[derive(Parser)]
struct Args {
/// URL of the HotShot orchestrator.
Expand All @@ -25,26 +18,6 @@ struct Args {
#[async_std::main]
async fn main() {
let args = Args::parse();

let st = init_stake_table_from_orchestrator(&args.orchestrator_url).await;
let (bls_comm, schnorr_comm, stake_comm) = st
.commitment(SnapshotVersion::LastEpochStart)
.expect("Commitment computation shouldn't fail.");
let threshold = st.total_stake(SnapshotVersion::LastEpochStart).unwrap() * 2 / 3;

let pi = vec![
u256_to_field(threshold),
F::from(0_u64), // Arbitrary value for view number
F::from(0_u64), // Arbitrary value for block height
F::from(0_u64), // Arbitrary value for state commitment
F::from(0_u64), // Arbitrary value for fee ledger commitment
bls_comm,
schnorr_comm,
stake_comm,
];
let pi: GenericPublicInput<F> = pi.into();

let pi: ParsedLightClientState = pi.into();

let pi = light_client_genesis(&args.orchestrator_url).await.unwrap();
println!("{}", pi.encode_hex());
}
Loading

0 comments on commit 060cd76

Please sign in to comment.