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
2 changes: 2 additions & 0 deletions data/simulation/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export interface Config {
/** Only supported by Rust simulation. */
"tx-validation-cpu-time-ms": number;
/** Only supported by Rust simulation. */
"tx-validation-cpu-time-ms-per-byte": 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?
Expand Down
1 change: 1 addition & 0 deletions data/simulation/config.default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ tx-overcollateralization-factor-distribution:
distribution: constant
value: 0
tx-validation-cpu-time-ms: 1.5
tx-validation-cpu-time-ms-per-byte: 0
tx-max-size-bytes: 16384
tx-conflict-fraction: 0

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 @@ -511,6 +511,10 @@
"description": "Only supported by Rust simulation.",
"type": "number"
},
"tx-validation-cpu-time-ms-per-byte": {
"description": "Only supported by Rust simulation.",
"type": "number"
},
"vote-bundle-size-bytes-constant": {
"additionalProperties": false,
"properties": {},
Expand Down
14 changes: 14 additions & 0 deletions sim-rs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## v1.2.0

### All Leios variants

Add a `tx-validation-cpu-time-ms-per-byte` setting, a CPU cost which applies to transactions before adding them to the mempool (or to an EB in Linear Leios).

### Linear Leios

Respect cerificate CPU time settings:
- `cert-generation-cpu-time-ms-constant`
- `cert-generation-cpu-time-ms-per-node` (currently set to 0)
- `cert-validation-cpu-time-ms-constant`
- `cert-validation-cpu-time-ms-per-node` (currently set to 0)

## v1.1.0

### Linear Leios
Expand Down
4 changes: 2 additions & 2 deletions sim-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sim-rs/implementations/CLASSIC_LEIOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ If more than one EB matches all of these criteria, we use for tiebreakers
## CPU model
|Task name in logs|Task name in code|When does it run|What happens when it completes|CPU cost
|---|---|---|---|---|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms`|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms` + `tx-validation-cpu-time-ms-per-byte` for each byte of TX|
|`GenRB`|`RBBlockGenerated`|After a new ranking block has been generated.|That RB is announced to peers.|`rb-generation-cpu-time-ms` + `cert-generation-cpu-time-ms-constant` + `cert-generation-cpu-time-ms-per-node` for each node that voted for the endorsed EB|
|`ValRB`|`RBBlockValidated`|After a ranking block has been received.|That RB body is announced to peers and (potentially) accepted as the tip of the chain.|`rb-body-legacy-praos-payload-validation-cpu-time-ms-constant` + `rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte` for each byte of TX + `cert-generation-cpu-time-ms-constant` + `cert-generation-cpu-time-ms-per-node` for each node that voted for the endorsed EB|
|`GenIB`|`IBBlockGenerated`|After a new IB has been generated.|That IB is announced to peers.|`ib-generation-cpu-time-ms`|
Expand Down
6 changes: 3 additions & 3 deletions sim-rs/implementations/LINEAR_LEIOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ When a node receives an RB body, it immediately removes all referenced/conflicti
## CPU model
|Task name in logs|Task name in code|When does it run|What happens when it completes|CPU cost
|---|---|---|---|---|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms`|
|`GenRB`|`RBBlockGenerated`|After a new ranking block has been generated.|That RB and its EB are announced to peers.|RB generation and EB generation run in parallel.</br>**RB generation**: `rb-generation-cpu-time-ms` + the CPU time of `ValRB`<br/>**EB generation**: `eb-generation-cpu-time-ms` + the CPU time of `ValEB`|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms` + `tx-validation-cpu-time-ms-per-byte` for each byte of TX|
|`GenRB`|`RBBlockGenerated`|After a new ranking block has been generated.|That RB and its EB are announced to peers.|RB generation and EB generation run in parallel.</br>**RB generation**: `rb-generation-cpu-time-ms` + `cert-generation-cpu-time-ms-constant` + `cert-generation-cpu-time-ms-per-node` for each node that voted for the endorsed EB + `rb-body-legacy-praos-payload-validation-cpu-time-ms-constant` + `rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte` for each byte of TX<br/>**EB generation**: `eb-generation-cpu-time-ms` + the CPU time of `ValEB`|
|`ValRH`|`RBHeaderValidated`|After a ranking block header has been received.|That RB is announced to peers.<br/>The referenced EB is queued to be downloaded when available.|`rb-head-validation-cpu-time-ms`|
|`ValRB`|`RBBlockValidated`|After a ranking block body has been received.|That RB body is announced to peers and (potentially) accepted as the tip of the chain.|`rb-body-legacy-praos-payload-validation-cpu-time-ms-constant` + `rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte` for each byte of TX|
|`ValRB`|`RBBlockValidated`|After a ranking block body has been received.|That RB body is announced to peers and (potentially) accepted as the tip of the chain.|`rb-body-legacy-praos-payload-validation-cpu-time-ms-constant` + `rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte` for each byte of TX + `cert-validation-cpu-time-ms-constant` + `cert-validation-cpu-time-ms-per-node` for each node that voted for the endorsed EB|
|`ValEH`|`EBHeaderValidated`|After an EB header has been received and validated.|That EB is announced to peers, and body validation begins in the background.|`eb-header-validation-cpu-time-ms`|
|`ValEB`|`EBBlockValidated`|After an EB's body has been validated.|If eligible, the node will vote for that EB.|`eb-body-validation-cpu-time-ms-constant` + `eb-body-validation-cpu-time-ms-per-byte` for each byte of TX|
|`GenVote`|`VTBundleGenerated`|After a vote bundle has been generated.|That vote bundle is announced to peers.|`vote-generation-cpu-time-ms-constant` + `vote-generation-cpu-time-ms-per-tx` for each TX in the EB|
Expand Down
2 changes: 1 addition & 1 deletion sim-rs/implementations/STRACCIATELLA.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Voting for endorser blocks also behaves mostly the same as in the original Leios
## CPU model
|Task name in logs|Task name in code|When does it run|What happens when it completes|CPU cost
|---|---|---|---|---|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms`|
|`ValTX`|`TransactionValidated`|After a transaction has been received from a peer.|That TX is announced to other peers.|`tx-validation-cpu-time-ms` + `tx-validation-cpu-time-ms-per-byte` for each byte of TX|
|`GenRB`|`RBBlockGenerated`|After a new ranking block has been generated.|That RB is announced to peers.|`rb-generation-cpu-time-ms` + `cert-generation-cpu-time-ms-constant` + `cert-generation-cpu-time-ms-per-node` for each node that voted for the endorsed EB|
|`ValRB`|`RBBlockValidated`|After a ranking block has been received.|That RB body is announced to peers and (potentially) accepted as the tip of the chain.|`rb-body-legacy-praos-payload-validation-cpu-time-ms-constant` + `rb-body-legacy-praos-payload-validation-cpu-time-ms-per-byte` for each byte of TX + `cert-generation-cpu-time-ms-constant` + `cert-generation-cpu-time-ms-per-node` for each node that voted for the endorsed EB|
|`GenEB`|`EBBlockGenerated`|After a new EB has been generated.|That EB is announced to peers.|`eb-generation-cpu-time-ms`|
Expand Down
2 changes: 1 addition & 1 deletion sim-rs/sim-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sim-cli"
version = "1.1.0"
version = "1.2.0"
edition = "2024"
default-run = "sim-cli"
rust-version = "1.88"
Expand Down
2 changes: 1 addition & 1 deletion sim-rs/sim-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sim-core"
version = "1.1.0"
version = "1.2.0"
edition = "2024"
rust-version = "1.88"

Expand Down
7 changes: 5 additions & 2 deletions sim-rs/sim-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub struct RawParameters {
pub tx_size_bytes_distribution: DistributionConfig,
pub tx_overcollateralization_factor_distribution: DistributionConfig,
pub tx_validation_cpu_time_ms: f64,
pub tx_validation_cpu_time_ms_per_byte: f64,
pub tx_max_size_bytes: u64,
pub tx_conflict_fraction: Option<f64>,
pub tx_start_time: Option<f64>,
Expand Down Expand Up @@ -393,7 +394,8 @@ impl From<RawTopology> for Topology {

#[derive(Debug, Clone)]
pub(crate) struct CpuTimeConfig {
pub tx_validation: Duration,
pub tx_validation_constant: Duration,
pub tx_validation_per_byte: Duration,
pub rb_generation: Duration,
pub rb_head_validation: Duration,
pub rb_body_validation_constant: Duration,
Expand All @@ -419,7 +421,8 @@ pub(crate) struct CpuTimeConfig {
impl CpuTimeConfig {
fn new(params: &RawParameters) -> Self {
Self {
tx_validation: duration_ms(params.tx_validation_cpu_time_ms),
tx_validation_constant: duration_ms(params.tx_validation_cpu_time_ms),
tx_validation_per_byte: duration_ms(params.tx_validation_cpu_time_ms_per_byte),
rb_generation: duration_ms(params.rb_generation_cpu_time_ms),
rb_head_validation: duration_ms(params.rb_head_validation_cpu_time_ms),
rb_body_validation_constant: duration_ms(
Expand Down
4 changes: 3 additions & 1 deletion sim-rs/sim-core/src/sim/leios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ impl SimCpuTask for Task {

fn times(&self, config: &crate::config::CpuTimeConfig) -> Vec<Duration> {
match self {
Self::TransactionValidated(_, _) => vec![config.tx_validation],
Self::TransactionValidated(_, tx) => vec![
config.tx_validation_constant + config.tx_validation_per_byte * tx.bytes as u32,
],
Self::RBBlockGenerated(block) => {
let mut time = config.rb_generation;
if let Some(endorsement) = &block.endorsement {
Expand Down
14 changes: 13 additions & 1 deletion sim-rs/sim-core/src/sim/linear_leios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ impl SimCpuTask for CpuTask {

fn times(&self, config: &CpuTimeConfig) -> Vec<Duration> {
match self {
Self::TransactionValidated(_, _) => vec![config.tx_validation],
Self::TransactionValidated(_, tx) => vec![
config.tx_validation_constant + config.tx_validation_per_byte * tx.bytes as u32,
],
Self::RBBlockGenerated(rb, eb, _) => {
let mut rb_time = config.rb_generation + config.rb_body_validation_constant;
let rb_bytes: u64 = rb.transactions.iter().map(|tx| tx.bytes).sum();
rb_time += config.rb_validation_per_byte * (rb_bytes as u32);
if let Some(endorsement) = &rb.endorsement {
let nodes = endorsement.votes.len();
rb_time += config.cert_generation_constant
+ (config.cert_generation_per_node * nodes as u32);
}

let mut eb_time = config.eb_generation + config.eb_body_validation_constant;
let eb_bytes: u64 = eb.txs.iter().map(|tx| tx.bytes).sum();
Expand All @@ -180,6 +187,11 @@ impl SimCpuTask for CpuTask {
let mut time = config.rb_body_validation_constant;
let bytes: u64 = rb.transactions.iter().map(|tx| tx.bytes).sum();
time += config.rb_validation_per_byte * (bytes as u32);
if let Some(endorsement) = &rb.endorsement {
let nodes = endorsement.votes.len();
time += config.cert_validation_constant
+ (config.cert_validation_per_node * nodes as u32);
}
vec![time]
}
Self::EBHeaderValidated(_, _) => vec![config.eb_header_validation],
Expand Down
4 changes: 3 additions & 1 deletion sim-rs/sim-core/src/sim/stracciatella.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ impl SimCpuTask for CpuTask {

fn times(&self, config: &crate::config::CpuTimeConfig) -> Vec<std::time::Duration> {
match self {
Self::TransactionValidated(_, _) => vec![config.tx_validation],
Self::TransactionValidated(_, tx) => vec![
config.tx_validation_constant + config.tx_validation_per_byte * tx.bytes as u32,
],
Self::RBBlockGenerated(rb) => {
let mut time = config.rb_generation;
if let Some(endorsement) = &rb.endorsement {
Expand Down