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

feat: add encoded_length to ValidPoolTransaction #1512

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ where
TransactionValidationOutcome::Valid { balance, state_nonce, transaction } => {
let sender_id = self.get_sender_id(transaction.sender());
let transaction_id = TransactionId::new(sender_id, transaction.nonce());
let encoded_length = transaction.encoded_length();

let tx = ValidPoolTransaction {
cost: transaction.cost(),
Expand All @@ -210,6 +211,7 @@ where
propagate: false,
timestamp: Instant::now(),
origin,
encoded_length,
};

let added = self.pool.write().add_transaction(tx, balance, state_nonce)?;
Expand Down
2 changes: 2 additions & 0 deletions crates/transaction-pool/src/test_utils/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,13 +438,15 @@ impl MockTransactionFactory {
transaction: MockTransaction,
) -> MockValidTx {
let transaction_id = self.tx_id(&transaction);
let encoded_length = transaction.encoded_length();
MockValidTx {
propagate: false,
transaction_id,
cost: transaction.cost(),
transaction,
timestamp: Instant::now(),
origin,
encoded_length,
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/transaction-pool/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub struct ValidPoolTransaction<T: PoolTransaction> {
pub timestamp: Instant,
/// Where this transaction originated from.
pub origin: TransactionOrigin,
/// The length of the rlp encoded transaction (cached)
pub encoded_length: usize,
}

// === impl ValidPoolTransaction ===
Expand Down Expand Up @@ -160,6 +162,7 @@ impl<T: PoolTransaction + Clone> Clone for ValidPoolTransaction<T> {
cost: self.cost,
timestamp: self.timestamp,
origin: self.origin,
encoded_length: self.encoded_length,
}
}
}
Expand Down