Skip to content

Commit

Permalink
feat: add encoded_length to ValidPoolTransaction (#1512)
Browse files Browse the repository at this point in the history
  • Loading branch information
leruaa authored Feb 22, 2023
1 parent 8094ab1 commit fdff1b0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
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

0 comments on commit fdff1b0

Please sign in to comment.