Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use max fee policy to charge user #685

Merged
merged 55 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
1fbbbcf
refactor hard-to-read function
MitchTurner Feb 22, 2024
4d153f2
WIP
MitchTurner Feb 23, 2024
4312334
Remove comments
MitchTurner Feb 23, 2024
fddf65c
Remove fee checks, fmt
MitchTurner Feb 23, 2024
1cd417b
Remove `gas_price` from check
MitchTurner Feb 23, 2024
32b4aef
Get tests compiling but not passing
MitchTurner Feb 23, 2024
433368b
Replace limit tests with exists tests
MitchTurner Feb 23, 2024
d69ac55
Break down `create` tests, fix those tests
MitchTurner Feb 23, 2024
de11ae2
Break down `script` tests, fix those tests
MitchTurner Feb 23, 2024
2e6f566
Fix broken tx tests
MitchTurner Feb 23, 2024
7720f63
Fix warnings
MitchTurner Feb 24, 2024
e8be36c
Fix `run_script` to incude `max_fee`
MitchTurner Feb 24, 2024
6b0edf3
WIP
MitchTurner Feb 24, 2024
a2bca8f
WIP
MitchTurner Feb 26, 2024
409ed78
Take ref and clone instead of mut in finalize
MitchTurner Feb 26, 2024
45e95e5
Modify test builder to have default max_fee_limit of 0
MitchTurner Feb 26, 2024
b43ffc0
Fix input tests
MitchTurner Feb 26, 2024
e744168
WIP fixing tests
MitchTurner Feb 26, 2024
fbbf302
Merge remote-tracking branch 'origin' into use-max-fee-to-charge-user
MitchTurner Feb 26, 2024
0624105
Finish reconciling merge
MitchTurner Feb 26, 2024
6d1c279
Fix `blockchain` tests
MitchTurner Feb 26, 2024
ec6aa89
Fix setup function for many tests
MitchTurner Feb 27, 2024
bd4b8d6
Fix metadata tests
MitchTurner Feb 27, 2024
038ab0c
Fix predicate tests
MitchTurner Feb 27, 2024
2de6e37
Fix interpreter tests
MitchTurner Feb 27, 2024
d648d64
Merge branch 'master' into use-max-fee-to-charge-user
MitchTurner Feb 27, 2024
239d28e
Merge branch 'use-max-fee-to-charge-user' of github.com:FuelLabs/fuel…
MitchTurner Feb 27, 2024
6cea3fc
Fix a bunch of simpler tests
MitchTurner Feb 28, 2024
37be054
cargo +nightly fmt
xgreenx Feb 28, 2024
6e88904
Add `Immutable` type for txs
MitchTurner Feb 28, 2024
8f1d701
Fix more tests
MitchTurner Feb 28, 2024
e03e877
Add comments to `Immutable`
MitchTurner Feb 28, 2024
5e8a886
Remove setting of the max limit everywhere and removed unsuded variables
xgreenx Feb 28, 2024
2a800c7
WIP
MitchTurner Feb 28, 2024
38f5a6b
Something else
xgreenx Feb 28, 2024
d164d8f
Fixed the test `into_checked__tx_fails_when_provided_fees_dont_cover_…
xgreenx Feb 28, 2024
aad9b01
Minimized number of modifications
xgreenx Feb 28, 2024
04404b4
Added getter for the `gas_price`
xgreenx Feb 28, 2024
15c534f
Fixed several tests
xgreenx Feb 28, 2024
f1a267f
Fix more tests
MitchTurner Feb 28, 2024
ef14aa0
Use `Immutable` in transact
MitchTurner Feb 28, 2024
da69f7f
Fix warnings
MitchTurner Feb 28, 2024
25f4412
Rename types and functions
MitchTurner Feb 28, 2024
a148f4a
Update CHANGELOG
MitchTurner Feb 28, 2024
2653138
Merge remote-tracking branch 'origin' into use-max-fee-to-charge-user
MitchTurner Feb 28, 2024
fae7be8
Appease Clippy-sama
MitchTurner Feb 28, 2024
c2156f5
Fix bad import
MitchTurner Feb 28, 2024
bff6237
Revert "Rename types and functions"
MitchTurner Feb 28, 2024
b84e06b
Rename `Immutable` to `Ready`
MitchTurner Feb 28, 2024
0f76e91
Add test for verifying `Ready` txs
MitchTurner Feb 29, 2024
24f7144
Update CHANGELOG.md
MitchTurner Feb 29, 2024
e03c50d
Improve tests, change `decompose` method
MitchTurner Feb 29, 2024
741ad6f
Add `deploy` test for checking `Ready`
MitchTurner Feb 29, 2024
b9be7a8
Use `CheckError` instead of the `TransactionValidity`
xgreenx Feb 29, 2024
8b68fe4
Updated CHANGELOG.md
xgreenx Feb 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>`).
- [#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.
Expand Down
32 changes: 17 additions & 15 deletions fuel-tx/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ impl<T> BuildableAloc for T where
}

