Skip to content

Commit ca1c9d2

Browse files
authored
Mempool limits (#598)
* fix: handle warnings from latest cargo version * feat: mempool limits * fix: fix logic error * chore: update changelog * chore: release version 1.4.0 * Update README
1 parent d9ceffe commit ca1c9d2

File tree

13 files changed

+262
-32
lines changed

13 files changed

+262
-32
lines changed

data/simulation/config.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export interface Config {
6363
* If true, transactions will be removed from the Leios mempool if they conflict with in-flight IBs.
6464
*/
6565
"leios-mempool-aggressive-pruning": boolean;
66+
/**
67+
* The maximum size of a mempool, in bytes
68+
*/
69+
"leios-mempool-size-bytes"?: bigint | null;
6670
/**
6771
* Praos blockchain quality parameter.
6872
* This is η from the Leios paper.

data/simulation/config.default.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ leios-header-diffusion-time-ms: 1000.0
3232
leios-ib-generation-time-ms: 130.0
3333
leios-mempool-sampling-strategy: ordered-by-id
3434
leios-mempool-aggressive-pruning: false
35+
leios-mempool-size-bytes: null
3536
# TODO: revise default
3637
praos-chain-quality: 40
3738
praos-fallback-enabled: true

data/simulation/config.schema.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@
383383
"$ref": "#/definitions/MempoolSamplingStrategy",
384384
"description": "The strategy to use when selecting TXs from the Leios mempool."
385385
},
386+
"leios-mempool-size-bytes": {
387+
"additionalProperties": false,
388+
"description": "The maximum size of a mempool, in bytes",
389+
"properties": {},
390+
"type": "number"
391+
},
386392
"leios-stage-active-voting-slots": {
387393
"additionalProperties": false,
388394
"properties": {},

sim-rs/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## v1.4.0
4+
5+
### Linear Leios
6+
7+
- Add bounded mempools. Configure them with by setting `leios-mempool-size-bytes`. Incoming transactions which don't fit in the mempool will be queued for inclusion in the mempool when there is space. Transactions referenced by an EB which are not yet in the mempool will still be forwarded to peers.
8+
9+
### Other
10+
11+
- Fix warnings from new rust version
12+
313
## v1.3.1
414

515
### Linear Leios

sim-rs/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sim-rs/implementations/LINEAR_LEIOS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ When a node creates an RB, it will follow these steps in order:
5050

5151
When a node receives an RB body, it immediately removes all referenced/conflicting transactions from its mempool. If the RB has an EB certificate, it also removes that EB’s transactions from its mempool. If the certified EB arrives after the RB body, we remove its TXs from the mempool once it arrives.
5252

53+
### Bounded mempools
54+
55+
The mempool can be configured with an optional size limit, through the `leios-mempool-size-bytes` parameter. When a node tries adding a transaction to a full mempool, the transaction will go into an (unbounded) queue instead. Nodes will only announce transactions to their peers once those transactions have actually reached the mempool.
56+
57+
If a node has received an EB which references transactions, and those transactions are in the queue but not yet in the mempool, the node will announce those transactions to its peer as well. This is to simulate the behavior of the real protocol, where nodes may request transactions from an EB separately from the TxSubmission mini-protocol.
58+
5359
## New parameters
5460

5561
|Name|Description|Default value|

sim-rs/sim-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sim-cli"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
edition = "2024"
55
default-run = "sim-cli"
66
rust-version = "1.88"

sim-rs/sim-cli/src/events/aggregate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl TraceAggregator {
232232
let new_chunk = (event.time_s - Timestamp::zero()).as_millis() / 250;
233233
self.current_time = event.time_s;
234234
if current_chunk != new_chunk {
235-
if new_chunk % 4 == 0 {
235+
if new_chunk.is_multiple_of(4) {
236236
let timestamp = Timestamp::from_secs((new_chunk / 4) as u64);
237237
self.tx_counts.push(self.produce_tx_counts(timestamp));
238238
}

sim-rs/sim-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sim-core"
3-
version = "1.3.1"
3+
version = "1.4.0"
44
edition = "2024"
55
rust-version = "1.88"
66

sim-rs/sim-core/src/config.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ pub struct RawParameters {
7474
pub leios_ib_generation_time_ms: f64,
7575
pub leios_mempool_sampling_strategy: MempoolSamplingStrategy,
7676
pub leios_mempool_aggressive_pruning: bool,
77+
pub leios_mempool_size_bytes: Option<u64>,
7778
pub praos_chain_quality: u64,
7879
pub praos_fallback_enabled: bool,
7980
pub linear_vote_stage_length_slots: u64,
@@ -716,6 +717,7 @@ pub struct SimConfiguration {
716717
pub(crate) relay_strategy: RelayStrategy,
717718
pub(crate) mempool_strategy: MempoolSamplingStrategy,
718719
pub(crate) mempool_aggressive_pruning: bool,
720+
pub(crate) mempool_size_bytes: u64,
719721
pub(crate) praos_chain_quality: u64,
720722
pub(crate) block_generation_probability: f64,
721723
pub(crate) ib_generation_probability: f64,
@@ -742,7 +744,7 @@ pub struct SimConfiguration {
742744

743745
impl SimConfiguration {
744746
pub fn build(params: RawParameters, mut topology: Topology) -> Result<Self> {
745-
if params.ib_shards % params.ib_shard_group_count != 0 {
747+
if !params.ib_shards.is_multiple_of(params.ib_shard_group_count) {
746748
bail!(
747749
"ib-shards ({}) is not divisible by ib-shard-group-count ({})",
748750
params.ib_shards,
@@ -751,7 +753,9 @@ impl SimConfiguration {
751753
}
752754
if matches!(params.leios_variant, LeiosVariant::FullWithoutIbs)
753755
&& params.ib_shard_group_count != 1
754-
&& params.ib_shard_period_length_slots % params.leios_stage_length_slots != 0
756+
&& !params
757+
.ib_shard_period_length_slots
758+
.is_multiple_of(params.leios_stage_length_slots)
755759
{
756760
bail!(
757761
"Invalid sharding configuration. EBs are generated every {} slot(s). This sim is configured to choose EB shards from 1 of {} groups, using a different group every {} slot(s). Some groups would never be chosen.",
@@ -782,6 +786,7 @@ impl SimConfiguration {
782786
relay_strategy: params.relay_strategy,
783787
mempool_strategy: params.leios_mempool_sampling_strategy,
784788
mempool_aggressive_pruning: params.leios_mempool_aggressive_pruning,
789+
mempool_size_bytes: params.leios_mempool_size_bytes.unwrap_or(u64::MAX),
785790
praos_chain_quality: params.praos_chain_quality,
786791
block_generation_probability: params.rb_generation_probability,
787792
ib_generation_probability: params.ib_generation_probability,

0 commit comments

Comments
 (0)