Expand description
§Moonpool
Deterministic simulation testing for distributed systems in Rust.
Moonpool enables you to write distributed system logic once, test it with simulated networking for reproducible debugging, then deploy with real networking—all using identical application code.
Inspired by FoundationDB’s simulation testing.
§Crate Architecture
┌─────────────────────────────────────────────────┐
│ moonpool (this crate) │
│ Re-exports all functionality │
├─────────────────────────────────────────────────┤
│ moonpool-transport │ moonpool-sim │
│ • Peer connections │ • SimWorld runtime │
│ • Wire format │ • Chaos testing │
│ • NetTransport │ • Buggify macros │
│ • RPC primitives │ • Assertions │
├─────────────────────────────────────────────────┤
│ moonpool-core │
│ Provider traits: Time, Task, Network, Random │
│ Core types: UID, Endpoint, NetworkAddress │
└─────────────────────────────────────────────────┘§Quick Start
ⓘ
use moonpool::{SimulationBuilder, WorkloadTopology};
SimulationBuilder::new()
.topology(WorkloadTopology::ClientServer { clients: 2, servers: 1 })
.run(|ctx| async move {
// Your distributed system workload
});§Which Crate to Use
| Use case | Crate |
|---|---|
| Full framework (recommended) | moonpool |
| Provider traits only | moonpool-core |
| Simulation without transport | moonpool-sim |
| Transport without simulation | moonpool-transport |
§Documentation
moonpool_core- Provider traits and core typesmoonpool_sim- Simulation runtime and chaos testingmoonpool_transport- Network transport layer
Modules§
- chaos
- Chaos testing infrastructure for deterministic fault injection. Chaos testing infrastructure for deterministic fault injection.
- error
- Error types for transport operations. Error types for the moonpool messaging layer.
- flags
- Address flags.
- network
- Network simulation and configuration. Network simulation and configuration.
- peer
- Resilient peer connection management. Resilient peer connection management.
- providers
- Provider implementations for simulation. Provider implementations for simulation.
- rpc
- RPC layer with typed request/response patterns. FDB-style static messaging with fixed endpoints.
- runner
- Simulation runner and orchestration framework. Simulation runner and orchestration framework.
- sim
- Core simulation engine for deterministic testing. Core simulation engine for deterministic testing.
- wire
- Wire format with CRC32C checksums. Wire format for packet serialization.
Macros§
- always_
assert - Assert that a condition is always true, panicking on failure.
- buggify
- Buggify with 25% probability
- buggify_
with_ prob - Buggify with custom probability
- sometimes_
assert - Assert a condition that should sometimes be true, tracking the success rate.
Structs§
- Assertion
Stats - Statistics for a tracked assertion.
- Chaos
Configuration - Configuration for chaos injection in simulations.
- Endpoint
- Endpoint = Address + Token.
- Endpoint
Map - Maps endpoint tokens to message receivers.
- Event
Queue - A priority queue for scheduling events in chronological order.
- Json
Codec - JSON codec using serde_json.
- NetNotified
Queue - Type-safe message queue with async notification.
- NetTransport
- Central transport coordinator (FDB NetTransport equivalent).
- NetTransport
Builder - Builder for NetTransport that eliminates common footguns.
- Network
Address - Network address (IPv4/IPv6 + port + flags).
- Network
Configuration - Configuration for network simulation parameters
- Packet
Header - Packet header for wire format.
- Peer
- A resilient peer that manages connections to a remote address.
- Peer
Config - Configuration for peer behavior and reconnection parameters.
- Peer
Metrics - Metrics and state information for a peer connection.
- Reply
Future - Future that resolves when a reply is received from the server.
- Reply
Promise - Promise for sending a reply to a request.
- Request
Envelope - Envelope wrapping a request with its reply endpoint.
- Request
Stream - Stream for receiving typed requests with reply promises.
- Scheduled
Event - An event scheduled for execution at a specific simulation time.
- SimNetwork
Provider - Simulated networking implementation
- SimProviders
- Simulation providers bundle for deterministic testing.
- SimRandom
Provider - Random provider for simulation that uses the thread-local deterministic RNG.
- SimTime
Provider - Simulation time provider that integrates with SimWorld.
- SimWorld
- The central simulation coordinator that manages time and event processing.
- Simulation
Builder - Builder pattern for configuring and running simulation experiments.
- Simulation
Metrics - Core metrics collected during a simulation run.
- Simulation
Report - Comprehensive report of a simulation run with statistical analysis.
- Sleep
Future - Future that completes after a specified simulation time duration.
- State
Registry - Registry for actor state during simulation.
- Tokio
Network Provider - Real Tokio networking implementation.
- Tokio
Providers - Production providers using Tokio runtime.
- Tokio
Random Provider - Production random provider using thread-local RNG.
- Tokio
Report - Report generated after running workloads with TokioRunner.
- Tokio
Runner - Builder for executing workloads with real Tokio implementations.
- Tokio
Task Provider - Tokio-based task provider using spawn_local for single-threaded execution.
- Tokio
TcpListener - Wrapper for Tokio TcpListener to implement our trait.
- Tokio
Time Provider - Real time provider using Tokio’s time facilities.
- UID
- 128-bit unique identifier.
- Weak
SimWorld - A weak reference to a simulation world.
- Workload
Topology - Topology information provided to workloads to understand the simulation network.
Enums§
- Codec
Error - Error type for codec operations.
- Connect
Failure Mode - Connection establishment failure mode for fault injection.
- Connection
State Change - Connection state changes
- Event
- Events that can be scheduled in the simulation.
- Iteration
Control - Configuration for how many iterations a simulation should run.
- Messaging
Error - Errors that can occur in the messaging layer.
- Network
Address Parse Error - Error parsing a network address from string.
- Network
Operation - Network data operations
- Peer
Error - Errors that can occur during peer operations.
- Reply
Error - Errors that can occur during request-response operations.
- RpcError
- Unified error type for RPC operations.
- Simulation
Error - Errors that can occur during simulation operations.
- Well
Known Token - Well-known endpoint tokens.
- Wire
Error - Wire format error types.
Constants§
- HEADER_
SIZE - Header size: 4 (length) + 4 (checksum) + 16 (token) = 24 bytes.
- MAX_
PAYLOAD_ SIZE - Maximum payload size (1MB).
- WELL_
KNOWN_ RESERVED_ COUNT - Number of reserved well-known token slots.
Traits§
- Message
Codec - Pluggable message serialization format.
- Message
Receiver - Trait for receiving deserialized messages from the transport layer.
- Network
Provider - Provider trait for creating network connections and listeners.
- Providers
- Bundle of all provider types for a runtime environment.
- Random
Provider - Provider trait for random number generation.
- Task
Provider - Provider for spawning local tasks in single-threaded context.
- TcpListener
Trait - Trait for TCP listeners that can accept connections.
- Time
Provider - Provider trait for time operations.
Functions§
- buggify_
init - Initialize buggify for simulation run
- buggify_
reset - Reset/disable buggify
- deserialize_
packet - Deserialize a packet, validating checksum.
- get_
assertion_ results - Get current assertion statistics for all tracked assertions.
- get_
current_ sim_ seed - Get the current simulation seed.
- method_
endpoint - Generate method endpoint from base endpoint and index.
- method_
uid - Generate UID for a specific interface method.
- panic_
on_ assertion_ violations - Check assertion validation and panic if violations are found.
- reset_
assertion_ results - Reset all assertion statistics to empty state.
- reset_
sim_ rng - Reset the thread-local simulation RNG to a fresh state.
- sample_
duration - Sample a random duration from a range
- send_
request - Send a typed request and return a future for the response.
- serialize_
packet - Serialize a packet with token and payload.
- set_
sim_ seed - Set the seed for the thread-local simulation RNG.
- sim_
random - Generate a random value using the thread-local simulation RNG.
- sim_
random_ range - Generate a random value within a specified range using the thread-local simulation RNG.
- sim_
random_ range_ or_ default - Generate a random value within the given range, returning the start value if the range is empty.
- try_
deserialize_ packet - Try to deserialize from a buffer that may contain partial data.
- validate_
assertion_ contracts - Validate that all
sometimes_assert!assertions actually behave as “sometimes”.
Type Aliases§
- Invariant
Check - Type alias for invariant check functions.
- Peer
Receiver - Type alias for the peer receiver channel.
Used when taking ownership via
take_receiver(). - Simulation
Result - A type alias for
Result<T, SimulationError>.
Attribute Macros§
- interface
- Attribute macro for FDB-style Interface pattern.