From a3d9ad8b8ecb99637abf468b4185dfc08b25b127 Mon Sep 17 00:00:00 2001 From: crypto523 Date: Tue, 27 Feb 2024 05:07:24 -0500 Subject: [PATCH] feat: Add `ContractInfo` table and versionable `ContractInfoType` to on-chain storage (#1657) Related issues: - https://github.com/FuelLabs/fuel-core/issues/1654 --------- Co-authored-by: xgreenx --- CHANGELOG.md | 6 ++- Cargo.lock | 32 +++++++-------- Cargo.toml | 2 +- benches/src/default_gas_costs.rs | 6 ++- benches/src/lib.rs | 22 +++------- ...s__snapshot_configurable_block_height.snap | 7 +++- ...ests__snapshot_contract_with_balances.snap | 7 +++- ...__tests__snapshot_contract_with_state.snap | 7 +++- ...ts__snapshot_contract_with_tx_pointer.snap | 7 +++- ...tests__snapshot_contract_with_utxo_id.snap | 7 +++- ..._tests__snapshot_local_testnet_config.snap | 7 +++- ...ig__tests__snapshot_simple_coin_state.snap | 7 +++- ...nfig__tests__snapshot_simple_contract.snap | 7 +++- ..._tests__snapshot_simple_message_state.snap | 7 +++- crates/client/assets/schema.sdl | 3 +- crates/client/src/client/schema/chain.rs | 2 +- ..._chain__tests__chain_gql_query_output.snap | 14 +++++-- ...nt_transaction_by_id_query_gql_output.snap | 3 +- .../src/client/schema/tx/transparent_tx.rs | 7 ++++ crates/client/src/client/types/gas_costs.rs | 2 +- crates/fuel-core/src/database/contracts.rs | 4 +- crates/fuel-core/src/executor.rs | 5 +++ crates/fuel-core/src/query/contract.rs | 4 +- crates/fuel-core/src/schema/chain.rs | 8 ++-- crates/fuel-core/src/schema/tx/types.rs | 8 ++++ crates/fuel-core/src/service/genesis.rs | 10 +++-- crates/services/executor/src/executor.rs | 2 + crates/services/executor/src/ports.rs | 1 + .../services/txpool/src/service/tests_p2p.rs | 1 + .../src/structured_storage/contracts.rs | 6 ++- crates/storage/src/tables.rs | 16 +++++++- crates/storage/src/vm_storage.rs | 8 ++-- crates/types/src/entities/contract.rs | 40 ++++++++++++++++++- .../scripts/chainspec/beta_chainspec.json | 7 +++- .../scripts/chainspec/dev_chainspec.json | 7 +++- 35 files changed, 212 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a875ec88..aa42094d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,14 +6,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] -Description of the upcoming release here. - ### Added - [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): Added a new `Merklized` blueprint that maintains the binary Merkle tree over the storage data. It supports only the insertion of the objects without removing them. +- [#1657](https://github.com/FuelLabs/fuel-core/pull/1657): Moved `ContractsInfo` table from `fuel-vm` to on-chain tables, and created version-able `ContractsInfoType` to act as the table's data type. ### Changed +- [#1657](https://github.com/FuelLabs/fuel-core/pull/1657): Upgrade to `fuel-vm` 0.46.0. - [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): The logic related to the `FuelBlockIdsToHeights` is moved to the off-chain worker. - [#1663](https://github.com/FuelLabs/fuel-core/pull/1663): Reduce the punishment criteria for mempool gossipping. - [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Removed `Receipts` table. Instead, receipts are part of the `TransactionStatuses` table. @@ -38,6 +38,8 @@ Description of the upcoming release here. - [#1636](https://github.com/FuelLabs/fuel-core/pull/1636): Add more docs to GraphQL DAP API. #### Breaking + +- [#1657](https://github.com/FuelLabs/fuel-core/pull/1657): Changed `CROO` gas price type from `Word` to `DependentGasPrice`. The dependent gas price values are dummy values while awaiting updated benchmarks. - [#1671](https://github.com/FuelLabs/fuel-core/pull/1671): The GraphQL API uses block height instead of the block id where it is possible. The transaction status contains `block_height` instead of the `block_id`. - [#1675](https://github.com/FuelLabs/fuel-core/pull/1675): Simplify GQL schema by disabling contract resolvers in most cases, and just return a ContractId scalar instead. - [#1658](https://github.com/FuelLabs/fuel-core/pull/1658): Receipts are part of the transaction status. diff --git a/Cargo.lock b/Cargo.lock index 92105ea5..8bfd27af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2610,9 +2610,9 @@ dependencies = [ [[package]] name = "fuel-asm" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb9742c03ebf8a385c4ff06365fc0b34feb2a6c302ad5ea9fa7c2201c97e3787" +checksum = "860332346c3b1c4a893627b591e8db907b54a629d593981e55d833224cdaccc0" dependencies = [ "bitflags 2.4.2", "fuel-types", @@ -3150,9 +3150,9 @@ dependencies = [ [[package]] name = "fuel-crypto" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea44d0234e5f422b1e9102431fadbc544474537ca82f590e7979d49f6c6a9644" +checksum = "4c57b1f04f678e1a2396d1348903631da4b855b9594b3c0c7c589f18caa74658" dependencies = [ "coins-bip32", "coins-bip39", @@ -3171,9 +3171,9 @@ dependencies = [ [[package]] name = "fuel-derive" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14035997d8f28ac078227e72d081020c9383edc82fbf42ddd9ac8da120d71f1" +checksum = "cb8cc3c60e13b80177816f53f33d77f917f7cf9a480cb10ff9a64f78672359b1" dependencies = [ "proc-macro2", "quote", @@ -3183,9 +3183,9 @@ dependencies = [ [[package]] name = "fuel-merkle" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "625db7a9d7c06e5ed9a02fcc61214e660bdd8756c19e2b4bb0ed4cb5fea2791b" +checksum = "d7aeaf25539537561819c48c6f1dd79e6d77a238c45f45269a1452b92543fe64" dependencies = [ "derive_more", "digest 0.10.7", @@ -3198,15 +3198,15 @@ dependencies = [ [[package]] name = "fuel-storage" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b972d21d92bce35117c2dded7d9c820fc52628c586d4693f97e820c054148581" +checksum = "f374251c753bb601ad7dbe1efb45b14c170bcfc15f449b6029cc2e3c02dffee2" [[package]] name = "fuel-tx" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7ae78697a841869fef2a15ad050682f52874d469440e09732a5b0d18eb10bf" +checksum = "9ac64fab32d5058828ead93c74a41724d1082dc1cdc039415dc4566f5c2305e1" dependencies = [ "bitflags 2.4.2", "derivative", @@ -3226,9 +3226,9 @@ dependencies = [ [[package]] name = "fuel-types" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bbd77fd02a4390c120b1b5ba6543038965ab1c7aa9797d12cb8dcc5bb1157db" +checksum = "9829c1dbdeb29c203f3bd431a69d25bd557fa06ad5bb4dab7773d05e6ffd2824" dependencies = [ "fuel-derive", "hex", @@ -3238,9 +3238,9 @@ dependencies = [ [[package]] name = "fuel-vm" -version = "0.45.0" +version = "0.46.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b450088ac08da9570fad4a12b42ceae1725921140d95e07a1fbcfa055945b7" +checksum = "c8b451aa96729e97704d23238c7c28f6daec2d1761bc406a49856f189ee8b909" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 9e8f40fc..f5a03776 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.45.0", package = "fuel-vm", default-features = false } +fuel-vm-private = { version = "0.46.0", package = "fuel-vm", default-features = false } # Common dependencies anyhow = "1.0" diff --git a/benches/src/default_gas_costs.rs b/benches/src/default_gas_costs.rs index 3bcaa5a5..a117736b 100644 --- a/benches/src/default_gas_costs.rs +++ b/benches/src/default_gas_costs.rs @@ -13,7 +13,6 @@ pub fn default_gas_costs() -> GasCostsValues { cb: 2, cfei: 2, cfsi: 2, - croo: 40, div: 2, divi: 2, eck1: 3347, @@ -101,6 +100,11 @@ pub fn default_gas_costs() -> GasCostsValues { base: 59, units_per_gas: 20, }, + // TODO: Update CROO values based on benchmarks: https://github.com/FuelLabs/fuel-core/issues/1660 + croo: DependentCost::LightOperation { + base: 1, + units_per_gas: 1, + }, csiz: DependentCost::LightOperation { base: 59, units_per_gas: 195, diff --git a/benches/src/lib.rs b/benches/src/lib.rs index 8bef9f52..98f4e59b 100644 --- a/benches/src/lib.rs +++ b/benches/src/lib.rs @@ -61,10 +61,10 @@ impl From> for ContractCode { Self { contract, + salt, id, root, storage_root, - salt, slots, } } @@ -162,8 +162,6 @@ impl VmBench { let program = Witness::from(program); - let salt = rng.gen(); - let contract = Contract::from(program.as_ref()); let state_root = Contract::default_state_root(); let id = VmBench::CONTRACT; @@ -175,7 +173,7 @@ impl VmBench { let input = Input::contract(utxo_id, balance_root, state_root, tx_pointer, id); let output = Output::contract(0, rng.gen(), rng.gen()); - db.deploy_contract_with_id(&salt, &[], &contract, &state_root, &id)?; + db.deploy_contract_with_id(&[], &contract, &id)?; let data = id .iter() @@ -359,7 +357,6 @@ impl TryFrom for VmBenchPrepared { let code = iter::once(op::ret(RegId::ONE)); let code: Vec = code.collect(); let code = Contract::from(code); - let root = code.root(); let input = tx.inputs().len(); let output = @@ -375,16 +372,15 @@ impl TryFrom for VmBenchPrepared { tx.add_input(input); tx.add_output(output); - db.deploy_contract_with_id(&VmBench::SALT, &[], &code, &root, &contract)?; + db.deploy_contract_with_id(&[], &code, &contract)?; } if let Some(ContractCode { contract, - salt, id, - root, slots, storage_root, + .. }) = contract_code { let input_count = tx.inputs().len(); @@ -401,7 +397,7 @@ impl TryFrom for VmBenchPrepared { tx.add_input(input); tx.add_output(output); - db.deploy_contract_with_id(&salt, &slots, &contract, &root, &id)?; + db.deploy_contract_with_id(&slots, &contract, &id)?; } for contract_id in empty_contracts { @@ -419,13 +415,7 @@ impl TryFrom for VmBenchPrepared { tx.add_input(input); tx.add_output(output); - db.deploy_contract_with_id( - &VmBench::SALT, - &[], - &Contract::default(), - &Bytes32::zeroed(), - &contract_id, - )?; + db.deploy_contract_with_id(&[], &Contract::default(), &contract_id)?; } inputs.into_iter().for_each(|i| { 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 89d4b12b..cae09b5f 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 @@ -48,7 +48,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -137,6 +136,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 10fe5c63..6d3474a6 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 @@ -60,7 +60,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -149,6 +148,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 f229c4dc..fdec4af2 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 @@ -60,7 +60,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -149,6 +148,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 bd6825f6..d1e5371b 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 @@ -56,7 +56,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -145,6 +144,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 0c6ca69e..56aa3aa4 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 @@ -56,7 +56,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -145,6 +144,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 51002946..89f44d18 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 @@ -74,7 +74,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -163,6 +162,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 ab9bcb57..86468fcc 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 @@ -59,7 +59,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -148,6 +147,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 f5106e57..91cf7e0a 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 @@ -54,7 +54,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -143,6 +142,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, 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 5ae1f15c..36887ff4 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 @@ -57,7 +57,6 @@ expression: json "cb": 1, "cfei": 1, "cfsi": 1, - "croo": 16, "div": 1, "divi": 1, "eck1": 951, @@ -146,6 +145,12 @@ expression: json "units_per_gas": 103 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 17, diff --git a/crates/client/assets/schema.sdl b/crates/client/assets/schema.sdl index a760d45c..0726ef81 100644 --- a/crates/client/assets/schema.sdl +++ b/crates/client/assets/schema.sdl @@ -318,7 +318,6 @@ type GasCosts { cb: U64! cfei: U64! cfsi: U64! - croo: U64! div: U64! divi: U64! ecr1: U64! @@ -397,6 +396,7 @@ type GasCosts { xori: U64! call: DependentCost! ccp: DependentCost! + croo: DependentCost! csiz: DependentCost! k256: DependentCost! ldc: DependentCost! @@ -969,6 +969,7 @@ type Transaction { maturity: U32 mintAmount: U64 mintAssetId: AssetId + mintGasPrice: U64 txPointer: TxPointer isScript: Boolean! isCreate: Boolean! diff --git a/crates/client/src/client/schema/chain.rs b/crates/client/src/client/schema/chain.rs index 3c3bacf8..3b552d4d 100644 --- a/crates/client/src/client/schema/chain.rs +++ b/crates/client/src/client/schema/chain.rs @@ -145,7 +145,6 @@ include_from_impls_and_cynic! { pub cb: U64, pub cfei: U64, pub cfsi: U64, - pub croo: U64, pub div: U64, pub divi: U64, pub eck1: U64, @@ -225,6 +224,7 @@ include_from_impls_and_cynic! { pub call: DependentCost, pub ccp: DependentCost, + pub croo: DependentCost, pub csiz: DependentCost, pub k256: DependentCost, pub ldc: DependentCost, 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 77256901..0cc14d28 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 @@ -77,7 +77,6 @@ query { cb cfei cfsi - croo div divi eck1 @@ -176,6 +175,17 @@ query { gasPerUnit } } + croo { + __typename + ... on LightOperation { + base + unitsPerGas + } + ... on HeavyOperation { + base + gasPerUnit + } + } csiz { __typename ... on LightOperation { @@ -379,5 +389,3 @@ query { } } } - - diff --git a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap index 5f5e7b01..7b9508e7 100644 --- a/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap +++ b/crates/client/src/client/schema/snapshots/fuel_core_client__client__schema__tx__tests__transparent_transaction_by_id_query_gql_output.snap @@ -86,6 +86,7 @@ query($id: TransactionId!) { } mintAmount mintAssetId + mintGasPrice receiptsRoot status { __typename @@ -194,5 +195,3 @@ query($id: TransactionId!) { bytecodeLength } } - - diff --git a/crates/client/src/client/schema/tx/transparent_tx.rs b/crates/client/src/client/schema/tx/transparent_tx.rs index 3962a0f2..2d357ccf 100644 --- a/crates/client/src/client/schema/tx/transparent_tx.rs +++ b/crates/client/src/client/schema/tx/transparent_tx.rs @@ -123,6 +123,8 @@ pub struct Transaction { pub mint_amount: Option, /// The field of the `Transaction::Mint`. pub mint_asset_id: Option, + /// The field of the `Transaction::Mint`. + pub mint_gas_price: Option, /// The field of the `Transaction::Script`. pub receipts_root: Option, /// The status of the transaction fetched from the database. @@ -274,6 +276,11 @@ impl TryFrom for fuel_tx::Transaction { ConversionError::MissingField("mint_asset_id".to_string()) })? .into(), + tx.mint_gas_price + .ok_or_else(|| { + ConversionError::MissingField("mint_gas_price".to_string()) + })? + .into(), ); mint.into() }; diff --git a/crates/client/src/client/types/gas_costs.rs b/crates/client/src/client/types/gas_costs.rs index e7f1fd7c..f84dbee0 100644 --- a/crates/client/src/client/types/gas_costs.rs +++ b/crates/client/src/client/types/gas_costs.rs @@ -44,7 +44,6 @@ include_from_impls! { pub cb: u64, pub cfei: u64, pub cfsi: u64, - pub croo: u64, pub div: u64, pub divi: u64, pub eck1: u64, @@ -125,6 +124,7 @@ include_from_impls! { pub call: DependentCost, pub ccp: DependentCost, pub csiz: DependentCost, + pub croo: DependentCost, pub k256: DependentCost, pub ldc: DependentCost, pub logd: DependentCost, diff --git a/crates/fuel-core/src/database/contracts.rs b/crates/fuel-core/src/database/contracts.rs index f6bb2cbe..d6a5b136 100644 --- a/crates/fuel-core/src/database/contracts.rs +++ b/crates/fuel-core/src/database/contracts.rs @@ -35,12 +35,12 @@ impl Database { .into_owned() .into(); - let (salt, _) = self + let salt = *self .storage::() .get(&contract_id) .unwrap() .expect("Contract does not exist") - .into_owned(); + .salt(); let ContractUtxoInfo { utxo_id, diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index 58397046..4cc401b5 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -757,6 +757,7 @@ mod tests { Default::default(), Default::default(), Default::default(), + Default::default(), ); let mut block = Block::default(); @@ -787,6 +788,7 @@ mod tests { Default::default(), Default::default(), Default::default(), + Default::default(), ); let tx = Transaction::default_test_tx(); @@ -823,6 +825,7 @@ mod tests { Default::default(), Default::default(), Default::default(), + Default::default(), ); let mut block = Block::default(); @@ -850,6 +853,7 @@ mod tests { Default::default(), Default::default(), Default::default(), + Default::default(), ); let mut block = Block::default(); @@ -879,6 +883,7 @@ mod tests { Default::default(), 123, Default::default(), + Default::default(), ); let mut block = Block::default(); diff --git a/crates/fuel-core/src/query/contract.rs b/crates/fuel-core/src/query/contract.rs index d4bbb8b5..1a6fd8d4 100644 --- a/crates/fuel-core/src/query/contract.rs +++ b/crates/fuel-core/src/query/contract.rs @@ -64,11 +64,11 @@ impl ContractQueryData for D { } fn contract_salt(&self, id: ContractId) -> StorageResult { - let (salt, _) = self + let salt = *self .storage::() .get(&id)? .ok_or(not_found!(ContractsInfo))? - .into_owned(); + .salt(); Ok(salt) } diff --git a/crates/fuel-core/src/schema/chain.rs b/crates/fuel-core/src/schema/chain.rs index 535f1c11..5f65f3eb 100644 --- a/crates/fuel-core/src/schema/chain.rs +++ b/crates/fuel-core/src/schema/chain.rs @@ -264,10 +264,6 @@ impl GasCosts { self.0.cfsi.into() } - async fn croo(&self) -> U64 { - self.0.croo.into() - } - async fn div(&self) -> U64 { self.0.div.into() } @@ -580,6 +576,10 @@ impl GasCosts { self.0.ccp.into() } + async fn croo(&self) -> DependentCost { + self.0.croo.into() + } + async fn csiz(&self) -> DependentCost { self.0.csiz.into() } diff --git a/crates/fuel-core/src/schema/tx/types.rs b/crates/fuel-core/src/schema/tx/types.rs index 42793611..a2723ab6 100644 --- a/crates/fuel-core/src/schema/tx/types.rs +++ b/crates/fuel-core/src/schema/tx/types.rs @@ -430,6 +430,14 @@ impl Transaction { } } + async fn mint_gas_price(&self) -> Option { + match &self.0 { + fuel_tx::Transaction::Script(_) | fuel_tx::Transaction::Create(_) => None, + // TODO: We need to add a getter for the `gas_price` field in `Mint` transaction + fuel_tx::Transaction::Mint(_) => Some((0).into()), + } + } + // TODO: Maybe we need to do the same `Script` and `Create` async fn tx_pointer(&self) -> Option { match &self.0 { diff --git a/crates/fuel-core/src/service/genesis.rs b/crates/fuel-core/src/service/genesis.rs index de11eaf3..b6598e9e 100644 --- a/crates/fuel-core/src/service/genesis.rs +++ b/crates/fuel-core/src/service/genesis.rs @@ -42,7 +42,10 @@ use fuel_core_types::{ }, entities::{ coins::coin::Coin, - contract::ContractUtxoInfo, + contract::{ + ContractUtxoInfo, + ContractsInfoType, + }, message::Message, }, fuel_merkle::binary, @@ -198,7 +201,6 @@ fn init_contracts( { let contract = Contract::from(contract_config.code.as_slice()); let salt = contract_config.salt; - let root = contract.root(); let contract_id = contract_config.contract_id; let utxo_id = if let (Some(tx_id), Some(output_idx)) = (contract_config.tx_id, contract_config.output_index) @@ -247,10 +249,10 @@ fn init_contracts( return Err(anyhow!("Contract code should not exist")) } - // insert contract root + // insert contract salt if db .storage::() - .insert(&contract_id, &(salt, root))? + .insert(&contract_id, &ContractsInfoType::V1(salt.into()))? .is_some() { return Err(anyhow!("Contract info should not exist")) diff --git a/crates/services/executor/src/executor.rs b/crates/services/executor/src/executor.rs index 92a4cf7f..1b220ab7 100644 --- a/crates/services/executor/src/executor.rs +++ b/crates/services/executor/src/executor.rs @@ -642,6 +642,8 @@ where }, amount_to_mint, self.config.consensus_parameters.base_asset_id, + // TODO: Provide gas price https://github.com/FuelLabs/fuel-core/issues/1642 + 0, ); execute_transaction( diff --git a/crates/services/executor/src/ports.rs b/crates/services/executor/src/ports.rs index 7176731f..17e78c3b 100644 --- a/crates/services/executor/src/ports.rs +++ b/crates/services/executor/src/ports.rs @@ -78,6 +78,7 @@ pub trait ExecutorDatabaseTrait: + StorageMutate + StorageMutate + StorageMutate + + StorageMutate + StorageRead + StorageMutate + MerkleRootStorage diff --git a/crates/services/txpool/src/service/tests_p2p.rs b/crates/services/txpool/src/service/tests_p2p.rs index 614f6153..71270fee 100644 --- a/crates/services/txpool/src/service/tests_p2p.rs +++ b/crates/services/txpool/src/service/tests_p2p.rs @@ -193,6 +193,7 @@ async fn test_gossipped_mint_rejected() { Default::default(), 1, AssetId::BASE, + Default::default(), ) .finalize_as_transaction(); // setup p2p mock - with tx incoming from p2p diff --git a/crates/storage/src/structured_storage/contracts.rs b/crates/storage/src/structured_storage/contracts.rs index 58bb9c2b..8a9b4fd5 100644 --- a/crates/storage/src/structured_storage/contracts.rs +++ b/crates/storage/src/structured_storage/contracts.rs @@ -76,6 +76,10 @@ impl TableWithBlueprint for ContractsLatestUtxo { #[cfg(test)] mod test { use super::*; + use fuel_core_types::{ + entities::contract::ContractsInfoType, + fuel_tx::Salt, + }; crate::basic_storage_tests!( ContractsRawCode, @@ -87,7 +91,7 @@ mod test { crate::basic_storage_tests!( ContractsInfo, ::Key::from([1u8; 32]), - ([2u8; 32].into(), [3u8; 32].into()) + ContractsInfoType::V1(Salt::new([2u8; 32]).into()) ); crate::basic_storage_tests!( diff --git a/crates/storage/src/tables.rs b/crates/storage/src/tables.rs index e9a73bed..e72fc624 100644 --- a/crates/storage/src/tables.rs +++ b/crates/storage/src/tables.rs @@ -9,7 +9,10 @@ use fuel_core_types::{ }, entities::{ coins::coin::CompressedCoin, - contract::ContractUtxoInfo, + contract::{ + ContractUtxoInfo, + ContractsInfoType, + }, message::Message, }, fuel_tx::{ @@ -25,7 +28,6 @@ use fuel_core_types::{ }; pub use fuel_vm_private::storage::{ ContractsAssets, - ContractsInfo, ContractsRawCode, ContractsState, }; @@ -55,6 +57,16 @@ impl Mappable for ContractsLatestUtxo { type OwnedValue = ContractUtxoInfo; } +/// Contract info +pub struct ContractsInfo; + +impl Mappable for ContractsInfo { + type Key = Self::OwnedKey; + type OwnedKey = ContractId; + type Value = Self::OwnedValue; + type OwnedValue = ContractsInfoType; +} + /// The table of consensus metadata associated with sealed (finalized) blocks pub struct SealedBlockConsensus; diff --git a/crates/storage/src/vm_storage.rs b/crates/storage/src/vm_storage.rs index f378e709..d8566634 100644 --- a/crates/storage/src/vm_storage.rs +++ b/crates/storage/src/vm_storage.rs @@ -36,7 +36,6 @@ use fuel_core_types::{ BlockHeight, Bytes32, ContractId, - Salt, Word, }, fuel_vm::InterpreterStorage, @@ -173,6 +172,7 @@ where impl ContractsAssetsStorage for VmStorage where D: MerkleRootStorage + + StorageMutate { } @@ -180,7 +180,9 @@ impl InterpreterStorage for VmStorage where D: StorageMutate + MerkleRootStorage + + StorageMutate + StorageMutate + + StorageMutate + StorageRead + MerkleRootStorage + VmStorageRequirements, @@ -224,15 +226,11 @@ where fn deploy_contract_with_id( &mut self, - salt: &Salt, slots: &[StorageSlot], contract: &Contract, - root: &Bytes32, id: &ContractId, ) -> Result<(), Self::DataError> { self.storage_contract_insert(id, contract)?; - self.storage_contract_root_insert(id, salt, root)?; - self.database.init_contract_state( id, slots.iter().map(|slot| (*slot.key(), *slot.value())), diff --git a/crates/types/src/entities/contract.rs b/crates/types/src/entities/contract.rs index 7ac16bf9..b7f95b4f 100644 --- a/crates/types/src/entities/contract.rs +++ b/crates/types/src/entities/contract.rs @@ -1,14 +1,50 @@ //! Contract entities -use crate::fuel_tx::TxPointer; +use crate::fuel_tx::{ + Salt, + TxPointer, +}; use fuel_vm_private::fuel_tx::UtxoId; /// Contains information related to the latest contract utxo -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] #[derive(Debug, Default, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ContractUtxoInfo { /// the utxo id of the contract pub utxo_id: UtxoId, /// the tx pointer to the utxo pub tx_pointer: TxPointer, } + +/// Versioned type for storing information about a contract. Contract +/// information is off-chain data. +// TODO: Move ContractsInfoType to off-chain data storage https://github.com/FuelLabs/fuel-core/issues/1654 +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[non_exhaustive] +pub enum ContractsInfoType { + /// V1 ContractsInfoType + V1(ContractsInfoTypeV1), +} + +impl ContractsInfoType { + /// Get the contract salt + pub fn salt(&self) -> &Salt { + match self { + ContractsInfoType::V1(info) => &info.salt, + } + } +} + +/// Version 1 of the ContractsInfoType +#[derive(Debug, Default, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub struct ContractsInfoTypeV1 { + salt: Salt, +} + +impl From for ContractsInfoTypeV1 { + fn from(salt: Salt) -> Self { + Self { salt } + } +} diff --git a/deployment/scripts/chainspec/beta_chainspec.json b/deployment/scripts/chainspec/beta_chainspec.json index a2695bc4..f0430c60 100644 --- a/deployment/scripts/chainspec/beta_chainspec.json +++ b/deployment/scripts/chainspec/beta_chainspec.json @@ -87,7 +87,6 @@ "cb": 2, "cfei": 2, "cfsi": 2, - "croo": 40, "div": 2, "divi": 2, "eck1": 3347, @@ -176,6 +175,12 @@ "units_per_gas": 20 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 59, diff --git a/deployment/scripts/chainspec/dev_chainspec.json b/deployment/scripts/chainspec/dev_chainspec.json index d41afd02..097e11e7 100644 --- a/deployment/scripts/chainspec/dev_chainspec.json +++ b/deployment/scripts/chainspec/dev_chainspec.json @@ -117,7 +117,6 @@ "cb": 2, "cfei": 2, "cfsi": 2, - "croo": 40, "div": 2, "divi": 2, "eck1": 3347, @@ -206,6 +205,12 @@ "units_per_gas": 20 } }, + "croo": { + "LightOperation": { + "base": 1, + "units_per_gas": 1 + } + }, "csiz": { "LightOperation": { "base": 59,