Skip to content

Commit eb80e15

Browse files
authored
Implement overcollateralization (#419)
* sim-rs: add config/output for overcollateralization * sim-rs: respect overcollateralization when building IBs
1 parent 8569547 commit eb80e15

File tree

11 files changed

+58
-3
lines changed

11 files changed

+58
-3
lines changed

data/simulation/config.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export interface Config {
7575
"tx-generation-distribution": Distribution;
7676
/** Only supported by Rust simulation. */
7777
"tx-size-bytes-distribution": Distribution;
78+
/**
79+
* Distribution used to choose the "over-collateralization factor" for a transaction.
80+
* 0 means the transaction is not over-collateralized, n means it has enough extra collateral to be included in n shards.
81+
* Only supported by Rust simulation. */
82+
"tx-overcollateralization-factor-distribution": Distribution;
7883
/** Only supported by Rust simulation. */
7984
"tx-validation-cpu-time-ms": number;
8085
/** Only supported by Rust simulation. */

data/simulation/config.default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ tx-size-bytes-distribution:
4747
distribution: log-normal
4848
mu: 6.833
4949
sigma: 1.127
50+
tx-overcollateralization-factor-distribution:
51+
distribution: constant
52+
value: 0
5053
tx-validation-cpu-time-ms: 1.5
5154
tx-max-size-bytes: 16384
5255
tx-conflict-fraction: 0

data/simulation/config.schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,10 @@
273273
"description": "Extends Leios so that EB producers include IBs directly from previous pipelines\nwhere no certified EB was observed.\n\nOnly supported by Rust simulation.",
274274
"type": "boolean"
275275
},
276+
"leios-mempool-aggressive-pruning": {
277+
"description": "If true, transactions will be removed from the Leios mempool if they conflict with in-flight IBs.",
278+
"type": "boolean"
279+
},
276280
"leios-mempool-sampling-strategy": {
277281
"$ref": "#/definitions/MempoolSamplingStrategy",
278282
"description": "The strategy to use when selecting TXs from the Leios mempool."
@@ -369,6 +373,10 @@
369373
"properties": {},
370374
"type": "number"
371375
},
376+
"tx-overcollateralization-factor-distribution": {
377+
"$ref": "#/definitions/Distribution",
378+
"description": "Distribution used to choose the \"over-collateralization factor\" for a transaction.\n0 means the transaction is not over-collateralized, n means it has enough extra collateral to be included in n shards.\nOnly supported by Rust simulation."
379+
},
372380
"tx-size-bytes-distribution": {
373381
"$ref": "#/definitions/Distribution",
374382
"description": "Only supported by Rust simulation."

data/simulation/example.rust.jsonl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{"time_s":0.0,"message":{"type":"CpuTaskScheduled","task":{"node":"node-0","index":1},"task_type":"GenIB","subtasks":1}}
88
{"time_s":0.0,"message":{"type":"Cpu","task":{"node":"node-0","index":1},"node":"node-0","cpu_time_s":0.13,"task_label":"GenIB: node-0-1-0","task_type":"GenIB","id":"node-0-1-0"}}
99
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-1","slot":0,"pipeline":0,"producer":"node-1"}}
10-
{"time_s":0.0,"message":{"type":"TXGenerated","id":"0","publisher":"node-11","size_bytes":156,"input_id":0}}
10+
{"time_s":0.0,"message":{"type":"TXGenerated","id":"0","publisher":"node-11","size_bytes":156,"input_id":0,"shard":0,"overcollateralization_factor":0}}
1111
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-3","slot":0,"pipeline":0,"producer":"node-3"}}
1212
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-4","slot":0,"pipeline":0,"producer":"node-4"}}
1313
{"time_s":0.0,"message":{"type":"EBLotteryWon","id":"0-node-4","slot":0,"pipeline":1,"producer":"node-4"}}

data/simulation/trace.rust.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ interface GeneratedTransaction {
5757
publisher: string;
5858
size_bytes: number;
5959
input_id: number;
60+
shard: number;
61+
overcollateralization_factor: number;
6062
}
6163

6264
interface LostTransaction {

data/simulation/trace.rust.schema.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,15 @@
242242
"input_id": {
243243
"type": "number"
244244
},
245+
"overcollateralization_factor": {
246+
"type": "number"
247+
},
245248
"publisher": {
246249
"type": "string"
247250
},
251+
"shard": {
252+
"type": "number"
253+
},
248254
"size_bytes": {
249255
"type": "number"
250256
},
@@ -253,7 +259,15 @@
253259
"type": "string"
254260
}
255261
},
256-
"required": ["id", "input_id", "publisher", "size_bytes", "type"],
262+
"required": [
263+
"id",
264+
"input_id",
265+
"overcollateralization_factor",
266+
"publisher",
267+
"shard",
268+
"size_bytes",
269+
"type"
270+
],
257271
"type": "object"
258272
},
259273
"GeneratedVote": {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ pub struct RawParameters {
7575
// Transaction configuration
7676
pub tx_generation_distribution: DistributionConfig,
7777
pub tx_size_bytes_distribution: DistributionConfig,
78+
pub tx_overcollateralization_factor_distribution: DistributionConfig,
7879
pub tx_validation_cpu_time_ms: f64,
7980
pub tx_max_size_bytes: u64,
8081
pub tx_conflict_fraction: Option<f64>,
@@ -408,6 +409,9 @@ impl TransactionConfig {
408409
max_size: params.tx_max_size_bytes,
409410
frequency_ms: params.tx_generation_distribution.into(),
410411
size_bytes: params.tx_size_bytes_distribution.into(),
412+
overcollateralization_factor: params
413+
.tx_overcollateralization_factor_distribution
414+
.into(),
411415
conflict_fraction: params.tx_conflict_fraction.unwrap_or_default(),
412416
start_time: params
413417
.tx_start_time
@@ -431,6 +435,7 @@ pub(crate) struct RealTransactionConfig {
431435
pub max_size: u64,
432436
pub frequency_ms: FloatDistribution,
433437
pub size_bytes: FloatDistribution,
438+
pub overcollateralization_factor: FloatDistribution,
434439
pub conflict_fraction: f64,
435440
pub start_time: Option<Timestamp>,
436441
pub stop_time: Option<Timestamp>,
@@ -453,6 +458,7 @@ impl MockTransactionConfig {
453458
shard: 0,
454459
bytes,
455460
input_id: id,
461+
overcollateralization_factor: 0,
456462
}
457463
}
458464
}

sim-rs/sim-core/src/events.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub enum Event {
104104
size_bytes: u64,
105105
shard: u64,
106106
input_id: u64,
107+
overcollateralization_factor: u64,
107108
},
108109
TXSent {
109110
id: TransactionId,
@@ -430,6 +431,7 @@ impl EventTracker {
430431
size_bytes: transaction.bytes,
431432
shard: transaction.shard,
432433
input_id: transaction.input_id,
434+
overcollateralization_factor: transaction.overcollateralization_factor,
433435
});
434436
}
435437

sim-rs/sim-core/src/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub struct Transaction {
9292
pub shard: u64,
9393
pub bytes: u64,
9494
pub input_id: u64,
95+
pub overcollateralization_factor: u64,
9596
}
9697

9798
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]

sim-rs/sim-core/src/sim/node.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1407,9 +1407,20 @@ impl Node {
14071407
vec![Arc::new(tx)]
14081408
} else {
14091409
let ledger_state = self.resolve_ledger_state(rb_ref);
1410+
let ib_shards = self.sim_config.ib_shards;
1411+
let tx_may_use_shard = |tx: &Transaction, ib_shard: u64| {
1412+
for shard in tx.shard..=tx.shard + tx.overcollateralization_factor {
1413+
let shard = shard % ib_shards;
1414+
if shard == ib_shard {
1415+
return true;
1416+
}
1417+
}
1418+
false
1419+
};
14101420
self.select_txs(
14111421
|seen| {
1412-
seen.tx.shard == shard && !ledger_state.spent_inputs.contains(&seen.tx.input_id)
1422+
tx_may_use_shard(&seen.tx, shard)
1423+
&& !ledger_state.spent_inputs.contains(&seen.tx.input_id)
14131424
},
14141425
self.sim_config.max_ib_size,
14151426
)

0 commit comments

Comments
 (0)