Skip to content

Commit

Permalink
Merge branch 'sb-sync-main-sls' into sb-additional-server-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavBreadless committed Dec 18, 2024
2 parents 4f09340 + fa83edd commit e8b245e
Show file tree
Hide file tree
Showing 15 changed files with 34 additions and 56 deletions.
16 changes: 10 additions & 6 deletions core/lib/config/src/configs/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ impl EthConfig {
max_base_fee_samples: 10000,
pricing_formula_parameter_a: 1.5,
pricing_formula_parameter_b: 1.0005,
internal_sl_pricing_multiplier: 0.8,
internal_enforced_sl_gas_price: None,
internal_l1_pricing_multiplier: 0.8,
internal_enforced_l1_gas_price: None,
internal_enforced_pubdata_price: None,
poll_period: 5,
max_l1_gas_price: None,
Expand Down Expand Up @@ -193,10 +193,14 @@ pub struct GasAdjusterConfig {
/// Parameter of the transaction base_fee_per_gas pricing formula
#[serde(default = "GasAdjusterConfig::default_pricing_formula_parameter_b")]
pub pricing_formula_parameter_b: f64,
/// Parameter by which the base fee will be multiplied for internal purposes
pub internal_sl_pricing_multiplier: f64,
/// If equal to Some(x), then it will always provide `x` as the L1 gas price
pub internal_enforced_sl_gas_price: Option<u64>,
/// Parameter by which the base fee will be multiplied for internal purposes.
/// TODO(EVM-920): Note, that while the name says "L1", this same parameter is actually used for
/// any settlement layer.
pub internal_l1_pricing_multiplier: f64,
/// If equal to Some(x), then it will always provide `x` as the L1 gas price.
/// TODO(EVM-920): Note, that while the name says "L1", this same parameter is actually used for
/// any settlement layer.
pub internal_enforced_l1_gas_price: Option<u64>,
/// If equal to Some(x), then it will always provide `x` as the pubdata price
pub internal_enforced_pubdata_price: Option<u64>,
/// Node polling period in seconds
Expand Down
4 changes: 2 additions & 2 deletions core/lib/config/src/testonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ impl Distribution<configs::eth_sender::GasAdjusterConfig> for EncodeDist {
max_base_fee_samples: self.sample(rng),
pricing_formula_parameter_a: self.sample(rng),
pricing_formula_parameter_b: self.sample(rng),
internal_sl_pricing_multiplier: self.sample(rng),
internal_enforced_sl_gas_price: self.sample(rng),
internal_l1_pricing_multiplier: self.sample(rng),
internal_enforced_l1_gas_price: self.sample(rng),
internal_enforced_pubdata_price: self.sample(rng),
poll_period: self.sample(rng),
max_l1_gas_price: self.sample(rng),
Expand Down
4 changes: 2 additions & 2 deletions core/lib/env_config/src/eth_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ mod tests {
max_base_fee_samples: 10000,
pricing_formula_parameter_a: 1.5,
pricing_formula_parameter_b: 1.0005,
internal_sl_pricing_multiplier: 0.8,
internal_enforced_sl_gas_price: None,
internal_l1_pricing_multiplier: 0.8,
internal_enforced_l1_gas_price: None,
internal_enforced_pubdata_price: None,
poll_period: 15,
max_l1_gas_price: Some(100000000),
Expand Down
10 changes: 5 additions & 5 deletions core/lib/protobuf_config/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ impl ProtoRepr for proto::GasAdjuster {
.unwrap_or(&Self::Type::default_pricing_formula_parameter_a()),
pricing_formula_parameter_b: *required(&self.pricing_formula_parameter_b)
.unwrap_or(&Self::Type::default_pricing_formula_parameter_b()),
internal_sl_pricing_multiplier: *required(&self.internal_sl_pricing_multiplier)
.context("internal_sl_pricing_multiplier")?,
internal_enforced_sl_gas_price: self.internal_enforced_sl_gas_price,
internal_l1_pricing_multiplier: *required(&self.internal_l1_pricing_multiplier)
.context("internal_l1_pricing_multiplier")?,
internal_enforced_l1_gas_price: self.internal_enforced_l1_gas_price,
internal_enforced_pubdata_price: self.internal_enforced_pubdata_price,
poll_period: *required(&self.poll_period).context("poll_period")?,
max_l1_gas_price: self.max_l1_gas_price,
Expand Down Expand Up @@ -206,8 +206,8 @@ impl ProtoRepr for proto::GasAdjuster {
max_base_fee_samples: Some(this.max_base_fee_samples.try_into().unwrap()),
pricing_formula_parameter_a: Some(this.pricing_formula_parameter_a),
pricing_formula_parameter_b: Some(this.pricing_formula_parameter_b),
internal_sl_pricing_multiplier: Some(this.internal_sl_pricing_multiplier),
internal_enforced_sl_gas_price: this.internal_enforced_sl_gas_price,
internal_l1_pricing_multiplier: Some(this.internal_l1_pricing_multiplier),
internal_enforced_l1_gas_price: this.internal_enforced_l1_gas_price,
internal_enforced_pubdata_price: this.internal_enforced_pubdata_price,
poll_period: Some(this.poll_period),
max_l1_gas_price: this.max_l1_gas_price,
Expand Down
4 changes: 2 additions & 2 deletions core/lib/protobuf_config/src/proto/config/eth_sender.proto
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ message GasAdjuster {
optional uint64 max_base_fee_samples = 2; // required;
optional double pricing_formula_parameter_a = 3; // required
optional double pricing_formula_parameter_b = 4; // required
optional double internal_sl_pricing_multiplier = 5; // required
optional uint64 internal_enforced_sl_gas_price = 6; // optional; wei
optional double internal_l1_pricing_multiplier = 5; // required
optional uint64 internal_enforced_l1_gas_price = 6; // optional; wei
optional uint64 internal_enforced_pubdata_price = 12; // optional; wei
optional uint64 poll_period = 7; // required; s
optional uint64 max_l1_gas_price = 8; // optional; wei?
Expand Down
4 changes: 2 additions & 2 deletions core/node/fee_model/src/l1_gas_price/gas_adjuster/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ impl GasAdjuster {
/// Returns the sum of base and priority fee, in wei, not considering time in mempool.
/// Can be used to get an estimate of current gas price.
pub(crate) fn estimate_effective_gas_price(&self) -> u64 {
if let Some(price) = self.config.internal_enforced_sl_gas_price {
if let Some(price) = self.config.internal_enforced_l1_gas_price {
return price;
}

let effective_gas_price = self.get_base_fee(0) + self.get_priority_fee();

let calculated_price =
(self.config.internal_sl_pricing_multiplier * effective_gas_price as f64) as u64;
(self.config.internal_l1_pricing_multiplier * effective_gas_price as f64) as u64;

// Bound the price if it's too high.
self.bound_gas_price(calculated_price)
Expand Down
4 changes: 2 additions & 2 deletions core/node/fee_model/src/l1_gas_price/gas_adjuster/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ fn test_config(settlement_mode: SettlementMode) -> GasAdjusterConfig {
max_base_fee_samples: 5,
pricing_formula_parameter_a: 1.5,
pricing_formula_parameter_b: 1.0005,
internal_sl_pricing_multiplier: 0.8,
internal_enforced_sl_gas_price: None,
internal_l1_pricing_multiplier: 0.8,
internal_enforced_l1_gas_price: None,
internal_enforced_pubdata_price: None,
poll_period: 5,
max_l1_gas_price: None,
Expand Down
2 changes: 1 addition & 1 deletion core/node/fee_model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mod tests {
mock.advance_block_number(2); // Ensure we have enough blocks for the fee history

let gas_adjuster_config = GasAdjusterConfig {
internal_enforced_sl_gas_price: Some(l1_gas_price),
internal_enforced_l1_gas_price: Some(l1_gas_price),
internal_enforced_pubdata_price: Some(l1_pubdata_price),
max_base_fee_samples: 1, // Ensure this is less than the number of blocks
num_samples_for_blob_base_fee_estimate: 2,
Expand Down
4 changes: 2 additions & 2 deletions core/node/state_keeper/src/io/tests/tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl Tester {
max_base_fee_samples: 10,
pricing_formula_parameter_a: 1.0,
pricing_formula_parameter_b: 1.0,
internal_sl_pricing_multiplier: 1.0,
internal_enforced_sl_gas_price: None,
internal_l1_pricing_multiplier: 1.0,
internal_enforced_l1_gas_price: None,
internal_enforced_pubdata_price: None,
poll_period: 10,
max_l1_gas_price: None,
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guides/advanced/07_fee_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ decentralized, more deterministic rules will be established for this price.

The L1 gas price is fetched by querying L1 every 20 seconds. This is managed by the [`GasAdjuster`][gas_adjuster], which
calculates the median price from recent blocks and enables more precise price control via the config (for example,
adjusting the price with `internal_sl_pricing_multiplier` or setting a specific value using
`internal_enforced_sl_gas_price`).
adjusting the price with `internal_l1_pricing_multiplier` or setting a specific value using
`internal_enforced_l1_gas_price`).

### Overhead gas

Expand Down
2 changes: 1 addition & 1 deletion etc/env/base/eth_sender.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ max_base_fee_samples = 10_000
# To confirm, see core/bin/zksync_core/src/eth_sender/gas_adjuster/mod.rs
pricing_formula_parameter_a = 1.5
pricing_formula_parameter_b = 1.0005
internal_sl_pricing_multiplier = 0.8
internal_l1_pricing_multiplier = 0.8
# Node polling period in seconds.
poll_period = 5
2 changes: 1 addition & 1 deletion etc/env/file_based/general.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ eth:
max_base_fee_samples: 100
pricing_formula_parameter_a: 1.5
pricing_formula_parameter_b: 1.001
internal_sl_pricing_multiplier: 0.8
internal_l1_pricing_multiplier: 0.8
num_samples_for_blob_base_fee_estimate: 10
internal_pubdata_pricing_multiplier: 1.0
poll_period: 5
Expand Down
2 changes: 1 addition & 1 deletion etc/env/file_based/overrides/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ eth:
wait_confirmations: null
gas_adjuster:
pricing_formula_parameter_a: 1.06
internal_sl_pricing_multiplier: 1
internal_l1_pricing_multiplier: 1
internal_pubdata_pricing_multiplier: 1.50
poll_period: 60
watcher:
Expand Down
2 changes: 1 addition & 1 deletion etc/env/file_based/overrides/testnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ eth:
wait_confirmations: null
gas_adjuster:
pricing_formula_parameter_a: 1.1
internal_sl_pricing_multiplier: 1
internal_l1_pricing_multiplier: 1
poll_period: 60
watcher:
confirmations_for_eth_event: 10
Expand Down
26 changes: 0 additions & 26 deletions zkstack_cli/crates/zkstack/src/commands/chain/gateway_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,23 +146,6 @@ pub fn encode_ntv_asset_id(l1_chain_id: U256, addr: Address) -> H256 {
H256(keccak256(&encoded_data))
}

fn replace_in_file(file_path: &str, target: &str, replacement: &str) -> std::io::Result<()> {
// Read the file content
let content = std::fs::read_to_string(file_path)?;

// Replace all occurrences of the target substring
let modified_content = content.replace(target, replacement);

// Write the modified content back to the file
let mut file = std::fs::OpenOptions::new()
.write(true)
.truncate(true) // Clear the file before writing
.open(file_path)?;

file.write_all(modified_content.as_bytes())?;
Ok(())
}

async fn adapt_config(shell: &Shell, chain_config: ChainConfig) -> anyhow::Result<()> {
println!("Adapting config");
let mut contracts_config = chain_config.get_contracts_config()?;
Expand All @@ -175,15 +158,6 @@ async fn adapt_config(shell: &Shell, chain_config: ChainConfig) -> anyhow::Resul
));

contracts_config.save_with_base_path(shell, &chain_config.configs)?;

replace_in_file(
chain_config
.path_to_general_config()
.to_str()
.context("failed to get general config path")?,
"internal_l1_pricing_multiplier",
"internal_sl_pricing_multiplier",
)?;
println!("Done");

Ok(())
Expand Down

0 comments on commit e8b245e

Please sign in to comment.