Skip to content

Commit

Permalink
Speed up demo-native (#2378)
Browse files Browse the repository at this point in the history
- Adds `period_seconds: 1` to readiness_probe of process-compose service
definitions (default value is 10, so if we're not ready immediately, we
waste 10 seconds)
- sets `ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL` to 100ms (was unset,
default is 7s)
- Adds `ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL` equivalents to utilities
used in demo-native
  • Loading branch information
QuentinI authored Dec 9, 2024
2 parents 006ce0c + 79fcacb commit a38dce3
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 22 deletions.
5 changes: 3 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ESPRESSO_SEQUENCER_MAX_CONNECTIONS=25
ESPRESSO_SEQUENCER_STORAGE_PATH=/store/sequencer
ESPRESSO_SEQUENCER_GENESIS_FILE=/genesis/demo.toml
ESPRESSO_SEQUENCER_L1_PORT=8545
ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL=100ms
ESPRESSO_SEQUENCER_L1_WS_PORT=8546
ESPRESSO_SEQUENCER_L1_PROVIDER=http://demo-l1-network:${ESPRESSO_SEQUENCER_L1_PORT}
ESPRESSO_SEQUENCER_L1_WS_PROVIDER=ws://demo-l1-network:${ESPRESSO_SEQUENCER_L1_WS_PORT}
Expand Down Expand Up @@ -149,5 +150,5 @@ INTEGRATION_TEST_PROTO=http
# `03`, marketplace upgrade will be tested.
INTEGRATION_TEST_SEQUENCER_VERSION=02

# max database connections
ESPRESSO_SEQUENCER_DATABASE_MAX_CONNECTIONS=25
# max database connections
ESPRESSO_SEQUENCER_DATABASE_MAX_CONNECTIONS=25
11 changes: 9 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ services:
environment:
- ESPRESSO_SEQUENCER_ETH_MULTISIG_ADDRESS
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_DEPLOYER_ACCOUNT_INDEX
- RUST_LOG
- RUST_LOG_FORMAT
Expand All @@ -35,6 +36,7 @@ services:
environment:
- ESPRESSO_SEQUENCER_ORCHESTRATOR_URL
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_URL
- ESPRESSO_SEQUENCER_STAKE_TABLE_CAPACITY
- ESPRESSO_SEQUENCER_PERMISSIONED_PROVER
Expand All @@ -57,6 +59,7 @@ services:
command: espresso-bridge deposit
environment:
- L1_PROVIDER=$ESPRESSO_SEQUENCER_L1_PROVIDER
- L1_POLLING_INTERVAL=$ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_PROVIDER=http://sequencer1:$ESPRESSO_SEQUENCER_API_PORT
- CONTRACT_ADDRESS=0xa15bb66138824a1c7167f5e85b957d04dd34e468
- MNEMONIC=$ESPRESSO_BUILDER_ETH_MNEMONIC
Expand Down Expand Up @@ -236,6 +239,7 @@ services:
- ESPRESSO_SEQUENCER_POSTGRES_PASSWORD=password
- ESPRESSO_SEQUENCER_POSTGRES_DATABASE=sequencer
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_0
Expand Down Expand Up @@ -293,6 +297,7 @@ services:
- ESPRESSO_SEQUENCER_POSTGRES_PASSWORD=password
- ESPRESSO_SEQUENCER_POSTGRES_DATABASE=sequencer
- ESPRESSO_SEQUENCER_L1_PROVIDER=$ESPRESSO_SEQUENCER_L1_WS_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_1
Expand Down Expand Up @@ -345,6 +350,7 @@ services:
- ESPRESSO_SEQUENCER_MAX_CONNECTIONS
- ESPRESSO_SEQUENCER_STATE_PEERS=http://sequencer3:$ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_2
Expand Down Expand Up @@ -395,6 +401,7 @@ services:
- ESPRESSO_SEQUENCER_MAX_CONNECTIONS
- ESPRESSO_SEQUENCER_STATE_PEERS=http://sequencer4:$ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_L1_PROVIDER=$ESPRESSO_SEQUENCER_L1_WS_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_3
Expand Down Expand Up @@ -446,6 +453,7 @@ services:
- ESPRESSO_SEQUENCER_STATE_PEERS=http://sequencer0:$ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_API_PEERS=http://sequencer0:$ESPRESSO_SEQUENCER_API_PORT
- ESPRESSO_SEQUENCER_L1_PROVIDER
- ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE
- ESPRESSO_STATE_RELAY_SERVER_URL
- ESPRESSO_SEQUENCER_PRIVATE_STAKING_KEY=$ESPRESSO_DEMO_SEQUENCER_STAKING_PRIVATE_KEY_4
Expand Down Expand Up @@ -733,8 +741,7 @@ services:

dev-rollup:
image: ghcr.io/espressosystems/espresso-sequencer/dev-rollup:main
command:
dev-rollup register --ns 1; dev-rollup register --ns 2; dev-rollup register --ns 3
command: dev-rollup register --ns 1; dev-rollup register --ns 2; dev-rollup register --ns 3
environment:
- ESPRESSO_MARKETPLACE_SOLVER_API_URL=http://marketplace-solver:$ESPRESSO_MARKETPLACE_SOLVER_API_PORT
depends_on:
Expand Down
24 changes: 18 additions & 6 deletions process-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ processes:
readiness_probe:
exec:
command: "[ $(docker inspect -f '{{.State.Health.Status}}' espresso-sequencer-demo-l1-network-1) = 'healthy' ]"
initial_delay_seconds: 5
period_seconds: 6
period_seconds: 1
timeout_seconds: 5
success_threshold: 1
failure_threshold: 20
failure_threshold: 30

deploy-sequencer-contracts:
# The contract addresses are implicitly inherited from .env. We need to unset these or else the
Expand Down Expand Up @@ -56,6 +54,7 @@ processes:
namespace: setup
environment:
- L1_PROVIDER=http://localhost:$ESPRESSO_SEQUENCER_L1_PORT
- L1_POLLING_INTERVAL=$ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL
- ESPRESSO_PROVIDER=http://localhost:$ESPRESSO_SEQUENCER1_API_PORT
- CONTRACT_ADDRESS=0xa15bb66138824a1c7167f5e85b957d04dd34e468
- MNEMONIC=$ESPRESSO_BUILDER_ETH_MNEMONIC
Expand Down Expand Up @@ -89,6 +88,8 @@ processes:
state-relay-server:
command: state-relay-server
readiness_probe:
failure_threshold: 10
period_seconds: 1
http_get:
scheme: http
host: localhost
Expand Down Expand Up @@ -163,6 +164,7 @@ processes:
host: localhost
port: $ESPRESSO_SEQUENCER_API_PORT
path: /healthcheck
period_seconds: 1
failure_threshold: 100

sequencer1:
Expand Down Expand Up @@ -215,6 +217,7 @@ processes:
host: localhost
port: $ESPRESSO_SEQUENCER1_API_PORT
path: /healthcheck
period_seconds: 1
failure_threshold: 100
availability:
restart: exit_on_failure
Expand Down Expand Up @@ -262,6 +265,7 @@ processes:
port: $ESPRESSO_SEQUENCER2_API_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
exit_on_skipped: true
restart: exit_on_failure
Expand Down Expand Up @@ -310,6 +314,7 @@ processes:
port: $ESPRESSO_SEQUENCER3_API_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
exit_on_skipped: true
restart: exit_on_failure
Expand Down Expand Up @@ -356,6 +361,7 @@ processes:
port: $ESPRESSO_SEQUENCER4_API_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
exit_on_skipped: true
restart: exit_on_failure
Expand Down Expand Up @@ -387,9 +393,9 @@ processes:
host: localhost
port: $ESPRESSO_SEQUENCER1_API_PORT
path: /healthcheck
period_seconds: 1
failure_threshold: 100


# We use KeyDB (a Redis variant) to maintain consistency between
# different parts of the CDN
# Cheating a bit here too, but KeyDB is not available as a Nix package.
Expand All @@ -416,6 +422,7 @@ processes:
host: 127.0.0.1
port: 9093
path: /metrics
period_seconds: 1
failure_threshold: 100

# A broker is the main message-routing unit of the CDN
Expand All @@ -430,6 +437,7 @@ processes:
host: 127.0.0.1
port: 9091
path: /metrics
period_seconds: 1
failure_threshold: 100

# A broker is the main message-routing unit of the CDN
Expand All @@ -448,6 +456,7 @@ processes:
host: 127.0.0.1
port: 9092
path: /metrics
period_seconds: 1
failure_threshold: 100

cdn-whitelist:
Expand Down Expand Up @@ -477,6 +486,7 @@ processes:
port: $ESPRESSO_SUBMIT_TRANSACTIONS_PUBLIC_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
exit_on_skipped: true

Expand All @@ -497,6 +507,7 @@ processes:
port: $ESPRESSO_SUBMIT_TRANSACTIONS_PRIVATE_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
exit_on_skipped: true

Expand All @@ -520,6 +531,7 @@ processes:
port: $ESPRESSO_BUILDER_SERVER_PORT
path: /healthcheck
failure_threshold: 100
period_seconds: 1
availability:
restart: "exit_on_failure"

Expand Down Expand Up @@ -560,6 +572,7 @@ processes:
host: localhost
port: $ESPRESSO_MARKETPLACE_SOLVER_API_PORT
path: /healthcheck
period_seconds: 1
failure_threshold: 100

sequencer-db-0:
Expand Down Expand Up @@ -623,4 +636,3 @@ processes:
depends_on:
sequencer1:
condition: process_healthy

2 changes: 1 addition & 1 deletion sequencer-sqlite/Cargo.lock

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

13 changes: 12 additions & 1 deletion sequencer/src/bin/deploy.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::{fs::File, io::stdout, path::PathBuf};
use std::{fs::File, io::stdout, path::PathBuf, time::Duration};

use clap::Parser;
use espresso_types::parse_duration;
use ethers::types::Address;
use futures::FutureExt;
use hotshot_stake_table::config::STAKE_TABLE_CAPACITY;
Expand Down Expand Up @@ -38,6 +39,15 @@ struct Options {
)]
rpc_url: Url,

