diff --git a/CHANGELOG.md b/CHANGELOG.md index f70e425d..b9be2bca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ Description of the upcoming release here. ### Added -- [#1503](https://github.com/FuelLabs/fuel-core/pull/1503): Add `gtf` opcode sanity check +- [#1503](https://github.com/FuelLabs/fuel-core/pull/1503): Add `gtf` opcode sanity check. - [#1502](https://github.com/FuelLabs/fuel-core/pull/1502): Added price benchmark for `vm_initialization`. - [#1492](https://github.com/FuelLabs/fuel-core/pull/1492): Support backward iteration in the RocksDB. It allows backward queries that were not allowed before. - [#1490](https://github.com/FuelLabs/fuel-core/pull/1490): Add push and pop benchmarks. @@ -55,6 +55,7 @@ Description of the upcoming release here. ### Changed +- [#1507](https://github.com/FuelLabs/fuel-core/pull/1507): Updated chain configuration to be ready for beta 5 network. It includes opcode prices from the latest benchmark and contract for the block producer. - [#1477](https://github.com/FuelLabs/fuel-core/pull/1477): Upgraded the Rust version used in CI and containers to 1.73.0. Also includes associated Clippy changes. - [#1469](https://github.com/FuelLabs/fuel-core/pull/1469): Replaced usage of `MemoryTransactionView` by `Checkpoint` database in the benchmarks. - [#1466](https://github.com/FuelLabs/fuel-core/pull/1466): Handling overflows during arithmetic operations. diff --git a/Cargo.lock b/Cargo.lock index 92e4e9fd..622fea11 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3177,6 +3177,7 @@ dependencies = [ "cynic", "ethers", "fuel-core", + "fuel-core-benches", "fuel-core-client", "fuel-core-p2p", "fuel-core-poa", diff --git a/benches/benches/block_target_gas.rs b/benches/benches/block_target_gas.rs index e4493caf..2eed808f 100644 --- a/benches/benches/block_target_gas.rs +++ b/benches/benches/block_target_gas.rs @@ -1,4 +1,3 @@ -use crate::block_target_gas_set::default_gas_costs::default_gas_costs; use block_target_gas_set::{ alu::run_alu, contract::run_contract, @@ -25,7 +24,10 @@ use fuel_core::{ }, txpool::types::Word, }; -use fuel_core_benches::*; +use fuel_core_benches::{ + default_gas_costs::default_gas_costs, + *, +}; use fuel_core_chain_config::ContractConfig; use fuel_core_storage::{ tables::ContractsRawCode, diff --git a/benches/benches/block_target_gas_set/mod.rs b/benches/benches/block_target_gas_set/mod.rs index 01dbc5ca..09244bfd 100644 --- a/benches/benches/block_target_gas_set/mod.rs +++ b/benches/benches/block_target_gas_set/mod.rs @@ -1,8 +1,3 @@ -use fuel_core_types::fuel_tx::{ - DependentCost, - GasCostsValues, -}; - pub mod alu; pub mod crypto; @@ -14,5 +9,3 @@ pub mod contract; pub mod memory; pub mod other; - -pub mod default_gas_costs; diff --git a/benches/benches/block_target_gas_set/default_gas_costs.rs b/benches/src/default_gas_costs.rs similarity index 59% rename from benches/benches/block_target_gas_set/default_gas_costs.rs rename to benches/src/default_gas_costs.rs index e2246fe9..9173fab9 100644 --- a/benches/benches/block_target_gas_set/default_gas_costs.rs +++ b/benches/src/default_gas_costs.rs @@ -6,170 +6,170 @@ pub fn default_gas_costs() -> GasCostsValues { aloc: 1, and: 2, andi: 2, - bal: 328, - bhei: 1, + bal: 366, + bhei: 2, bhsh: 2, - burn: 27738, + burn: 33949, cb: 2, cfei: 2, - cfsi: 1, + cfsi: 2, croo: 40, div: 2, divi: 2, - eck1: 3107, - ecr1: 42738, - ed19: 2897, + eck1: 3347, + ecr1: 46165, + ed19: 4210, eq: 2, exp: 2, expi: 2, flag: 1, gm: 2, gt: 2, - gtf: 2, + gtf: 16, ji: 2, jmp: 2, jne: 2, jnei: 2, jnzi: 2, - jmpf: 1, - jmpb: 1, - jnzf: 1, - jnzb: 1, - jnef: 1, - jneb: 1, + jmpf: 2, + jmpb: 2, + jnzf: 2, + jnzb: 2, + jnef: 2, + jneb: 2, lb: 2, - log: 87, + log: 754, lt: 2, lw: 2, - mint: 25515, + mint: 35718, mlog: 2, - vm_initialization: DependentCost::HeavyOperation { - base: 2000, - gas_per_unit: 0, + vm_initialization: DependentCost::LightOperation { + base: 1645, + units_per_gas: 14, }, modi: 2, mod_op: 2, movi: 2, - mroo: 4, + mroo: 5, mul: 2, muli: 2, mldv: 4, noop: 1, - not: 1, + not: 2, or: 2, ori: 2, poph: 3, popl: 3, - pshh: 3, - pshl: 3, - move_op: 1, - ret: 127, + pshh: 4, + pshl: 4, + move_op: 2, + ret: 733, sb: 2, sll: 2, slli: 2, srl: 2, srli: 2, - srw: 224, + srw: 253, sub: 2, subi: 2, sw: 2, - sww: 26247, - time: 76, - tr: 38925, - tro: 26756, - wdcm: 2, + sww: 29053, + time: 79, + tr: 46242, + tro: 33251, + wdcm: 3, wqcm: 3, wdop: 3, wqop: 3, wdml: 3, wqml: 4, wddv: 5, - wqdv: 6, - wdmd: 10, - wqmd: 17, + wqdv: 7, + wdmd: 11, + wqmd: 18, wdam: 9, - wqam: 10, - wdmm: 10, - wqmm: 10, + wqam: 12, + wdmm: 11, + wqmm: 11, xor: 2, xori: 2, call: DependentCost::LightOperation { - base: 17510, - units_per_gas: 5, + base: 21687, + units_per_gas: 4, }, ccp: DependentCost::LightOperation { - base: 54, - units_per_gas: 21, + base: 59, + units_per_gas: 20, }, csiz: DependentCost::LightOperation { - base: 58, - units_per_gas: 212, + base: 59, + units_per_gas: 195, }, k256: DependentCost::LightOperation { - base: 259, - units_per_gas: 4, + base: 282, + units_per_gas: 3, }, ldc: DependentCost::LightOperation { - base: 42, + base: 45, units_per_gas: 65, }, logd: DependentCost::LightOperation { - base: 413, - units_per_gas: 3, + base: 1134, + units_per_gas: 2, }, mcl: DependentCost::LightOperation { - base: 2, - units_per_gas: 568, + base: 3, + units_per_gas: 523, }, mcli: DependentCost::LightOperation { base: 3, - units_per_gas: 568, + units_per_gas: 526, }, mcp: DependentCost::LightOperation { base: 3, - units_per_gas: 470, + units_per_gas: 448, }, mcpi: DependentCost::LightOperation { - base: 6, - units_per_gas: 682, + base: 7, + units_per_gas: 585, }, meq: DependentCost::LightOperation { - base: 10, - units_per_gas: 1161, + base: 11, + units_per_gas: 1097, }, - rvrt: 127, + rvrt: 722, s256: DependentCost::LightOperation { - base: 42, + base: 45, units_per_gas: 3, }, scwq: DependentCost::HeavyOperation { - base: 27337, - gas_per_unit: 25552, + base: 30375, + gas_per_unit: 28628, }, smo: DependentCost::LightOperation { - base: 55851, + base: 64196, units_per_gas: 1, }, srwq: DependentCost::HeavyOperation { - base: 501, - gas_per_unit: 22, + base: 579, + gas_per_unit: 24, }, swwq: DependentCost::HeavyOperation { - base: 25619, - gas_per_unit: 24002, + base: 28484, + gas_per_unit: 26613, }, contract_root: DependentCost::LightOperation { - base: 43, - units_per_gas: 2, + base: 45, + units_per_gas: 1, }, state_root: DependentCost::HeavyOperation { - base: 324, - gas_per_unit: 164, + base: 350, + gas_per_unit: 176, }, - new_storage_per_byte: 1, + new_storage_per_byte: 63, retd: DependentCost::LightOperation { - base: 434, - units_per_gas: 3, + base: 1086, + units_per_gas: 2, }, } } diff --git a/benches/src/lib.rs b/benches/src/lib.rs index c97e72b4..c0444093 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -1,3 +1,4 @@ +pub mod default_gas_costs; pub mod import; use fuel_core::database::vm_database::VmDatabase; diff --git a/bin/e2e-test-client/README.md b/bin/e2e-test-client/README.md index 23588fd0..5a191011 100644 --- a/bin/e2e-test-client/README.md +++ b/bin/e2e-test-client/README.md @@ -10,6 +10,8 @@ When `FUEL_CORE_E2E_CONFIG` is unset a default configuration is used which is su endpoint = "http://localhost:4000" wallet_sync_timeout = "10s" full_test = false +coinbase_contract_id = "7777777777777777777777777777777777777777777777777777777777777777" + [wallet_a] secret = "de97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c" diff --git a/bin/e2e-test-client/src/config.rs b/bin/e2e-test-client/src/config.rs index 319e12b3..456bd34b 100644 --- a/bin/e2e-test-client/src/config.rs +++ b/bin/e2e-test-client/src/config.rs @@ -1,10 +1,16 @@ use crate::SYNC_TIMEOUT; -use fuel_core_types::fuel_vm::SecretKey; +use fuel_core_types::{ + fuel_tx::ContractId, + fuel_vm::SecretKey, +}; use serde::{ Deserialize, Serialize, }; -use std::time::Duration; +use std::{ + str::FromStr, + time::Duration, +}; #[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)] pub struct SuiteConfig { @@ -16,6 +22,8 @@ pub struct SuiteConfig { pub wallet_sync_timeout: Duration, /// Enable slower but more stressful tests. Should be used in full E2E tests but not in CI. pub full_test: bool, + /// The contract id of the coinbase contract. + pub coinbase_contract_id: ContractId, /// Wallet A must contain pre-existing funds pub wallet_a: ClientConfig, pub wallet_b: ClientConfig, @@ -33,6 +41,10 @@ impl Default for SuiteConfig { endpoint: "http://localhost:4000".to_string(), wallet_sync_timeout: SYNC_TIMEOUT, full_test: false, + coinbase_contract_id: ContractId::from_str( + "0x7777777777777777777777777777777777777777777777777777777777777777", + ) + .unwrap(), wallet_a: ClientConfig { endpoint: None, secret: diff --git a/bin/e2e-test-client/src/lib.rs b/bin/e2e-test-client/src/lib.rs index 0a7bc042..87bdb77c 100644 --- a/bin/e2e-test-client/src/lib.rs +++ b/bin/e2e-test-client/src/lib.rs @@ -52,6 +52,15 @@ pub fn main_body(config: SuiteConfig, mut args: Arguments) { }) }), ), + Trial::test( + "can collect fee from alice", + with_cloned(&config, |config| { + async_execute(async { + let ctx = TestContext::new(config).await; + tests::collect_fee::collect_fee(&ctx).await + }) + }), + ), Trial::test( "can execute script and get receipts", with_cloned(&config, |config| { diff --git a/bin/e2e-test-client/src/snapshots/fuel_core_e2e_client__config__tests__default_config_snapshot.snap b/bin/e2e-test-client/src/snapshots/fuel_core_e2e_client__config__tests__default_config_snapshot.snap index b83f5fee..e56ef483 100644 --- a/bin/e2e-test-client/src/snapshots/fuel_core_e2e_client__config__tests__default_config_snapshot.snap +++ b/bin/e2e-test-client/src/snapshots/fuel_core_e2e_client__config__tests__default_config_snapshot.snap @@ -5,6 +5,7 @@ expression: serialized endpoint = "http://localhost:4000" wallet_sync_timeout = "10s" full_test = false +coinbase_contract_id = "7777777777777777777777777777777777777777777777777777777777777777" [wallet_a] secret = "de97d8624a438121b86a1956544bd72ed68cd69f2c99555b08b1e8c51ffd511c" diff --git a/bin/e2e-test-client/src/test_context.rs b/bin/e2e-test-client/src/test_context.rs index da465fdf..d5dad40d 100644 --- a/bin/e2e-test-client/src/test_context.rs +++ b/bin/e2e-test-client/src/test_context.rs @@ -17,10 +17,16 @@ use fuel_core_client::client::{ FuelClient, }; use fuel_core_types::{ + fuel_asm::{ + op, + GTFArgs, + RegId, + }, fuel_crypto::PublicKey, fuel_tx::{ ConsensusParameters, Contract, + ContractId, Finalizable, Input, Output, @@ -45,7 +51,7 @@ use crate::config::{ }; // The base amount needed to cover the cost of a simple transaction -pub const BASE_AMOUNT: u64 = 10_000; +pub const BASE_AMOUNT: u64 = 1_000_000; pub struct TestContext { pub alice: Wallet, @@ -157,7 +163,7 @@ impl Wallet { // build transaction let mut tx = TransactionBuilder::script(Default::default(), Default::default()); tx.gas_price(1); - tx.script_gas_limit(BASE_AMOUNT); + tx.script_gas_limit(0); for coin in coins { if let CoinType::Coin(coin) = coin { @@ -186,6 +192,87 @@ impl Wallet { Ok(tx.finalize_as_transaction()) } + /// Creates the script transaction that collects fee. + pub async fn collect_fee_tx( + &self, + coinbase_contract: ContractId, + asset_id: AssetId, + ) -> anyhow::Result { + // select coins + let coins = &self + .client + .coins_to_spend( + &self.address, + vec![(AssetId::BASE, BASE_AMOUNT, None)], + None, + ) + .await?[0]; + + let output_index = 2u64; + let call_struct_register = 0x10; + // Now call the fee collection contract to withdraw the fees + let script = vec![ + // Point to the call structure + op::gtf_args(call_struct_register, 0x00, GTFArgs::ScriptData), + op::addi( + call_struct_register, + call_struct_register, + (asset_id.size() + output_index.size()) as u16, + ), + op::call(call_struct_register, RegId::ZERO, RegId::ZERO, RegId::CGAS), + op::ret(RegId::ONE), + ]; + + // build transaction + let mut tx = TransactionBuilder::script( + script.into_iter().collect(), + asset_id + .to_bytes() + .into_iter() + .chain(output_index.to_bytes().into_iter()) + .chain(coinbase_contract.to_bytes().into_iter()) + .chain(0u64.to_bytes().into_iter()) + .chain(0u64.to_bytes().into_iter()) + .collect(), + ); + tx.gas_price(1); + tx.script_gas_limit(BASE_AMOUNT); + + tx.add_input(Input::contract( + Default::default(), + Default::default(), + Default::default(), + Default::default(), + coinbase_contract, + )); + for coin in coins { + if let CoinType::Coin(coin) = coin { + tx.add_unsigned_coin_input( + self.secret, + coin.utxo_id, + coin.amount, + coin.asset_id, + Default::default(), + coin.maturity.into(), + ); + } + } + tx.add_output(Output::contract(0, Default::default(), Default::default())); + tx.add_output(Output::Change { + to: self.address, + amount: 0, + asset_id, + }); + tx.add_output(Output::Variable { + to: Default::default(), + amount: Default::default(), + asset_id: Default::default(), + }); + tx.with_params(self.consensus_params.clone()); + + Ok(tx.finalize_as_transaction()) + } + /// Transfers coins from this wallet to another pub async fn transfer( &self, diff --git a/bin/e2e-test-client/src/tests.rs b/bin/e2e-test-client/src/tests.rs index be11eb0a..c5182faa 100644 --- a/bin/e2e-test-client/src/tests.rs +++ b/bin/e2e-test-client/src/tests.rs @@ -1,3 +1,4 @@ +pub mod collect_fee; pub mod contracts; pub mod script; pub mod transfers; diff --git a/bin/e2e-test-client/src/tests/collect_fee.rs b/bin/e2e-test-client/src/tests/collect_fee.rs new file mode 100644 index 00000000..228bbb28 --- /dev/null +++ b/bin/e2e-test-client/src/tests/collect_fee.rs @@ -0,0 +1,37 @@ +use crate::test_context::TestContext; +use fuel_core_types::fuel_tx::{ + AssetId, + Receipt, +}; +use libtest_mimic::Failed; + +// Alice collects tokens from coinbase contract. +pub async fn collect_fee(ctx: &TestContext) -> Result<(), Failed> { + let tx = ctx + .alice + .collect_fee_tx(ctx.config.coinbase_contract_id, AssetId::BASE) + .await?; + let (status, receipts) = ctx + .alice + .client + .submit_and_await_commit_with_receipts(&tx) + .await?; + + if !matches!( + status, + fuel_core_client::client::types::TransactionStatus::Success { .. } + ) { + return Err("collect fee transaction is not successful".into()) + } + + let receipts = receipts.ok_or("collect fee transaction doesn't have receipts")?; + + if !receipts + .iter() + .any(|receipt| matches!(receipt, Receipt::TransferOut { .. })) + { + return Err("collect fee hasn't produced `TransferOut` receipt".into()) + } + + Ok(()) +} diff --git a/bin/e2e-test-client/tests/integration_tests.rs b/bin/e2e-test-client/tests/integration_tests.rs index 530df1a6..54840381 100644 --- a/bin/e2e-test-client/tests/integration_tests.rs +++ b/bin/e2e-test-client/tests/integration_tests.rs @@ -4,8 +4,13 @@ use fuel_core::service::{ }; // Add methods on commands +use fuel_core::txpool::types::ContractId; +use fuel_core_chain_config::ChainConfig; use fuel_core_e2e_client::config::SuiteConfig; -use std::fs; +use std::{ + fs, + str::FromStr, +}; use tempfile::TempDir; // Used for writing assertions // Run programs // Use Jemalloc @@ -15,7 +20,7 @@ static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; #[tokio::test(flavor = "multi_thread")] async fn works_in_local_env() { // setup a local node - let srv = setup_local_node().await; + let srv = setup_dev_node().await; // generate a config file let config = generate_config_file(srv.bound_address.to_string()); // execute suite @@ -38,6 +43,7 @@ async fn works_in_multinode_local_env() { fuel_tx::Input, }; + let config = dev_config(); let mut rng = StdRng::seed_from_u64(line!() as u64); let secret = SecretKey::random(&mut rng); let pub_key = Input::owner(&secret.public_key()); @@ -51,6 +57,7 @@ async fn works_in_multinode_local_env() { ProducerSetup::new(secret).with_txs(1).with_name("Alice"), )], [Some(ValidatorSetup::new(pub_key).with_name("Bob"))], + Some(config), ) .await; @@ -84,15 +91,34 @@ async fn execute_suite(config_path: String) { .await; } -async fn setup_local_node() -> FuelService { +fn dev_config() -> Config { let mut config = Config::local_node(); + let dev_config_bytes = + include_str!("../../../deployment/scripts/chainspec/dev_chainspec.json"); + let chain_config: ChainConfig = serde_json::from_str(dev_config_bytes) + .expect("Should be able to decode chain config"); + // The `run_contract_large_state` test creates a contract with a huge state + assert!( + chain_config + .consensus_parameters + .contract_params + .max_storage_slots + >= 1 << 17 // 131072 + ); + + config.chain_conf = chain_config; + config.block_producer.coinbase_recipient = Some( + ContractId::from_str( + "0x7777777777777777777777777777777777777777777777777777777777777777", + ) + .unwrap(), + ); config - .chain_conf - .consensus_parameters - .contract_params - .max_storage_slots = 1 << 17; // 131072 - FuelService::new_node(config).await.unwrap() +} + +async fn setup_dev_node() -> FuelService { + FuelService::new_node(dev_config()).await.unwrap() } fn generate_config_file(endpoint: String) -> TestConfig { diff --git a/crates/fuel-core/src/p2p_test_helpers.rs b/crates/fuel-core/src/p2p_test_helpers.rs index a572bbad..ec331f3e 100644 --- a/crates/fuel-core/src/p2p_test_helpers.rs +++ b/crates/fuel-core/src/p2p_test_helpers.rs @@ -178,6 +178,7 @@ pub async fn make_nodes( bootstrap_setup: impl IntoIterator>, producers_setup: impl IntoIterator>, validators_setup: impl IntoIterator>, + config: Option, ) -> Nodes { let producers: Vec<_> = producers_setup.into_iter().collect(); @@ -216,11 +217,7 @@ pub async fn make_nodes( .collect(); let mut producers_with_txs = Vec::with_capacity(producers.len()); - let mut chain_config = ChainConfig::local_testnet(); - chain_config - .consensus_parameters - .contract_params - .max_storage_slots = 1 << 17; // 131072 + let mut config = config.unwrap_or(Config::local_node()); for (all, producer) in txs_coins.into_iter().zip(producers.into_iter()) { match all { @@ -228,7 +225,8 @@ pub async fn make_nodes( let mut txs = Vec::with_capacity(all.len()); for (tx, initial_coin) in all { txs.push(tx); - chain_config + config + .chain_conf .initial_state .as_mut() .unwrap() @@ -245,18 +243,20 @@ pub async fn make_nodes( } } + let config = config; + let bootstrap_nodes: Vec = futures::stream::iter(bootstrap_setup.into_iter().enumerate()) .then(|(i, boot)| { - let chain_config = chain_config.clone(); + let config = config.clone(); async move { - let chain_config = chain_config.clone(); + let config = config.clone(); let name = boot.as_ref().map_or(String::new(), |s| s.name.clone()); let mut node_config = make_config( (!name.is_empty()) .then_some(name) .unwrap_or_else(|| format!("b:{i}")), - chain_config.clone(), + config.clone(), ); if let Some(BootstrapSetup { pub_key, .. }) = boot { match &mut node_config.chain_conf.consensus { @@ -275,13 +275,13 @@ pub async fn make_nodes( let mut producers = Vec::with_capacity(producers_with_txs.len()); for (i, s) in producers_with_txs.into_iter().enumerate() { - let chain_config = chain_config.clone(); + let config = config.clone(); let name = s.as_ref().map_or(String::new(), |s| s.0.name.clone()); let mut node_config = make_config( (!name.is_empty()) .then_some(name) .unwrap_or_else(|| format!("p:{i}")), - chain_config.clone(), + config.clone(), ); let mut test_txs = Vec::with_capacity(0); @@ -325,13 +325,13 @@ pub async fn make_nodes( let mut validators = vec![]; for (i, s) in validators_setup.into_iter().enumerate() { - let chain_config = chain_config.clone(); + let config = config.clone(); let name = s.as_ref().map_or(String::new(), |s| s.name.clone()); let mut node_config = make_config( (!name.is_empty()) .then_some(name) .unwrap_or_else(|| format!("v:{i}")), - chain_config.clone(), + config.clone(), ); node_config.block_production = Trigger::Never; @@ -368,9 +368,8 @@ pub async fn make_nodes( } } -pub fn make_config(name: String, chain_config: ChainConfig) -> Config { - let mut node_config = Config::local_node(); - node_config.chain_conf = chain_config; +pub fn make_config(name: String, mut node_config: Config) -> Config { + node_config.p2p = Config::local_node().p2p; node_config.utxo_validation = true; node_config.name = name; node_config diff --git a/deployment/scripts/chainspec/beta_chainspec.json b/deployment/scripts/chainspec/beta_chainspec.json index b9289c4a..5e4da862 100644 --- a/deployment/scripts/chainspec/beta_chainspec.json +++ b/deployment/scripts/chainspec/beta_chainspec.json @@ -1,5 +1,5 @@ { - "chain_name": "Testnet Beta 4", + "chain_name": "Testnet Beta 5", "block_gas_limit": 30000000, "initial_state": { "coins": [ @@ -38,6 +38,13 @@ "amount": "0x1000000000000000", "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" } + ], + "contracts": [ + { + "contract_id": "0x7777777777777777777777777777777777777777777777777777777777777777", + "code": "0x9000000994318e6e453f30e85bf6088f7161d44e57b86a6af0c955d22b353f91b2465f5e6140000a504d00205d4d30001a4860004945048076440001240400005050c0043d51345024040000", + "salt": "0x1bfd51cb31b8d0bc7d93d38f97ab771267d8786ab87073e0c2b8f9ddc44b274e" + } ] }, "consensus_parameters": { @@ -45,14 +52,14 @@ "max_inputs": 255, "max_outputs": 255, "max_witnesses": 255, - "max_gas_per_tx": 10000000, + "max_gas_per_tx": 30000000, "max_size": 17825792 }, "predicate_params": { "max_predicate_length": 1048576, "max_predicate_data_length": 1048576, "max_message_data_length": 1048576, - "max_gas_per_predicate": 10000000 + "max_gas_per_predicate": 30000000 }, "script_params": { "max_script_length": 1048576, @@ -60,7 +67,7 @@ }, "contract_params": { "contract_max_size": 16777216, - "max_storage_slots": 255 + "max_storage_slots": 65536 }, "fee_params": { "gas_price_factor": 92, @@ -68,214 +75,214 @@ }, "chain_id": 0, "gas_costs": { - "add": 1, - "addi": 1, + "add": 2, + "addi": 2, "aloc": 1, - "and": 1, - "andi": 1, - "bal": 13, - "bhei": 1, - "bhsh": 1, - "burn": 132, - "cb": 1, - "cfei": 1, - "cfsi": 1, - "croo": 16, - "div": 1, - "divi": 1, - "eck1": 951, - "ecr1": 3000, - "ed19": 3000, - "eq": 1, - "exp": 1, - "expi": 1, + "and": 2, + "andi": 2, + "bal": 366, + "bhei": 2, + "bhsh": 2, + "burn": 33949, + "cb": 2, + "cfei": 2, + "cfsi": 2, + "croo": 40, + "div": 2, + "divi": 2, + "eck1": 3347, + "ecr1": 46165, + "ed19": 4210, + "eq": 2, + "exp": 2, + "expi": 2, "flag": 1, - "gm": 1, - "gt": 1, - "gtf": 1, - "ji": 1, - "jmp": 1, - "jne": 1, - "jnei": 1, - "jnzi": 1, - "jmpf": 1, - "jmpb": 1, - "jnzf": 1, - "jnzb": 1, - "jnef": 1, - "jneb": 1, - "lb": 1, - "log": 9, - "lt": 1, - "lw": 1, - "mint": 135, - "mlog": 1, - "mod": 1, - "modi": 1, - "move": 1, - "movi": 1, - "mroo": 2, - "mul": 1, - "muli": 1, - "mldv": 1, + "gm": 2, + "gt": 2, + "gtf": 16, + "ji": 2, + "jmp": 2, + "jne": 2, + "jnei": 2, + "jnzi": 2, + "jmpf": 2, + "jmpb": 2, + "jnzf": 2, + "jnzb": 2, + "jnef": 2, + "jneb": 2, + "lb": 2, + "log": 754, + "lt": 2, + "lw": 2, + "mint": 35718, + "mlog": 2, + "mod": 2, + "modi": 2, + "move": 2, + "movi": 2, + "mroo": 5, + "mul": 2, + "muli": 2, + "mldv": 4, "noop": 1, - "not": 1, - "or": 1, - "ori": 1, - "poph": 2, - "popl": 2, - "pshh": 2, - "pshl": 2, - "ret_contract": 13, - "rvrt_contract": 13, - "sb": 1, - "sll": 1, - "slli": 1, - "srl": 1, - "srli": 1, - "srw": 12, - "sub": 1, - "subi": 1, - "sw": 1, - "sww": 43, - "time": 1, - "tr": 105, - "tro": 60, - "wdcm": 1, - "wqcm": 1, - "wdop": 1, - "wqop": 1, - "wdml": 1, - "wqml": 1, - "wddv": 1, - "wqdv": 2, - "wdmd": 3, - "wqmd": 4, - "wdam": 2, - "wqam": 3, - "wdmm": 3, - "wqmm": 3, - "xor": 1, - "xori": 1, + "not": 2, + "or": 2, + "ori": 2, + "poph": 3, + "popl": 3, + "pshh": 4, + "pshl": 4, + "ret_contract": 733, + "rvrt_contract": 722, + "sb": 2, + "sll": 2, + "slli": 2, + "srl": 2, + "srli": 2, + "srw": 253, + "sub": 2, + "subi": 2, + "sw": 2, + "sww": 29053, + "time": 79, + "tr": 46242, + "tro": 33251, + "wdcm": 3, + "wqcm": 3, + "wdop": 3, + "wqop": 3, + "wdml": 3, + "wqml": 4, + "wddv": 5, + "wqdv": 7, + "wdmd": 11, + "wqmd": 18, + "wdam": 9, + "wqam": 12, + "wdmm": 11, + "wqmm": 11, + "xor": 2, + "xori": 2, "call": { "LightOperation": { - "base": 144, - "units_per_gas": 214 + "base": 21687, + "units_per_gas": 4 } }, "ccp": { "LightOperation": { - "base": 15, - "units_per_gas": 103 + "base": 59, + "units_per_gas": 20 } }, "csiz": { "LightOperation": { - "base": 17, - "units_per_gas": 790 + "base": 59, + "units_per_gas": 195 } }, "k256": { "LightOperation": { - "base": 11, - "units_per_gas": 214 + "base": 282, + "units_per_gas": 3 } }, "ldc": { "LightOperation": { - "base": 15, - "units_per_gas": 272 + "base": 45, + "units_per_gas": 65 } }, "logd": { "LightOperation": { - "base": 26, - "units_per_gas": 64 + "base": 1134, + "units_per_gas": 2 } }, "mcl": { "LightOperation": { - "base": 1, - "units_per_gas": 3333 + "base": 3, + "units_per_gas": 523 } }, "mcli": { "LightOperation": { - "base": 1, - "units_per_gas": 3333 + "base": 3, + "units_per_gas": 526 } }, "mcp": { "LightOperation": { - "base": 1, - "units_per_gas": 2000 + "base": 3, + "units_per_gas": 448 } }, "mcpi": { "LightOperation": { - "base": 3, - "units_per_gas": 2000 + "base": 7, + "units_per_gas": 585 } }, "meq": { "LightOperation": { - "base": 1, - "units_per_gas": 2500 + "base": 11, + "units_per_gas": 1097 } }, "retd_contract": { "LightOperation": { - "base": 29, - "units_per_gas": 62 + "base": 1086, + "units_per_gas": 2 } }, "s256": { "LightOperation": { - "base": 2, - "units_per_gas": 214 + "base": 45, + "units_per_gas": 3 } }, "scwq": { - "LightOperation": { - "base": 13, - "units_per_gas": 5 + "HeavyOperation": { + "base": 30375, + "gas_per_unit": 28628 } }, "smo": { "LightOperation": { - "base": 209, - "units_per_gas": 55 + "base": 64196, + "units_per_gas": 1 } }, "srwq": { - "LightOperation": { - "base": 47, - "units_per_gas": 5 + "HeavyOperation": { + "base": 579, + "gas_per_unit": 24 } }, "swwq": { - "LightOperation": { - "base": 44, - "units_per_gas": 5 + "HeavyOperation": { + "base": 28484, + "gas_per_unit": 26613 } }, "contract_root": { "LightOperation": { - "base": 75, + "base": 45, "units_per_gas": 1 } }, "state_root": { - "LightOperation": { - "base": 412, - "units_per_gas": 1 + "HeavyOperation": { + "base": 350, + "gas_per_unit": 176 } }, - "new_storage_per_byte": 100, + "new_storage_per_byte": 63, "vm_initialization": { - "HeavyOperation": { - "base": 2000, - "gas_per_unit": 0 + "LightOperation": { + "base": 1645, + "units_per_gas": 14 } } }, diff --git a/deployment/scripts/chainspec/dev_chainspec.json b/deployment/scripts/chainspec/dev_chainspec.json index d2696fb6..fc88b1c0 100644 --- a/deployment/scripts/chainspec/dev_chainspec.json +++ b/deployment/scripts/chainspec/dev_chainspec.json @@ -1,13 +1,45 @@ { "chain_name": "Testnet", - "block_gas_limit": 10000000, + "block_gas_limit": 1000000000, "initial_state": { "coins": [ + { + "owner": "0x6b63804cfbf9856e68e5b6e7aef238dc8311ec55bec04df774003a2c96e0418e", + "amount": "0x1000000000000000", + "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "owner": "0x54944e5b8189827e470e5a8bacfc6c3667397dc4e1eef7ef3519d16d6d6c6610", + "amount": "0x1000000000000000", + "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "owner": "0xe10f526b192593793b7a1559a391445faba82a1d669e3eb2dcd17f9c121b24b1", + "amount": "0x1000000000000000", + "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "owner": "0x577e424ee53a16e6a85291feabc8443862495f74ac39a706d2dd0b9fc16955eb", + "amount": "0x1000000000000000", + "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "owner": "0xc36be0e14d3eaf5d8d233e0f4a40b3b4e48427d25f84c460d2b03b242a38479e", + "amount": "0x1000000000000000", + "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, { "owner": "0x53a9c6a74bee79c5e04115a007984f4bddaafed75f512f68766c6ed59d0aedec", "amount": "0x0004000000000000", "asset_id": "0x0000000000000000000000000000000000000000000000000000000000000000" } + ], + "contracts": [ + { + "contract_id": "0x7777777777777777777777777777777777777777777777777777777777777777", + "code": "0x9000000994318e6e453f30e85bf6088f7161d44e57b86a6af0c955d22b353f91b2465f5e6140000a504d00205d4d30001a4860004945048076440001240400005050c0043d51345024040000", + "salt": "0x1bfd51cb31b8d0bc7d93d38f97ab771267d8786ab87073e0c2b8f9ddc44b274e" + } ] }, "consensus_parameters": { @@ -15,14 +47,14 @@ "max_inputs": 255, "max_outputs": 255, "max_witnesses": 255, - "max_gas_per_tx": 100000000, + "max_gas_per_tx": 1000000000, "max_size": 17825792 }, "predicate_params": { "max_predicate_length": 1048576, "max_predicate_data_length": 1048576, "max_message_data_length": 1048576, - "max_gas_per_predicate": 100000000 + "max_gas_per_predicate": 1000000000 }, "script_params": { "max_script_length": 1048576, @@ -30,222 +62,222 @@ }, "contract_params": { "contract_max_size": 16777216, - "max_storage_slots": 255 + "max_storage_slots": 131072 }, "fee_params": { - "gas_price_factor": 1000000000, + "gas_price_factor": 92, "gas_per_byte": 63 }, "chain_id": 0, "gas_costs": { - "add": 1, - "addi": 1, + "add": 2, + "addi": 2, "aloc": 1, - "and": 1, - "andi": 1, - "bal": 13, - "bhei": 1, - "bhsh": 1, - "burn": 132, - "cb": 1, - "cfei": 1, - "cfsi": 1, - "croo": 16, - "div": 1, - "divi": 1, - "eck1": 951, - "ecr1": 3000, - "ed19": 3000, - "eq": 1, - "exp": 1, - "expi": 1, + "and": 2, + "andi": 2, + "bal": 366, + "bhei": 2, + "bhsh": 2, + "burn": 33949, + "cb": 2, + "cfei": 2, + "cfsi": 2, + "croo": 40, + "div": 2, + "divi": 2, + "eck1": 3347, + "ecr1": 46165, + "ed19": 4210, + "eq": 2, + "exp": 2, + "expi": 2, "flag": 1, - "gm": 1, - "gt": 1, - "gtf": 1, - "ji": 1, - "jmp": 1, - "jne": 1, - "jnei": 1, - "jnzi": 1, - "jmpf": 1, - "jmpb": 1, - "jnzf": 1, - "jnzb": 1, - "jnef": 1, - "jneb": 1, - "lb": 1, - "log": 9, - "lt": 1, - "lw": 1, - "mint": 135, - "mlog": 1, - "mod": 1, - "modi": 1, - "move": 1, - "movi": 1, - "mroo": 2, - "mul": 1, - "muli": 1, - "mldv": 1, + "gm": 2, + "gt": 2, + "gtf": 16, + "ji": 2, + "jmp": 2, + "jne": 2, + "jnei": 2, + "jnzi": 2, + "jmpf": 2, + "jmpb": 2, + "jnzf": 2, + "jnzb": 2, + "jnef": 2, + "jneb": 2, + "lb": 2, + "log": 754, + "lt": 2, + "lw": 2, + "mint": 35718, + "mlog": 2, + "mod": 2, + "modi": 2, + "move": 2, + "movi": 2, + "mroo": 5, + "mul": 2, + "muli": 2, + "mldv": 4, "noop": 1, - "not": 1, - "or": 1, - "ori": 1, - "poph": 2, - "popl": 2, - "pshh": 2, - "pshl": 2, - "ret_contract": 13, - "rvrt_contract": 13, - "sb": 1, - "sll": 1, - "slli": 1, - "srl": 1, - "srli": 1, - "srw": 12, - "sub": 1, - "subi": 1, - "sw": 1, - "sww": 43, - "time": 1, - "tr": 105, - "tro": 60, - "wdcm": 1, - "wqcm": 1, - "wdop": 1, - "wqop": 1, - "wdml": 1, - "wqml": 1, - "wddv": 1, - "wqdv": 2, - "wdmd": 3, - "wqmd": 4, - "wdam": 2, - "wqam": 3, - "wdmm": 3, - "wqmm": 3, - "xor": 1, - "xori": 1, + "not": 2, + "or": 2, + "ori": 2, + "poph": 3, + "popl": 3, + "pshh": 4, + "pshl": 4, + "ret_contract": 733, + "rvrt_contract": 722, + "sb": 2, + "sll": 2, + "slli": 2, + "srl": 2, + "srli": 2, + "srw": 253, + "sub": 2, + "subi": 2, + "sw": 2, + "sww": 29053, + "time": 79, + "tr": 46242, + "tro": 33251, + "wdcm": 3, + "wqcm": 3, + "wdop": 3, + "wqop": 3, + "wdml": 3, + "wqml": 4, + "wddv": 5, + "wqdv": 7, + "wdmd": 11, + "wqmd": 18, + "wdam": 9, + "wqam": 12, + "wdmm": 11, + "wqmm": 11, + "xor": 2, + "xori": 2, "call": { "LightOperation": { - "base": 144, - "units_per_gas": 214 + "base": 21687, + "units_per_gas": 4 } }, "ccp": { "LightOperation": { - "base": 15, - "units_per_gas": 103 + "base": 59, + "units_per_gas": 20 } }, "csiz": { "LightOperation": { - "base": 17, - "units_per_gas": 790 + "base": 59, + "units_per_gas": 195 } }, "k256": { "LightOperation": { - "base": 11, - "units_per_gas": 214 + "base": 282, + "units_per_gas": 3 } }, "ldc": { "LightOperation": { - "base": 15, - "units_per_gas": 272 + "base": 45, + "units_per_gas": 65 } }, "logd": { "LightOperation": { - "base": 26, - "units_per_gas": 64 + "base": 1134, + "units_per_gas": 2 } }, "mcl": { "LightOperation": { - "base": 1, - "units_per_gas": 3333 + "base": 3, + "units_per_gas": 523 } }, "mcli": { "LightOperation": { - "base": 1, - "units_per_gas": 3333 + "base": 3, + "units_per_gas": 526 } }, "mcp": { "LightOperation": { - "base": 1, - "units_per_gas": 2000 + "base": 3, + "units_per_gas": 448 } }, "mcpi": { "LightOperation": { - "base": 3, - "units_per_gas": 2000 + "base": 7, + "units_per_gas": 585 } }, "meq": { "LightOperation": { - "base": 1, - "units_per_gas": 2500 + "base": 11, + "units_per_gas": 1097 } }, "retd_contract": { "LightOperation": { - "base": 29, - "units_per_gas": 62 + "base": 1086, + "units_per_gas": 2 } }, "s256": { "LightOperation": { - "base": 2, - "units_per_gas": 214 + "base": 45, + "units_per_gas": 3 } }, "scwq": { - "LightOperation": { - "base": 13, - "units_per_gas": 5 + "HeavyOperation": { + "base": 30375, + "gas_per_unit": 28628 } }, "smo": { "LightOperation": { - "base": 209, - "units_per_gas": 55 + "base": 64196, + "units_per_gas": 1 } }, "srwq": { - "LightOperation": { - "base": 47, - "units_per_gas": 5 + "HeavyOperation": { + "base": 579, + "gas_per_unit": 24 } }, "swwq": { - "LightOperation": { - "base": 44, - "units_per_gas": 5 + "HeavyOperation": { + "base": 28484, + "gas_per_unit": 26613 } }, "contract_root": { "LightOperation": { - "base": 75, + "base": 45, "units_per_gas": 1 } }, "state_root": { - "LightOperation": { - "base": 412, - "units_per_gas": 1 + "HeavyOperation": { + "base": 350, + "gas_per_unit": 176 } }, - "new_storage_per_byte": 100, + "new_storage_per_byte": 63, "vm_initialization": { - "HeavyOperation": { - "base": 2000, - "gas_per_unit": 0 + "LightOperation": { + "base": 1645, + "units_per_gas": 14 } } }, diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 59988034..836117a3 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -22,6 +22,7 @@ async-trait = { workspace = true } cynic = { workspace = true } ethers = "2" fuel-core = { path = "../crates/fuel-core", default-features = false, features = ["test-helpers"] } +fuel-core-benches = { path = "../benches" } fuel-core-client = { path = "../crates/client", features = ["test-helpers"] } fuel-core-p2p = { path = "../crates/services/p2p", features = ["test-helpers"], optional = true } fuel-core-poa = { path = "../crates/services/consensus_module/poa" } diff --git a/tests/tests/deployment.rs b/tests/tests/deployment.rs index 5814be72..857c03ad 100644 --- a/tests/tests/deployment.rs +++ b/tests/tests/deployment.rs @@ -1,4 +1,5 @@ use fuel_core::chain_config::ChainConfig; +use fuel_core_types::fuel_tx::GasCosts; #[test_case::test_case( include_str!("../../deployment/scripts/chainspec/beta_chainspec.json"); @@ -9,9 +10,18 @@ use fuel_core::chain_config::ChainConfig; "Dev chainconfig" )] fn test_deployment_chainconfig(bytes: &str) { - let chain_config: ChainConfig = + let mut chain_config: ChainConfig = serde_json::from_str(bytes).expect("Should be able to decode chain config"); + let benchmark_gas_costs = + GasCosts::new(fuel_core_benches::default_gas_costs::default_gas_costs()); + // Deployment configuration should use gas costs from benchmarks. + chain_config.consensus_parameters.gas_costs = benchmark_gas_costs; let actual_bytes = serde_json::to_string_pretty(&chain_config) .expect("Should be able to encode the chain config"); assert_eq!(actual_bytes, bytes); } + +/// This dummy test allows to run tests from IDE in this file. +#[test] +#[ignore] +fn dummy() {} diff --git a/tests/tests/poa.rs b/tests/tests/poa.rs index 40bde7ce..10fb590a 100644 --- a/tests/tests/poa.rs +++ b/tests/tests/poa.rs @@ -89,10 +89,7 @@ async fn can_get_sealed_block_from_poa_produced_block() { mod p2p { use super::*; use fuel_core::{ - chain_config::{ - ChainConfig, - ConsensusConfig, - }, + chain_config::ConsensusConfig, p2p_test_helpers::{ make_config, make_node, @@ -119,16 +116,16 @@ mod p2p { let secret = SecretKey::random(&mut rng); let pub_key = Input::owner(&secret.public_key()); - let mut chain_config = ChainConfig::local_testnet(); - chain_config.consensus = ConsensusConfig::PoA { + let mut config = Config::local_node(); + config.chain_conf.consensus = ConsensusConfig::PoA { signing_key: pub_key, }; - let bootstrap_config = make_config("Bootstrap".to_string(), chain_config.clone()); + let bootstrap_config = make_config("Bootstrap".to_string(), config.clone()); let bootstrap = Bootstrap::new(&bootstrap_config).await; let make_node_config = |name: &str| { - let mut config = make_config(name.to_string(), chain_config.clone()); + let mut config = make_config(name.to_string(), config.clone()); config.block_production = Trigger::Interval { block_time: Duration::from_secs(INTERVAL), }; diff --git a/tests/tests/sync.rs b/tests/tests/sync.rs index eb806c77..d07a402c 100644 --- a/tests/tests/sync.rs +++ b/tests/tests/sync.rs @@ -38,6 +38,7 @@ async fn test_producer_getting_own_blocks_back() { ProducerSetup::new(secret).with_txs(1).with_name("Alice"), )], [Some(ValidatorSetup::new(pub_key).with_name("Bob"))], + None, ) .await; @@ -88,6 +89,7 @@ async fn test_partition_single(num_txs: usize) { Some(ValidatorSetup::new(pub_key).with_name("Bob")), Some(ValidatorSetup::new(pub_key).with_name("Carol")), ], + None, ) .await; @@ -152,6 +154,7 @@ async fn test_partitions_larger_groups( (0..num_validators).map(|i| { Some(ValidatorSetup::new(pub_key).with_name(format!("{pub_key}:{i}"))) }), + None, ) .await; @@ -252,6 +255,7 @@ async fn test_multiple_producers_different_keys() { Some(ValidatorSetup::new(*pub_key).with_name(format!("{pub_key}:{i}"))) }) }), + None, ) .await; @@ -308,6 +312,7 @@ async fn test_multiple_producers_same_key() { std::iter::repeat(Some(BootstrapSetup::new(pub_key))).take(num_producers), std::iter::repeat(Some(ProducerSetup::new(secret))).take(num_producers), std::iter::repeat(Some(ValidatorSetup::new(pub_key))).take(num_validators), + None, ) .await; diff --git a/tests/tests/tx_gossip.rs b/tests/tests/tx_gossip.rs index 6b8c5ae1..5e9f72f4 100644 --- a/tests/tests/tx_gossip.rs +++ b/tests/tests/tx_gossip.rs @@ -70,6 +70,7 @@ async fn test_tx_gossiping() { Some(ValidatorSetup::new(*pub_key).with_name(format!("{pub_key}:{i}"))) }) }), + None, ) .await; @@ -147,6 +148,7 @@ async fn test_tx_gossiping_invalid_txs( ) }) }), + None, ) .await;