Skip to content

reorg detection is may not handle blocks off the top case. #2179

@zancas

Description

@zancas

This reorg detection is only expected to run at initialization time. All other things being equal it would be nice to break it out cleanly into an obvious initialization scope.

{
tracing::info!("Re-org detected.");
let sync_state = wallet
.get_sync_state_mut()
.map_err(SyncError::WalletError)?;
let last_known_chain_height = sync_state
.last_known_chain_height()
.expect("scan ranges should be non-empty in this scope");
// reset scan range from `Scanning` to `Verify`
state::set_scan_priority(
sync_state,
scan_range.block_range(),
ScanPriority::Verify,
);
// extend verification range to VERIFY_BLOCK_RANGE_SIZE blocks below current verification range
let verification_start = state::set_verify_scan_range(
sync_state,
height - 1,
state::VerifyEnd::VerifyHighest,
)
.block_range()
.start;
state::merge_scan_ranges(sync_state, ScanPriority::Verify);
if initial_unscanned_height - verification_start > MAX_REORG_ALLOWANCE {
clear_wallet_data(wallet)?;
return Err(ServerError::ChainVerificationError.into());
}
truncate_wallet_data(wallet, verification_start - 1)?;
state::set_initial_state(
consensus_parameters,
fetch_request_sender.clone(),
wallet,
last_known_chain_height,
)
.await?;
} else {

Sub-issues

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions