1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/// Clients events related logic and type definitions.
pub(crate) mod client_events;
/// Peer node configuration.
pub mod config;
/// Handling of contracts and delegates functionality.
mod contract;
// Re-export for integration tests (tests/ directory needs pub access)
#[cfg(any(test, feature = "testing", feature = "redb"))]
pub use contract::storages;
/// Generated messages from the flatbuffers schema for the network monitor.
pub mod generated;
/// Network messages for transactions.
mod message;
/// Node configuration, implementations and execution (entry points for the binaries).
mod node;
pub use node::{
EventLoopExitReason, Node, ShutdownHandle, enable_abort_on_fatal_listener_exit,
enable_abort_on_redb_poison, enable_fast_crash_exit_code, run_local_node, run_network_node,
};
/// Network operation/transaction state machines.
mod operations;
/// Ring connections and routing.
mod ring;
/// Router implementation.
mod router;
/// Local server used to communicate with the peer core.
#[cfg(feature = "websocket")]
pub mod server;
/// Local network topology management.
mod topology;
/// Outlier-detection primitive shared by per-contract governance and
/// peer-side load-shedding. See `docs/design/contract-hardening.md`.
mod governance;
/// Tracing and loging infrastructure. Includes our custom event log register. Tracing collectors, etc.
#[cfg_attr(test, allow(dead_code))]
pub mod tracing;
/// Code for communicating with other peers over UDP, handles hole-punching, error handling, etc.
pub mod transport;
pub mod util;
/// WASM code execution runtime, tailored for the contract and delegate APIs.
mod wasm_runtime;
/// Deterministic simulation testing framework.
pub mod simulation;
/// Exports to build a running local node.
pub mod local_node {
use super::*;
pub use contract::Executor;
pub use contract::OperationMode;
pub use node::NodeConfig;
}
/// Exports for the dev tool.
pub mod dev_tool {
use super::*;
pub use crate::config::{
Config, GlobalTestMetrics, KEK_SIZE, KekBackend, KekBackendKind, KekError, Secrets,
ensure_kek_loaded, load_from_backend, read_backend_marker, replace_backend_marker,
write_backend_marker,
};
// Backend constructors live in the `kek` submodule rather than the
// top-level `config` re-export to keep `Config`'s public surface
// free of platform-specific concrete types.
pub use crate::config::kek::{FileKek, KeyringKek, SystemdCredentialKek, build_backend_for};
pub use client_events::{
AuthToken, ClientEventsProxy, ClientId, OpenRequest, test::MemoryEventsGen,
test::NetworkEventGenerator,
};
pub use contract::{
Executor, OperationMode, clear_crdt_contracts, is_crdt_contract, register_crdt_contract,
storages::Storage,
};
pub use flatbuffers;
pub use message::Transaction;
pub use node::{
InitPeerNode, NetworkStats, NodeConfig, PeerId,
testing_impl::{
ChurnConfig, ContractDistribution, ControlledEventChain, ControlledSimulationResult,
ConvergedContract, ConvergenceResult, DivergedContract, EventChain, EventSummary,
NetworkPeer, NodeLabel, OperationStats, OperationSummary, PeerMessage, PeerStatus,
PutOperationStats, RunningNode, ScheduledOperation, SimNetwork, SimOperation,
TurmoilConfig, TurmoilResult, UpdateOperationStats, check_convergence_from_logs,
run_turmoil_simulation,
},
};
pub use ring::Location;
pub use transport::{TransportKeypair, TransportPublicKey};
// Nearest-neighbor ring lattice (successor+predecessor base edges). Always
// ON in production above the minimum-degree floor; `set_nn_lattice_enabled` is
// the test-only per-thread override the findability validation harness flips
// to run the stock (lattice-off) arm against the fix (lattice-on) arm on
// identical seeds — it ALSO force-activates the lattice below the floor so the
// benefit tests exercise the ON path at their sparse max_connections.
// `set_nn_lattice_force_active` resets only the floor bypass (used by the
// benefit-test cleanup guard). No-op in production builds (compiled out).
#[cfg(any(test, feature = "testing"))]
pub use ring::{set_nn_lattice_enabled, set_nn_lattice_force_active};
// Test-only findability measurement harness (NOT for ship): scatter/cache
// disable hook (guarantees a single copy) + per-op terminus tracing (rank /
// HTL / hop / stop-reason / connectivity-gap-vs-give-up). See
// operations::findability_probe. Compiled out in production.
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::findability_probe::{
OpTraceRecord, ProbeOpKind, ProbeStopReason, clear_op_traces, scatter_disabled,
set_scatter_disabled, take_op_traces,
};
// Test hooks: per-op driver call counters. Tests assert these
// increment to confirm wire variants dispatch through their
// driver (not a local-cache shortcut or legacy path).
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::get::op_ctx_task::DRIVER_CALL_COUNT as GET_DRIVER_CALL_COUNT;
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::get::op_ctx_task::RELAY_DRIVER_CALL_COUNT as GET_RELAY_DRIVER_CALL_COUNT;
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::get::op_ctx_task::RELAY_GET_STREAMING_FORWARD_COUNT;
// Deterministic stream-assembly fault injection + retry counter for
// the GET driver's assembly-retry path (#4345).
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::get::op_ctx_task::assembly_fault_injection as get_assembly_fault_injection;
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::put::op_ctx_task::RELAY_PUT_DRIVER_CALL_COUNT;
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::put::op_ctx_task::RELAY_PUT_STREAMING_DRIVER_CALL_COUNT;
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::subscribe::op_ctx_task::RELAY_SUBSCRIBE_DRIVER_CALL_COUNT;
// Test hooks for the relay-hop routing-event plumbing. Each counter
// increments every time `operations::record_relay_route_event` fires
// for the corresponding op type. Used by simulation tests to verify
// that relay-forwarded operations actually feed the local Router's
// failure-probability model — without these hooks, the router would
// only see events from originator paths (the bug this work fixes).
#[cfg(any(test, feature = "testing"))]
pub use crate::operations::{
RELAY_GET_ROUTE_EVENT_COUNT, RELAY_PUT_ROUTE_EVENT_COUNT,
RELAY_SUBSCRIBE_ROUTE_EVENT_COUNT, RELAY_UPDATE_ROUTE_EVENT_COUNT,
};
// Re-export state verification for telemetry-based consistency analysis
pub use crate::tracing::state_verifier::{StateAnomaly, StateVerifier, VerificationReport};
// Re-export topology registry for subscription validation in tests
pub use ring::topology_registry::{
ContractSubscription, ProximityViolation, RenewalMetrics, TopologySnapshot,
TopologyValidationResult, aggregate_renewal_metrics, clear_all_topology_snapshots,
clear_current_network_name, clear_renewal_metrics, clear_topology_snapshots,
get_all_renewal_metrics, get_all_topology_snapshots, get_current_network_name,
get_renewal_metrics, get_topology_snapshot, register_topology_snapshot,
set_current_network_name, validate_topology, validate_topology_from_snapshots,
};
pub use wasm_runtime::secret_export::{
BundleKeyMaterial, ExportError, ImportReport, TargetScope, export_bundle, import_bundle,
write_bundle_file,
};
pub use wasm_runtime::secret_snapshots::{
RestoreError, RetentionPolicy, SnapshotMetadata, list_snapshots, restore_snapshot_file,
snapshot_dir_for_encoded, thin_snapshots,
};
pub use wasm_runtime::{
ContractStore, DelegateStore, ExportSecretEntry, MockStateStorage, Runtime, SecretScope,
SecretStoreError, SecretsStore, StateStore, UserSecretContext,
};
/// Maximum size (in bytes) of a single contract-state blob a node will
/// accept, re-exported for client-side pre-flight checks. This is the
/// binding publish limit; see
/// `wasm_runtime::state_store::MAX_STATE_SIZE` for the full limit
/// hierarchy. `fdev website publish` uses this to reject oversized sites
/// before sending a PUT (#4653).
pub use wasm_runtime::MAX_STATE_SIZE as MAX_CONTRACT_STATE_SIZE;
// Re-export simulation types for test infrastructure
pub use crate::simulation::{
FaultConfig, FaultConfigBuilder, Partition, SimulationRng, TimeSource, VirtualTime,
WakeupId,
};
// Re-export fault injector for mid-simulation fault injection in Turmoil tests
pub use crate::node::{FaultInjectorState, get_fault_injector, set_fault_injector};
// Re-export counter reset functions for deterministic simulation testing
pub use crate::client_events::RequestId;
pub use crate::contract::reset_event_id_counter;
pub use crate::node::reset_channel_id_counter;
pub use crate::test_utils::reset_global_node_index;
pub use crate::transport::StreamId;
pub use crate::transport::reset_nonce_counter;
}
/// Deadlock detection for parking_lot locks in test builds.
///
/// Available when compiled with `--cfg test` (unit tests) or with the `testing`
/// feature flag (integration tests). Uses parking_lot's `deadlock_detection`
/// feature to catch Mutex/RwLock deadlocks at runtime.
#[cfg(any(test, feature = "testing"))]
pub mod deadlock_detection;
pub mod test_utils;