mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use correct compressed size estimation fn (#13876)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -8333,6 +8333,7 @@ dependencies = [
|
|||||||
"derive_more",
|
"derive_more",
|
||||||
"eyre",
|
"eyre",
|
||||||
"futures",
|
"futures",
|
||||||
|
"maili-flz",
|
||||||
"op-alloy-consensus",
|
"op-alloy-consensus",
|
||||||
"op-alloy-rpc-types-engine",
|
"op-alloy-rpc-types-engine",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
|||||||
@ -472,9 +472,11 @@ alloy-transport-ws = { version = "0.9.2", default-features = false }
|
|||||||
# op
|
# op
|
||||||
op-alloy-rpc-types = { version = "0.9.0", default-features = false }
|
op-alloy-rpc-types = { version = "0.9.0", default-features = false }
|
||||||
op-alloy-rpc-types-engine = { 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-network = { version = "0.9.0", default-features = false }
|
||||||
op-alloy-consensus = { 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
|
# misc
|
||||||
aquamarine = "0.6"
|
aquamarine = "0.6"
|
||||||
|
|||||||
@ -52,6 +52,7 @@ alloy-eips.workspace = true
|
|||||||
alloy-primitives.workspace = true
|
alloy-primitives.workspace = true
|
||||||
op-alloy-consensus.workspace = true
|
op-alloy-consensus.workspace = true
|
||||||
op-alloy-rpc-types-engine.workspace = true
|
op-alloy-rpc-types-engine.workspace = true
|
||||||
|
maili-flz.workspace = true
|
||||||
alloy-rpc-types-engine.workspace = true
|
alloy-rpc-types-engine.workspace = true
|
||||||
alloy-consensus.workspace = true
|
alloy-consensus.workspace = true
|
||||||
|
|
||||||
|
|||||||
@ -45,7 +45,7 @@ pub struct OpPooledTransaction {
|
|||||||
#[deref]
|
#[deref]
|
||||||
inner: EthPooledTransaction<OpTransactionSigned>,
|
inner: EthPooledTransaction<OpTransactionSigned>,
|
||||||
/// The estimated size of this transaction, lazily computed.
|
/// The estimated size of this transaction, lazily computed.
|
||||||
estimated_tx_compressed_size: OnceLock<u32>,
|
estimated_tx_compressed_size: OnceLock<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpPooledTransaction {
|
impl OpPooledTransaction {
|
||||||
@ -58,14 +58,25 @@ impl OpPooledTransaction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// 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)`
|
||||||
pub fn estimated_compressed_size(&self) -> u32 {
|
pub fn estimated_compressed_size(&self) -> u64 {
|
||||||
// TODO(mattsse): use standalone flz compute function
|
*self
|
||||||
*self.estimated_tx_compressed_size.get_or_init(|| self.inner.encoded_length as u32)
|
.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]) -> u64 {
|
||||||
|
let fastlz_size = maili_flz::flz_compress_len(input) as u64;
|
||||||
|
|
||||||
|
fastlz_size.saturating_mul(836_500).saturating_sub(42_585_600).max(100_000_000)
|
||||||
|
}
|
||||||
|
|
||||||
impl From<RecoveredTx<op_alloy_consensus::OpPooledTransaction>> for OpPooledTransaction {
|
impl From<RecoveredTx<op_alloy_consensus::OpPooledTransaction>> for OpPooledTransaction {
|
||||||
fn from(tx: RecoveredTx<op_alloy_consensus::OpPooledTransaction>) -> Self {
|
fn from(tx: RecoveredTx<op_alloy_consensus::OpPooledTransaction>) -> Self {
|
||||||
let encoded_len = tx.encode_2718_len();
|
let encoded_len = tx.encode_2718_len();
|
||||||
|
|||||||
Reference in New Issue
Block a user