Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce base fee #1390

Merged
merged 12 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ ESPRESSO_SEQUENCER_L1_PROVIDER=http://demo-l1-network:${ESPRESSO_SEQUENCER_L1_PO
# Only allow 1 block to be processed for events at a time, simulating a very bad L1 provider.
ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE=1
ESPRESSO_SEQUENCER_ETH_MNEMONIC="test test test test test test test test test test test junk"
# The first account is the permission less builder, the last are sequencer0 to 4
ESPRESSO_SEQUENCER_PREFUNDED_BUILDER_ACCOUNTS=0x23618e81E3f5cdF7f54C3d65f7FBc0aBf5B21E8f
ESPRESSO_COMMITMENT_TASK_PORT=30010
ESPRESSO_SEQUENCER0_DB_PORT=5432
ESPRESSO_SEQUENCER1_DB_PORT=5433
Expand All @@ -55,8 +53,9 @@ ESPRESSO_BUILDER_ETH_ACCOUNT_INDEX=8
ESPRESSO_DEPLOYER_ACCOUNT_INDEX=9

# Contracts
ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS=0x700b6a60ce7eaaea56f065753d8dcb9653dbad35
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xe1aa25618fa0c7a1cfdab5d6b456af611873b629
ESPRESSO_SEQUENCER_HOTSHOT_ADDRESS=0xb19b36b1456e65e3a6d514d3f715f204bd59f431
ESPRESSO_SEQUENCER_FEE_CONTRACT_PROXY_ADDRESS=0xa15bb66138824a1c7167f5e85b957d04dd34e468
ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS=0xe1da8919f262ee86f9be05059c9280142cf23f48
ESPRESSO_SEQUENCER_LIGHTCLIENT_ADDRESS=$ESPRESSO_SEQUENCER_LIGHT_CLIENT_PROXY_ADDRESS

# Example sequencer demo private keys
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
target/release/permissionless-builder
target/release/nasty-client
target/release/pub-key
target/release/bridge

build-arm:
runs-on: buildjet-4vcpu-ubuntu-2204-arm
Expand Down Expand Up @@ -117,6 +118,7 @@ jobs:
target/release/permissionless-builder
target/release/nasty-client
target/release/pub-key
target/release/bridge

build-dockers:
runs-on: ubuntu-latest
Expand All @@ -134,6 +136,7 @@ jobs:
deploy-tag: ${{ steps.deploy.outputs.tags }}
builder-tag: ${{ steps.builder.outputs.tags }}
nasty-client-tag: ${{ steps.nasty-client.outputs.tags }}
bridge-tag: ${{ steps.bridge.outputs.tags }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
Expand Down Expand Up @@ -235,6 +238,12 @@ jobs:
with:
images: ghcr.io/espressosystems/espresso-sequencer/nasty-client

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

- name: Build and push sequencer docker
uses: docker/build-push-action@v5
with:
Expand Down Expand Up @@ -355,6 +364,16 @@ jobs:
tags: ${{ steps.nasty-client.outputs.tags }}
labels: ${{ steps.nasty-client.outputs.labels }}

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

test-demo:
if: ${{ github.event_name != 'pull_request' }}
runs-on: ubuntu-latest
Expand Down Expand Up @@ -382,6 +401,7 @@ jobs:
docker pull ${{ needs.build-dockers.outputs.deploy-tag }}
docker pull ${{ needs.build-dockers.outputs.builder-tag }}
docker pull ${{ needs.build-dockers.outputs.nasty-client-tag }}
docker pull ${{ needs.build-dockers.outputs.bridge-tag }}
- name: Tag new docker images
run: |
docker tag ${{ needs.build-dockers.outputs.sequencer-tag }} ghcr.io/espressosystems/espresso-sequencer/sequencer:main
Expand All @@ -396,6 +416,7 @@ jobs:
docker tag ${{ needs.build-dockers.outputs.deploy-tag }} ghcr.io/espressosystems/espresso-sequencer/deploy:main
docker tag ${{ needs.build-dockers.outputs.builder-tag }} ghcr.io/espressosystems/espresso-sequencer/builder:main
docker tag ${{ needs.build-dockers.outputs.nasty-client-tag }} ghcr.io/espressosystems/espresso-sequencer/nasty-client:main
docker tag ${{ needs.build-dockers.outputs.bridge-tag }} ghcr.io/espressosystems/espresso-sequencer/bridge:main

- name: Test docker demo
run: |
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/build_static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ jobs:
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/deploy
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/keygen
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/pub-key
${{ env.CARGO_TARGET_DIR }}/${{ env.TARGET_TRIPLET }}/release/bridge

static-dockers:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -192,6 +193,13 @@ jobs:
images: ghcr.io/espressosystems/espresso-sequencer/deploy
flavor: suffix=musl

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

- name: Build and push sequencer docker
uses: docker/build-push-action@v5
with:
Expand Down Expand Up @@ -291,3 +299,13 @@ jobs:
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.deploy.outputs.tags }}
labels: ${{ steps.deploy.outputs.labels }}

