Merge #1316: electrum: don't roll the tip forward upon reorg

87593befd4a85accbab7e7417b322ea74393b69d electrum: don't roll the tip forward upon reorg (Michael Mallan)

Pull request description:

  For Electrum, we detect reorgs while syncing based on our local chain.

  When a user requests a rescan, we roll the DB back to genesis block, but leave the local chain as it is. If there's then a reorg, we would find the common ancestor with respect to our local chain, which would be later than the DB's tip. In order not to miss any updates, we shouldn't roll the DB tip forward in that case.

ACKs for top commit:
  darosior:
    utACK 87593befd4a85accbab7e7417b322ea74393b69d.

Tree-SHA512: d89f95d15a55b21479ace2757d2f343bbff8919dd31733d9bff3165d0cfdcb1256e0894dab414f57d363331ef81c15fb4efdae572394640fbc620bcea8c8c57c
This commit is contained in:
Antoine Poinsot 2024-09-12 09:08:07 +02:00
commit 47592be412
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304

View File

@ -275,8 +275,20 @@ fn updates(
Ok(Some(reorg_common_ancestor)) => {
// The block chain was reorganized. Rollback our state down to the common ancestor
// between our former chain and the new one, then restart fresh.
db_conn.rollback_tip(&reorg_common_ancestor);
log::info!("Tip was rolled back to '{}'.", &reorg_common_ancestor);
// Make sure the common ancestor is not higher than the current DB tip, which could
// happen if a rescan has been detected and the DB tip rolled back accordingly.
if reorg_common_ancestor.height <= current_tip.height
// check hash in case height is the same
&& reorg_common_ancestor.hash != current_tip.hash
{
db_conn.rollback_tip(&reorg_common_ancestor);
log::info!("Tip was rolled back to '{}'.", &reorg_common_ancestor);
} else {
log::info!(
"Tip was already earlier than common ancestor '{}'.",
&reorg_common_ancestor
);
}
return updates(db_conn, bit, descs, secp);
}
Err(e) => {