fix faucet empty commitment
Some checks failed
build-and-push-ext / build_push (push) Failing after 7s
Some checks failed
build-and-push-ext / build_push (push) Failing after 7s
This commit is contained in:
parent
fcd3477582
commit
a867cc616a
43
src/main.rs
43
src/main.rs
@ -610,24 +610,35 @@ async fn main() -> Result<()> {
|
|||||||
let do_faucet = config.bootstrap_faucet;
|
let do_faucet = config.bootstrap_faucet;
|
||||||
let our_sp = our_sp_address.to_string();
|
let our_sp = our_sp_address.to_string();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
|
log::info!("Starting bootstrap connection and sync");
|
||||||
if let Err(e) = crate::sync::bootstrap_connect_and_sync(bs_url.clone()).await {
|
if let Err(e) = crate::sync::bootstrap_connect_and_sync(bs_url.clone()).await {
|
||||||
log::warn!("bootstrap failed: {}", e);
|
log::warn!("bootstrap failed: {}", e);
|
||||||
} else if do_faucet && !peer_store::faucet_already_done(&bs_url) {
|
} else {
|
||||||
let env = sdk_common::network::Envelope {
|
log::info!("Bootstrap sync successful, checking faucet request");
|
||||||
flag: sdk_common::network::AnkFlag::Faucet,
|
if do_faucet && !peer_store::faucet_already_done(&bs_url) {
|
||||||
content: serde_json::json!({
|
log::info!("Sending faucet request to bootstrap");
|
||||||
"sp_address": our_sp,
|
let env = sdk_common::network::Envelope {
|
||||||
"commitment": "",
|
flag: sdk_common::network::AnkFlag::Faucet,
|
||||||
"error": null
|
content: serde_json::json!({
|
||||||
}).to_string(),
|
"sp_address": our_sp,
|
||||||
};
|
"commitment": "",
|
||||||
if let Ok((mut ws, _)) = tokio_tungstenite::connect_async(&bs_url).await {
|
"error": null
|
||||||
let _ = ws
|
}).to_string(),
|
||||||
.send(tokio_tungstenite::tungstenite::Message::Text(
|
};
|
||||||
serde_json::to_string(&env).unwrap(),
|
if let Ok((mut ws, _)) = tokio_tungstenite::connect_async(&bs_url).await {
|
||||||
))
|
log::info!("Connected to bootstrap for faucet request");
|
||||||
.await;
|
let _ = ws
|
||||||
peer_store::mark_faucet_done(&bs_url);
|
.send(tokio_tungstenite::tungstenite::Message::Text(
|
||||||
|
serde_json::to_string(&env).unwrap(),
|
||||||
|
))
|
||||||
|
.await;
|
||||||
|
log::info!("Faucet request sent to bootstrap");
|
||||||
|
peer_store::mark_faucet_done(&bs_url);
|
||||||
|
} else {
|
||||||
|
log::error!("Failed to connect to bootstrap for faucet request");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log::info!("Faucet request skipped: do_faucet={}, already_done={}", do_faucet, peer_store::faucet_already_done(&bs_url));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
12
src/sync.rs
12
src/sync.rs
@ -6,16 +6,21 @@ use crate::peers;
|
|||||||
use sdk_common::network::{AnkFlag, Envelope};
|
use sdk_common::network::{AnkFlag, Envelope};
|
||||||
|
|
||||||
pub async fn bootstrap_connect_and_sync(bootstrap_url: String) -> Result<()> {
|
pub async fn bootstrap_connect_and_sync(bootstrap_url: String) -> Result<()> {
|
||||||
|
log::info!("Connecting to bootstrap: {}", bootstrap_url);
|
||||||
let (ws_stream, _) = tokio_tungstenite::connect_async(&bootstrap_url).await?;
|
let (ws_stream, _) = tokio_tungstenite::connect_async(&bootstrap_url).await?;
|
||||||
|
log::info!("Connected to bootstrap successfully");
|
||||||
let (mut write, mut read) = ws_stream.split();
|
let (mut write, mut read) = ws_stream.split();
|
||||||
|
|
||||||
// Send our empty Sync (we don't share, just ask implicitly)
|
// Send our empty Sync (we don't share, just ask implicitly)
|
||||||
let ask = Envelope { flag: AnkFlag::Sync, content: serde_json::json!({"peers": []}).to_string() };
|
let ask = Envelope { flag: AnkFlag::Sync, content: serde_json::json!({"peers": []}).to_string() };
|
||||||
|
log::info!("Sending sync request to bootstrap");
|
||||||
write.send(Message::Text(serde_json::to_string(&ask)?)).await?;
|
write.send(Message::Text(serde_json::to_string(&ask)?)).await?;
|
||||||
|
|
||||||
// Wait one message for peer list
|
// Wait one message for peer list
|
||||||
if let Some(Ok(Message::Text(txt))) = read.next().await {
|
if let Some(Ok(Message::Text(txt))) = read.next().await {
|
||||||
|
log::info!("Received response from bootstrap: {}", txt);
|
||||||
if let Ok(env) = serde_json::from_str::<Envelope>(&txt) {
|
if let Ok(env) = serde_json::from_str::<Envelope>(&txt) {
|
||||||
|
log::info!("Parsed envelope with flag: {:?}", env.flag);
|
||||||
if let AnkFlag::Sync = env.flag {
|
if let AnkFlag::Sync = env.flag {
|
||||||
if let Ok(val) = serde_json::from_str::<serde_json::Value>(&env.content) {
|
if let Ok(val) = serde_json::from_str::<serde_json::Value>(&env.content) {
|
||||||
if let Some(arr) = val.get("peers").and_then(|v| v.as_array()) {
|
if let Some(arr) = val.get("peers").and_then(|v| v.as_array()) {
|
||||||
@ -26,10 +31,17 @@ pub async fn bootstrap_connect_and_sync(bootstrap_url: String) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!("Bootstrap response is not a Sync message, flag: {:?}", env.flag);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!("Failed to parse bootstrap response as envelope: {}", txt);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn!("No response received from bootstrap");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optionally request one faucet if configured is handled by higher layer
|
// Optionally request one faucet if configured is handled by higher layer
|
||||||
|
log::info!("Bootstrap sync completed");
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user