Skip to content

Commit

Permalink
feat!: update fuel-core to 0.23.0 (#1292)
Browse files Browse the repository at this point in the history
This PR updates `fuel-core` to `0.23.0` and `fuel-vm` to `0.47.1`.

Added `dry_run_multiple` and `dry_run_no_validation_multiple`. Both
accept a new type called `Transactions`. Example usage:
`Transactions::new().insert(tx).insert(tx2)`


BREAKING CHANGE: 
- `TxPolicies` `gas_price` is replaced with `tip`
- `dry_run` now returns `TxStatus` the receipts can be taken with
`tx_status.take_receipts()`
- `checked_dry_run` is deleted
- `TransactionResponse`'s `block_id` is replaced with `block_height`
- `estimate_transaction_cost` has a new argument `block_horizon` used to
estimate the gas price.

Co-authored-by: Ahmed Sagdati <[email protected]>
  • Loading branch information
hal3e and segfault-magnet authored Mar 14, 2024
1 parent 91c3ae6 commit 250250c
Show file tree
Hide file tree
Showing 27 changed files with 351 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ env:
CARGO_TERM_COLOR: always
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64
RUSTFLAGS: "-D warnings"
FUEL_CORE_VERSION: 0.22.1
FUEL_CORE_VERSION: 0.23.0
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.74.0
FORC_VERSION: 0.51.1
Expand Down
28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,25 @@ tokio = { version = "1.34.0", default-features = false }
tracing = "0.1.40"
trybuild = "1.0.85"
uint = { version = "0.9.5", default-features = false }
which = { version = "5.0.0", default-features = false }
which = { version = "6.0.0", default-features = false }
zeroize = "1.7.0"

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.22.1", default-features = false }
fuel-core-chain-config = { version = "0.22.1", default-features = false }
fuel-core-client = { version = "0.22.1", default-features = false }
fuel-core-poa = { version = "0.22.1", default-features = false }
fuel-core-services = { version = "0.22.1", default-features = false }
fuel-core-types = { version = "0.22.1", default-features = false }
fuel-core = { version = "0.23.0", default-features = false }
fuel-core-chain-config = { version = "0.23.0", default-features = false }
fuel-core-client = { version = "0.23.0", default-features = false }
fuel-core-poa = { version = "0.23.0", default-features = false }
fuel-core-services = { version = "0.23.0", default-features = false }
fuel-core-types = { version = "0.23.0", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = { version = "0.43.2" }
fuel-crypto = { version = "0.43.2" }
fuel-merkle = { version = "0.43.2" }
fuel-storage = { version = "0.43.2" }
fuel-tx = { version = "0.43.2" }
fuel-types = { version = "0.43.2" }
fuel-vm = { version = "0.43.2" }
fuel-asm = { version = "0.47.1" }
fuel-crypto = { version = "0.47.1" }
fuel-merkle = { version = "0.47.1" }
fuel-storage = { version = "0.47.1" }
fuel-tx = { version = "0.47.1" }
fuel-types = { version = "0.47.1" }
fuel-vm = { version = "0.47.1" }

# Workspace projects
fuels = { version = "0.55.0", path = "./packages/fuels" }
Expand Down
13 changes: 4 additions & 9 deletions docs/src/calling-contracts/cost-estimation.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
# Estimating contract call cost

With the function `estimate_transaction_cost(tolerance: Option<f64>)` provided by `ContractCallHandler` and `ContractMultiCallHandler`, you can get a cost estimation for a specific call. The return type, `TransactionCost`, is a struct that contains relevant information for the estimation:
With the function `estimate_transaction_cost(tolerance: Option<f64>, block_horizon: Option<u32>)` provided by `ContractCallHandler` and `ContractMultiCallHandler`, you can get a cost estimation for a specific call. The return type, `TransactionCost`, is a struct that contains relevant information for the estimation:

```rust,ignore
TransactionCost {
min_gas_price: u64,
min_byte_price: u64,
gas_price: u64,
gas_used: u64,
metered_bytes_size: u64,
total_fee: f64, // where total_fee is the sum of the gas and byte fees
}
{{#include ../../../packages/fuels-accounts/src/provider.rs:transaction_cost}}
```

Below are examples that show how to get the estimated transaction cost from single and multi call transactions.
Expand All @@ -24,3 +17,5 @@ Below are examples that show how to get the estimated transaction cost from sing
```

The transaction cost estimation can be used to set the gas limit for an actual call, or to show the user the estimated cost.

> **Note** The same estimation interface is available for scripts.
4 changes: 2 additions & 2 deletions docs/src/calling-contracts/tx-policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Transaction policies are defined as follows:

Where:

1. **Gas Price** - Maximum gas price for transaction.
1. **Tip** - amount to pay the block producer to prioritize the transaction.
2. **Witness Limit** - The maximum amount of witness data allowed for the transaction.
3. **Maturity** - Block until which the transaction cannot be included.
4. **Max Fee** - The maximum fee payable by this transaction.
5. **Script Gas Limit** - The maximum amount of gas the transaction may consume for executing its script code.

When the **Script Gas Limit** is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit. Similarly, if no **Gas Price** is defined, the Rust SDK defaults to the network's minimum gas price.
When the **Script Gas Limit** is not set, the Rust SDK will estimate the consumed gas in the background and set it as the limit.

If the **Witness Limit** is not set, the SDK will set it to the size of all witnesses and signatures defined in the transaction builder.

Expand Down
14 changes: 8 additions & 6 deletions examples/contracts/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ mod tests {
// ANCHOR: contract_call_cost_estimation
let contract_instance = MyContract::new(contract_id, wallet);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = contract_instance
.methods()
.initialize_counter(42) // Build the ABI call
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
// ANCHOR_END: contract_call_cost_estimation

Expand Down Expand Up @@ -144,7 +145,7 @@ mod tests {

// Optional: Configure deployment parameters
let tx_policies = TxPolicies::default()
.with_gas_price(0)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down Expand Up @@ -281,7 +282,7 @@ mod tests {
let contract_methods = MyContract::new(contract_id.clone(), wallet.clone()).methods();

let tx_policies = TxPolicies::default()
.with_gas_price(1)
.with_tip(1)
.with_script_gas_limit(1_000_000)
.with_maturity(0);

Expand Down Expand Up @@ -594,9 +595,10 @@ mod tests {
.add_call(call_handler_1)
.add_call(call_handler_2);

let tolerance = 0.0;
let tolerance = Some(0.0);
let block_horizon = Some(1);
let transaction_cost = multi_call_handler
.estimate_transaction_cost(Some(tolerance)) // Get estimated transaction cost
.estimate_transaction_cost(tolerance, block_horizon) // Get estimated transaction cost
.await?;
// ANCHOR_END: multi_call_cost_estimation

Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ mod tests {
// ANCHOR_END: custom_tx_adjust

// ANCHOR: custom_tx_policies
let tx_policies = TxPolicies::default().with_gas_price(1);
let tx_policies = TxPolicies::default().with_tip(1);
let tb = tb.with_tx_policies(tx_policies);
// ANCHOR_END: custom_tx_policies

Expand Down
1 change: 1 addition & 0 deletions packages/fuels-accounts/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ chrono = { workspace = true }
elliptic-curve = { workspace = true, default-features = false }
eth-keystore = { workspace = true, optional = true }
fuel-core-client = { workspace = true, optional = true }
fuel-core-types = { workspace = true }
fuel-crypto = { workspace = true, features = ["random"] }
fuel-tx = { workspace = true }
fuel-types = { workspace = true, features = ["random"] }
Expand Down
6 changes: 4 additions & 2 deletions packages/fuels-accounts/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,12 @@ mod tests {
async fn dry_run_and_get_used_gas(&self, _: FuelTransaction, _: f32) -> Result<u64> {
Ok(0)
}

fn consensus_parameters(&self) -> &ConsensusParameters {
&self.c_param
}
async fn min_gas_price(&self) -> Result<u64> {

async fn estimate_gas_price(&self, _block_header: u32) -> Result<u64> {
Ok(0)
}
}
Expand Down Expand Up @@ -390,7 +392,7 @@ mod tests {
assert_eq!(signature, tx_signature);

// Check if the signature is what we expect it to be
assert_eq!(signature, Signature::from_str("a7446cb9703d3bc9e68677715fc7ef6ed72ff4eeac0c67bdb0d9b9c8ba38048e078e38fdd85bf988cefd3737005f1be97ed8b9662f002b0480d4404ebb397fed")?);
assert_eq!(signature, Signature::from_str("37cf6bdefc9e673f99a7fdbbeff454cb5c1bdf632c072f19cf8ac68fa1ede2749c568c56f87d73fc5c97f73b76dfe637422b77c1fdc6010fb4f488444ff5df1a")?);

// Recover the address that signed the transaction
let recovered_address = signature.recover(&message)?;
Expand Down
Loading

0 comments on commit 250250c

Please sign in to comment.