Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve handling of old base nodes and reorgs in wallet recovery #3608

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions base_layer/wallet/src/utxo_scanner_service/utxo_scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,9 @@ where TBackend: WalletBackend + 'static
Err(RpcError::RequestFailed(err)) if err.as_status_code().is_not_found() => {
warn!(target: LOG_TARGET, "Reorg detected: {}", err);
// The node does not know of the last hash we scanned, thus we had a chain split.
// We now start at 0 again.
Ok(0)
// We now start at the wallet birthday again
let birthday_metdadata = self.get_birthday_metadata(client).await?;
Ok(birthday_metdadata.utxo_index)
},
Err(err) => Err(err.into()),
}
Expand Down Expand Up @@ -645,7 +646,16 @@ where TBackend: WalletBackend + 'static
// Calculate the unix epoch time of two days before the wallet birthday. This is to avoid any weird time zone
// issues
let epoch_time = (birthday.saturating_sub(2) as u64) * 60 * 60 * 24;
let block_height = client.get_height_at_time(epoch_time).await?;
let block_height = match client.get_height_at_time(epoch_time).await {
Ok(b) => b,
Err(e) => {
warn!(
target: LOG_TARGET,
"Problem requesting `height_at_time` from Base Node: {}", e
);
0
},
};
let header = client.get_header_by_height(block_height).await?;
let header = BlockHeader::try_from(header).map_err(|_| UtxoScannerError::ConversionError)?;

Expand Down