feat: track encoded length with pooled txs (#4976)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Dan Cline
2023-10-13 06:46:37 -04:00
committed by GitHub
parent 34bc4983e7
commit 6c8c084e36
12 changed files with 136 additions and 41 deletions

View File

@ -20,7 +20,13 @@ fn decode_pooled_transactions_data() {
}
// now do another decoding, on what we encoded - this should succeed
let _txs2 = PooledTransactions::decode(&mut &buf[..]).unwrap();
let txs2 = PooledTransactions::decode(&mut &buf[..]).unwrap();
// ensure that the payload length is the same
assert_eq!(txs.length(), txs2.length());
// ensure that the length is equal to the length of the encoded data
assert_eq!(txs.length(), buf.len());
}
#[test]

View File

@ -845,7 +845,7 @@ impl PropagateTransaction {
/// Create a new instance from a pooled transaction
fn new<T: PoolTransaction>(tx: Arc<ValidPoolTransaction<T>>) -> Self {
let size = tx.encoded_length;
let size = tx.encoded_length();
let transaction = Arc::new(tx.transaction.to_recovered_transaction().into_signed());
Self { size, transaction }
}
@ -900,7 +900,7 @@ impl PooledTransactionsHashesBuilder {
PooledTransactionsHashesBuilder::Eth66(msg) => msg.0.push(*pooled_tx.hash()),
PooledTransactionsHashesBuilder::Eth68(msg) => {
msg.hashes.push(*pooled_tx.hash());
msg.sizes.push(pooled_tx.encoded_length);
msg.sizes.push(pooled_tx.encoded_length());
msg.types.push(pooled_tx.transaction.tx_type());
}
}