/// Request rate when polling L1.
#[clap(
long,
env = "ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL",
default_value = "7s",
value_parser = parse_duration,
)]
pub l1_polling_interval: Duration,

/// URL of a sequencer node that is currently providing the HotShot config.
/// This is used to initialize the stake table.
#[clap(
Expand Down Expand Up @@ -128,6 +138,7 @@ async fn main() -> anyhow::Result<()> {

let contracts = deploy(
opt.rpc_url,
opt.l1_polling_interval,
opt.mnemonic,
opt.account_index,
opt.multisig_address,
Expand Down
30 changes: 25 additions & 5 deletions sequencer/src/bin/espresso-bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ use anyhow::{bail, ensure, Context};
use clap::{Parser, Subcommand};
use client::SequencerClient;
use contract_bindings::fee_contract::FeeContract;
use espresso_types::{eth_signature_key::EthKeyPair, Header};
use espresso_types::{eth_signature_key::EthKeyPair, parse_duration, Header};
use ethers::{
middleware::{Middleware, SignerMiddleware},
providers::Provider,
types::{Address, BlockId, U256},
};
use futures::stream::StreamExt;
use sequencer_utils::logging;
use std::sync::Arc;
use std::{sync::Arc, time::Duration};
use surf_disco::Url;

/// Command-line utility for working with the Espresso bridge.
Expand All @@ -37,6 +37,16 @@ struct Deposit {
#[clap(short, long, env = "L1_PROVIDER")]
rpc_url: Url,

/// Request rate when polling L1.
#[clap(
short,
long,
env = "L1_POLLING_INTERVAL",
default_value = "7s",
value_parser = parse_duration
)]
l1_interval: Duration,

/// Espresso query service provider.
///
/// This must point to an Espresso node running the /availability, /node and Merklized state
Expand Down Expand Up @@ -106,6 +116,16 @@ struct L1Balance {
#[clap(short, long, env = "L1_PROVIDER")]
rpc_url: Url,

/// Request rate when polling L1.
#[clap(
short,
long,
env = "L1_POLLING_INTERVAL",
default_value = "7s",
value_parser = parse_duration
)]
l1_interval: Duration,

