From 1a51aa6f8b2e7fbf35c982ee55718a40d9171e7d Mon Sep 17 00:00:00 2001 From: Goshawk Date: Wed, 14 Aug 2024 12:38:28 +0300 Subject: [PATCH 1/5] consensus: Retrieve block_gas_limit from the Executor --- consensus/src/config.rs | 2 -- consensus/src/operations.rs | 3 ++- consensus/src/proposal/block_generator.rs | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/consensus/src/config.rs b/consensus/src/config.rs index 746e1b9586..2698d748fc 100644 --- a/consensus/src/config.rs +++ b/consensus/src/config.rs @@ -23,8 +23,6 @@ pub const RATIFICATION_COMMITTEE_CREDITS: usize = 64; pub const RATIFICATION_COMMITTEE_QUORUM: f64 = RATIFICATION_COMMITTEE_CREDITS as f64 * SUPERMAJORITY_THRESHOLD; -pub const DEFAULT_BLOCK_GAS_LIMIT: u64 = 5 * 1_000_000_000; - pub const RELAX_ITERATION_THRESHOLD: u8 = 8; /// Emergency mode is enabled after 16 iterations diff --git a/consensus/src/operations.rs b/consensus/src/operations.rs index 3011102cfb..482f48fcc2 100644 --- a/consensus/src/operations.rs +++ b/consensus/src/operations.rs @@ -50,7 +50,6 @@ impl From for Error { #[derive(Default, Clone, Debug)] pub struct CallParams { pub round: u64, - pub block_gas_limit: u64, pub generator_pubkey: node_data::bls::PublicKey, pub to_slash: Vec, pub voters_pubkey: Option>, @@ -111,4 +110,6 @@ pub trait Operations: Send + Sync { step_name: StepName, elapsed: Duration, ) -> Result<(), Error>; + + async fn get_block_gas_limit(&self) -> u64; } diff --git a/consensus/src/proposal/block_generator.rs b/consensus/src/proposal/block_generator.rs index d38f8c2c03..854bb4c5e3 100644 --- a/consensus/src/proposal/block_generator.rs +++ b/consensus/src/proposal/block_generator.rs @@ -11,7 +11,6 @@ use node_data::ledger::{ }; use std::cmp::max; -use crate::config; use crate::merkle::merkle_root; use crate::config::MINIMUM_BLOCK_TIME; @@ -97,7 +96,6 @@ impl Generator { let call_params = CallParams { round: ru.round, - block_gas_limit: config::DEFAULT_BLOCK_GAS_LIMIT, generator_pubkey: ru.pubkey_bls.clone(), to_slash, voters_pubkey: Some(voters.to_owned()), @@ -106,6 +104,8 @@ impl Generator { let result = self.executor.execute_state_transition(call_params).await?; + let block_gas_limit = self.executor.get_block_gas_limit().await; + let tx_hashes: Vec<_> = result.txs.iter().map(|t| t.inner.hash()).collect(); let txs: Vec<_> = result.txs.into_iter().map(|t| t.inner).collect(); @@ -122,7 +122,7 @@ impl Generator { version: 0, height: ru.round, timestamp, - gas_limit: config::DEFAULT_BLOCK_GAS_LIMIT, + gas_limit: block_gas_limit, prev_block_hash, seed, generator_bls_pubkey: *ru.pubkey_bls.bytes(), From 9feb3c4e827b3150b6edfac0ccea81f23f99ec52 Mon Sep 17 00:00:00 2001 From: Goshawk Date: Wed, 14 Aug 2024 12:39:24 +0300 Subject: [PATCH 2/5] rusk: Provide block_gas_limit getters --- rusk/src/bin/config/chain.rs | 14 +++++++++++--- rusk/src/bin/main.rs | 1 + rusk/src/lib/node.rs | 1 + rusk/src/lib/node/rusk.rs | 8 +++++++- rusk/src/lib/node/vm.rs | 4 ++++ 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/rusk/src/bin/config/chain.rs b/rusk/src/bin/config/chain.rs index 01ecfce0cf..fff953373b 100644 --- a/rusk/src/bin/config/chain.rs +++ b/rusk/src/bin/config/chain.rs @@ -9,6 +9,8 @@ use std::{path::PathBuf, time::Duration}; use node::database::DatabaseOptions; use serde::{Deserialize, Serialize}; +pub const DEFAULT_BLOCK_GAS_LIMIT: u64 = 5 * 1_000_000_000; + use crate::args::Args; #[derive(Serialize, Deserialize, Clone, Default)] @@ -19,11 +21,13 @@ pub(crate) struct ChainConfig { consensus_keys_path: Option, #[serde(with = "humantime_serde")] generation_timeout: Option, - // Note: changing the gas per deploy byte parameter is equivalent to - // forking the chain. - gas_per_deploy_byte: Option, max_queue_size: Option, + + // NB: changing the gas_per_deploy_byte/block_gas_limit is equivalent to + // forking the chain. + gas_per_deploy_byte: Option, + block_gas_limit: Option, } impl ChainConfig { @@ -78,4 +82,8 @@ impl ChainConfig { pub(crate) fn max_queue_size(&self) -> usize { self.max_queue_size.unwrap_or(10_000) } + + pub(crate) fn block_gas_limit(&self) -> u64 { + self.block_gas_limit.unwrap_or(DEFAULT_BLOCK_GAS_LIMIT) + } } diff --git a/rusk/src/bin/main.rs b/rusk/src/bin/main.rs index 8a264c607e..b798d78306 100644 --- a/rusk/src/bin/main.rs +++ b/rusk/src/bin/main.rs @@ -66,6 +66,7 @@ async fn main() -> Result<(), Box> { state_dir, config.chain.generation_timeout(), config.chain.gas_per_deploy_byte(), + config.chain.block_gas_limit(), config.http.feeder_call_gas, _event_sender.clone(), )?; diff --git a/rusk/src/lib/node.rs b/rusk/src/lib/node.rs index 392031f51a..4e33f6e8c4 100644 --- a/rusk/src/lib/node.rs +++ b/rusk/src/lib/node.rs @@ -45,6 +45,7 @@ pub struct Rusk { pub(crate) generation_timeout: Option, pub(crate) gas_per_deploy_byte: Option, pub(crate) feeder_gas_limit: u64, + pub(crate) block_gas_limit: u64, pub(crate) event_sender: broadcast::Sender, } diff --git a/rusk/src/lib/node/rusk.rs b/rusk/src/lib/node/rusk.rs index 32cfcc2de3..a558863236 100644 --- a/rusk/src/lib/node/rusk.rs +++ b/rusk/src/lib/node/rusk.rs @@ -55,6 +55,7 @@ impl Rusk { dir: P, generation_timeout: Option, gas_per_deploy_byte: Option, + block_gas_limit: u64, feeder_gas_limit: u64, event_sender: broadcast::Sender, ) -> Result { @@ -90,6 +91,7 @@ impl Rusk { gas_per_deploy_byte, feeder_gas_limit, event_sender, + block_gas_limit, }) } @@ -102,7 +104,7 @@ impl Rusk { let started = Instant::now(); let block_height = params.round; - let block_gas_limit = params.block_gas_limit; + let block_gas_limit = self.block_gas_limit; let generator = params.generator_pubkey.inner(); let to_slash = params.to_slash.clone(); @@ -418,6 +420,10 @@ impl Rusk { // finalization to wait, we spawn a new task to delete the commits. task::spawn(delete_commits(self.vm.clone(), to_delete)); } + + pub(crate) fn block_gas_limit(&self) -> u64 { + self.block_gas_limit + } } async fn delete_commits(vm: Arc, commits: Vec<[u8; 32]>) { diff --git a/rusk/src/lib/node/vm.rs b/rusk/src/lib/node/vm.rs index 918f4161eb..ad85255941 100644 --- a/rusk/src/lib/node/vm.rs +++ b/rusk/src/lib/node/vm.rs @@ -214,6 +214,10 @@ impl VMExecution for Rusk { Ok(state_hash) } + + fn get_block_gas_limit(&self) -> u64 { + self.block_gas_limit() + } } impl Rusk { From bfa3ade2d0983d075c7d8e24270b0174c73e7bca Mon Sep 17 00:00:00 2001 From: Goshawk Date: Wed, 14 Aug 2024 12:40:20 +0300 Subject: [PATCH 3/5] node: Provide block_gas_limit getters --- node/default.config.toml | 1 + node/src/chain/consensus.rs | 4 ++++ node/src/vm.rs | 3 +++ 3 files changed, 8 insertions(+) diff --git a/node/default.config.toml b/node/default.config.toml index 2661b8f403..c4a200ce3a 100644 --- a/node/default.config.toml +++ b/node/default.config.toml @@ -6,6 +6,7 @@ db_path = '/tmp/rusk-harness/' consensus_keys_path = '/tmp/consensus_bls.keys' generation_timeout = '3s' max_queue_size = 5000 +block_gas_limit = 5000000000 [chain.db_options] enable_debug = false diff --git a/node/src/chain/consensus.rs b/node/src/chain/consensus.rs index d2838cad01..d8150151bd 100644 --- a/node/src/chain/consensus.rs +++ b/node/src/chain/consensus.rs @@ -361,4 +361,8 @@ impl Operations for Executor { Ok(()) } + + async fn get_block_gas_limit(&self) -> u64 { + self.vm.read().await.get_block_gas_limit() + } } diff --git a/node/src/vm.rs b/node/src/vm.rs index 72d2f9361a..8e29e30184 100644 --- a/node/src/vm.rs +++ b/node/src/vm.rs @@ -66,6 +66,9 @@ pub trait VMExecution: Send + Sync + 'static { /// Returns last finalized state root fn get_finalized_state_root(&self) -> anyhow::Result<[u8; 32]>; + /// Returns block gas limit + fn get_block_gas_limit(&self) -> u64; + fn revert(&self, state_hash: [u8; 32]) -> anyhow::Result<[u8; 32]>; fn revert_to_finalized(&self) -> anyhow::Result<[u8; 32]>; } From 4592fe21cfb992343c744277abd0ebd54ba22a6c Mon Sep 17 00:00:00 2001 From: Goshawk Date: Mon, 19 Aug 2024 12:32:22 +0300 Subject: [PATCH 4/5] rusk: Pass proper block_gas_limit value to new_state --- rusk/benches/block_ingestion.rs | 5 ++++- rusk/tests/common/state.rs | 9 ++++++--- rusk/tests/rusk-state.rs | 7 ++++--- rusk/tests/services/contract_deployment.rs | 2 +- rusk/tests/services/gas_behavior.rs | 2 +- rusk/tests/services/multi_transfer.rs | 2 +- rusk/tests/services/stake.rs | 4 ++-- rusk/tests/services/transfer.rs | 2 +- rusk/tests/services/unspendable.rs | 2 +- 9 files changed, 21 insertions(+), 14 deletions(-) diff --git a/rusk/benches/block_ingestion.rs b/rusk/benches/block_ingestion.rs index 84962d803c..1bcb328320 100644 --- a/rusk/benches/block_ingestion.rs +++ b/rusk/benches/block_ingestion.rs @@ -29,6 +29,8 @@ use tempfile::tempdir; use common::state::new_state; +const BLOCK_GAS_LIMIT: u64 = 1_000_000_000_000; + fn load_phoenix_txs() -> Vec { // The file "phoenix-txs" can be generated using // `generate_phoenix_txs()` in "tests/rusk-state.rs". @@ -164,7 +166,8 @@ pub fn accept_benchmark(c: &mut Criterion) { let snapshot = toml::from_str(include_str!("../tests/config/bench.toml")) .expect("Cannot deserialize config"); - let rusk = new_state(&tmp, &snapshot).expect("Creating state should work"); + let rusk = new_state(&tmp, &snapshot, BLOCK_GAS_LIMIT) + .expect("Creating state should work"); let phoenix_txs = load_phoenix_txs(); let moonlight_txs = load_moonlight_txs(); diff --git a/rusk/tests/common/state.rs b/rusk/tests/common/state.rs index e4c3965c2a..ee97c9c8a6 100644 --- a/rusk/tests/common/state.rs +++ b/rusk/tests/common/state.rs @@ -30,7 +30,11 @@ use tracing::info; use crate::common::keys::STAKE_SK; // Creates a Rusk initial state in the given directory -pub fn new_state>(dir: P, snapshot: &Snapshot) -> Result { +pub fn new_state>( + dir: P, + snapshot: &Snapshot, + block_gas_limit: u64, +) -> Result { let dir = dir.as_ref(); let (_, commit_id) = state::deploy(dir, snapshot, |_| {}) @@ -38,7 +42,7 @@ pub fn new_state>(dir: P, snapshot: &Snapshot) -> Result { let (sender, _) = broadcast::channel(10); - let rusk = Rusk::new(dir, None, None, u64::MAX, sender) + let rusk = Rusk::new(dir, None, None, block_gas_limit, u64::MAX, sender) .expect("Instantiating rusk should succeed"); assert_eq!( @@ -109,7 +113,6 @@ pub fn generator_procedure( let call_params = CallParams { round, - block_gas_limit, generator_pubkey, to_slash, voters_pubkey: None, diff --git a/rusk/tests/rusk-state.rs b/rusk/tests/rusk-state.rs index 5656a46224..ecdb1982a3 100644 --- a/rusk/tests/rusk-state.rs +++ b/rusk/tests/rusk-state.rs @@ -35,6 +35,7 @@ use tracing::info; use crate::common::state::new_state; const BLOCK_HEIGHT: u64 = 1; +const BLOCK_GAS_LIMIT: u64 = 100_000_000_000; const INITIAL_BALANCE: u64 = 10_000_000_000; // Creates the Rusk initial state for the tests below @@ -42,7 +43,7 @@ fn initial_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("./config/rusk-state.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } fn leaves_from_height(rusk: &Rusk, height: u64) -> Result> { @@ -183,7 +184,7 @@ async fn generate_phoenix_txs() -> Result<(), Box> { let snapshot = toml::from_str(include_str!("./config/bench.toml")) .expect("Cannot deserialize config"); - let rusk = new_state(&tmp, &snapshot)?; + let rusk = new_state(&tmp, &snapshot, 100_000_000_000)?; let cache = Arc::new(std::sync::RwLock::new(std::collections::HashMap::new())); @@ -248,7 +249,7 @@ async fn generate_moonlight_txs() -> Result<(), Box> { let snapshot = toml::from_str(include_str!("./config/bench.toml")) .expect("Cannot deserialize config"); - let rusk = new_state(&tmp, &snapshot)?; + let rusk = new_state(&tmp, &snapshot, 100_000_000_000)?; let cache = Arc::new(std::sync::RwLock::new(std::collections::HashMap::new())); diff --git a/rusk/tests/services/contract_deployment.rs b/rusk/tests/services/contract_deployment.rs index 4cbf3b6035..59db166d7d 100644 --- a/rusk/tests/services/contract_deployment.rs +++ b/rusk/tests/services/contract_deployment.rs @@ -95,7 +95,7 @@ fn initial_state>(dir: P, deploy_bob: bool) -> Result { let (sender, _) = broadcast::channel(10); - let rusk = Rusk::new(dir, None, None, u64::MAX, sender) + let rusk = Rusk::new(dir, None, None, BLOCK_GAS_LIMIT, u64::MAX, sender) .expect("Instantiating rusk should succeed"); Ok(rusk) } diff --git a/rusk/tests/services/gas_behavior.rs b/rusk/tests/services/gas_behavior.rs index 31a0e3678d..d6f1ce9b4f 100644 --- a/rusk/tests/services/gas_behavior.rs +++ b/rusk/tests/services/gas_behavior.rs @@ -35,7 +35,7 @@ fn initial_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("../config/gas-behavior.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } const SENDER_INDEX_0: u64 = 0; diff --git a/rusk/tests/services/multi_transfer.rs b/rusk/tests/services/multi_transfer.rs index 4619bcf650..a51c0c0439 100644 --- a/rusk/tests/services/multi_transfer.rs +++ b/rusk/tests/services/multi_transfer.rs @@ -32,7 +32,7 @@ fn initial_state>(dir: P) -> Result { toml::from_str(include_str!("../config/multi_transfer.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } /// Executes three different transactions in the same block, expecting only two diff --git a/rusk/tests/services/stake.rs b/rusk/tests/services/stake.rs index 5dbf9e8cd8..790e973de9 100644 --- a/rusk/tests/services/stake.rs +++ b/rusk/tests/services/stake.rs @@ -35,7 +35,7 @@ fn stake_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("../config/stake.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } // Creates the Rusk initial state for the tests below @@ -43,7 +43,7 @@ fn slash_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("../config/slash.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } /// Stakes an amount Dusk and produces a block with this single transaction, diff --git a/rusk/tests/services/transfer.rs b/rusk/tests/services/transfer.rs index 51e1095ff0..6bd77a7d03 100644 --- a/rusk/tests/services/transfer.rs +++ b/rusk/tests/services/transfer.rs @@ -29,7 +29,7 @@ fn initial_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("../config/transfer.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } /// Transacts between two accounts on the in the same wallet and produces a diff --git a/rusk/tests/services/unspendable.rs b/rusk/tests/services/unspendable.rs index 8ffeebe6b6..2f34669a07 100644 --- a/rusk/tests/services/unspendable.rs +++ b/rusk/tests/services/unspendable.rs @@ -36,7 +36,7 @@ fn initial_state>(dir: P) -> Result { let snapshot = toml::from_str(include_str!("../config/unspendable.toml")) .expect("Cannot deserialize config"); - new_state(dir, &snapshot) + new_state(dir, &snapshot, BLOCK_GAS_LIMIT) } const SENDER_INDEX_0: u64 = 0; From 1c9b6a26a5443f72e41e696f859ff27efd0d82c5 Mon Sep 17 00:00:00 2001 From: Goshawk Date: Mon, 19 Aug 2024 12:55:10 +0300 Subject: [PATCH 5/5] consensus: Trace gas_limit in 'gen_candidate' log event --- consensus/src/proposal/block_generator.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/consensus/src/proposal/block_generator.rs b/consensus/src/proposal/block_generator.rs index 854bb4c5e3..1d92fabe6a 100644 --- a/consensus/src/proposal/block_generator.rs +++ b/consensus/src/proposal/block_generator.rs @@ -59,6 +59,7 @@ impl Generator { info!( event = "gen_candidate", hash = &to_str(&candidate.header().hash), + gas_limit = candidate.header().gas_limit, state_hash = &to_str(&candidate.header().state_hash), dur = format!("{:?}ms", start.elapsed().as_millis()), );