Skip to content

Commit 3ddcee5

Browse files
committed
Implement reconnects for blockchain RPC client
- Implement subscription re-establishment after WebSocket reconnect - Add turmoil integration tests for reconnection and basic subscription The current Arc<RwLock<HashMap>> pattern is appropriate for blockchain RPC's simple use case (single subscription type, low concurrency), though OKX/Bitmex use a more sophisticated SubscriptionState with DashMaps for complex multi-parameter subscriptions. Future will extract the common SubscriptionState pattern to the nautilus-network crate.
1 parent a9638a9 commit 3ddcee5

File tree

7 files changed

+526
-72
lines changed

7 files changed

+526
-72
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/adapters/blockchain/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "nautilus-blockchain"
33
readme = "README.md"
4-
publish = false # Do not publish to crates.io for now
54
version.workspace = true
65
edition.workspace = true
76
rust-version.workspace = true
@@ -40,6 +39,7 @@ python = [
4039
"pyo3",
4140
"pyo3-stub-gen",
4241
]
42+
turmoil = ["dep:turmoil", "nautilus-network/turmoil"]
4343

4444
[package.metadata.docs.rs]
4545
features = ["python"]
@@ -84,9 +84,11 @@ hypersync-client = { workspace = true, optional = true }
8484
hypersync-schema = { workspace = true, optional = true }
8585
pyo3 = { workspace = true, optional = true }
8686
pyo3-stub-gen = { workspace = true, optional = true }
87+
turmoil = { workspace = true, optional = true }
8788

8889
[dev-dependencies]
8990
rstest = { workspace = true }
91+
turmoil = { workspace = true }
9092

9193
[[bin]]
9294
name = "node_test"

crates/adapters/blockchain/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This crate provides feature flags to control source code inclusion during compil
2020
- `hypersync`: Enables the [HyperSync](https://envio.dev/#hypersync) client integration.
2121
- `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
2222
- `extension-module`: Builds as a Python extension module (used with `python`).
23+
- `turmoil`: Enables integration tests with deterministic network simulation for testing reconnection logic.
2324

2425
## Scripts
2526

@@ -74,6 +75,20 @@ This script demonstrates how to use the blockchain data client to discover and c
7475
cargo run --bin sync_tokens_pools --features hypersync
7576
```
7677

78+
## Testing
79+
80+
### Running Integration Tests
81+
82+
The blockchain adapter includes integration tests that verify reconnection logic and subscription re-establishment using the turmoil network simulator.
83+
84+
Run all tests with the turmoil feature:
85+
86+
```bash
87+
cargo nextest run -p nautilus-blockchain --features turmoil
88+
```
89+
90+
**Note**: The `--features turmoil` flag is required to include integration tests that validate WebSocket reconnection, exponential backoff, and automatic subscription re-establishment under various network conditions.
91+
7792
## License
7893

7994
The source code for NautilusTrader is available on GitHub under the [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html).

crates/adapters/blockchain/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
//! - `hypersync`: Enables the [HyperSync](https://envio.dev/#hypersync) client integration.
3838
//! - `python`: Enables Python bindings from [PyO3](https://pyo3.rs).
3939
//! - `extension-module`: Builds as a Python extension module (used with `python`).
40+
//! - `turmoil`: Enables integration tests with deterministic network simulation for testing reconnection logic.
4041
4142
#![warn(rustc::all)]
4243
#![deny(unsafe_code)]

0 commit comments

Comments
 (0)