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

chore: use correct compressed size estimation fn #13876

Merged
merged 3 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,11 @@ alloy-transport-ws = { version = "0.9.2", default-features = false }
# op
op-alloy-rpc-types = { version = "0.9.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.9.0", default-features = false }
maili-rpc = { version = "0.1.6", default-features = false }
op-alloy-network = { version = "0.9.0", default-features = false }
op-alloy-consensus = { version = "0.9.0", default-features = false }
## op-maili
maili-rpc = { version = "0.1.6", default-features = false }
maili-flz = { version = "0.1.6", default-features = false }

# misc
aquamarine = "0.6"
Expand Down
1 change: 1 addition & 0 deletions crates/optimism/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ alloy-eips.workspace = true
alloy-primitives.workspace = true
op-alloy-consensus.workspace = true
op-alloy-rpc-types-engine.workspace = true
maili-flz.workspace = true
alloy-rpc-types-engine.workspace = true
alloy-consensus.workspace = true

Expand Down
19 changes: 15 additions & 4 deletions crates/optimism/node/src/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,25 @@ impl OpPooledTransaction {
}

/// Returns the estimated compressed size of a transaction in bytes scaled by 1e6.
// This value is computed based on the following formula:
// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
/// This value is computed based on the following formula:
/// `max(minTransactionSize, intercept + fastlzCoef*fastlzSize)`
pub fn estimated_compressed_size(&self) -> u32 {
// TODO(mattsse): use standalone flz compute function
*self.estimated_tx_compressed_size.get_or_init(|| self.inner.encoded_length as u32)
*self
.estimated_tx_compressed_size
.get_or_init(|| 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]) -> u32 {
let fastlz_size = maili_flz::flz_compress_len(input);

fastlz_size.saturating_mul(836_500).saturating_sub(42_585_600).max(100_000_000)
DaniPopes marked this conversation as resolved.
Show resolved Hide resolved
}

impl From<RecoveredTx<op_alloy_consensus::OpPooledTransaction>> for OpPooledTransaction {
fn from(tx: RecoveredTx<op_alloy_consensus::OpPooledTransaction>) -> Self {
let encoded_len = tx.encode_2718_len();
Expand Down
Loading