File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -430,6 +430,23 @@ func (w *Wallet) syncWithChain(birthdayStamp *waddrmgr.BlockStamp) error {
430
430
// before catching up with the rescan.
431
431
rollback := false
432
432
rollbackStamp := w .Manager .SyncedTo ()
433
+
434
+ // Handle corner cases where the chain has reorged to a lower height
435
+ // than the wallet had synced to. This could happen if the chain has
436
+ // reorged to a shorter chain with difficulty greater than the current.
437
+ // Most of the time, it's only temporary since the chain will grow
438
+ // past the previous height anyway. In regtest, however, it burdens
439
+ // the testing setup without this check.
440
+ bestBlockHash , bestBlockHeight , err := chainClient .GetBestBlock ()
441
+ if err != nil {
442
+ return err
443
+ }
444
+ if rollbackStamp .Height > bestBlockHeight {
445
+ rollbackStamp .Hash = * bestBlockHash
446
+ rollbackStamp .Height = bestBlockHeight
447
+ rollback = true
448
+ }
449
+
433
450
err = walletdb .Update (w .db , func (tx walletdb.ReadWriteTx ) error {
434
451
addrmgrNs := tx .ReadWriteBucket (waddrmgrNamespaceKey )
435
452
txmgrNs := tx .ReadWriteBucket (wtxmgrNamespaceKey )
You can’t perform that action at this time.
0 commit comments