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

Account-base fee collection #1407

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,4 @@ tempfile = "3.4"
tikv-jemallocator = "0.5"

[patch.crates-io]
fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm/", branch = "feature/mint-tx-rework-contract" }
fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm/", branch = "master" }
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 4 additions & 0 deletions crates/client/src/client/schema/tx/transparent_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ pub struct Transaction {
pub id: TransactionId,
pub tx_pointer: Option<TxPointer>,
pub input_asset_ids: Option<Vec<AssetId>>,
/// The list of all contracts from the inputs of the transaction.
///
/// It is a helper function and doesn't have a corresponding field in the transaction.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the "helper function"? This is a field on a struct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. The function isn't public though, but this doc comment is public, so maybe mentioning the function isn't necessary as long as you say it's generated rather than part of the original Transaction.

pub input_contracts: Option<Vec<ContractIdFragment>>,
/// The field of the `Mint` transaction.
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
pub input_contract: Option<InputContract>,
pub inputs: Option<Vec<Input>>,
pub is_script: bool,
Expand Down
20 changes: 10 additions & 10 deletions crates/fuel-core/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ where
block.transactions.push(tx);
execution_data.tx_count = tx_count
.checked_add(1)
.ok_or(ExecutorError::TooMuchTransactions)?;
.ok_or(ExecutorError::TooManyTransactions)?;

Ok(())
};
Expand Down Expand Up @@ -643,7 +643,7 @@ where
}

if execution_kind != ExecutionKind::DryRun && !data.found_mint {
return Err(ExecutorError::CoinbaseIsMissed)
return Err(ExecutorError::MintMissing)
}

Ok(data)
Expand Down Expand Up @@ -715,12 +715,12 @@ where
options: ExecutionOptions,
) -> ExecutorResult<Transaction> {
if execution_data.found_mint {
return Err(ExecutorError::CoinbaseSecondTransaction)
return Err(ExecutorError::MintFoundSecondEntry)
}
execution_data.found_mint = true;

if checked_mint.transaction().tx_pointer().tx_index() != execution_data.tx_count {
return Err(ExecutorError::CoinbaseIsNotLastTransaction)
return Err(ExecutorError::MintIsNotLastTransaction)
}

let coinbase_id = checked_mint.id();
Expand Down Expand Up @@ -779,7 +779,7 @@ where
*mint.mint_amount(),
)
.map_err(|e| anyhow::anyhow!(e))
.map_err(ExecutorError::CoinbaseCantIncreaseBalance)?;
.map_err(ExecutorError::CoinbaseCannotIncreaseBalance)?;
bvrooman marked this conversation as resolved.
Show resolved Hide resolved
sub_block_db_commit.commit()?;

self.persist_output_utxos(
Expand Down Expand Up @@ -817,7 +817,7 @@ where

if execution_kind == ExecutionKind::Validation {
if mint.input_contract() != &input || mint.output_contract() != &output {
return Err(ExecutorError::CoinbaseMismatch)
return Err(ExecutorError::MintMismatch)
}
} else {
*mint.input_contract_mut() = input;
Expand All @@ -830,7 +830,7 @@ where
let input = input::contract::Contract::default();
let output = output::contract::Contract::default();
if mint.input_contract() != &input || mint.output_contract() != &output {
return Err(ExecutorError::CoinbaseMismatch)
return Err(ExecutorError::MintMismatch)
}
}

Expand Down Expand Up @@ -2407,7 +2407,7 @@ mod tests {
.expect_err("Expected error because coinbase if invalid");
assert!(matches!(
validation_err,
ExecutorError::CoinbaseIsNotLastTransaction
ExecutorError::MintIsNotLastTransaction
));
}

Expand All @@ -2419,7 +2419,7 @@ mod tests {
let validation_err = validator
.execute_and_commit(ExecutionBlock::Validation(block), Default::default())
.expect_err("Expected error because coinbase is missing");
assert!(matches!(validation_err, ExecutorError::CoinbaseIsMissed));
assert!(matches!(validation_err, ExecutorError::MintMissing));
}

#[test]
Expand Down Expand Up @@ -2529,7 +2529,7 @@ mod tests {
.expect_err("Expected error because coinbase if invalid");
assert!(matches!(
validation_err,
ExecutorError::CoinbaseSecondTransaction
ExecutorError::MintFoundSecondEntry
));
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/fuel-core/src/schema/tx/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,9 @@ impl Transaction {
fuel_tx::Transaction::Create(create) => {
Some(create.input_contracts().map(|v| Contract(*v)).collect())
}
fuel_tx::Transaction::Mint(_) => None,
fuel_tx::Transaction::Mint(mint) => {
Some(vec![Contract(mint.input_contract().contract_id)])
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/services/txpool/src/transaction_selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn select_transactions(
// Future improvements to this algorithm may take into account the parallel nature of
// transactions to maximize throughput.
let mut used_block_space: Word = 0;
// The maximum index for the transaction is `u16`, so we need to
// The type of the index for the transaction is `u16`, so we need to
// limit it to `MAX` value minus 1(because of the `Mint` transaction).
let takes_txs = u16::MAX - 1;

Expand Down
22 changes: 11 additions & 11 deletions crates/types/src/services/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ impl ExecutionKind {
pub enum Error {
#[error("Transaction id was already used: {0:#x}")]
TransactionIdCollision(Bytes32),
#[error("Too much transactions in the block")]
TooMuchTransactions,
#[error("Too many transactions in the block")]
TooManyTransactions,
#[error("output already exists")]
OutputAlreadyExists,
#[error("The computed fee caused an integer overflow")]
FeeOverflow,
#[error("The blocks is missing `Mint` transaction.")]
CoinbaseIsMissed,
#[error("The second entry of the `Mint` - coinbase transaction.")]
CoinbaseSecondTransaction,
#[error("The last transaction in the block is not `Mint` - coinbase.")]
CoinbaseIsNotLastTransaction,
#[error("Coinbase mismatches expectations.")]
CoinbaseMismatch,
#[error("The block is missing `Mint` transaction.")]
MintMissing,
#[error("Found the second entry of the `Mint` transaction in the block.")]
MintFoundSecondEntry,
#[error("The last transaction in the block is not `Mint`.")]
MintIsNotLastTransaction,
#[error("The `Mint` transaction mismatches expectations.")]
MintMismatch,
#[error("Can't increase the balance of the coinbase contract: {0}.")]
CoinbaseCantIncreaseBalance(anyhow::Error),
CoinbaseCannotIncreaseBalance(anyhow::Error),
#[error("Coinbase amount mismatches with expected.")]
CoinbaseAmountMismatch,
#[error("Invalid transaction: {0}")]
Expand Down
6 changes: 3 additions & 3 deletions tests/tests/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,12 @@ async fn get_transactions() {
.iter()
.map(|tx| tx.transaction.id(&ChainId::default()))
.collect_vec();
// coinbase_tx1
assert_eq!(transactions[0], tx1);
// coinbase_tx2
// coinbase_tx1
assert_eq!(transactions[2], tx2);
// coinbase_tx3
// coinbase_tx2
assert_eq!(transactions[4], tx3);
// coinbase_tx3
// Check pagination state for first page
assert!(response.has_next_page);
assert!(!response.has_previous_page);
Expand Down