Skip to content

Commit

Permalink
Improve wallet sync error messages (ordinals#4126)
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph authored Dec 11, 2024
1 parent fcfc93c commit 080fcef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions src/wallet/wallet_constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,21 @@ impl WalletConstructor {
client
};

let chain_block_count = bitcoin_client.get_block_count().unwrap() + 1;
let bitcoin_block_count = bitcoin_client.get_block_count().unwrap() + 1;

if !self.no_sync {
for i in 0.. {
let response = self.get("/blockcount")?;

if response
.text()?
.parse::<u64>()
.expect("wallet failed to talk to server. Make sure `ord server` is running.")
>= chain_block_count
{
let ord_block_count = self.get("/blockcount")?.text()?.parse::<u64>().expect(
"wallet failed to retreive block count from server. Make sure `ord server` is running.",
);

if ord_block_count >= bitcoin_block_count {
break;
} else if i == 20 {
bail!("wallet failed to synchronize with `ord server` after {i} attempts");
bail!(
"`ord server` {} blocks behind `bitcoind`, consider using `--no-sync` to ignore this error",
bitcoin_block_count - ord_block_count
);
}
std::thread::sleep(Duration::from_millis(50));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/wallet/balance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn unsynced_wallet_fails_with_unindexed_output() {
.ord(&no_sync_ord)
.core(&core)
.expected_exit_code(1)
.expected_stderr("error: wallet failed to synchronize with `ord server` after 20 attempts\n")
.expected_stderr("error: `ord server` 4 blocks behind `bitcoind`, consider using `--no-sync` to ignore this error\n")
.run_and_extract_stdout();

CommandBuilder::new("wallet --no-sync balance")
Expand Down

0 comments on commit 080fcef

Please sign in to comment.