Skip to content

Commit

Permalink
Wait for healtcheck when creating WebServerNetwork
Browse files Browse the repository at this point in the history
  • Loading branch information
QuentinI committed Dec 14, 2023
1 parent 463c78e commit 15b359c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/ValidatorConfigOutput
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ValidatorConfig { public_key: BLSPubKey { pub_key: VerKey((QuadExtField(2264797523581107490935262917175769123227923636811928330606075281145117212394 + 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u), QuadExtField(7996517616082121122160563552650547601395271017260499735456299700133762512689 + 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u), QuadExtField(1515973040548822760825076242090160370742046237881440422068330135941139244581 + 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u))) }, private_key: BLSPrivKey { priv_key: SignKey(BigInt([3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578])) }, stake_value: 1 }
ValidatorConfig { public_key: BLSPubKey { pub_key: VerKey((QuadExtField(2264797523581107490935262917175769123227923636811928330606075281145117212394 + 15807017392833049888165434456991157794698032464874424842715555348468160607934 * u), QuadExtField(7996517616082121122160563552650547601395271017260499735456299700133762512689 + 7504045709281061282278228438613345070383424761478787301859187055302953740948 * u), QuadExtField(1515973040548822760825076242090160370742046237881440422068330135941139244581 + 20251846261653098602911417004145145971080304248810966341160788194007704966108 * u))) }, private_key: BLSPrivKey { priv_key: SignKey(BigInt([3505488234151006356, 6655477166151225138, 3291219027844407676, 2153641080015542578])) }, stake_value: 1, state_key_pair: StateKeyPair(KeyPair { sk: SignKey(BigInt([2822822805887490846, 6664316196088353173, 4926510007447087464, 116097479308258694])), vk: VerKey(Projective { x: BigInt([11315198235793138814, 4744451806709910489, 6921831025042192557, 1125393823825936625]), y: BigInt([13035879815613524256, 18225673961538637854, 12006860967936477969, 1516668567229692859]), t: BigInt([13450777528397789701, 12242009376162249168, 12596256366242272750, 3368076418495976469]), z: BigInt([10465708325245823445, 13967918689717629445, 14943426723808572731, 621075342718756551]) }) }) }
43 changes: 38 additions & 5 deletions crates/hotshot/examples/infra/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,15 @@ async fn webserver_network_from_config<TYPES: NodeType>(
wait_between_polls,
}: WebServerConfig = config.web_server_config.unwrap();

WebServerNetwork::create(url, wait_between_polls, pub_key, false)
WebServerNetwork::create(
url,
Duration::from_millis(500),
wait_between_polls,
pub_key,
false,
)
.await
.expect("Failed to connect to web server")
}

async fn libp2p_network_from_config<TYPES: NodeType>(
Expand Down Expand Up @@ -543,11 +551,29 @@ where
WebCommChannel::new(underlying_quorum_network.into());

let da_channel: WebCommChannel<TYPES> = WebCommChannel::new(
WebServerNetwork::create(url.clone(), wait_between_polls, pub_key.clone(), true).into(),
WebServerNetwork::create(
url.clone(),
Duration::from_millis(500),
wait_between_polls,
pub_key.clone(),
true,
)
.await
.expect("Failed to connect to web server")
.into(),
);

let vid_channel: WebCommChannel<TYPES> = WebCommChannel::new(
WebServerNetwork::create(url, wait_between_polls, pub_key, true).into(),
WebServerNetwork::create(
url,
Duration::from_millis(500),
wait_between_polls,
pub_key,
true,
)
.await
.expect("Failed to connect to web server")
.into(),
);

WebServerDARun {
Expand Down Expand Up @@ -738,8 +764,15 @@ where
let webserver_underlying_quorum_network =
webserver_network_from_config::<TYPES>(config.clone(), pub_key.clone()).await;

let webserver_underlying_da_network =
WebServerNetwork::create(url, wait_between_polls, pub_key, true);
let webserver_underlying_da_network = WebServerNetwork::create(
url,
Duration::from_millis(500),
wait_between_polls,
pub_key,
true,
)
.await
.expect("Failed to connect to da network");

webserver_underlying_quorum_network.wait_for_ready().await;

Expand Down
24 changes: 17 additions & 7 deletions crates/hotshot/src/traits/networking/web_server_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! To run the web server, see the `./web_server/` folder in this repo.
//!
use async_compatibility_layer::art::async_block_on;
use async_compatibility_layer::channel::{unbounded, UnboundedReceiver, UnboundedSender};

use async_compatibility_layer::{
Expand Down Expand Up @@ -472,18 +473,25 @@ impl<M: NetworkMsg> NetworkMsg for RecvMsg<M> {}

impl<TYPES: NodeType + 'static> WebServerNetwork<TYPES> {
/// Creates a new instance of the `WebServerNetwork`
/// # Errors
/// if couldn't connect to server before `connect_timeout`
/// # Panics
/// if the web server url is malformed
pub fn create(
pub async fn create(
url: Url,
connect_timeout: Duration,
wait_between_polls: Duration,
key: TYPES::SignatureKey,
is_da_server: bool,
) -> Self {
) -> Result<Self, WebServerNetworkError> {
info!("Connecting to web server at {url:?} is da: {is_da_server}");

// TODO ED Wait for healthcheck
let client = surf_disco::Client::<ClientError>::new(url);
client
.connect(Some(connect_timeout))
.await
.then_some(())
.ok_or(WebServerNetworkError::ClientError)?;

let inner = Arc::new(Inner {
broadcast_poll_queue: Arc::default(),
Expand All @@ -506,10 +514,10 @@ impl<TYPES: NodeType + 'static> WebServerNetwork<TYPES> {

inner.connected.store(true, Ordering::Relaxed);

Self {
Ok(Self {
inner,
server_shutdown_signal: None,
}
})
}

/// Parses a message to find the appropriate endpoint
Expand Down Expand Up @@ -1149,12 +1157,14 @@ impl<TYPES: NodeType> TestableNetworkingImplementation<TYPES> for WebServerNetwo
Box::new(move |id| {
let sender = Arc::clone(&sender);
let url = Url::parse(format!("http://localhost:{port}").as_str()).unwrap();
let mut network = WebServerNetwork::create(
let mut network = async_block_on(WebServerNetwork::create(
url,
Duration::from_millis(500),
Duration::from_millis(100),
known_nodes[id as usize].clone(),
is_da,
);
))
.expect("Failed to connect to web server");
network.server_shutdown_signal = Some(sender);
network
})
Expand Down

0 comments on commit 15b359c

Please sign in to comment.