Skip to content

Commit

Permalink
feat!: beta-5 support (#1200)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
3 people authored Nov 17, 2023
1 parent d8704e1 commit b9cac99
Show file tree
Hide file tree
Showing 58 changed files with 1,143 additions and 858 deletions.
21 changes: 13 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ 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.20.6
RUST_VERSION: 1.72.1
FUEL_CORE_VERSION: 0.21.0-rc.1
FUEL_CORE_PATCH_BRANCH:
RUST_VERSION: 1.73.0
FORC_VERSION: 0.46.0
FORC_PATCH_BRANCH: "xunilrj/fix-implicit-std-env-vars"
FORC_PATCH_BRANCH: "feat/transaction-policies"
FORC_PATCH_REVISION: ""
FORC_IMPLICIT_STD_GIT_BRANCH: "xunilrj/fix-implicit-std-env-vars"
FORC_IMPLICIT_STD_GIT_BRANCH: ""

jobs:
setup-test-projects:
Expand Down Expand Up @@ -202,10 +203,14 @@ jobs:
- name: Install Fuel Core
if: ${{ matrix.install_fuel_core }}
run: |
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
tar -xvf fuel-core.tar.gz
chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core
mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core
if [[ -n $FUEL_CORE_PATCH_BRANCH ]]; then
cargo install --locked fuel-core-bin --git https://github.com/FuelLabs/fuel-core --branch "$FUEL_CORE_PATCH_BRANCH"
else
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
tar -xvf fuel-core.tar.gz
chmod +x fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core
mv fuel-core-${{ env.FUEL_CORE_VERSION }}-x86_64-unknown-linux-gnu/fuel-core /usr/local/bin/fuel-core
fi
- name: Download sway example artifacts
if: ${{ matrix.download_sway_artifacts }}
Expand Down
28 changes: 15 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ homepage = "https://fuel.network/"
readme = "README.md"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/fuels-rs"
rust-version = "1.72.1"
rust-version = "1.73.0"
version = "0.50.1"

[workspace.dependencies]
Expand Down Expand Up @@ -68,23 +68,25 @@ tokio = { version = "1.33.0", default-features = false }
tracing = "0.1.37"
trybuild = "1.0.85"
uint = { version = "0.9.5", default-features = false }
which = { version = "4.4.2", default-features = false }
which = { version = "5.0.0", default-features = false }
zeroize = "1.6.0"

# Dependencies from the `fuel-core` repository:
fuel-core = { version = "0.20.6", default-features = false }
fuel-core-chain-config = { version = "0.20.6", default-features = false }
fuel-core-client = { version = "0.20.6", default-features = false }
fuel-core-types = { version = "0.20.6", default-features = false }
fuel-core = { version = "0.21.0-rc.1", default-features = false }
fuel-core-chain-config = { version = "0.21.0-rc.1", default-features = false }
fuel-core-client = { version = "0.21.0-rc.1", default-features = false }
fuel-core-poa = { version = "0.21.0-rc.1", default-features = false }
fuel-core-services = { version = "0.21.0-rc.1", default-features = false }
fuel-core-types = { version = "0.21.0-rc.1", default-features = false }

# Dependencies from the `fuel-vm` repository:
fuel-asm = "0.35.4"
fuel-crypto = "0.35.4"
fuel-merkle = "0.35.4"
fuel-storage = "0.35.4"
fuel-tx = "0.35.4"
fuel-types = { version = "0.35.4", default-features = false }
fuel-vm = "0.35.4"
fuel-asm = { version = "0.42.0"}
fuel-crypto = { version = "0.42.0"}
fuel-merkle = { version = "0.42.0"}
fuel-storage = { version = "0.42.0"}
fuel-tx = { version = "0.42.0"}
fuel-types = { version = "0.42.0"}
fuel-vm = { version = "0.42.0"}

# Workspace projects
fuels = { version = "0.50.1", path = "./packages/fuels" }
Expand Down
2 changes: 1 addition & 1 deletion docs/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- [The FuelVM Binary file](./deploying/the-fuelvm-binary-file.md)
- [Calling contracts](./calling-contracts/index.md)
- [Connecting wallets](./calling-contracts/calls-with-different-wallets.md)
- [Transaction parameters](./calling-contracts/tx-params.md)
- [Transaction policies](./calling-contracts/tx-policies.md)
- [Call parameters](./calling-contracts/call-params.md)
- [Custom asset transfer](./calling-contracts/custom-asset-transfer.md)
- [Call response](./calling-contracts/call-response.md)
Expand Down
2 changes: 1 addition & 1 deletion docs/src/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ For transferring assets to the base layer chain, you can use `wallet.withdraw_to
{{#include ../../examples/wallets/src/lib.rs:wallet_withdraw_to_base}}
```

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.
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.
2 changes: 1 addition & 1 deletion docs/src/calling-contracts/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Once you've deployed your contract, as seen in the previous sections, you'll likely want to:

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

Expand Down
4 changes: 2 additions & 2 deletions docs/src/calling-contracts/multicalls.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ With `MultiContractCallHandler`, you can execute multiple contract calls within

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()`.

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

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

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

Expand Down
31 changes: 0 additions & 31 deletions docs/src/calling-contracts/tx-params.md

This file was deleted.

45 changes: 45 additions & 0 deletions docs/src/calling-contracts/tx-policies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Transaction policies

<!-- This section should explain what tx policies are and how to configure them -->
<!-- tx_policies:example:start -->
Transaction policies are defined as follows:

```rust,ignore
{{#include ../../../packages/fuels-core/src/types/wrappers/transaction.rs:tx_policies_struct}}
```

Where:

1. **Gas Price** - Maximum gas price for 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.

**Witness Limit** makes use of the following default values for script and create transactions:

```rust,ignore
{{#include ../../../packages/fuels-core/src/utils/constants.rs:witness_default}}
```

You can configure these parameters by creating an instance of `TxPolicies` and passing it to a chain method called `with_tx_policies`:
<!-- tx_policies:example:end-->

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:tx_policies}}
```

<!-- This section should explain how to use the default tx policy -->
<!-- tx_policies_default:example:start -->
You can also use `TxPolicies::default()` to use the default values.
<!-- tx_policies_default:example:end -->

This way:

```rust,ignore
{{#include ../../../examples/contracts/src/lib.rs:tx_policies_default}}
```

As you might have noticed, `TxPolicies` can also be specified when deploying contracts or transferring assets by passing it to the respective methods.
6 changes: 3 additions & 3 deletions docs/src/running-scripts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ Furthermore, if you need to separate submission from value retrieval for any rea
{{#include ../../packages/fuels/tests/scripts.rs:submit_response_script}}
```

## Running scripts with transaction parameters
## Running scripts with transaction policies

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:
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:

```rust,ignore
{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_params}}
{{#include ../../packages/fuels/tests/scripts.rs:script_with_tx_policies}}
```

## Logs
Expand Down
Loading

0 comments on commit b9cac99

Please sign in to comment.