Skip to content

Commit acf2dc9

Browse files
Gianmarco Fraccarolitzemanovic
authored andcommitted
ledger: wait for node to sync before running cli commands
1 parent 5ec964e commit acf2dc9

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

  • apps/src/bin/namada-client

apps/src/bin/namada-client/cli.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ use namada_apps::facade::tendermint_config::net::Address as TendermintAddress;
1111
use namada_apps::facade::tendermint_rpc::{Client, HttpClient};
1212
use tokio::time::sleep;
1313

14-
const WAIT_FOR_LEDGER_SYNC: u64 = 5;
15-
1614
pub async fn main() -> Result<()> {
1715
match cli::namada_client_cli()? {
1816
cli::NamadaClient::WithContext(cmd_box) => {
@@ -168,7 +166,8 @@ pub async fn main() -> Result<()> {
168166
async fn wait_until_node_is_synched(ledger_address: &TendermintAddress) {
169167
let client = HttpClient::new(ledger_address.clone()).unwrap();
170168
let height_one = Height::try_from(1_u64).unwrap();
171-
let mut try_count = 0;
169+
let mut try_count = 0_u64;
170+
const MAX_TRIES: u64 = 5;
172171

173172
loop {
174173
let node_status = client.status().await;
@@ -187,8 +186,17 @@ async fn wait_until_node_is_synched(ledger_address: &TendermintAddress) {
187186
);
188187
safe_exit(1)
189188
} else {
190-
println!("Waiting for node to sync...");
191-
sleep(Duration::from_secs(try_count.pow(try_count)))
189+
println!(
190+
" Waiting for {} ({}/{} tries)...",
191+
if is_at_least_height_one {
192+
"a first block"
193+
} else {
194+
"node to sync"
195+
},
196+
try_count + 1,
197+
MAX_TRIES
198+
);
199+
sleep(Duration::from_secs((try_count + 1).pow(2)))
192200
.await;
193201
}
194202
try_count += 1;

0 commit comments

Comments
 (0)