impl<T> BuildableStd for T where T: Signable + Cacheable {}

impl<T> BuildableSet for T where T: BuildableAloc + BuildableStd {}

impl<T> Buildable for T where T: BuildableSet {}

#[derive(Debug, Clone)]
Expand All @@ -117,7 +119,7 @@ impl TransactionBuilder<Script> {
script_gas_limit: Default::default(),
script,
script_data,
policies: Policies::new(),
policies: Policies::new().with_max_fee(0),
inputs: Default::default(),
outputs: Default::default(),
witnesses: Default::default(),
Expand All @@ -141,7 +143,7 @@ impl TransactionBuilder<Create> {
bytecode_witness_index: Default::default(),
salt,
storage_slots,
policies: Policies::new(),
policies: Policies::new().with_max_fee(0),
inputs: Default::default(),
outputs: Default::default(),
witnesses: Default::default(),
Expand Down Expand Up @@ -412,8 +414,8 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
*witness_index
}

fn finalize_inner(&mut self) -> Tx {
let mut tx = core::mem::take(&mut self.tx);
fn finalize_inner(&self) -> Tx {
let mut tx = self.tx.clone();

self.sign_keys
.iter()
Expand All @@ -425,8 +427,8 @@ impl<Tx: Buildable> TransactionBuilder<Tx> {
tx
}

pub fn finalize_without_signature_inner(&mut self) -> Tx {
let mut tx = core::mem::take(&mut self.tx);
pub fn finalize_without_signature_inner(&self) -> Tx {
let mut tx = self.tx.clone();

tx.precompute(&self.get_chain_id())
.expect("Should be able to calculate cache");
Expand All @@ -443,40 +445,40 @@ impl<Tx: field::Outputs> TransactionBuilder<Tx> {
}

pub trait Finalizable<Tx> {
fn finalize(&mut self) -> Tx;
fn finalize(&self) -> Tx;

fn finalize_without_signature(&mut self) -> Tx;
fn finalize_without_signature(&self) -> Tx;
}

impl Finalizable<Mint> for TransactionBuilder<Mint> {
fn finalize(&mut self) -> Mint {
let mut tx = core::mem::take(&mut self.tx);
fn finalize(&self) -> Mint {
let mut tx = self.tx.clone();
tx.precompute(&self.get_chain_id())
.expect("Should be able to calculate cache");
tx
}

fn finalize_without_signature(&mut self) -> Mint {
fn finalize_without_signature(&self) -> Mint {
self.finalize()
}
}

impl Finalizable<Create> for TransactionBuilder<Create> {
fn finalize(&mut self) -> Create {
fn finalize(&self) -> Create {
self.finalize_inner()
}

fn finalize_without_signature(&mut self) -> Create {
fn finalize_without_signature(&self) -> Create {
self.finalize_without_signature_inner()
}
}

impl Finalizable<Script> for TransactionBuilder<Script> {
fn finalize(&mut self) -> Script {
fn finalize(&self) -> Script {
self.finalize_inner()
}

fn finalize_without_signature(&mut self) -> Script {
fn finalize_without_signature(&self) -> Script {
self.finalize_without_signature_inner()
}
}
Expand Down
56 changes: 10 additions & 46 deletions fuel-tx/src/tests/valid_cases/input.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::cast_possible_truncation)]

use super::PREDICATE_PARAMS;

use fuel_crypto::{
Expand Down Expand Up @@ -139,21 +140,15 @@ fn input_coin_message_signature() {
#[test]
fn coin_signed() {
let rng = &mut StdRng::seed_from_u64(8586);
let arb_gas_price = 1;

let mut tx = Script::default();
let mut tx = TransactionBuilder::script(vec![], vec![]).finalize();

let input =
Input::coin_signed(rng.gen(), rng.gen(), rng.gen(), rng.gen(), rng.gen(), 0);
tx.add_input(input);

let block_height = rng.gen();
let err = tx
.check(
block_height,
&ConsensusParameters::standard(),
arb_gas_price,
)
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err);
Expand All @@ -164,7 +159,6 @@ fn duplicate_secrets_reuse_witness() {
let rng = &mut StdRng::seed_from_u64(10000);
let key = SecretKey::random(rng);

// verify witness reuse for script txs
let script = TransactionBuilder::script(vec![], vec![])
// coin 1
.add_unsigned_coin_input(key, rng.gen(), 100, Default::default(), Default::default())
Expand Down Expand Up @@ -326,8 +320,6 @@ fn contract() {
#[test]
fn message_metadata() {
let rng = &mut StdRng::seed_from_u64(8586);
let arb_gas_price = 1;

let txhash: Bytes32 = rng.gen();

let predicate = generate_nonempty_padded_bytes(rng);
Expand All @@ -346,7 +338,7 @@ fn message_metadata() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect("failed to validate empty message input");

let mut tx = Script::default();
let mut tx = TransactionBuilder::script(vec![], vec![]).finalize();

let input = Input::message_data_signed(
rng.gen(),
Expand All @@ -364,11 +356,7 @@ fn message_metadata() {

let block_height = rng.gen();
let err = tx
.check(
block_height,
&ConsensusParameters::standard(),
arb_gas_price,
)
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err,);
Expand Down Expand Up @@ -468,9 +456,6 @@ fn message_metadata() {
#[test]
fn message_message_coin() {
let rng = &mut StdRng::seed_from_u64(8586);

let arb_gas_price = 1;

let txhash: Bytes32 = rng.gen();

let predicate = generate_nonempty_padded_bytes(rng);
Expand All @@ -488,18 +473,14 @@ fn message_message_coin() {
.check(1, &txhash, &[], &[], &Default::default(), &mut None)
.expect("failed to validate empty message input");

let mut tx = Script::default();
let mut tx = TransactionBuilder::script(vec![], vec![]).finalize();

let input = Input::message_coin_signed(rng.gen(), rng.gen(), rng.gen(), rng.gen(), 0);
tx.add_input(input);

let block_height = rng.gen();
let err = tx
.check(
block_height,
&ConsensusParameters::standard(),
arb_gas_price,
)
.check(block_height, &ConsensusParameters::standard())
.expect_err("Expected failure");

assert_eq!(ValidityError::InputWitnessIndexBounds { index: 0 }, err,);
Expand Down Expand Up @@ -560,7 +541,6 @@ fn message_message_coin() {
fn transaction_with_duplicate_coin_inputs_is_invalid() {
let rng = &mut StdRng::seed_from_u64(8586);
let utxo_id = rng.gen();
let arb_gas_price = 1;

let a = Input::coin_signed(utxo_id, rng.gen(), rng.gen(), rng.gen(), rng.gen(), 0);
let b = Input::coin_signed(utxo_id, rng.gen(), rng.gen(), rng.gen(), rng.gen(), 0);
Expand All @@ -570,11 +550,7 @@ fn transaction_with_duplicate_coin_inputs_is_invalid() {
.add_input(b)
.add_witness(rng.gen())
.finalize()
.check_without_signatures(
Default::default(),
&ConsensusParameters::standard(),
arb_gas_price,
)
.check_without_signatures(Default::default(), &ConsensusParameters::standard())
.expect_err("Expected checkable failure");

assert_eq!(err, ValidityError::DuplicateInputUtxoId { utxo_id });
Expand All @@ -583,7 +559,6 @@ fn transaction_with_duplicate_coin_inputs_is_invalid() {
#[test]
fn transaction_with_duplicate_message_inputs_is_invalid() {
let rng = &mut StdRng::seed_from_u64(8586);
let arb_gas_price = 1;
let message_input = Input::message_data_signed(
rng.gen(),
rng.gen(),
Expand Down Expand Up @@ -612,7 +587,6 @@ fn transaction_with_duplicate_message_inputs_is_invalid() {
.check_without_signatures(
Default::default(),
&ConsensusParameters::standard(),
arb_gas_price,
)
.expect_err("Expected checkable failure");

Expand All @@ -622,7 +596,6 @@ fn transaction_with_duplicate_message_inputs_is_invalid() {
#[test]
fn transaction_with_duplicate_contract_inputs_is_invalid() {
let rng = &mut StdRng::seed_from_u64(8586);
let arb_gas_price = 1;
let contract_id = rng.gen();
let fee = Input::coin_signed(
rng.gen(),
Expand All @@ -646,11 +619,7 @@ fn transaction_with_duplicate_contract_inputs_is_invalid() {
.add_output(o)
.add_output(p)
.finalize()
.check_without_signatures(
Default::default(),
&ConsensusParameters::standard(),
arb_gas_price,
)
.check_without_signatures(Default::default(), &ConsensusParameters::standard())
.expect_err("Expected checkable failure");

assert_eq!(err, ValidityError::DuplicateInputContractId { contract_id });
Expand All @@ -660,7 +629,6 @@ fn transaction_with_duplicate_contract_inputs_is_invalid() {
fn transaction_with_duplicate_contract_utxo_id_is_valid() {
let rng = &mut StdRng::seed_from_u64(8586);
let input_utxo_id: UtxoId = rng.gen();
let arb_gas_price = 1;

let a = Input::contract(input_utxo_id, rng.gen(), rng.gen(), rng.gen(), rng.gen());
let b = Input::contract(input_utxo_id, rng.gen(), rng.gen(), rng.gen(), rng.gen());
Expand All @@ -678,10 +646,6 @@ fn transaction_with_duplicate_contract_utxo_id_is_valid() {
.add_output(p)
.add_witness(rng.gen())
.finalize()
.check_without_signatures(
Default::default(),
&ConsensusParameters::standard(),
arb_gas_price,
)
.check_without_signatures(Default::default(), &ConsensusParameters::standard())
.expect("Duplicated UTXO id is valid for contract input");
}
Loading
Loading