mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat(op-pool-tx): add new field to store encoded 2718 bytes (#14665)
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
@ -33,6 +33,9 @@ pub struct OpPooledTransaction<
|
|||||||
|
|
||||||
/// Optional conditional attached to this transaction.
|
/// Optional conditional attached to this transaction.
|
||||||
conditional: Option<Box<TransactionConditional>>,
|
conditional: Option<Box<TransactionConditional>>,
|
||||||
|
|
||||||
|
/// Cached EIP-2718 encoded bytes of the transaction, lazily computed.
|
||||||
|
encoded_2718: OnceLock<Bytes>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Cons: SignedTransaction, Pooled> OpPooledTransaction<Cons, Pooled> {
|
impl<Cons: SignedTransaction, Pooled> OpPooledTransaction<Cons, Pooled> {
|
||||||
@ -43,16 +46,23 @@ impl<Cons: SignedTransaction, Pooled> OpPooledTransaction<Cons, Pooled> {
|
|||||||
estimated_tx_compressed_size: Default::default(),
|
estimated_tx_compressed_size: Default::default(),
|
||||||
conditional: None,
|
conditional: None,
|
||||||
_pd: core::marker::PhantomData,
|
_pd: core::marker::PhantomData,
|
||||||
|
encoded_2718: Default::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the estimated compressed size of a transaction in bytes scaled by 1e6.
|
/// Returns the estimated compressed size of a transaction in bytes scaled by 1e6.
|
||||||
/// This value is computed based on the following formula:
|
/// This value is computed based on the following formula:
|
||||||
/// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
|
/// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
|
||||||
|
/// Uses cached EIP-2718 encoded bytes to avoid recomputing the encoding for each estimation.
|
||||||
pub fn estimated_compressed_size(&self) -> u64 {
|
pub fn estimated_compressed_size(&self) -> u64 {
|
||||||
*self.estimated_tx_compressed_size.get_or_init(|| {
|
*self
|
||||||
op_alloy_flz::tx_estimated_size_fjord(&self.inner.transaction().encoded_2718())
|
.estimated_tx_compressed_size
|
||||||
})
|
.get_or_init(|| op_alloy_flz::tx_estimated_size_fjord(self.encoded_2718()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns lazily computed EIP-2718 encoded bytes of the transaction.
|
||||||
|
pub fn encoded_2718(&self) -> &Bytes {
|
||||||
|
self.encoded_2718.get_or_init(|| self.inner.transaction().encoded_2718().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Conditional setter.
|
/// Conditional setter.
|
||||||
|
|||||||
Reference in New Issue
Block a user