- name: Build and push bridge docker
uses: docker/build-push-action@v5
with:
context: ./
file: ./docker/bridge.Dockerfile
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.bridge.outputs.tags }}
labels: ${{ steps.bridge.outputs.labels }}
34 changes: 19 additions & 15 deletions builder/src/bin/permissionless-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use builder::non_permissioned::{build_instance_state, BuilderConfig};
use clap::Parser;
use cld::ClDuration;
use es_version::SEQUENCER_VERSION;
use ethers::types::U256;
use hotshot_types::data::ViewNumber;
use hotshot_types::traits::node_implementation::ConsensusTime;
use sequencer::L1Params;
use sequencer::{eth_signature_key::EthKeyPair, options::parse_size};
use sequencer::{eth_signature_key::EthKeyPair, options::parse_size, ChainConfig, L1Params};
use snafu::Snafu;
use std::num::NonZeroUsize;
use std::{str::FromStr, time::Duration};
Expand Down Expand Up @@ -42,9 +42,17 @@ struct NonPermissionedBuilderOptions {
#[clap(long, env = "ESPRESSO_SEQUENCER_STATE_PEERS", value_delimiter = ',')]
state_peers: Vec<Url>,

/// Unique identifier for this instance of the sequencer network.
#[clap(long, env = "ESPRESSO_SEQUENCER_CHAIN_ID", default_value = "0")]
chain_id: u64,

/// Maximum size in bytes of a block
#[clap(long, env = "ESPRESSO_SEQUENCER_MAX_BLOCK_SIZE", value_parser = parse_size)]
pub max_block_size: u64,
max_block_size: u64,

/// Minimum fee in WEI per byte of payload
#[clap(long, env = "ESPRESSO_SEQUENCER_BASE_FEE")]
base_fee: U256,

/// Port to run the builder server on.
#[clap(short, long, env = "ESPRESSO_BUILDER_SERVER_PORT")]
Expand Down Expand Up @@ -79,10 +87,6 @@ struct NonPermissionedBuilderOptions {
default_value = "15"
)]
buffer_view_num_count: usize,

/// Base Fee for a block
#[clap(long, env = "ESPRESSO_BUILDER_BLOCK_BASE_FEE", default_value = "0")]
base_fee: u64,
}