/// Account to check.
#[clap(short, long, env = "ADDRESS", required_unless_present = "mnemonic")]
address: Option<Address>,
Expand Down Expand Up @@ -134,7 +154,7 @@ async fn deposit(opt: Deposit) -> anyhow::Result<()> {
let key_pair = EthKeyPair::from_mnemonic(opt.mnemonic, opt.account_index)?;

// Connect to L1.
let rpc = Provider::try_from(opt.rpc_url.to_string())?;
let rpc = Provider::try_from(opt.rpc_url.to_string())?.interval(opt.l1_interval);
let signer = key_pair.signer();
let l1 = Arc::new(SignerMiddleware::new_with_provider_chain(rpc, signer).await?);
let contract = FeeContract::new(opt.contract_address, l1.clone());
Expand Down Expand Up @@ -198,7 +218,7 @@ async fn deposit(opt: Deposit) -> anyhow::Result<()> {
let Some(l1_finalized) = header.l1_finalized() else {
continue;
};
if l1_finalized.number >= l1_block {
if l1_finalized.number() >= l1_block {
tracing::info!(block = header.height(), "deposit finalized on Espresso");
break header.height();
} else {
Expand Down Expand Up @@ -258,7 +278,7 @@ async fn l1_balance(opt: L1Balance) -> anyhow::Result<()> {
bail!("address or mnemonic must be provided");
};

let l1 = Provider::try_from(opt.rpc_url.to_string())?;
let l1 = Provider::try_from(opt.rpc_url.to_string())?.interval(opt.l1_interval);

let block = opt.block.map(BlockId::from);
tracing::debug!(%address, ?block, "fetching L1 balance");
Expand Down
17 changes: 16 additions & 1 deletion sequencer/src/bin/espresso-dev-node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ struct Args {
/// If this is not provided, an Avil node will be launched automatically.
#[clap(short, long, env = "ESPRESSO_SEQUENCER_L1_PROVIDER")]
rpc_url: Option<Url>,

/// Request rate when polling L1.
#[clap(
short,
long,
env = "ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL",
default_value = "7s",
value_parser = parse_duration
)]
l1_interval: Duration,

/// Mnemonic for an L1 wallet.
///
/// This wallet is used to deploy the contracts,
Expand Down Expand Up @@ -165,6 +176,7 @@ async fn main() -> anyhow::Result<()> {
retry_interval,
alt_prover_retry_intervals,
alt_prover_update_intervals,
l1_interval,
} = cli_params;

logging.init();
Expand Down Expand Up @@ -262,6 +274,7 @@ async fn main() -> anyhow::Result<()> {

let contracts = deploy(
url.clone(),
l1_interval,
mnemonic.clone(),
account_index,
multisig_address,
Expand All @@ -273,7 +286,9 @@ async fn main() -> anyhow::Result<()> {
)
.await?;

let provider = Provider::<Http>::try_from(url.as_str()).unwrap();
let provider = Provider::<Http>::try_from(url.as_str())
.unwrap()
.interval(l1_interval);
let chain_id = provider.get_chainid().await.unwrap().as_u64();

let wallet = MnemonicBuilder::<English>::default()
Expand Down
Loading

0 comments on commit a38dce3

Please sign in to comment.