-
Notifications
You must be signed in to change notification settings - Fork 26
feat/simulation readme #352
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
52ad0e2
docs: update simulation readme
stevana f7bfe60
Merge remote-tracking branch 'origin/main' into stevan/sim-readme
stevana 36564bb
Merge branch 'stevan/shrink' into stevan/sim-readme
stevana 946228b
feat: make it possible to control simulation parameters via env vars
stevana e67ecfb
refactor: clean up and a couple of small fixes
stevana bca44a6
Merge remote-tracking branch 'origin/main' into stevan/sim-readme
stevana 436e531
refactor: tidy up
stevana 0bf67a6
refactor: fix reviewers comments
stevana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1,108 @@ | ||
| # Amaru Simulator | ||
|
|
||
| This component aims at implementing a _Simulator_ for the Ouroboros Consensus, in Rust, using Amaru components. The main goal of this work is to be able to test the consensus part as deeply as possible, using different strategies, in increasing order of fidelity: | ||
| This component aims at implementing a _Simulator_ for the Ouroboros Consensus, | ||
| in Rust, using Amaru components. The main goal of this work is to be able to | ||
| test the consensus part as deeply as possible, using different strategies, in | ||
| increasing order of fidelity: | ||
|
|
||
| 1. ✅ In-process deterministic testing, completely simulating the environment, allowing arbitrary fault injections and full control over concurrency and other side-effects | ||
| 2. ✅ [Maelstrom](https://github.com/jepsen-io/maelstrom/)-like testing through stdin/stdout interface ignoring network interactions | ||
| 3. 🔴 [Jepsen](https://github.com/jepsen-io/jepsen)-like testing through full-blown deployment of a cluster and actual networking stack | ||
| 1. ✅ In-process deterministic testing, completely simulating the environment, | ||
| allowing arbitrary fault injections and full control over concurrency and | ||
| other side-effects | ||
| 2. ✅ [Maelstrom](https://github.com/jepsen-io/maelstrom/)-like testing through | ||
| stdin/stdout interface ignoring network interactions | ||
| 3. 🔴 [Jepsen](https://github.com/jepsen-io/jepsen)-like testing through | ||
| full-blown deployment of a cluster and actual networking stack | ||
| 4. 🔴 [Antithesis](https://antithesis.com) support | ||
|
|
||
| ## Overview | ||
|
|
||
| The main components of the simulator are: | ||
|
|
||
| * Test case generation, found in | ||
| [`src/simulator/generate.rs`](src/simulator/generate.rs), which uses the | ||
| pre-generated block tree which is saved in | ||
| [`tests/data/chain.json`](tests/data/chain.json); | ||
| * The (discrete-event) simulator itself, lives in | ||
| [`src/simulator/simulate.rs`](src/simulator/simulate.rs); | ||
| * The property-based test and property that uses the simulator, defined in | ||
| [`src/simulator/mod.rs`](src/simulator/mod.rs); | ||
| and property that uses the simulator is defined; | ||
| * The actual Rust `#test` which gets picked up by `cargo test`, found in | ||
| [`tests/simulation.rs`](tests/simulation.rs). | ||
|
|
||
| ## Usage | ||
|
|
||
| The `simulator` executable is a pared-down version of Amaru where network communications are abstracted away. It's packaged as a test so running it amounts to: | ||
| The `simulator` test uses is a pared-down version of Amaru where network | ||
| communications are abstracted away. | ||
|
|
||
| The test can be run as with default options follows: | ||
|
stevana marked this conversation as resolved.
Outdated
|
||
|
|
||
| ``` | ||
| cargo test -p amaru-sim | ||
| AMARU_NUMBER_OF_TESTS=50 # Set the number of test cases to generate. \ | ||
| AMARU_NUMBER_OF_NODES=1 # Set the number of nodes in a simulation. \ | ||
| AMARU_NUMBER_OF_UPSTREAM_PEERS=2 # Set the number of upstream peers. | ||
| AMARU_DISABLE_SHRINKING=0 # Set to 1 to disable shrinking. \ | ||
| AMARU_TEST_SEED= # Seed to use to reproduce a test case. \ | ||
| AMARU_PERSIST_ON_SUCCESS=0 # Set to 1 to persist pure-stage schedule on success. \ | ||
| AMARU_SIMULATION_LOG="error" # Only show error-level logging. \ | ||
| \ | ||
| cargo test run_simulator | ||
| ``` | ||
|
|
||
| By default, it only logs `error` level and above log entries, but one filter logs by setting the `AMARU_SIMULATION_LOG` environment variable to an appropriate value. | ||
| ## Debugging failures | ||
|
|
||
| When the test fails, the output looks something like this: | ||
|
|
||
| ``` | ||
| Minimised input (0 shrinks): | ||
|
|
||
| Envelope { src: "c1", dest: "n1", body: Fwd { msg_id: 0, slot: Slot(31), hash: "2487bd", header: "828a0118" } } | ||
| Envelope { src: "c1", dest: "n1", body: Fwd { msg_id: 1, slot: Slot(38), hash: "4fcd1d", header: "828a0218" } } | ||
| Envelope { src: "c1", dest: "n1", body: Fwd { msg_id: 2, slot: Slot(41), hash: "739307", header: "828a0318" } } | ||
| Envelope { src: "c1", dest: "n1", body: Fwd { msg_id: 3, slot: Slot(55), hash: "726ef3", header: "828a0418" } } | ||
| Envelope { src: "c1", dest: "n1", body: Fwd { msg_id: 4, slot: Slot(93), hash: "597ea6", header: "828a0518" } } | ||
| [...] | ||
|
|
||
| History: | ||
|
|
||
| 0. "c1" ==> "n1" Fwd { msg_id: 0, slot: Slot(31), hash: "2487bd", header: "828a0118" } | ||
| 1. "n1" ==> "c1" Fwd { msg_id: 0, slot: Slot(31), hash: "2487bd", header: "828a0118" } | ||
| 2. "c2" ==> "n1" Fwd { msg_id: 0, slot: Slot(31), hash: "2487bd", header: "828a0118" } | ||
| 3. "c2" ==> "n1" Fwd { msg_id: 1, slot: Slot(38), hash: "4fcd1d", header: "828a0218" } | ||
| 4. "n1" ==> "c2" Fwd { msg_id: 1, slot: Slot(38), hash: "4fcd1d", header: "828a0218" } | ||
| [...] | ||
|
|
||
| Error message: | ||
|
|
||
| tip of chains don't match, expected: | ||
| (Bytes { bytes: "fcb4a51..." }, Slot(990)) | ||
| got: | ||
| (Bytes { bytes: "gcb4a51..." }, Slot(990)) | ||
|
|
||
| Saved schedule: "./failure-1752489042.schedule" | ||
|
|
||
| Seed: 42 | ||
| ``` | ||
|
|
||
| Let's break the components down: | ||
|
|
||
| * The minimised failing test case is printed so that it can be copy-pasted into a | ||
| `#test` to create a regression test; | ||
| * The history is the same as test case, but the `src` and `dest` of each | ||
| message has been pretty printed to be easier to read and it also contains the | ||
| responses that we got back from the system under test. The history is what the | ||
| property is checked against; | ||
| * The error message is how the property failed; | ||
| * Saved schedule is the execution schedule from `pure-stage`, which can provide | ||
| low-level details about how the stage processing happened. See the following | ||
| [note](https://github.com/pragma-org/amaru/wiki/log-::-2025%E2%80%9006#debugging-simulation-tests-failure) | ||
| for more details of how to use this information; | ||
| * The seed is what was used to produce the test case, it can be used to replay | ||
| the test (see `AMARU_TEST_SEED` above). | ||
|
|
||
| ## References | ||
|
|
||
| * [Cardano Consensus and Storage Layer](https://ouroboros-consensus.cardano.intersectmbo.org/assets/files/report-b72e7d765cfee85b26dc035c52c6de84.pdf) | ||
| * [Ouroboros Network Specification](https://ouroboros-network.cardano.intersectmbo.org/pdfs/network-spec/network-spec.pdf) | ||
| * [Cardano Consensus and Storage | ||
| Layer](https://ouroboros-consensus.cardano.intersectmbo.org/assets/files/report-b72e7d765cfee85b26dc035c52c6de84.pdf) | ||
| * [Ouroboros Network | ||
| Specification](https://ouroboros-network.cardano.intersectmbo.org/pdfs/network-spec/network-spec.pdf) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.