Skip to content

Commit

Permalink
Revert endpoint and health related changes (#182)
Browse files Browse the repository at this point in the history
* Revert "Refactor endpoint (#178)"

This reverts commit 7fa3132.

* Revert "ensure we reconnect on failure (#173)"

This reverts commit 5039cfa.

* Revert "improve reconnect wait time (#168)"

This reverts commit 7cb7c73.

* Revert "Await healthy endpoint (#158)"

This reverts commit ef1c524.

* Revert "endpoint health (#152)"

This reverts commit cdbdd9b.

* redo validate middleware

* fix
  • Loading branch information
xlc authored May 18, 2024
1 parent 8e8247c commit aa48c3a
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 1,220 deletions.
1 change: 0 additions & 1 deletion benches/bench/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ fn config() -> Config {
format!("ws://{}", SERVER_TWO_ENDPOINT),
],
shuffle_endpoints: false,
health_check: None,
}),
server: Some(ServerConfig {
listen_address: SUBWAY_SERVER_ADDR.to_string(),
Expand Down
8 changes: 0 additions & 8 deletions configs/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ extensions:
endpoints:
- wss://acala-rpc.dwellir.com
- wss://acala-rpc-0.aca-api.network
health_check:
interval_sec: 10 # check interval, default is 10s
healthy_response_time_ms: 500 # max response time to be considered healthy, default is 500ms
health_method: system_health
response: # response contains { isSyncing: false }
!contains
- - isSyncing
- !eq false
event_bus:
substrate_api:
stale_timeout_seconds: 180 # rotate endpoint if no new blocks for 3 minutes
Expand Down
12 changes: 0 additions & 12 deletions configs/eth_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,6 @@ extensions:
client:
endpoints:
- wss://eth-rpc-karura-testnet.aca-staging.network
health_check:
interval_sec: 10 # check interval, default is 10s
healthy_response_time_ms: 500 # max response time to be considered healthy, default is 500ms
health_method: net_health # eth-rpc-adapter bodhijs
response: # response contains { isHealthy: true, isRPCOK: true }
!contains
- - isHealthy
- !eq true
- - isRPCOK
- !eq true
# health_method: eth_syncing # eth node
# response: !eq false
event_bus:
eth_api:
stale_timeout_seconds: 180 # rotate endpoint if no new blocks for 3 minutes
Expand Down
5 changes: 5 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ fn render_template(templated_config_str: &str) -> Result<String, anyhow::Error>
}

pub async fn validate(config: &Config) -> Result<(), anyhow::Error> {
tracing::debug!("Validating config");

// validate use garde::Validate
config.validate(&())?;
// since endpoints connection test is async
Expand All @@ -214,6 +216,9 @@ pub async fn validate(config: &Config) -> Result<(), anyhow::Error> {
anyhow::bail!("Unable to connect to all endpoints");
}
}

tracing::debug!("Validation completed");

Ok(())
}

Expand Down
51 changes: 6 additions & 45 deletions src/extensions/api/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use jsonrpsee::server::ServerHandle;
use serde_json::json;
use std::{net::SocketAddr, sync::Arc, time::Duration};
use std::{net::SocketAddr, sync::Arc};
use tokio::sync::mpsc;

use super::eth::EthApi;
Expand Down Expand Up @@ -61,14 +61,7 @@ async fn create_client() -> (
) {
let (addr, server, head_rx, finalized_head_rx, block_hash_rx) = create_server().await;

let client = Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();
let client = Client::with_endpoints([format!("ws://{addr}")]).unwrap();

(client, server, head_rx, finalized_head_rx, block_hash_rx)
}
Expand Down Expand Up @@ -175,14 +168,7 @@ async fn rotate_endpoint_on_stale() {
let (addr, server, mut head_rx, _, mut block_rx) = create_server().await;
let (addr2, server2, mut head_rx2, _, mut block_rx2) = create_server().await;

let client = Client::new(
[format!("ws://{addr}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();
let client = Client::with_endpoints([format!("ws://{addr}"), format!("ws://{addr2}")]).unwrap();
let api = SubstrateApi::new(Arc::new(client), std::time::Duration::from_millis(100));

let head = api.get_head();
Expand Down Expand Up @@ -245,14 +231,7 @@ async fn rotate_endpoint_on_head_mismatch() {
let (addr1, server1, mut head_rx1, mut finalized_head_rx1, mut block_rx1) = create_server().await;
let (addr2, server2, mut head_rx2, mut finalized_head_rx2, mut block_rx2) = create_server().await;

let client = Client::new(
[format!("ws://{addr1}"), format!("ws://{addr2}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap();
let client = Client::with_endpoints([format!("ws://{addr1}"), format!("ws://{addr2}")]).unwrap();

let client = Arc::new(client);
let api = SubstrateApi::new(client.clone(), std::time::Duration::from_millis(100));
Expand Down Expand Up @@ -353,16 +332,7 @@ async fn rotate_endpoint_on_head_mismatch() {
#[tokio::test]
async fn substrate_background_tasks_abort_on_drop() {
let (addr, _server, mut head_rx, mut finalized_head_rx, _) = create_server().await;
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());
let api = SubstrateApi::new(client, std::time::Duration::from_millis(100));

// background tasks started
Expand All @@ -382,16 +352,7 @@ async fn substrate_background_tasks_abort_on_drop() {
#[tokio::test]
async fn eth_background_tasks_abort_on_drop() {
let (addr, _server, mut subscription_rx, mut block_rx) = create_eth_server().await;
let client = Arc::new(
Client::new(
[format!("ws://{addr}")],
Duration::from_secs(1),
Duration::from_secs(1),
None,
None,
)
.unwrap(),
);
let client = Arc::new(Client::with_endpoints([format!("ws://{addr}")]).unwrap());

let api = EthApi::new(client, std::time::Duration::from_millis(100));

Expand Down
Loading

0 comments on commit aa48c3a

Please sign in to comment.