Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions data/simulation/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export interface Config {
* The strategy to use when selecting TXs from the Leios mempool.
*/
"leios-mempool-sampling-strategy": MempoolSamplingStrategy;
/**
* If true, transactions will be removed from the Leios mempool if they conflict with in-flight IBs.
*/
"leios-mempool-aggressive-pruning": boolean;
/**
* Praos blockchain quality parameter.
* This is η from the Leios paper.
Expand All @@ -75,6 +79,10 @@ export interface Config {
"tx-validation-cpu-time-ms": number;
/** Only supported by Rust simulation. */
"tx-max-size-bytes": bigint;
/**
* What fraction of TXs (from 0 to 1) should introduce conflicts with transactions which were produced before?
* Only supported by Rust simulation. */
"tx-conflict-fraction": number | null;
/**
* When the first transaction should appear.
* Only supported by Rust simulation. */
Expand Down
2 changes: 2 additions & 0 deletions data/simulation/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ leios-vote-send-recv-stages: false
leios-late-ib-inclusion: true
leios-header-diffusion-time-ms: 1000.0
leios-mempool-sampling-strategy: ordered-by-id
leios-mempool-aggressive-pruning: false
# TODO: revise default
praos-chain-quality: 40
praos-fallback-enabled: true
Expand All @@ -48,6 +49,7 @@ tx-size-bytes-distribution:
sigma: 1.127
tx-validation-cpu-time-ms: 1.5
tx-max-size-bytes: 16384
tx-conflict-fraction: 0

################################################################################
# Ranking Block Configuration
Expand Down
4 changes: 4 additions & 0 deletions data/simulation/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@
"description": "When `true`, any delays and message sizes are calculated as if\neach block contained as much data as the expected average, rounded up.\nIn particular, for the sake of the above, we consider that:\n - Each RB includes a certificate.\n - Certificates contain votes from `vote-threshold` nodes.\n - Vote bundles vote for `ceil eb-generation-probability` EBs.\n - EBs reference `ceil (ib-generation-probability * leios-stage-length-slots)` IBs.\nOnly supported by Haskell simulation.",
"type": "boolean"
},
"tx-conflict-fraction": {
"description": "What fraction of TXs (from 0 to 1) should introduce conflicts with transactions which were produced before?\nOnly supported by Rust simulation.",
"type": "number"
},
"tx-generation-distribution": {
"$ref": "#/definitions/Distribution",
"description": "Only supported by Rust simulation."
Expand Down
2 changes: 1 addition & 1 deletion data/simulation/example.rust.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{"time_s":0.0,"message":{"type":"CpuTaskScheduled","task":{"node":"node-0","index":1},"task_type":"GenIB","subtasks":1}}
{"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"}}
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-1","slot":0,"pipeline":0,"producer":"node-1"}}
{"time_s":0.0,"message":{"type":"TXGenerated","id":"0","publisher":"node-11","size_bytes":156}}
{"time_s":0.0,"message":{"type":"TXGenerated","id":"0","publisher":"node-11","size_bytes":156,"input_id":0}}
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-3","slot":0,"pipeline":0,"producer":"node-3"}}
{"time_s":0.0,"message":{"type":"VTLotteryWon","id":"0-node-4","slot":0,"pipeline":0,"producer":"node-4"}}
{"time_s":0.0,"message":{"type":"EBLotteryWon","id":"0-node-4","slot":0,"pipeline":1,"producer":"node-4"}}
Expand Down
16 changes: 10 additions & 6 deletions data/simulation/topology.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
*/
export interface Topology {
nodes:
| {
[name: NodeName]: Node<Cluster>;
}
| {
[name: NodeName]: Node<Coord2D>;
};
| {
[name: NodeName]: Node<Cluster>;
}
| {
[name: NodeName]: Node<Coord2D>;
};
}

