mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
bin/darkirc: configurable dag sync attempt and retries
This commit is contained in:
@@ -30,6 +30,12 @@ autojoin = [
|
||||
## (optional, but once configured, it is required from the IRC client side)
|
||||
#password = "CHANGE_ME"
|
||||
|
||||
## Number of attempts to sync the DAG.
|
||||
#sync_attempts = 5
|
||||
|
||||
## Number of seconds to wait before trying again if sync fails.
|
||||
#sync_timeout = 10
|
||||
|
||||
# Log to file. Off by default.
|
||||
#log = "/tmp/darkirc.log"
|
||||
# Set log level. 1 is info (default), 2 is debug, 3 is trace
|
||||
|
||||
@@ -100,9 +100,18 @@ struct Args {
|
||||
#[structopt(long)]
|
||||
get_chacha_pubkey: Option<String>,
|
||||
|
||||
/// Flag to skip syncing the DAG (no history).
|
||||
#[structopt(long)]
|
||||
skip_dag_sync: bool,
|
||||
|
||||
/// Number of attempts to sync the DAG.
|
||||
#[structopt(long, default_value = "5")]
|
||||
sync_attempts: u8,
|
||||
|
||||
/// Number of seconds to wait before trying again if sync fails.
|
||||
#[structopt(long, default_value = "10")]
|
||||
sync_timeout: u8,
|
||||
|
||||
/// P2P network settings
|
||||
#[structopt(flatten)]
|
||||
net: SettingsOpt,
|
||||
@@ -309,22 +318,22 @@ async fn realmain(args: Args, ex: Arc<Executor<'static>>) -> Result<()> {
|
||||
info!("Waiting for some P2P connections...");
|
||||
sleep(5).await;
|
||||
|
||||
// We'll attempt to sync 5 times
|
||||
// We'll attempt to sync {sync_attempts} times
|
||||
if !args.skip_dag_sync {
|
||||
for i in 1..=6 {
|
||||
for i in 1..=args.sync_attempts {
|
||||
info!("Syncing event DAG (attempt #{})", i);
|
||||
match event_graph.dag_sync().await {
|
||||
Ok(()) => break,
|
||||
Err(e) => {
|
||||
if i == 6 {
|
||||
if i == args.sync_attempts {
|
||||
error!("Failed syncing DAG. Exiting.");
|
||||
p2p.stop().await;
|
||||
return Err(Error::DagSyncFailed)
|
||||
} else {
|
||||
// TODO: Maybe at this point we should prune or something?
|
||||
// TODO: Or maybe just tell the user to delete the DAG from FS.
|
||||
error!("Failed syncing DAG ({}), retrying in 10s...", e);
|
||||
sleep(10).await;
|
||||
error!("Failed syncing DAG ({}), retrying in {}s...", e, args.sync_timeout);
|
||||
sleep(args.sync_timeout.into()).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user