Skip to content

Commit

Permalink
Add default-gas-limit command line argument
Browse files Browse the repository at this point in the history
  • Loading branch information
povi committed Dec 10, 2024
1 parent 993779a commit 3d891c2
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions builder_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pub use crate::{
Config as BuilderConfig, DEFAULT_BUILDER_MAX_SKIPPED_SLOTS,
DEFAULT_BUILDER_MAX_SKIPPED_SLOTS_PER_EPOCH,
},
consts::PREFERRED_EXECUTION_GAS_LIMIT,
};

pub mod combined;
Expand Down
9 changes: 8 additions & 1 deletion grandine/src/grandine_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use anyhow::{ensure, Result};
use bls::PublicKeyBytes;
use builder_api::{
BuilderConfig, DEFAULT_BUILDER_MAX_SKIPPED_SLOTS, DEFAULT_BUILDER_MAX_SKIPPED_SLOTS_PER_EPOCH,
PREFERRED_EXECUTION_GAS_LIMIT,
};
use bytesize::ByteSize;
use clap::{error::ErrorKind, Args, CommandFactory as _, Error as ClapError, Parser, ValueEnum};
Expand Down Expand Up @@ -54,7 +55,7 @@ use std_ext::ArcExt as _;
use thiserror::Error;
use tower_http::cors::AllowOrigin;
use types::{
bellatrix::primitives::Difficulty,
bellatrix::primitives::{Difficulty, Gas},
config::Config as ChainConfig,
nonstandard::Phase,
phase0::primitives::{
Expand Down Expand Up @@ -720,6 +721,10 @@ struct ValidatorOptions {
#[clap(long, default_value_t = DEFAULT_BUILDER_MAX_SKIPPED_SLOTS_PER_EPOCH)]
builder_max_skipped_slots_per_epoch: u64,

/// Default execution gas limit for all validators
#[clap(long, default_value_t = PREFERRED_EXECUTION_GAS_LIMIT)]
default_gas_limit: Gas,

/// List of public keys to use from Web3Signer
#[clap(long, num_args = 1.., value_delimiter = ',')]
web3signer_public_keys: Vec<PublicKeyBytes>,
Expand Down Expand Up @@ -922,6 +927,7 @@ impl GrandineArgs {
builder_disable_checks,
builder_max_skipped_slots,
builder_max_skipped_slots_per_epoch,
default_gas_limit,
use_validator_key_cache,
web3signer_public_keys,
web3signer_refresh_keys_every_epoch,
Expand Down Expand Up @@ -1238,6 +1244,7 @@ impl GrandineArgs {
graffiti,
max_empty_slots,
suggested_fee_recipient: suggested_fee_recipient.unwrap_or(GRANDINE_DONATION_ADDRESS),
default_gas_limit,
network_config: network_config_options.into_config(
network,
directories.network_dir.clone().unwrap_or_default(),
Expand Down
2 changes: 2 additions & 0 deletions grandine/src/grandine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use p2p::NetworkConfig;
use runtime::{MetricsConfig, StorageConfig};
use signer::Web3SignerConfig;
use types::{
bellatrix::primitives::Gas,
config::Config as ChainConfig,
phase0::primitives::{ExecutionAddress, ExecutionBlockNumber, Slot, H256},
redacting_url::RedactingUrl,
Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct GrandineConfig {
pub graffiti: Vec<H256>,
pub max_empty_slots: u64,
pub suggested_fee_recipient: ExecutionAddress,
pub default_gas_limit: Gas,
pub network_config: NetworkConfig,
pub storage_config: StorageConfig,
pub unfinalized_states_in_memory: u64,
Expand Down
2 changes: 2 additions & 0 deletions grandine/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ fn try_main() -> Result<()> {
graffiti,
max_empty_slots,
suggested_fee_recipient,
default_gas_limit,
network_config,
storage_config,
request_timeout,
Expand Down Expand Up @@ -416,6 +417,7 @@ fn try_main() -> Result<()> {
graffiti,
max_empty_slots,
suggested_fee_recipient,
default_gas_limit,
keystore_storage_password_file,
});

Expand Down
1 change: 1 addition & 0 deletions http_api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ impl<P: Preset> Context<P> {
slashing_protector.clone_arc(),
anchor_state.genesis_validators_root(),
validator_config.suggested_fee_recipient,
validator_config.default_gas_limit,
H256::default(),
));

Expand Down
1 change: 0 additions & 1 deletion keymanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ authors = ["Grandine <info@grandine.io>"]
[dependencies]
anyhow = { workspace = true }
bls = { workspace = true }
builder_api = { workspace = true }
bytesize = { workspace = true }
database = { workspace = true }
derive_more = { workspace = true }
Expand Down
6 changes: 6 additions & 0 deletions keymanager/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pub use keystores::{load_key_storage, load_key_storage_password, ValidatingPubkey};
pub use misc::OperationStatus as KeymanagerOperationStatus;
pub use remote_keys::{ListedRemoteKey, RemoteKey};
pub use types::bellatrix::primitives::Gas;

pub use crate::proposer_configs::ProposerConfigs;

Expand Down Expand Up @@ -35,10 +36,12 @@ impl KeyManager {
slashing_protector: Arc<Mutex<SlashingProtector>>,
genesis_validators_root: H256,
default_fee_recipient: ExecutionAddress,
default_gas_limit: Gas,
default_graffiti: H256,
) -> Self {
let proposer_configs = Arc::new(ProposerConfigs::new_in_memory(
default_fee_recipient,
default_gas_limit,
default_graffiti,
));

Expand All @@ -57,18 +60,21 @@ impl KeyManager {
}
}

#[expect(clippy::too_many_arguments)]
pub fn new_persistent(
signer: Arc<Signer>,
slashing_protector: Arc<Mutex<SlashingProtector>>,
genesis_validators_root: H256,
validator_directory: PathBuf,
keystore_storage_password_path: Option<&Path>,
default_fee_recipient: ExecutionAddress,
default_gas_limit: Gas,
default_graffiti: H256,
) -> Result<Self> {
let proposer_configs = Arc::new(ProposerConfigs::new_persistent(
&validator_directory,
default_fee_recipient,
default_gas_limit,
default_graffiti,
)?);

Expand Down
28 changes: 20 additions & 8 deletions keymanager/src/proposer_configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::{path::Path, str};

use anyhow::{ensure, Result};
use bls::PublicKeyBytes;
use builder_api::consts::PREFERRED_EXECUTION_GAS_LIMIT;
use bytesize::ByteSize;
use database::Database;
use derive_more::Display;
Expand All @@ -19,24 +18,31 @@ const DB_MAX_SIZE: ByteSize = ByteSize::gib(1);
pub struct ProposerConfigs {
database: Database,
default_fee_recipient: ExecutionAddress,
default_gas_limit: Gas,
default_graffiti: H256,
}

impl ProposerConfigs {
#[must_use]
pub fn new_in_memory(default_fee_recipient: ExecutionAddress, default_graffiti: H256) -> Self {
pub fn new_in_memory(
default_fee_recipient: ExecutionAddress,
default_gas_limit: Gas,
default_graffiti: H256,
) -> Self {
let database = Database::in_memory();

Self {
database,
default_fee_recipient,
default_gas_limit,
default_graffiti,
}
}

pub fn new_persistent(
validator_directory: &Path,
default_fee_recipient: ExecutionAddress,
default_gas_limit: Gas,
default_graffiti: H256,
) -> Result<Self> {
let database =
Expand All @@ -45,6 +51,7 @@ impl ProposerConfigs {
Ok(Self {
database,
default_fee_recipient,
default_gas_limit,
default_graffiti,
})
}
Expand All @@ -70,7 +77,7 @@ impl ProposerConfigs {
pub fn gas_limit(&self, pubkey: PublicKeyBytes) -> Result<Gas> {
let gas_limit = self.db_get(GasLimitByPubkey(pubkey))?;

Ok(gas_limit.unwrap_or(PREFERRED_EXECUTION_GAS_LIMIT))
Ok(gas_limit.unwrap_or(self.default_gas_limit))
}

pub fn set_gas_limit(&self, pubkey: PublicKeyBytes, gas_limit: Gas) -> Result<()> {
Expand Down Expand Up @@ -165,18 +172,23 @@ mod tests {

const DEFAULT_GRAFFITI: &str = "Grandine";
const DEFAULT_FEE_RECIPIENT: ExecutionAddress = ExecutionAddress::repeat_byte(1);
const DEFAULT_GAS_LIMIT: Gas = 30_000_000;
const TEST_FEE_RECIPIENT: ExecutionAddress = ExecutionAddress::repeat_byte(2);
const PUBKEY: PublicKeyBytes = PublicKeyBytes::repeat_byte(1);

fn build_proposer_configs(validator_dir: Option<&Path>) -> Result<ProposerConfigs> {
let graffiti_bytes = parse_graffiti(DEFAULT_GRAFFITI)?;

match validator_dir {
Some(dir) => {
ProposerConfigs::new_persistent(dir, DEFAULT_FEE_RECIPIENT, graffiti_bytes)
}
Some(dir) => ProposerConfigs::new_persistent(
dir,
DEFAULT_FEE_RECIPIENT,
DEFAULT_GAS_LIMIT,
graffiti_bytes,
),
None => Ok(ProposerConfigs::new_in_memory(
DEFAULT_FEE_RECIPIENT,
DEFAULT_GAS_LIMIT,
graffiti_bytes,
)),
}
Expand Down Expand Up @@ -226,7 +238,7 @@ mod tests {

let gas_limit = proposer_configs.gas_limit(PUBKEY)?;

assert_eq!(gas_limit, PREFERRED_EXECUTION_GAS_LIMIT);
assert_eq!(gas_limit, DEFAULT_GAS_LIMIT);

Ok(())
}
Expand All @@ -253,7 +265,7 @@ mod tests {

let gas_limit = proposer_configs.gas_limit(PUBKEY)?;

assert_eq!(gas_limit, PREFERRED_EXECUTION_GAS_LIMIT);
assert_eq!(gas_limit, DEFAULT_GAS_LIMIT);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ pub async fn run_after_genesis<P: Preset>(
slashing_protector.clone_arc(),
anchor_state.genesis_validators_root(),
validator_config.suggested_fee_recipient,
validator_config.default_gas_limit,
graffiti,
))
} else {
Expand All @@ -457,6 +458,7 @@ pub async fn run_after_genesis<P: Preset>(
directories.validator_dir.clone().unwrap_or_default(),
validator_config.keystore_storage_password_file.as_deref(),
validator_config.suggested_fee_recipient,
validator_config.default_gas_limit,
graffiti,
)?)
};
Expand Down
6 changes: 5 additions & 1 deletion validator/src/validator_config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use std::path::PathBuf;

use derivative::Derivative;
use types::phase0::primitives::{ExecutionAddress, H256};
use types::{
bellatrix::primitives::Gas,
phase0::primitives::{ExecutionAddress, H256},
};

#[derive(Clone, Debug, Derivative)]
#[derivative(Default)]
Expand All @@ -10,5 +13,6 @@ pub struct ValidatorConfig {
#[derivative(Default(value = "32"))]
pub max_empty_slots: u64,
pub suggested_fee_recipient: ExecutionAddress,
pub default_gas_limit: Gas,
pub keystore_storage_password_file: Option<PathBuf>,
}

0 comments on commit 3d891c2

Please sign in to comment.