Skip to content

Commit

Permalink
Decompose consensus params struct (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner authored Aug 10, 2023
1 parent 7de12e7 commit 647ad62
Show file tree
Hide file tree
Showing 66 changed files with 2,870 additions and 2,447 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ Description of the upcoming release here.
- Something changed here 2

#### Breaking
- Some breaking change here 3
- Some breaking change here 4
- [#1262](https://github.com/FuelLabs/fuel-core/pull/1262): The `ConsensusParameters` aggregates all configuration data related to the consensus. It contains many fields that are segregated by the usage. The API of some functions was affected to use lesser types instead the whole `ConsensusParameters`. It is a huge breaking change requiring repetitively monotonically updating all places that use the `ConsensusParameters`. But during updating, consider that maybe you can use lesser types. Usage of them may simplify signatures of methods and make them more user-friendly and transparent.

### Fixed

Expand Down
29 changes: 15 additions & 14 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fuel-core-tests = { version = "0.0.0", path = "./tests" }
fuel-core-xtask = { version = "0.0.0", path = "./xtask" }

# Fuel dependencies
fuel-vm-private = { version = "0.35.3", package = "fuel-vm" }
fuel-vm-private = { version = "0.36.0", package = "fuel-vm" }

# Common dependencies
anyhow = "1.0"
Expand Down Expand Up @@ -112,3 +112,5 @@ itertools = "0.10"
insta = "1.8"
tempfile = "3.4"
tikv-jemallocator = "0.5"


3 changes: 2 additions & 1 deletion benches/benches-outputs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use fuel_core_types::fuel_vm::{
use fuel_core_types::fuel_tx::{
DependentCost,
GasCostsValues,
};

#[allow(dead_code)]
mod test_gas_costs_output;
7 changes: 4 additions & 3 deletions benches/benches/block_target_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ fn run(id: &str, group: &mut BenchmarkGroup<WallTime>, script: Vec<Instruction>)

let database = Database::rocksdb();
let mut config = Config::local_node();
config.chain_conf.transaction_parameters.max_gas_per_tx = TARGET_BLOCK_GAS_LIMIT;
config.chain_conf.consensus_parameters.tx_params.max_gas_per_tx = TARGET_BLOCK_GAS_LIMIT;
config
.chain_conf
.transaction_parameters
.consensus_parameters
.predicate_params
.max_gas_per_predicate = TARGET_BLOCK_GAS_LIMIT;
config.chain_conf.block_gas_limit = TARGET_BLOCK_GAS_LIMIT;
config.utxo_validation = false;
Expand Down Expand Up @@ -73,7 +74,7 @@ fn run(id: &str, group: &mut BenchmarkGroup<WallTime>, script: Vec<Instruction>)
)
.finalize_as_transaction();
async move {
let tx_id = tx.id(&config.chain_conf.transaction_parameters.chain_id);
let tx_id = tx.id(&config.chain_conf.consensus_parameters.chain_id);

let mut sub = shared.block_importer.block_importer.subscribe();
shared
Expand Down
8 changes: 3 additions & 5 deletions benches/benches/set/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use fuel_core_types::{
RegId,
},
fuel_tx::{
ConsensusParameters,
Input,
Output,
Word,
},
fuel_types::*,
fuel_vm::{
Expand Down Expand Up @@ -374,8 +374,7 @@ pub fn run(c: &mut Criterion) {
let coin_output = Output::variable(Address::zeroed(), 100, AssetId::zeroed());
input.outputs.push(coin_output);
let predicate = op::ret(RegId::ONE).to_bytes().to_vec();
let owner =
Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT.chain_id);
let owner = Input::predicate_owner(&predicate, &ChainId::default());
let coin_input = Input::coin_predicate(
Default::default(),
owner,
Expand Down Expand Up @@ -456,8 +455,7 @@ pub fn run(c: &mut Criterion) {
.chain(vec![2u8; i as usize]),
);
let predicate = op::ret(RegId::ONE).to_bytes().to_vec();
let owner =
Input::predicate_owner(&predicate, &ConsensusParameters::DEFAULT.chain_id);
let owner = Input::predicate_owner(&predicate, &ChainId::default());
let coin_input = Input::coin_predicate(
Default::default(),
owner,
Expand Down
3 changes: 2 additions & 1 deletion benches/src/bin/collect.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Parser;
use fuel_core_types::fuel_vm::GasCostsValues;
use fuel_core_types::fuel_tx::GasCostsValues;
use serde::{
Deserialize,
Serialize,
Expand Down Expand Up @@ -822,6 +822,7 @@ mod tests {
.output()
.unwrap();
println!("{}", String::from_utf8(output.stderr).unwrap());

assert!(output.status.success());
}

Expand Down
32 changes: 23 additions & 9 deletions benches/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,25 @@ use fuel_core_types::{
RegId,
},
fuel_tx::*,
fuel_types::*,
fuel_types::{
BlockHeight,
Word,
},
fuel_vm::{
checked_transaction::{
CheckPredicateParams,
EstimatePredicates,
IntoChecked,
},
consts::*,
interpreter::diff,
interpreter::{
diff,
InterpreterParams,
},
*,
},
};

pub use rand::Rng;
use std::{
io,
Expand Down Expand Up @@ -100,9 +108,13 @@ impl VmBench {
pub const CONTRACT: ContractId = ContractId::zeroed();

pub fn new(instruction: Instruction) -> Self {
let tx_params = TxParameters {
max_gas_per_tx: LARGE_GAS_LIMIT + 1,
..Default::default()
};
Self {
params: ConsensusParameters {
max_gas_per_tx: LARGE_GAS_LIMIT + 1,
tx_params,
..Default::default()
},
gas_price: 0,
Expand Down Expand Up @@ -386,18 +398,20 @@ impl TryFrom<VmBench> for VmBenchPrepared {
// add at least one coin input
tx.add_random_fee_input();

let mut p = params;
p.gas_per_byte = 0;
let mut p = params.clone();
p.fee_params.gas_per_byte = 0;
p.gas_costs = GasCosts::free();
let mut tx = tx
.gas_price(gas_price)
.gas_limit(gas_limit)
.maturity(maturity)
.with_params(p)
.with_params(p.clone())
.finalize();
tx.estimate_predicates(&p, &GasCosts::free()).unwrap();
let tx = tx.into_checked(height, &p, &GasCosts::free()).unwrap();
tx.estimate_predicates(&CheckPredicateParams::from(&p))
.unwrap();
let tx = tx.into_checked(height, &p).unwrap();

let mut txtor = Transactor::new(db, params, GasCosts::free());
let mut txtor = Transactor::new(db, InterpreterParams::from(&params));

txtor.transact(tx);

Expand Down
2 changes: 1 addition & 1 deletion bin/e2e-test-client/src/test_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Wallet {
amount: 0,
asset_id,
});
tx.with_params(self.consensus_params);
tx.with_params(self.consensus_params.clone());

Ok(tx.finalize_as_transaction())
}
Expand Down
6 changes: 5 additions & 1 deletion bin/e2e-test-client/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ async fn execute_suite(config_path: String) {
async fn setup_local_node() -> FuelService {
let mut config = Config::local_node();
// The `run_contract_large_state` test creates a contract with a huge state
config.chain_conf.transaction_parameters.max_storage_slots = 1 << 17; // 131072
config
.chain_conf
.consensus_parameters
.contract_params
.max_storage_slots = 1 << 17; // 131072
FuelService::new_node(config).await.unwrap()
}

Expand Down
25 changes: 8 additions & 17 deletions crates/chain-config/src/config/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ use fuel_core_types::{
fuel_crypto::Hasher,
fuel_tx::{
ConsensusParameters,
GasCosts,
TxParameters,
UtxoId,
},
fuel_types::{
Address,
AssetId,
Bytes32,
},
fuel_vm::{
GasCosts,
GasCostsValues,
SecretKey,
},
fuel_vm::SecretKey,
};
use itertools::Itertools;
use rand::{
Expand All @@ -32,7 +30,6 @@ use serde::{
use serde_with::{
serde_as,
skip_serializing_none,
FromInto,
};
use std::{
io::ErrorKind,
Expand Down Expand Up @@ -64,21 +61,17 @@ pub struct ChainConfig {
pub block_gas_limit: u64,
#[serde(default)]
pub initial_state: Option<StateConfig>,
pub transaction_parameters: ConsensusParameters,
#[serde(default)]
#[serde_as(as = "FromInto<GasCostsValues>")]
pub gas_costs: GasCosts,
pub consensus_parameters: ConsensusParameters,
pub consensus: ConsensusConfig,
}

impl Default for ChainConfig {
fn default() -> Self {
Self {
chain_name: "local".into(),
block_gas_limit: ConsensusParameters::DEFAULT.max_gas_per_tx * 10, /* TODO: Pick a sensible default */
transaction_parameters: ConsensusParameters::DEFAULT,
block_gas_limit: TxParameters::DEFAULT.max_gas_per_tx * 10, /* TODO: Pick a sensible default */
consensus_parameters: ConsensusParameters::default(),
initial_state: None,
gas_costs: GasCosts::default(),
consensus: ConsensusConfig::default_poa(),
}
}
Expand Down Expand Up @@ -172,17 +165,15 @@ impl GenesisCommitment for ChainConfig {
block_gas_limit,
// Skip the `initial_state` bec
initial_state: _,
transaction_parameters,
gas_costs,
consensus_parameters,
consensus,
} = self;

// TODO: Hash settlement configuration when it will be available.
let config_hash = *Hasher::default()
.chain(chain_name.as_bytes())
.chain(block_gas_limit.to_be_bytes())
.chain(transaction_parameters.root()?)
.chain(gas_costs.root()?)
.chain(consensus_parameters.root()?)
.chain(consensus.root()?)
.finalize();

Expand Down
Loading

0 comments on commit 647ad62

Please sign in to comment.