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

use max base fee in builder #1764

Merged
merged 1 commit into from
Jul 23, 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
12 changes: 7 additions & 5 deletions builder/src/bin/permissionless-builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ use async_compatibility_layer::logging::{setup_backtrace, setup_logging};
use builder::non_permissioned::{build_instance_state, BuilderConfig};
use clap::Parser;
use cld::ClDuration;
use es_version::SEQUENCER_VERSION;
use espresso_types::eth_signature_key::EthKeyPair;
use espresso_types::{eth_signature_key::EthKeyPair, SeqTypes};
use hotshot::traits::ValidatedState;
use hotshot_builder_core::testing::basic_test::NodeType;
use hotshot_types::{data::ViewNumber, traits::node_implementation::ConsensusTime};
use sequencer::{Genesis, L1Params};
use snafu::Snafu;
use url::Url;
use vbs::version::StaticVersionType;

#[derive(Parser, Clone, Debug)]
struct NonPermissionedBuilderOptions {
Expand Down Expand Up @@ -106,8 +107,6 @@ async fn main() -> anyhow::Result<()> {
let opt = NonPermissionedBuilderOptions::parse();
let genesis = Genesis::from_file(&opt.genesis_file)?;

let sequencer_version = SEQUENCER_VERSION;

let l1_params = L1Params {
url: opt.l1_provider_url,
events_max_block_range: 10000,
Expand All @@ -122,10 +121,12 @@ async fn main() -> anyhow::Result<()> {
genesis.chain_config,
l1_params,
opt.state_peers,
sequencer_version,
<SeqTypes as NodeType>::Base::instance(),
)
.unwrap();

let base_fee = genesis.max_base_fee();

let validated_state = ValidatedState::genesis(&instance_state).0;

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

Expand Down
2 changes: 2 additions & 0 deletions builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ pub mod testing {
Duration::from_millis(2000),
15,
Duration::from_millis(500),
ChainConfig::default().base_fee,
)
.await
.unwrap();
Expand Down Expand Up @@ -640,6 +641,7 @@ pub mod testing {
Duration::from_millis(2000),
15,
Duration::from_millis(500),
ChainConfig::default().base_fee,
)
.await
.unwrap();
Expand Down
7 changes: 3 additions & 4 deletions builder/src/non_permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use async_compatibility_layer::{
};
use async_std::sync::{Arc, RwLock};
use espresso_types::{
eth_signature_key::EthKeyPair, ChainConfig, L1Client, NodeState, Payload, SeqTypes,
eth_signature_key::EthKeyPair, ChainConfig, FeeAmount, L1Client, NodeState, Payload, SeqTypes,
ValidatedState,
};
use ethers::{
Expand Down Expand Up @@ -94,6 +94,7 @@ impl BuilderConfig {
max_api_timeout_duration: Duration,
buffered_view_num_count: usize,
maximize_txns_count_timeout_duration: Duration,
base_fee: FeeAmount,
) -> anyhow::Result<Self> {
tracing::info!(
address = %builder_key_pair.fee_account(),
Expand Down Expand Up @@ -168,9 +169,7 @@ impl BuilderConfig {
global_state_clone,
node_count,
maximize_txns_count_timeout_duration,
instance_state
.chain_config
.base_fee
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
9 changes: 5 additions & 4 deletions builder/src/permissioned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use async_std::{
use espresso_types::{
eth_signature_key::EthKeyPair,
v0::traits::{PersistenceOptions, SequencerPersistence, StateCatchup},
L1Client, NodeState, Payload, PubKey, SeqTypes, ValidatedState,
FeeAmount, L1Client, NodeState, Payload, PubKey, SeqTypes, ValidatedState,
};
use ethers::{
core::k256::ecdsa::SigningKey,
Expand Down Expand Up @@ -247,6 +247,7 @@ pub async fn init_node<P: SequencerPersistence, Ver: StaticVersionType + 'static
#[cfg(not(feature = "libp2p"))]
let network = Arc::from(cdn_network.clone());

let base_fee = genesis.max_base_fee();
let mut genesis_state = ValidatedState {
chain_config: genesis.chain_config.into(),
..Default::default()
Expand Down Expand Up @@ -311,6 +312,7 @@ 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 @@ -411,6 +413,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver: StaticVersionTyp
max_api_timeout_duration: Duration,
buffered_view_num_count: usize,
maximize_txns_count_timeout_duration: Duration,
base_fee: FeeAmount,
) -> anyhow::Result<Self> {
// tx channel
let (mut tx_sender, tx_receiver) =
Expand Down Expand Up @@ -476,9 +479,7 @@ impl<N: ConnectedNetwork<PubKey>, P: SequencerPersistence, Ver: StaticVersionTyp
global_state_clone,
NonZeroUsize::new(1).unwrap(),
maximize_txns_count_timeout_duration,
instance_state
.chain_config
.base_fee
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
4 changes: 2 additions & 2 deletions data/genesis/demo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ capacity = 10

[chain_config]
chain_id = 999999999
base_fee = '1 wei'
base_fee = '0 wei'
max_block_size = '1mb'
fee_recipient = '0x0000000000000000000000000000000000000000'
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'
Expand All @@ -18,7 +18,7 @@ stop_proposing_view = 15

[upgrade.chain_config]
chain_id = 999999999
base_fee = '2 wei'
base_fee = '1 wei'
max_block_size = '1mb'
fee_recipient = '0x0000000000000000000000000000000000000000'
fee_contract = '0xa15bb66138824a1c7167f5e85b957d04dd34e468'
22 changes: 21 additions & 1 deletion sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::{
};

use anyhow::Context;
use espresso_types::{ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, Upgrade};
use espresso_types::{
ChainConfig, FeeAccount, FeeAmount, GenesisHeader, L1BlockInfo, Upgrade, UpgradeType,
};
use serde::{Deserialize, Serialize};
use vbs::version::Version;

Expand Down Expand Up @@ -47,6 +49,24 @@ pub struct Genesis {
pub upgrades: BTreeMap<Version, Upgrade>,
}

impl Genesis {
pub fn max_base_fee(&self) -> FeeAmount {
let mut base_fee = self.chain_config.base_fee;

let upgrades: Vec<&Upgrade> = self.upgrades.values().collect();

for upgrade in upgrades {
match upgrade.upgrade_type {
UpgradeType::ChainConfig { chain_config } => {
base_fee = std::cmp::max(chain_config.base_fee, base_fee);
}
}
}

base_fee
}
}

mod upgrade_serialization {

use std::{collections::BTreeMap, fmt};
Expand Down
Loading