Skip to content

Commit b9cac99

Browse files
hal3eMujkicAsegfault-magnet
authored
feat!: beta-5 support (#1200)
BREAKING CHANGE: - `TxParameters` are replaced with `TxPolicies` - `GasPrice` and `Maturity` fields are optional - `TxPolicies` introduced new fields: - `WitnessLimit` - allows the limitation of the maximum size of witnesses in bytes. - `MaxFee` - allows the upper bound for the maximum fee that users agree to pay for the transaction. - The `ScriptGasLimit` only limits the script execution. Previously, the `ScriptGasLimit` also limited the predicate execution time, but it is not valid anymore. So, it is not possible to use the `ScriptGasLimit` for transaction cost limitations. A new `MaxFee` policy is a way to do that. The `GasLimit` field was removed from the `Create` transaction because it only relates to the script execution(which the `Create` transaction doesn't have). - The new `WhitnessLimit` also impacts the `max_gas` and `max_fee` calculation along with the `ScriptGasLimit`(in the case of `Create` transaction only `WitnessLimit` affects the `max_gas` and `max_fee`). - The minimal gas also charges the user for transaction ID calculation. - Each transaction requires setting the `GasPrice` policy. - Previously, `GasLimit` should be less than the `MAX_GAS_PER_TX` constant. After removing this field from the `Create` transaction, it is impossible to require it. Instead, it requires that `max_gas <= MAX_GAS_PER_TX` for any transaction. Consequently, any `Script` transaction that uses `MAX_GAS_PER_TX` as a `GasLimit` will always fail because of a new rule. Setting the estimated gas usage instead solves the problem. - If the `max_fee > policies.max_fee`, then transaction will be rejected. - If the `witnessses_size > policies.witness_limit`, then transaction will be rejected. - `get_message_proof` not uses `Nonce` instead of the message_id - predicates do not use `ChainId` for address calculation - `manual_blocks_enabled` is replaced with `debug` in local chain config - `fee_checked_from_tx` uses `FeeParameters` - `fuel_tx::ConsensusParameters` were refactored - this also affects us - when building a transaction_builder the `BuildableTransacion` trait needs to be in scope - `utxo_validation` and `manual_blocks` are enabled by default for test providers - node config does not have `local_node` anymore use `default` - `let node_config = Config::default();` Thanks @MujkicA for updating the documentation. Co-authored-by: MujkicA <[email protected]> Co-authored-by: Ahmed Sagdati <[email protected]>
1 parent d8704e1 commit b9cac99

File tree

58 files changed

+1143
-858
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1143
-858
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ env:
1616
CARGO_TERM_COLOR: always
1717
DASEL_VERSION: https://github.com/TomWright/dasel/releases/download/v2.3.6/dasel_linux_amd64
1818
RUSTFLAGS: "-D warnings"
19-
FUEL_CORE_VERSION: 0.20.6
20-
RUST_VERSION: 1.72.1
19+
FUEL_CORE_VERSION: 0.21.0-rc.1
20+
FUEL_CORE_PATCH_BRANCH:
21+
RUST_VERSION: 1.73.0
2122
FORC_VERSION: 0.46.0
22-
FORC_PATCH_BRANCH: "xunilrj/fix-implicit-std-env-vars"
23+
FORC_PATCH_BRANCH: "feat/transaction-policies"
2324
FORC_PATCH_REVISION: ""
24-
FORC_IMPLICIT_STD_GIT_BRANCH: "xunilrj/fix-implicit-std-env-vars"
25+
FORC_IMPLICIT_STD_GIT_BRANCH: ""
2526

2627
jobs:
2728
setup-test-projects:
@@ -202,10 +203,14 @@ jobs:
202203
- name: Install Fuel Core
203204
if: ${{ matrix.install_fuel_core }}
204205
run: |
205-
curl -sSLf https://github.com/FuelLabs/fuel-core/releases/download/v${{ env.FUEL_CORE_VERSION }}/fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -L -o fuel-core.tar.gz
206-
tar -xvf fuel-core.tar.gz
207-
chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core
208-
mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core
206+
if [[ -n $FUEL_CORE_PATCH_BRANCH ]]; then
207+
cargo install --locked fuel-core-bin --git https://github.com/FuelLabs/fuel-core --branch "$FUEL_CORE_PATCH_BRANCH"
208+
else
209+
curl -sSLf https://github.com/FuelLabs/fuel-core/releases/download/v${{ env.FUEL_CORE_VERSION }}/fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu.tar.gz -L -o fuel-core.tar.gz
210+
tar -xvf fuel-core.tar.gz
211+
chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core
212+
mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core
213+
fi
209214
210215
- name: Download sway example artifacts
211216
if: ${{ matrix.download_sway_artifacts }}

Cargo.toml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ homepage = "https://fuel.network/"
3535
readme = "README.md"
3636
license = "Apache-2.0"
3737
repository = "https://github.com/FuelLabs/fuels-rs"
38-
rust-version = "1.72.1"
38+
rust-version = "1.73.0"
3939
version = "0.50.1"
4040

4141
[workspace.dependencies]
@@ -68,23 +68,25 @@ tokio = { version = "1.33.0", default-features = false }
6868
tracing = "0.1.37"
6969
trybuild = "1.0.85"
7070
uint = { version = "0.9.5", default-features = false }
71-
which = { version = "4.4.2", default-features = false }
71+
which = { version = "5.0.0", default-features = false }
7272
zeroize = "1.6.0"
7373

7474
# Dependencies from the `fuel-core` repository:
75-
fuel-core = { version = "0.20.6", default-features = false }
76-
fuel-core-chain-config = { version = "0.20.6", default-features = false }
77-
fuel-core-client = { version = "0.20.6", default-features = false }
78-
fuel-core-types = { version = "0.20.6", default-features = false }
75+
fuel-core = { version = "0.21.0-rc.1", default-features = false }
76+
fuel-core-chain-config = { version = "0.21.0-rc.1", default-features = false }
77+
fuel-core-client = { version = "0.21.0-rc.1", default-features = false }
78+
fuel-core-poa = { version = "0.21.0-rc.1", default-features = false }
79+
fuel-core-services = { version = "0.21.0-rc.1", default-features = false }
80+
fuel-core-types = { version = "0.21.0-rc.1", default-features = false }
7981

8082
# Dependencies from the `fuel-vm` repository:
81-
fuel-asm = "0.35.4"
82-
fuel-crypto = "0.35.4"
83-
fuel-merkle = "0.35.4"
84-
fuel-storage = "0.35.4"
85-
fuel-tx = "0.35.4"
86-
fuel-types = { version = "0.35.4", default-features = false }
87-
fuel-vm = "0.35.4"
83+
fuel-asm = { version = "0.42.0"}
84+
fuel-crypto = { version = "0.42.0"}
85+
fuel-merkle = { version = "0.42.0"}
86+
fuel-storage = { version = "0.42.0"}
87+
fuel-tx = { version = "0.42.0"}
88+
fuel-types = { version = "0.42.0"}
89+
fuel-vm = { version = "0.42.0"}
8890

8991
# Workspace projects
9092
fuels = { version = "0.50.1", path = "./packages/fuels" }

docs/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- [The FuelVM Binary file](./deploying/the-fuelvm-binary-file.md)
2929
- [Calling contracts](./calling-contracts/index.md)
3030
- [Connecting wallets](./calling-contracts/calls-with-different-wallets.md)
31-
- [Transaction parameters](./calling-contracts/tx-params.md)
31+
- [Transaction policies](./calling-contracts/tx-policies.md)
3232
- [Call parameters](./calling-contracts/call-params.md)
3333
- [Custom asset transfer](./calling-contracts/custom-asset-transfer.md)
3434
- [Call response](./calling-contracts/call-response.md)

docs/src/accounts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ For transferring assets to the base layer chain, you can use `wallet.withdraw_to
3737
{{#include ../../examples/wallets/src/lib.rs:wallet_withdraw_to_base}}
3838
```
3939

40-
The above example creates an `Address` from a string and converts it to a `Bech32Address`. Next, it calls `wallet.withdraw_to_base_layer` by providing the address, the amount to be transferred, and the transaction parameters. Lastly, to verify that the transfer succeeded, the relevant message proof is retrieved with `provider.get_message_proof,` and the amount and the recipient are verified.
40+
The above example creates an `Address` from a string and converts it to a `Bech32Address`. Next, it calls `wallet.withdraw_to_base_layer` by providing the address, the amount to be transferred, and the transaction policies. Lastly, to verify that the transfer succeeded, the relevant message proof is retrieved with `provider.get_message_proof,` and the amount and the recipient are verified.

docs/src/calling-contracts/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Once you've deployed your contract, as seen in the previous sections, you'll likely want to:
44

55
1. Call contract methods;
6-
2. Configure call and transaction parameters such as gas price, byte price, and gas limit;
6+
2. Configure call parameters and transaction policies;
77
3. Forward coins and gas in your contract calls;
88
4. Read and interpret returned values and logs.
99

docs/src/calling-contracts/multicalls.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ With `MultiContractCallHandler`, you can execute multiple contract calls within
88

99
You can also set call parameters, variable outputs, or external contracts for every contract call, as long as you don't execute it with `call()` or `simulate()`.
1010

11-
Next, you provide the prepared calls to your `MultiContractCallHandler` and optionally configure transaction parameters:
11+
Next, you provide the prepared calls to your `MultiContractCallHandler` and optionally configure transaction policies:
1212

1313
```rust,ignore
1414
{{#include ../../../examples/contracts/src/lib.rs:multi_call_build}}
1515
```
1616

17-
> **Note:** any transaction parameters configured on separate contract calls are disregarded in favor of the parameters provided to `MultiContractCallHandler`.
17+
> **Note:** any transaction policies configured on separate contract calls are disregarded in favor of the parameters provided to `MultiContractCallHandler`.
1818
1919
Furthermore, if you need to separate submission from value retrieval for any reason, you can do so as follows:
2020

docs/src/calling-contracts/tx-params.md

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Transaction policies
2+
3+
<!-- This section should explain what tx policies are and how to configure them -->
4+
<!-- tx_policies:example:start -->
5+
Transaction policies are defined as follows:
6+
7+
```rust,ignore
8+
{{#include ../../../packages/fuels-core/src/types/wrappers/transaction.rs:tx_policies_struct}}
9+
```
10+
11+
Where:
12+
13+
1. **Gas Price** - Maximum gas price for transaction.
14+
2. **Witness Limit** - The maximum amount of witness data allowed for the transaction.
15+
3. **Maturity** - Block until which the transaction cannot be included.
16+
4. **Max Fee** - The maximum fee payable by this transaction.
17+
5. **Script Gas Limit** - The maximum amount of gas the transaction may consume for executing its script code.
18+
19+
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.
20+
21+
**Witness Limit** makes use of the following default values for script and create transactions:
22+
23+
```rust,ignore
24+
{{#include ../../../packages/fuels-core/src/utils/constants.rs:witness_default}}
25+
```
26+
27+
You can configure these parameters by creating an instance of `TxPolicies` and passing it to a chain method called `with_tx_policies`:
28+
<!-- tx_policies:example:end-->
29+
30+
```rust,ignore
31+
{{#include ../../../examples/contracts/src/lib.rs:tx_policies}}
32+
```
33+
34+
<!-- This section should explain how to use the default tx policy -->
35+
<!-- tx_policies_default:example:start -->
36+
You can also use `TxPolicies::default()` to use the default values.
37+
<!-- tx_policies_default:example:end -->
38+
39+
This way:
40+
41+
```rust,ignore
42+
{{#include ../../../examples/contracts/src/lib.rs:tx_policies_default}}
43+
```
44+
45+
As you might have noticed, `TxPolicies` can also be specified when deploying contracts or transferring assets by passing it to the respective methods.

docs/src/running-scripts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ Furthermore, if you need to separate submission from value retrieval for any rea
1212
{{#include ../../packages/fuels/tests/scripts.rs:submit_response_script}}
1313
```
1414

15-
## Running scripts with transaction parameters
15+
## Running scripts with transaction policies
1616

17-
The method for passing transaction parameters is the same as [with contracts](./calling-contracts/tx-params.md). As a reminder, the workflow would look like this:
17+
The method for passing transaction policies is the same as [with contracts](./calling-contracts/tx-policies.md). As a reminder, the workflow would look like this:
1818

1919
```rust,ignore
20-
{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_params}}
20+
{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_policies}}
2121
```
2222

2323
## Logs

0 commit comments

Comments
 (0)