Skip to content

Commit 87d3af4

Browse files
apollo_mempool_config: split config to static and dynamic (#9454)
1 parent eae23c8 commit 87d3af4

File tree

7 files changed

+204
-88
lines changed

7 files changed

+204
-88
lines changed
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"mempool_config.capacity_in_bytes": 1073741824,
3-
"mempool_config.committed_nonce_retention_block_count": 100,
4-
"mempool_config.declare_delay": 20,
5-
"mempool_config.enable_fee_escalation": true,
6-
"mempool_config.fee_escalation_percentage": 10,
7-
"mempool_config.transaction_ttl": 300
2+
"mempool_config.dynamic_config.transaction_ttl": 300,
3+
"mempool_config.static_config.capacity_in_bytes": 1073741824,
4+
"mempool_config.static_config.committed_nonce_retention_block_count": 100,
5+
"mempool_config.static_config.declare_delay": 20,
6+
"mempool_config.static_config.enable_fee_escalation": true,
7+
"mempool_config.static_config.fee_escalation_percentage": 10
88
}

crates/apollo_integration_tests/src/utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use apollo_l1_gas_price_provider_config::config::{
3434
use apollo_l1_gas_price_types::DEFAULT_ETH_TO_FRI_RATE;
3535
use apollo_l1_provider_config::config::L1ProviderConfig;
3636
use apollo_l1_scraper_config::config::L1ScraperConfig;
37-
use apollo_mempool_config::config::MempoolConfig;
37+
use apollo_mempool_config::config::{MempoolConfig, MempoolDynamicConfig, MempoolStaticConfig};
3838
use apollo_mempool_p2p_config::config::MempoolP2pConfig;
3939
use apollo_monitoring_endpoint_config::config::MonitoringEndpointConfig;
4040
use apollo_network::network_manager::test_utils::create_connected_network_configs;
@@ -664,9 +664,8 @@ pub fn create_batcher_config(
664664

665665
pub fn create_mempool_config(validate_resource_bounds: bool) -> MempoolConfig {
666666
MempoolConfig {
667-
transaction_ttl: Duration::from_secs(5 * 60),
668-
validate_resource_bounds,
669-
..Default::default()
667+
dynamic_config: MempoolDynamicConfig { transaction_ttl: Duration::from_secs(5 * 60) },
668+
static_config: MempoolStaticConfig { validate_resource_bounds, ..Default::default() },
670669
}
671670
}
672671

crates/apollo_mempool/src/mempool.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl Mempool {
257257
tx_pool: TransactionPool::new(clock.clone()),
258258
tx_queue: TransactionQueue::default(),
259259
accounts_with_gap: AccountsWithGap::new(),
260-
state: MempoolState::new(config.committed_nonce_retention_block_count),
260+
state: MempoolState::new(config.static_config.committed_nonce_retention_block_count),
261261
clock,
262262
}
263263
}
@@ -379,7 +379,7 @@ impl Mempool {
379379
}
380380

381381
fn insert_to_tx_queue(&mut self, tx_reference: TransactionReference) {
382-
self.tx_queue.insert(tx_reference, self.config.validate_resource_bounds);
382+
self.tx_queue.insert(tx_reference, self.config.static_config.validate_resource_bounds);
383383
}
384384

385385
fn add_tx_inner(&mut self, args: AddTransactionArgs) {
@@ -407,7 +407,7 @@ impl Mempool {
407407
fn add_ready_declares(&mut self) {
408408
let now = self.clock.now();
409409
while let Some((submission_time, _args)) = self.delayed_declares.front() {
410-
if now - self.config.declare_delay < *submission_time {
410+
if now - self.config.static_config.declare_delay < *submission_time {
411411
break;
412412
}
413413
let (_submission_time, args) =
@@ -564,7 +564,7 @@ impl Mempool {
564564

565565
self.validate_no_delayed_declare_front_run(incoming_tx_reference)?;
566566

567-
if !self.config.enable_fee_escalation {
567+
if !self.config.static_config.enable_fee_escalation {
568568
if self.tx_pool.get_by_address_and_nonce(address, nonce).is_some() {
569569
return Err(MempoolError::DuplicateNonce { address, nonce });
570570
};
@@ -612,7 +612,7 @@ impl Mempool {
612612
}
613613

614614
fn increased_enough(&self, existing_value: u128, incoming_value: u128) -> bool {
615-
let percentage = u128::from(self.config.fee_escalation_percentage);
615+
let percentage = u128::from(self.config.static_config.fee_escalation_percentage);
616616

617617
// Note: To reduce precision loss, we first multiply by the percentage and then divide by
618618
// 100. This could cause an overflow and an automatic rejection of the transaction, but the
@@ -630,8 +630,9 @@ impl Mempool {
630630
}
631631

632632
fn remove_expired_txs(&mut self) -> AddressToNonce {
633-
let removed_txs =
634-
self.tx_pool.remove_txs_older_than(self.config.transaction_ttl, &self.state.staged);
633+
let removed_txs = self
634+
.tx_pool
635+
.remove_txs_older_than(self.config.dynamic_config.transaction_ttl, &self.state.staged);
635636
let queued_txs = self.tx_queue.remove_txs(&removed_txs);
636637

637638
metric_count_expired_txs(removed_txs.len());
@@ -651,7 +652,7 @@ impl Mempool {
651652
) -> (Vec<TransactionReference>, AddressToNonce) {
652653
// Divide the chunk into transactions that are old and no longer valid and those that
653654
// remain valid.
654-
let submission_cutoff_time = self.clock.now() - self.config.transaction_ttl;
655+
let submission_cutoff_time = self.clock.now() - self.config.dynamic_config.transaction_ttl;
655656
let (old_txs, valid_txs): (Vec<_>, Vec<_>) = txs.into_iter().partition(|tx| {
656657
let tx_submission_time = self
657658
.tx_pool
@@ -695,7 +696,7 @@ impl Mempool {
695696

696697
// Returns true if the mempool will exceeds its capacity by adding the given transaction.
697698
fn exceeds_capacity(&self, tx: &InternalRpcTransaction) -> bool {
698-
self.size_in_bytes() + tx.total_bytes() > self.config.capacity_in_bytes
699+
self.size_in_bytes() + tx.total_bytes() > self.config.static_config.capacity_in_bytes
699700
}
700701

701702
fn update_accounts_with_gap(&mut self, address_to_nonce: AddressToNonce) {

0 commit comments

Comments
 (0)