From 5d4f9fe98471b32f20f81450e29a5636aaaae9c5 Mon Sep 17 00:00:00 2001 From: Mitchell Turner Date: Thu, 29 Feb 2024 00:50:26 -0800 Subject: [PATCH] Use max fee policy to charge user (#685) * refactor hard-to-read function * WIP * Remove comments * Remove fee checks, fmt * Remove `gas_price` from check * Get tests compiling but not passing * Replace limit tests with exists tests * Break down `create` tests, fix those tests * Break down `script` tests, fix those tests * Fix broken tx tests * Fix warnings * Fix `run_script` to incude `max_fee` * WIP * WIP * Take ref and clone instead of mut in finalize * Modify test builder to have default max_fee_limit of 0 * Fix input tests * WIP fixing tests * Finish reconciling merge * Fix `blockchain` tests * Fix setup function for many tests * Fix metadata tests * Fix predicate tests * Fix interpreter tests * Fix a bunch of simpler tests * cargo +nightly fmt * Add `Immutable` type for txs * Fix more tests * Add comments to `Immutable` * Remove setting of the max limit everywhere and removed unsuded variables * WIP * Something else * Fixed the test `into_checked__tx_fails_when_provided_fees_dont_cover_byte_costs` * Minimized number of modifications * Added getter for the `gas_price` * Fixed several tests * Fix more tests * Use `Immutable` in transact * Fix warnings * Rename types and functions * Update CHANGELOG * Appease Clippy-sama * Fix bad import * Revert "Rename types and functions" This reverts commit 25f44120f0baff4e1dee2ab69fe699e9d3bdb358. * Rename `Immutable` to `Ready` * Add test for verifying `Ready` txs * Update CHANGELOG.md Co-authored-by: Brandon Kite * Improve tests, change `decompose` method * Add `deploy` test for checking `Ready` * Use `CheckError` instead of the `TransactionValidity` * Updated CHANGELOG.md --------- Co-authored-by: xgreenx Co-authored-by: Brandon Kite --- CHANGELOG.md | 4 + fuel-tx/src/builder.rs | 32 +- fuel-tx/src/tests/valid_cases/input.rs | 56 +- fuel-tx/src/tests/valid_cases/transaction.rs | 340 ++++++++---- fuel-tx/src/transaction.rs | 6 + fuel-tx/src/transaction/policies.rs | 5 + fuel-tx/src/transaction/types/create.rs | 23 +- fuel-tx/src/transaction/types/mint.rs | 19 +- fuel-tx/src/transaction/types/script.rs | 3 +- fuel-tx/src/transaction/validity.rs | 20 +- fuel-tx/src/transaction/validity/error.rs | 2 +- fuel-tx/test-helpers/src/lib.rs | 2 +- fuel-vm/examples/external.rs | 9 +- fuel-vm/src/checked_transaction.rs | 517 ++++++++++-------- fuel-vm/src/checked_transaction/balances.rs | 59 +- fuel-vm/src/checked_transaction/builder.rs | 20 +- fuel-vm/src/checked_transaction/types.rs | 37 +- fuel-vm/src/error.rs | 40 +- fuel-vm/src/interpreter/debug.rs | 25 +- .../instruction/tests/reserved_registers.rs | 18 +- fuel-vm/src/interpreter/executors/main.rs | 43 +- .../src/interpreter/executors/main/tests.rs | 101 +++- fuel-vm/src/interpreter/initialization.rs | 5 +- fuel-vm/src/interpreter/internal/tests.rs | 30 +- fuel-vm/src/interpreter/memory/tests.rs | 76 +-- fuel-vm/src/predicate.rs | 9 +- fuel-vm/src/tests/blockchain.rs | 58 +- fuel-vm/src/tests/code_coverage.rs | 3 +- fuel-vm/src/tests/contract.rs | 7 +- fuel-vm/src/tests/crypto.rs | 36 +- fuel-vm/src/tests/external.rs | 8 +- fuel-vm/src/tests/gas_factor.rs | 22 +- fuel-vm/src/tests/memory.rs | 4 +- fuel-vm/src/tests/metadata.rs | 31 +- fuel-vm/src/tests/outputs.rs | 9 +- fuel-vm/src/tests/predicate.rs | 66 +-- fuel-vm/src/tests/profile_gas.rs | 7 +- fuel-vm/src/tests/test_helpers.rs | 19 +- fuel-vm/src/tests/validation.rs | 9 +- fuel-vm/src/transactor.rs | 55 +- fuel-vm/src/util.rs | 26 +- 41 files changed, 1139 insertions(+), 722 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bee6a315b..a0c8423ffc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). #### Breaking +- [#685](https://github.com/FuelLabs/fuel-vm/pull/685): + The `MaxFee` is a mandatory policy to set. The `MaxFee` policy is used to check that the transaction is valid. + Added a new stage for the `Checked` transaction - `Ready`. This type can be constructed with the + `gas_price` before being transacted by the `Interpreter`. - [#671](https://github.com/FuelLabs/fuel-vm/pull/671): Support dynamically sized values in the ContractsState table by using a vector data type (`Vec`). - [#682](https://github.com/FuelLabs/fuel-vm/pull/682): Include `Tip` policy in fee calculation - [#683](https://github.com/FuelLabs/fuel-vm/pull/683): Simplify `InterpreterStorage` by removing dependency on `MerkleRootStorage` and removing `merkle_` prefix from method names. diff --git a/fuel-tx/src/builder.rs b/fuel-tx/src/builder.rs index 1d57ce9a87..b5ac614c44 100644 --- a/fuel-tx/src/builder.rs +++ b/fuel-tx/src/builder.rs @@ -96,7 +96,9 @@ impl BuildableAloc for T where } impl BuildableStd for T where T: Signable + Cacheable {} + impl BuildableSet for T where T: BuildableAloc + BuildableStd {} + impl Buildable for T where T: BuildableSet {} #[derive(Debug, Clone)] @@ -117,7 +119,7 @@ impl TransactionBuilder