Expand description
§moonpool-core
Core abstractions for the moonpool simulation framework.
This crate provides the foundational traits and types that enable moonpool’s simulation capabilities. Application code depends on these abstractions rather than concrete implementations, allowing seamless switching between simulation and production environments.
§The Provider Pattern
The key insight is that distributed systems interact with the outside world through a small set of operations: time, networking, task spawning, and randomness. By abstracting these behind traits, we can substitute deterministic simulation implementations during testing.
┌──────────────────────────────────────────────────────┐
│ Application Code │
│ Uses: TimeProvider, NetworkProvider, etc. │
└───────────────────────┬──────────────────────────────┘
│ depends on traits
┌──────────────┴──────────────┐
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Simulation │ │ Production │
│ SimTimeProvider │ │ TokioTimeProvider│
│ SimNetworkProv. │ │ TokioNetworkProv.│
│ (deterministic) │ │ (real I/O) │
└─────────────────┘ └─────────────────┘§Provider Traits
| Trait | Simulation | Production | Purpose |
|---|---|---|---|
TimeProvider | Logical time | Wall clock | Sleep, timeout, now() |
TaskProvider | Event-driven | Tokio spawn | Task spawning |
RandomProvider | Seeded RNG | System RNG | Deterministic randomness |
NetworkProvider | Simulated TCP | Real TCP | Connect, listen, accept |
Important: Never call tokio directly in application code.
- ❌
tokio::time::sleep() - ✅
time_provider.sleep()
§Core Types
FDB-compatible types for endpoint addressing:
UID: 128-bit unique identifier (deterministically generated in simulation)Endpoint: Network address + token for direct addressingNetworkAddress: IP address + portWellKnownToken: Reserved tokens for system services
Modules§
- flags
- Address flags (FDB-compatible).
Structs§
- Endpoint
- Endpoint = Address + Token (FDB-compatible).
- Json
Codec - JSON codec using serde_json.
- Network
Address - Network address (IPv4/IPv6 + port + flags).
- Tokio
Network Provider - Real Tokio networking implementation.
- 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 (FDB-compatible).
Enums§
- Codec
Error - Error type for codec operations.
- Network
Address Parse Error - Error parsing a network address from string.
- Simulation
Error - Errors that can occur during simulation operations.
- Well
Known Token - Well-known endpoint tokens (FDB-compatible pattern).
Constants§
- WELL_
KNOWN_ RESERVED_ COUNT - Number of reserved well-known token slots.
Traits§
- Message
Codec - Pluggable message serialization format.
- Network
Provider - Provider trait for creating network connections and listeners.
- 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.
Type Aliases§
- Simulation
Result - A type alias for
Result<T, SimulationError>.