From be5e4b1187ca2e249de1bb39eb6ce539b50b9bcf Mon Sep 17 00:00:00 2001 From: Brandon Vrooman Date: Tue, 14 Nov 2023 22:20:59 +0300 Subject: [PATCH] feat: Separate light and heavy gas costs (core) (#1483) This PR is a subset of https://github.com/FuelLabs/fuel-core/pull/1470. It contains only the changes required for fuel-core crates and chainspec, including upgrading to `fuel-vm` v0.41. --------- Co-authored-by: xgreenx --- CHANGELOG.md | 1 + Cargo.lock | 32 +-- Cargo.toml | 2 +- benches/src/bin/collect.rs | 113 +++++----- ...s__snapshot_configurable_block_height.snap | 114 ++++++---- ...ests__snapshot_contract_with_balances.snap | 114 ++++++---- ...__tests__snapshot_contract_with_state.snap | 114 ++++++---- ...ts__snapshot_contract_with_tx_pointer.snap | 114 ++++++---- ...tests__snapshot_contract_with_utxo_id.snap | 114 ++++++---- ..._tests__snapshot_local_testnet_config.snap | 114 ++++++---- ...ig__tests__snapshot_simple_coin_state.snap | 114 ++++++---- ...nfig__tests__snapshot_simple_contract.snap | 114 ++++++---- ..._tests__snapshot_simple_message_state.snap | 114 ++++++---- crates/client/assets/schema.sdl | 15 +- crates/client/src/client/schema/chain.rs | 41 +++- ..._chain__tests__chain_gql_query_output.snap | 209 ++++++++++++++---- crates/client/src/client/types/gas_costs.rs | 46 +++- crates/fuel-core/src/schema/chain.rs | 50 ++++- .../scripts/chainspec/beta_chainspec.json | 114 ++++++---- .../scripts/chainspec/dev_chainspec.json | 114 ++++++---- 20 files changed, 1212 insertions(+), 551 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e36166fbdfa..a5b29707d61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ Description of the upcoming release here. - [#1408](https://github.com/FuelLabs/fuel-core/pull/1408): Update gas benchmarks for storage opcodes to use a pre-populated database to get more accurate worst-case costs. #### Breaking +- [#1470](https://github.com/FuelLabs/fuel-core/pull/1470): Divide `DependentCost` into "light" and "heavy" operations. - [#1464](https://github.com/FuelLabs/fuel-core/pull/1464): Avoid possible truncation of higher bits. It may invalidate the code that truncated higher bits causing different behavior on 32-bit vs. 64-bit systems. The change affects some endpoints that now require lesser integers. - [#1432](https://github.com/FuelLabs/fuel-core/pull/1432): All subscriptions and requests have a TTL now. So each subscription lifecycle is limited in time. If the subscription is closed because of TTL, it means that you subscribed after your transaction had been dropped by the network. - [#1407](https://github.com/FuelLabs/fuel-core/pull/1407): The recipient is a `ContractId` instead of `Address`. The block producer should deploy its contract to receive the transaction fee. The collected fee is zero until the recipient contract is set. diff --git a/Cargo.lock b/Cargo.lock index bd7d1dd9036..6160d7bac39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2719,9 +2719,9 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4a2dce6ade2d7804096e6dfd51e6fd9a16a87ee32b28bcc7a47674c2b497f363" +checksum = "ad6cf3a1d10eb176d845d92bc6c6e2b3089c641c675b38aa537a5a707b391489" dependencies = [ "bitflags 1.3.2", "fuel-types", @@ -3236,9 +3236,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2c58f23beb866369a194b21635f969fd94538cf3cea8e9bebd9d828042f0cf2" +checksum = "52c1a032a03b1bf57bc5c3bd281cd67237f96431e77820fb0aba4c190c5412f4" dependencies = [ "coins-bip32", "coins-bip39", @@ -3257,9 +3257,9 @@ dependencies = [ [[package]] name = "fuel-derive" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adba9deee62a53830736cfdd6a08192c399a3f92f67d26b6c550b544f24bd1e1" +checksum = "ce3a426f67fb1be14c3118e1d44e549f109924ae55fa8827a54fb1f106c6ade4" dependencies = [ "proc-macro2", "quote", @@ -3269,9 +3269,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd20b9ea8b953040507c39bc498478cfa17ecb9831f9fac9b6ca1f7f5ffd921" +checksum = "c231a584c82b0e456db5b91d051b4d9d755f6b17e90192f88884ab5befde9178" dependencies = [ "derive_more", "digest 0.10.7", @@ -3284,15 +3284,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "636d286c2c195f44587c69ae73d08ae9801ac8ee310ef4e87f1d493ed87f2e47" +checksum = "12971117f8b2f048a5906ee59299580d5885ba68f184a53a3f6e76da42ce4607" [[package]] name = "fuel-tx" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0e23732f33ace2ec5b48f17085ec9397f35c465538070269b1965723ed351fa" +checksum = "c37a0625a4f215fe04af9ffb8b4e4cc9e141a8e16cbade41ecc48881f2026bdd" dependencies = [ "derivative", "derive_more", @@ -3312,9 +3312,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465ab5a63b2d867ab1900d34dd6eee2e7cf1e1ad54d23fb6cd89f892367ff02" +checksum = "7a798d25d589bceccd9714146a827227bb2d54d88fa5109a9c46b0e7381a253a" dependencies = [ "fuel-derive", "hex", @@ -3324,9 +3324,9 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.40.0" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13437b5beecd473be158198bcd2ec0c1979783db3d4ed82ffff4fb8d9acb890f" +checksum = "db140c559a9cb3e86067e2752dfd02381a6860cd8f0881dcf015df950e521aca" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index f6c9d56aca5..35c4cb4484b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,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.40.0", package = "fuel-vm", default-features = false } +fuel-vm-private = { version = "0.41.0", package = "fuel-vm", default-features = false } # Common dependencies anyhow = "1.0" diff --git a/benches/src/bin/collect.rs b/benches/src/bin/collect.rs index 7d0a69b78ab..fd0db403d96 100644 --- a/benches/src/bin/collect.rs +++ b/benches/src/bin/collect.rs @@ -121,18 +121,17 @@ impl Default for State { #[derive(Debug, Default, Clone, Serialize, Deserialize)] struct Costs(HashMap); +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub enum DependentCost { + LightOperation { base: u64, units_per_gas: u64 }, + HeavyOperation { base: u64, gas_per_unit: u64 }, +} + #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(untagged)] -enum Cost { +pub enum Cost { Relative(u64), - Dependent { - base: u64, - dep_per_unit: u64, - }, - DependentAll { - samples: Vec, - dep_per_unit: u64, - }, + Dependent(DependentCost), } #[derive(Debug, Clone, Copy, Serialize, Deserialize)] @@ -423,17 +422,34 @@ impl State { serde_yaml::Value::Number(i) => { format!("\n{}{}: {},", indent, name, i.as_u64().unwrap()) } - serde_yaml::Value::Mapping(m) => { - format!( - "\n{}{}: DependentCost {{\n{} base: {},\n{} dep_per_unit: {},\n{}}},", - indent, - name, - indent, - m.get("base").unwrap().as_u64().unwrap(), - indent, - m.get("dep_per_unit").unwrap().as_u64().unwrap(), - indent, - ) + serde_yaml::Value::Tagged(m) => { + let tag = &m.tag; + let m = &m.value; + if tag.to_string().contains("HeavyOperation") { + let output = format!( + r" + {}: DependentCost::HeavyOperation {{ + base: {}, + gas_per_unit: {}, + }},", + name, + m.get("base").unwrap().as_u64().unwrap(), + m.get("gas_per_unit").unwrap().as_u64().unwrap(), + ); + output + } else { + let output = format!( + r" + {}: DependentCost::LightOperation {{ + base: {}, + units_per_gas: {}, + }},", + name, + m.get("base").unwrap().as_u64().unwrap(), + m.get("units_per_gas").unwrap().as_u64().unwrap(), + ); + output + } } _ => unreachable!(), } @@ -531,35 +547,14 @@ impl State { }) .collect::>(); - if all { - let iter = dependent_groups.into_iter().map(|(name, x_y)| { - groups.remove(&name); - let samples = x_y - .iter() - .map(|(x, y)| Sample { - throughput: *x, - time: *y, - }) - .collect(); - let (_, dep_per_unit) = dependent_cost(&name, x_y); - ( - name, - Cost::DependentAll { - samples, - dep_per_unit, - }, - ) - }); - costs.0.extend(iter); - } else { - let iter = dependent_groups.into_iter().map(|(name, x_y)| { - groups.remove(&name); - - let (base, dep_per_unit) = dependent_cost(&name, x_y); - (name, Cost::Dependent { base, dep_per_unit }) - }); - costs.0.extend(iter); - } + let iter = dependent_groups.into_iter().map(|(name, x_y)| { + groups.remove(&name); + + let cost = Cost::Dependent(dependent_cost(&name, x_y)); + (name, cost) + }); + costs.0.extend(iter); + ( Self { all, @@ -630,7 +625,7 @@ fn linear_regression(x_y: Vec<(u64, u64)>) -> f64 { sq_x / sum_x_y } -fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { +fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> DependentCost { const NEAR_LINEAR: f64 = 0.1; #[derive(PartialEq, Eq)] @@ -691,7 +686,7 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { Type::Exp }; - match expected_type { + let (base, amount): (u64, f64) = match expected_type { Type::Linear => { // The time of the first point is a base. // The minimal charge per element is the worse scenario @@ -703,7 +698,7 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { .map(|p| p.amount()) .min_by(|a, b| a.partial_cmp(b).unwrap()) .unwrap(); - (base, amount as u64) + (base, amount) } Type::Logarithm | Type::Exp => { if expected_type == Type::Exp { @@ -733,7 +728,19 @@ fn dependent_cost(name: &String, x_y: Vec<(u64, u64)>) -> (u64, u64) { .map(|p| p.amount()) .min_by(|a, b| a.partial_cmp(b).unwrap()) .unwrap_or(last); - (base.y, amount as u64) + (base.y, amount) + } + }; + + if amount > 1.0 { + DependentCost::LightOperation { + base, + units_per_gas: amount as u64, + } + } else { + DependentCost::HeavyOperation { + base, + gas_per_unit: (1.0 / amount) as u64, } } } diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap index 2639bae1451..bfd8f2681af 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_configurable_block_height.snap @@ -126,80 +126,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap index 2becb407227..d276df7aaa3 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_balances.snap @@ -138,80 +138,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap index 1ad599a3877..810ef7d7825 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_state.snap @@ -138,80 +138,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap index 5731b964f75..aec92bb0857 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_tx_pointer.snap @@ -134,80 +134,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap index 034162729c4..3315488e557 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_contract_with_utxo_id.snap @@ -134,80 +134,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap index f438c86b95f..3813e39fc29 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_local_testnet_config.snap @@ -152,80 +152,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap index f6940750673..565c10a791f 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_coin_state.snap @@ -137,80 +137,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap index 4ed306c5265..0d6cacdfaf4 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_contract.snap @@ -132,80 +132,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap index 28d22f496f0..6f258d46db8 100644 --- a/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap +++ b/crates/chain-config/src/snapshots/fuel_core_chain_config__config__tests__snapshot_simple_message_state.snap @@ -135,80 +135,118 @@ expression: json "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index faf2bdd3efb..71e09b1e285 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -251,10 +251,7 @@ type ContractParameters { maxStorageSlots: U64! } -type DependentCost { - base: U64! - depPerUnit: U64! -} +union DependentCost = LightOperation | HeavyOperation input ExcludeInput { """ @@ -454,6 +451,11 @@ type Header { applicationHash: Bytes32! } +type HeavyOperation { + base: U64! + gasPerUnit: U64! +} + scalar HexString @@ -493,6 +495,11 @@ type InputMessage { } +type LightOperation { + base: U64! + unitsPerGas: U64! +} + type MerkleProof { proofSet: [Bytes32!]! proofIndex: U64! diff --git a/crates/client/src/client/schema/chain.rs b/crates/client/src/client/schema/chain.rs index 0fa354c563a..96095106684 100644 --- a/crates/client/src/client/schema/chain.rs +++ b/crates/client/src/client/schema/chain.rs @@ -249,16 +249,47 @@ include_from_impls_and_cynic! { #[derive(cynic::QueryFragment, Debug)] #[cynic(schema_path = "./assets/schema.sdl")] -pub struct DependentCost { +pub struct LightOperation { pub base: U64, - pub dep_per_unit: U64, + pub units_per_gas: U64, +} + +#[derive(cynic::QueryFragment, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub struct HeavyOperation { + pub base: U64, + pub gas_per_unit: U64, +} + +#[derive(cynic::InlineFragments, Debug)] +#[cynic(schema_path = "./assets/schema.sdl")] +pub enum DependentCost { + LightOperation(LightOperation), + HeavyOperation(HeavyOperation), + #[cynic(fallback)] + Unknown, } impl From for fuel_core_types::fuel_tx::DependentCost { fn from(value: DependentCost) -> Self { - Self { - base: value.base.into(), - dep_per_unit: value.dep_per_unit.into(), + match value { + DependentCost::LightOperation(LightOperation { + base, + units_per_gas, + }) => fuel_core_types::fuel_tx::DependentCost::LightOperation { + base: base.into(), + units_per_gas: units_per_gas.into(), + }, + DependentCost::HeavyOperation(HeavyOperation { base, gas_per_unit }) => { + fuel_core_types::fuel_tx::DependentCost::HeavyOperation { + base: base.into(), + gas_per_unit: gas_per_unit.into(), + } + } + _ => fuel_core_types::fuel_tx::DependentCost::HeavyOperation { + base: 0u64, + gas_per_unit: 0u64, + }, } } } diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap index 2bcfbacc38e..aecc94e5e19 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__chain__tests__chain_gql_query_output.snap @@ -156,80 +156,213 @@ query { xor xori call { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } ccp { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } csiz { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } k256 { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } ldc { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } logd { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } mcl { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } mcli { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } mcp { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } mcpi { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } meq { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } retd { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } s256 { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } scwq { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } smo { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } srwq { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } swwq { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } contractRoot { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } stateRoot { - base - depPerUnit + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } } } } diff --git a/crates/client/src/client/types/gas_costs.rs b/crates/client/src/client/types/gas_costs.rs index 973a363ec91..0fc768f7228 100644 --- a/crates/client/src/client/types/gas_costs.rs +++ b/crates/client/src/client/types/gas_costs.rs @@ -147,25 +147,53 @@ include_from_impls! { } #[derive(Clone, Debug)] -pub struct DependentCost { - pub base: u64, - pub dep_per_unit: u64, +pub enum DependentCost { + LightOperation { base: u64, units_per_gas: u64 }, + HeavyOperation { base: u64, gas_per_unit: u64 }, } impl From for fuel_core_types::fuel_tx::DependentCost { fn from(value: DependentCost) -> Self { - Self { - base: value.base, - dep_per_unit: value.dep_per_unit, + match value { + DependentCost::LightOperation { + base, + units_per_gas, + } => fuel_core_types::fuel_tx::DependentCost::LightOperation { + base, + units_per_gas, + }, + DependentCost::HeavyOperation { base, gas_per_unit } => { + fuel_core_types::fuel_tx::DependentCost::HeavyOperation { + base, + gas_per_unit, + } + } } } } impl From for DependentCost { fn from(value: schema::chain::DependentCost) -> Self { - Self { - base: value.base.into(), - dep_per_unit: value.dep_per_unit.into(), + match value { + schema::chain::DependentCost::LightOperation( + schema::chain::LightOperation { + base, + units_per_gas, + }, + ) => DependentCost::LightOperation { + base: base.into(), + units_per_gas: units_per_gas.into(), + }, + schema::chain::DependentCost::HeavyOperation( + schema::chain::HeavyOperation { base, gas_per_unit }, + ) => DependentCost::HeavyOperation { + base: base.into(), + gas_per_unit: gas_per_unit.into(), + }, + schema::chain::DependentCost::Unknown => DependentCost::HeavyOperation { + base: 0, + gas_per_unit: 0, + }, } } } diff --git a/crates/fuel-core/src/schema/chain.rs b/crates/fuel-core/src/schema/chain.rs index e2ab150ea48..4366ac3091c 100644 --- a/crates/fuel-core/src/schema/chain.rs +++ b/crates/fuel-core/src/schema/chain.rs @@ -20,11 +20,11 @@ use crate::{ use async_graphql::{ Context, Object, + Union, }; use fuel_core_types::fuel_tx; pub struct ChainInfo; - pub struct ConsensusParameters(fuel_tx::ConsensusParameters); pub struct TxParameters(fuel_tx::TxParameters); pub struct PredicateParameters(fuel_tx::PredicateParameters); @@ -34,11 +34,36 @@ pub struct FeeParameters(fuel_tx::FeeParameters); pub struct GasCosts(fuel_tx::GasCosts); -pub struct DependentCost(fuel_tx::DependentCost); +#[derive(Union)] +pub enum DependentCost { + LightOperation(LightOperation), + HeavyOperation(HeavyOperation), +} + +pub struct LightOperation { + base: u64, + units_per_gas: u64, +} + +pub struct HeavyOperation { + base: u64, + gas_per_unit: u64, +} impl From for DependentCost { fn from(value: fuel_tx::DependentCost) -> Self { - Self(value) + match value { + fuel_tx::DependentCost::LightOperation { + base, + units_per_gas, + } => DependentCost::LightOperation(LightOperation { + base, + units_per_gas, + }), + fuel_tx::DependentCost::HeavyOperation { base, gas_per_unit } => { + DependentCost::HeavyOperation(HeavyOperation { base, gas_per_unit }) + } + } } } @@ -626,13 +651,24 @@ impl GasCosts { } #[Object] -impl DependentCost { +impl LightOperation { + async fn base(&self) -> U64 { + self.base.into() + } + + async fn units_per_gas(&self) -> U64 { + self.units_per_gas.into() + } +} + +#[Object] +impl HeavyOperation { async fn base(&self) -> U64 { - self.0.base.into() + self.base.into() } - async fn dep_per_unit(&self) -> U64 { - self.0.dep_per_unit.into() + async fn gas_per_unit(&self) -> U64 { + self.gas_per_unit.into() } } diff --git a/deployment/scripts/chainspec/beta_chainspec.json b/deployment/scripts/chainspec/beta_chainspec.json index 455008ec4b6..89817954f84 100644 --- a/deployment/scripts/chainspec/beta_chainspec.json +++ b/deployment/scripts/chainspec/beta_chainspec.json @@ -158,80 +158,118 @@ "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000" diff --git a/deployment/scripts/chainspec/dev_chainspec.json b/deployment/scripts/chainspec/dev_chainspec.json index db5f725c7e1..333c6f6cc0f 100644 --- a/deployment/scripts/chainspec/dev_chainspec.json +++ b/deployment/scripts/chainspec/dev_chainspec.json @@ -128,80 +128,118 @@ "xor": 1, "xori": 1, "call": { - "base": 144, - "dep_per_unit": 214 + "LightOperation": { + "base": 144, + "units_per_gas": 214 + } }, "ccp": { - "base": 15, - "dep_per_unit": 103 + "LightOperation": { + "base": 15, + "units_per_gas": 103 + } }, "csiz": { - "base": 17, - "dep_per_unit": 790 + "LightOperation": { + "base": 17, + "units_per_gas": 790 + } }, "k256": { - "base": 11, - "dep_per_unit": 214 + "LightOperation": { + "base": 11, + "units_per_gas": 214 + } }, "ldc": { - "base": 15, - "dep_per_unit": 272 + "LightOperation": { + "base": 15, + "units_per_gas": 272 + } }, "logd": { - "base": 26, - "dep_per_unit": 64 + "LightOperation": { + "base": 26, + "units_per_gas": 64 + } }, "mcl": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcli": { - "base": 1, - "dep_per_unit": 3333 + "LightOperation": { + "base": 1, + "units_per_gas": 3333 + } }, "mcp": { - "base": 1, - "dep_per_unit": 2000 + "LightOperation": { + "base": 1, + "units_per_gas": 2000 + } }, "mcpi": { - "base": 3, - "dep_per_unit": 2000 + "LightOperation": { + "base": 3, + "units_per_gas": 2000 + } }, "meq": { - "base": 1, - "dep_per_unit": 2500 + "LightOperation": { + "base": 1, + "units_per_gas": 2500 + } }, "retd_contract": { - "base": 29, - "dep_per_unit": 62 + "LightOperation": { + "base": 29, + "units_per_gas": 62 + } }, "s256": { - "base": 2, - "dep_per_unit": 214 + "LightOperation": { + "base": 2, + "units_per_gas": 214 + } }, "scwq": { - "base": 13, - "dep_per_unit": 5 + "LightOperation": { + "base": 13, + "units_per_gas": 5 + } }, "smo": { - "base": 209, - "dep_per_unit": 55 + "LightOperation": { + "base": 209, + "units_per_gas": 55 + } }, "srwq": { - "base": 47, - "dep_per_unit": 5 + "LightOperation": { + "base": 47, + "units_per_gas": 5 + } }, "swwq": { - "base": 44, - "dep_per_unit": 5 + "LightOperation": { + "base": 44, + "units_per_gas": 5 + } }, "contract_root": { - "base": 75, - "dep_per_unit": 1 + "LightOperation": { + "base": 75, + "units_per_gas": 1 + } }, "state_root": { - "base": 412, - "dep_per_unit": 1 + "LightOperation": { + "base": 412, + "units_per_gas": 1 + } } }, "base_asset_id": "0000000000000000000000000000000000000000000000000000000000000000"