/** A node. */
Expand All @@ -23,6 +23,10 @@ export interface Node<Location> {
"cpu-core-count"?: bigint | null;
location: Location;
producers: { [producer: NodeName]: LinkInfo };
/**
* What fraction of TXs (from 0 to 1) should introduce conflicts with transactions which were produced before?
* Only supported by Rust simulation. */
"tx-conflict-fraction"?: number | null;
/** If not null, the node will behave according to the given Behaviour.
*
* Only supported by Haskell simulation.
Expand Down
8 changes: 8 additions & 0 deletions data/simulation/topology.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
"additionalProperties": false,
"properties": {},
"type": "number"
},
"tx-conflict-fraction": {
"description": "What fraction of TXs (from 0 to 1) should introduce conflicts with transactions which were produced before?\nOnly supported by Rust simulation.",
"type": "number"
}
},
"type": "object"
Expand Down Expand Up @@ -87,6 +91,10 @@
"additionalProperties": false,
"properties": {},
"type": "number"
},
"tx-conflict-fraction": {
"description": "What fraction of TXs (from 0 to 1) should introduce conflicts with transactions which were produced before?\nOnly supported by Rust simulation.",
"type": "number"
}
},
"type": "object"
Expand Down
1 change: 1 addition & 0 deletions data/simulation/trace.rust.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface GeneratedTransaction {
id: string;
publisher: string;
size_bytes: number;
input_id: number;
}

interface LostTransaction {
Expand Down
5 changes: 4 additions & 1 deletion data/simulation/trace.rust.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@
"id": {
"type": "string"
},
"input_id": {
"type": "number"
},
"publisher": {
"type": "string"
},
Expand All @@ -250,7 +253,7 @@
"type": "string"
}
},
"required": ["id", "publisher", "size_bytes", "type"],
"required": ["id", "input_id", "publisher", "size_bytes", "type"],
"type": "object"
},
"GeneratedVote": {
Expand Down
5 changes: 3 additions & 2 deletions sim-rs/sim-cli/src/bin/gen-test-data/strategy/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ impl GraphBuilder {
let loc1 = to_netsim_location(self.location_of(node));
let loc2 = to_netsim_location(self.location_of(producer));
latency_between_locations(loc1, loc2, 1.)
.unwrap()
.to_duration()
.map(|d| d.to_duration())
.unwrap_or_default()
.max(Duration::from_millis(1))
});
self.links.push(RawLinkConfig {
Expand Down Expand Up @@ -170,6 +170,7 @@ impl GraphBuilder {
stake: n.stake,
location: RawNodeLocation::Coords(n.location),
cpu_core_count: n.cores,
tx_conflict_fraction: None,
producers: BTreeMap::new(),
};
(name, node)
Expand Down
19 changes: 17 additions & 2 deletions sim-rs/sim-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pub struct RawParameters {
pub leios_late_ib_inclusion: bool,
pub leios_header_diffusion_time_ms: f64,
pub leios_mempool_sampling_strategy: MempoolSamplingStrategy,
pub leios_mempool_aggressive_pruning: bool,
pub praos_chain_quality: u64,
pub praos_fallback_enabled: bool,

Expand All @@ -76,6 +77,7 @@ pub struct RawParameters {
pub tx_size_bytes_distribution: DistributionConfig,
pub tx_validation_cpu_time_ms: f64,
pub tx_max_size_bytes: u64,
pub tx_conflict_fraction: Option<f64>,
pub tx_start_time: Option<f64>,
pub tx_stop_time: Option<f64>,

Expand Down Expand Up @@ -177,6 +179,8 @@ pub struct RawNode {
pub location: RawNodeLocation,
#[serde(skip_serializing_if = "Option::is_none")]
pub cpu_core_count: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tx_conflict_fraction: Option<f64>,
pub producers: BTreeMap<String, RawLinkInfo>,
}

Expand Down Expand Up @@ -254,6 +258,7 @@ impl From<RawTopology> for Topology {
stake: node.stake.unwrap_or_default(),
cpu_multiplier: 1.0,
cores: node.cpu_core_count,
tx_conflict_fraction: node.tx_conflict_fraction,
consumers: vec![],
},
);
Expand Down Expand Up @@ -403,6 +408,7 @@ impl TransactionConfig {
max_size: params.tx_max_size_bytes,
frequency_ms: params.tx_generation_distribution.into(),
size_bytes: params.tx_size_bytes_distribution.into(),
conflict_fraction: params.tx_conflict_fraction.unwrap_or_default(),
start_time: params
.tx_start_time
.map(|t| Timestamp::zero() + Duration::from_secs_f64(t)),
Expand All @@ -425,6 +431,7 @@ pub(crate) struct RealTransactionConfig {
pub max_size: u64,
pub frequency_ms: FloatDistribution,
pub size_bytes: FloatDistribution,
pub conflict_fraction: f64,
pub start_time: Option<Timestamp>,
pub stop_time: Option<Timestamp>,
}
Expand All @@ -437,11 +444,16 @@ pub(crate) struct MockTransactionConfig {
}

impl MockTransactionConfig {
pub fn next_id(&self) -> TransactionId {
pub fn mock_tx(&self, bytes: u64) -> Transaction {
let id = self
.next_id
.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
TransactionId::new(id)
Transaction {
id: TransactionId::new(id),
shard: 0,
bytes,
input_id: id,
}
}
}

Expand All @@ -464,6 +476,7 @@ pub struct SimConfiguration {
pub(crate) header_diffusion_time: Duration,
pub(crate) relay_strategy: RelayStrategy,
pub(crate) mempool_strategy: MempoolSamplingStrategy,
pub(crate) mempool_aggressive_pruning: bool,
pub(crate) praos_chain_quality: u64,
pub(crate) block_generation_probability: f64,
pub(crate) ib_generation_probability: f64,
Expand Down Expand Up @@ -509,6 +522,7 @@ impl SimConfiguration {
header_diffusion_time: duration_ms(params.leios_header_diffusion_time_ms),
relay_strategy: params.relay_strategy,
mempool_strategy: params.leios_mempool_sampling_strategy,
mempool_aggressive_pruning: params.leios_mempool_aggressive_pruning,
praos_chain_quality: params.praos_chain_quality,
block_generation_probability: params.rb_generation_probability,
ib_generation_probability: params.ib_generation_probability,
Expand Down Expand Up @@ -542,6 +556,7 @@ pub struct NodeConfiguration {
pub stake: u64,
pub cpu_multiplier: f64,
pub cores: Option<u64>,
pub tx_conflict_fraction: Option<f64>,
pub consumers: Vec<NodeId>,
}

Expand Down
4 changes: 4 additions & 0 deletions sim-rs/sim-core/src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ pub enum Event {
publisher: Node,
size_bytes: u64,
shard: u64,
input_id: u64,
},
TXSent {
id: TransactionId,
Expand Down Expand Up @@ -168,6 +169,7 @@ pub enum Event {
tx_payload_bytes: u64,
size_bytes: u64,
transactions: Vec<TransactionId>,
rb_ref: Option<BlockId<Node>>,
},
NoIBGenerated {
node: Node,
Expand Down Expand Up @@ -427,6 +429,7 @@ impl EventTracker {
publisher: self.to_node(publisher),
size_bytes: transaction.bytes,
shard: transaction.shard,
input_id: transaction.input_id,
});
}

Expand Down Expand Up @@ -476,6 +479,7 @@ impl EventTracker {
tx_payload_bytes,
size_bytes: header_bytes + tx_payload_bytes,
transactions: block.transactions.iter().map(|tx| tx.id).collect(),
rb_ref: block.rb_ref.map(|b| self.to_block(b)),
});
}

Expand Down
2 changes: 2 additions & 0 deletions sim-rs/sim-core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Transaction {
pub id: TransactionId,
pub shard: u64,
pub bytes: u64,
pub input_id: u64,
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
Expand Down Expand Up @@ -135,6 +136,7 @@ pub struct InputBlock {
pub header: InputBlockHeader,
pub tx_payload_bytes: u64,
pub transactions: Vec<Arc<Transaction>>,
pub rb_ref: Option<BlockId>,
}
impl InputBlock {
pub fn bytes(&self) -> u64 {
Expand Down
6 changes: 3 additions & 3 deletions sim-rs/sim-core/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::{
config::SimConfiguration,
events::EventTracker,
model::{
Block, EndorserBlock, EndorserBlockId, InputBlock, InputBlockHeader, InputBlockId,
Block, BlockId, EndorserBlock, EndorserBlockId, InputBlock, InputBlockHeader, InputBlockId,
Transaction, TransactionId, VoteBundle, VoteBundleId,
},
network::Network,
Expand Down Expand Up @@ -132,8 +132,8 @@ enum SimulationMessage {
RequestTx(TransactionId),
Tx(Arc<Transaction>),
// praos block propagation
RollForward(u64),
RequestBlock(u64),
RollForward(BlockId),
RequestBlock(BlockId),
Block(Arc<Block>),
// IB header propagation
AnnounceIBHeader(InputBlockId),
Expand Down
Loading