Skip to content

Commit

Permalink
fix: improve handling of old base nodes and reorgs in wallet recovery (
Browse files Browse the repository at this point in the history
…#3608)

Description
---
This PR adds two quick improvements on the wallet recovery:
- Gracefully handle the case where the base node is older and doesn’t support the `get_height_at_time` RPC call yet.
- If a reorg is detected during recovery the process used to be restarted from the genesis block. Now it will restart from the wallet birthday

How Has This Been Tested?
---
Manually
  • Loading branch information
philipr-za committed Nov 23, 2021
1 parent fff45db commit bb94ea2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions base_layer/wallet/src/utxo_scanner_service/utxo_scanning.rs
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

0 comments on commit bb94ea2

Please sign in to comment.