#[derive(Clone, Debug, Snafu)]
Expand Down Expand Up @@ -118,13 +122,14 @@ async fn main() -> anyhow::Result<()> {

let builder_server_url: Url = format!("http://0.0.0.0:{}", opt.port).parse().unwrap();

let instance_state = build_instance_state(
l1_params,
opt.state_peers,
opt.max_block_size,
sequencer_version,
)
.unwrap();
let chain_config = ChainConfig {
chain_id: opt.chain_id.into(),
max_block_size: opt.max_block_size,
base_fee: opt.base_fee.into(),
..Default::default()
};
let instance_state =
build_instance_state(l1_params, opt.state_peers, chain_config, sequencer_version).unwrap();

let api_response_timeout_duration = opt.max_api_timeout_duration;

Expand All @@ -144,7 +149,6 @@ async fn main() -> anyhow::Result<()> {
api_response_timeout_duration,
buffer_view_num_count,
txn_timeout_duration,
opt.base_fee,
)
.await;

Expand Down
10 changes: 1 addition & 9 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,11 +391,7 @@ pub mod testing {
let node_state = NodeState::new(
i as u64,
ChainConfig::default(),
L1Client::new(
self.anvil.endpoint().parse().unwrap(),
Address::default(),
1,
),
L1Client::new(self.anvil.endpoint().parse().unwrap(), 1),
MockStateCatchup::default(),
)
.with_genesis(ValidatedState::default());
Expand Down Expand Up @@ -535,7 +531,6 @@ pub mod testing {
ChainConfig::default(),
L1Client::new(
hotshot_test_config.get_anvil().endpoint().parse().unwrap(),
Address::default(),
1,
),
MockStateCatchup::default(),
Expand Down Expand Up @@ -565,7 +560,6 @@ pub mod testing {
Duration::from_millis(2000),
15,
Duration::from_millis(500),
0,
)
.await
.unwrap();
Expand Down Expand Up @@ -601,7 +595,6 @@ pub mod testing {
ChainConfig::default(),
L1Client::new(
hotshot_test_config.get_anvil().endpoint().parse().unwrap(),
Address::default(),
1,
),
MockStateCatchup::default(),
Expand Down Expand Up @@ -630,7 +623,6 @@ pub mod testing {
Duration::from_millis(2000),
15,
Duration::from_millis(500),
0,
)
.await
.unwrap();
Expand Down
29 changes: 19 additions & 10 deletions builder/src/non_permissioned.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use async_broadcast::{
broadcast, Receiver as BroadcastReceiver, RecvError, Sender as BroadcastSender, TryRecvError,
};
Expand Down Expand Up @@ -59,17 +60,13 @@ pub struct BuilderConfig {
pub fn build_instance_state<Ver: StaticVersionType + 'static>(
l1_params: L1Params,
state_peers: Vec<Url>,
max_block_size: u64,
chain_config: ChainConfig,
_: Ver,
) -> anyhow::Result<NodeState> {
let l1_client = L1Client::new(
l1_params.url,
Address::default(),
l1_params.events_max_block_range,
);
let l1_client = L1Client::new(l1_params.url, l1_params.events_max_block_range);
let instance_state = NodeState::new(
u64::MAX, // dummy node ID, only used for debugging
ChainConfig::new(0, max_block_size, 0),
chain_config,
l1_client,
Arc::new(StatePeers::<Ver>::from_urls(state_peers)),
);
Expand All @@ -89,8 +86,17 @@ impl BuilderConfig {
max_api_timeout_duration: Duration,
buffered_view_num_count: usize,
maximize_txns_count_timeout_duration: Duration,
base_fee: u64,
) -> anyhow::Result<Self> {
tracing::info!(
address = %builder_key_pair.fee_account(),
?bootstrapped_view,
%channel_capacity,
?max_api_timeout_duration,
buffered_view_num_count,
?maximize_txns_count_timeout_duration,
"initializing builder",
);

// tx channel
let (tx_sender, tx_receiver) = broadcast::<MessageType<SeqTypes>>(channel_capacity.get());

Expand All @@ -113,7 +119,6 @@ impl BuilderConfig {
let builder_commitment = genesis_payload.builder_commitment(&genesis_ns_table);

let vid_commitment = {
// TODO we should not need to collect payload bytes just to compute vid_commitment
let payload_bytes = genesis_payload
.encode()
.expect("unable to encode genesis payload");
Expand Down Expand Up @@ -151,7 +156,11 @@ impl BuilderConfig {
bootstrapped_view,
buffered_view_num_count as u64,
maximize_txns_count_timeout_duration,
base_fee,
instance_state
.chain_config()
.base_fee
.as_u64()
.context("the base fee exceeds the maximum amount that a builder can pay (defined by u64::MAX)")?,
Arc::new(instance_state),
);

Expand Down
21 changes: 11 additions & 10 deletions builder/src/permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,15 +247,14 @@ pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static
genesis_state.prefund_account(address.into(), U256::max_value().into());
}

let l1_client = L1Client::new(
l1_params.url,
Address::default(),
l1_params.events_max_block_range,
);

let l1_client = L1Client::new(l1_params.url, l1_params.events_max_block_range);
let instance_state = NodeState::new(
node_index,
ChainConfig::new(0, max_block_size, 0),
ChainConfig {
max_block_size,
base_fee: base_fee.into(),
..Default::default()
},
l1_client,
Arc::new(StatePeers::<Ver>::from_urls(network_params.state_peers)),
);
Expand Down Expand Up @@ -289,7 +288,6 @@ pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static
max_api_timeout_duration,
buffered_view_num_count,
maximize_txns_count_timeout_duration,
base_fee,
)
.await?;

Expand Down Expand Up @@ -385,7 +383,6 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static
max_api_timeout_duration: Duration,
buffered_view_num_count: usize,
maximize_txns_count_timeout_duration: Duration,
base_fee: u64,
) -> anyhow::Result<Self> {
// tx channel
let (tx_sender, tx_receiver) = broadcast::<MessageType<SeqTypes>>(channel_capacity.get());
Expand Down Expand Up @@ -447,7 +444,11 @@ impl<N: network::Type, P: SequencerPersistence, Ver: StaticVersionType + 'static
bootstrapped_view,
buffered_view_num_count as u64,
maximize_txns_count_timeout_duration,
base_fee,
instance_state
.chain_config()
.base_fee
.as_u64()
.context("the base fee exceeds the maximum amount that a builder can pay (defined by u64::MAX)")?,
Arc::new(instance_state),
);

Expand Down
8 changes: 7 additions & 1 deletion data/header.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"block_merkle_tree_root": "MERKLE_COMM~yB4_Aqa35_PoskgTpcCR1oVLh6BUdLHIs7erHKWi-usUAAAAAAAAAAEAAAAAAAAAJg",
"fee_merkle_tree_root": "MERKLE_COMM~VJ9z239aP9GZDrHp3VxwPd_0l28Hc5KEAB1pFeCIxhYgAAAAAAAAAAIAAAAAAAAAdA",
"fee_info": { "account": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266", "amount": "0x0" },
"chain_config": { "chain_config": { "Left": { "chain_id": "0x8a19", "max_block_size": 10240, "base_fee": "0x0" } } }
"chain_config": { "chain_config": { "Left": {
"chain_id": "0x8a19",
"max_block_size": 10240,
"base_fee": "0x0",
"fee_contract": "0xa15bb66138824a1c7167f5e85b957d04dd34e468",
"fee_recipient": "0x0000000000000000000000000000000000000000"
} } }
}
Loading
Loading