Skip to content

Commit

Permalink
sync: Set status when manually rescanning.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeGruffins committed May 14, 2024
1 parent 5ce1163 commit 5e7f5c1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
28 changes: 21 additions & 7 deletions cgo/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ func syncWalletStatus(cName *C.char) *C.char {
// a bandaid to put us as synced in that case.
//
// TODO: Figure out why we would miss a notification.
if w.IsSynced() {
w.syncStatusMtx.Lock()
w.syncStatusMtx.Lock()
if ssc != SSCComplete && w.IsSynced() && !w.rescanning {
ssc = SSCComplete
w.syncStatusCode = ssc
w.syncStatusMtx.Unlock()
}
w.syncStatusMtx.Unlock()

ss := &SyncStatusRes{
SyncStatusCode: int(ssc),
Expand Down Expand Up @@ -167,8 +167,22 @@ func rescanFromHeight(cName, cHeight *C.char) *C.char {
if err != nil {
return errCResponse("height is not an uint32: %v", err)
}
if err := w.RescanFromHeight(ctx, int32(height)); err != nil {
return errCResponse("rescan wallet %q error: %v", name, err.Error())
}
return successCResponse("rescan from height %d for wallet %q ok", height, name)
// We don't seem to get any feedback from wallet when doing rescans here.
// Just set status to rescanning and then to complete when done.
w.syncStatusMtx.Lock()
w.syncStatusCode = SSCRescanning
w.rescanning = true
w.syncStatusMtx.Unlock()
go func() {
defer func() {
w.syncStatusMtx.Lock()
w.syncStatusCode = SSCComplete
w.rescanning = false
w.syncStatusMtx.Unlock()
}()
if err := w.RescanFromHeight(ctx, int32(height)); err != nil {
log.Errorf("rescan wallet %q error: %v", name, err)
}
}()
return successCResponse("rescan from height %d for wallet %q started", height, name)
}
1 change: 1 addition & 0 deletions cgo/walletloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type wallet struct {
syncStatusMtx sync.RWMutex
syncStatusCode SyncStatusCode
targetHeight, cfiltersHeight, headersHeight, rescanHeight, numPeers int
rescanning bool
}

//export createWallet
Expand Down

0 comments on commit 5e7f5c1

Please sign in to comment.