Skip to content

Commit

Permalink
Lock blockchain on rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
cpacia committed Oct 19, 2017
1 parent 943bc48 commit 50117d1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ func (b *Blockchain) GetCommonAncestor(bestHeader, prevBestHeader StoredHeader)
// Rollback the header database to the last header before time t.
// We shouldn't go back further than the checkpoint
func (b *Blockchain) Rollback(t time.Time) error {
b.lock.Lock()
defer b.lock.Unlock()
checkpoint := GetCheckpoint(b.crationDate, b.params)
checkPointHash := checkpoint.Header.BlockHash()
sh, err := b.db.GetBestHeader()
Expand Down
2 changes: 1 addition & 1 deletion wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,10 @@ func (w *SPVWallet) Close() {
}

func (w *SPVWallet) ReSyncBlockchain(fromDate time.Time) {
w.peerManager.Stop()
w.blockchain.Rollback(fromDate)
w.blockchain.SetChainState(SYNCING)
w.txstore.PopulateAdrs()
w.peerManager.Stop()
var err error
w.peerManager, err = NewPeerManager(w.config)
if err != nil {
Expand Down

0 comments on commit 50117d1

Please sign in to comment.