chore: use flz estimate (#13930)

This commit is contained in:
Matthias Seitz
2025-01-22 19:24:25 +01:00
committed by GitHub
parent d10dfaca1e
commit 82a0734c19

View File

@ -61,22 +61,12 @@ impl OpPooledTransaction {
/// This value is computed based on the following formula:
/// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
pub fn estimated_compressed_size(&self) -> u64 {
*self
.estimated_tx_compressed_size
.get_or_init(|| tx_estimated_size_fjord(&self.inner.transaction().encoded_2718()))
*self.estimated_tx_compressed_size.get_or_init(|| {
op_alloy_flz::tx_estimated_size_fjord(&self.inner.transaction().encoded_2718())
})
}
}
/// Calculate the estimated compressed transaction size in bytes, scaled by 1e6.
/// This value is computed based on the following formula:
/// max(minTransactionSize, intercept + fastlzCoef*fastlzSize)
// TODO(mattsse): replace with library fn from revm or maili once available
fn tx_estimated_size_fjord(input: &[u8]) -> u64 {
let fastlz_size = op_alloy_flz::flz_compress_len(input) as u64;
fastlz_size.saturating_mul(836_500).saturating_sub(42_585_600).max(100_000_000)
}
impl From<Recovered<op_alloy_consensus::OpPooledTransaction>> for OpPooledTransaction {
fn from(tx: Recovered<op_alloy_consensus::OpPooledTransaction>) -> Self {
let encoded_len = tx.encode_2718_len();