Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit 28b2dcc

Browse files
ziggie1984adrienlacombe
authored andcommitted
bugfix when intial wallet configuartion
1 parent 736ddf0 commit 28b2dcc

File tree

7 files changed

+39
-54
lines changed

7 files changed

+39
-54
lines changed

bus/infrastructure.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ func (b *Bus) DumpLatestRescanTime() error {
492492
if err != nil {
493493
log.WithFields(log.Fields{
494494
"prefix": "worker",
495-
}).Error("Error savng last timestamp to file: %s", err)
495+
}).Errorf("Error saving last timestamp to file: %s", err)
496496
return err
497497
}
498498

bus/workers.go

Lines changed: 28 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func getPreviousRescanBlock() (int64, error) {
126126
configRescan, err := config.LoadRescanConf()
127127

128128
if err != nil {
129-
log.Errorf("loading rescan config: %s", err)
130129
return -1, err
131130
}
132131

@@ -270,15 +269,20 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool,
270269

271270
}
272271

272+
// We check whether the lss_rescan.json exists
273+
startHeight, err := getPreviousRescanBlock()
274+
if err != nil {
275+
log.Debugf("No lss_rescan.json file found %s", err)
276+
}
277+
273278
// We allow the user to force an import of all descriptors
274279
// which will trigger a rescan automatically using the timestamp
275280
// in the importDescriptorRequest
276-
if forceImportDesc || isNewWallet {
281+
if forceImportDesc || isNewWallet || startHeight == -1 {
277282

278-
// updates status of the wallet
279-
// if wallet is syncing we do not want
280-
// to kill the syncing otherwise the importDescriptor call
281-
// will fail
283+
// Check whether the wallet is syncing in the background
284+
// if so, the sync is aborted so that we can import the
285+
// descriptors in the next step
282286
if forceImportDesc {
283287
err := b.checkWalletSyncStatus()
284288

@@ -320,7 +324,7 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool,
320324
b.IsPendingScan = false
321325

322326
} else {
323-
// wallet is loaded
327+
// wallet is loaded and exists in the backend
324328
err := b.checkWalletSyncStatus()
325329
if err != nil {
326330
log.WithFields(log.Fields{
@@ -333,56 +337,29 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool,
333337
}
334338

335339
if b.IsPendingScan {
336-
337-
for {
338-
err := b.checkWalletSyncStatus()
339-
if err != nil {
340-
log.WithFields(log.Fields{
341-
"prefix": "worker",
342-
"error": err,
343-
}).Error("failed to check wallet status")
344-
345-
sendInterruptSignal()
346-
return
347-
}
348-
349-
if !b.IsPendingScan {
350-
log.WithFields(log.Fields{
351-
"prefix": "worker",
352-
}).Info("Wallet Rescan finished")
353-
break
354-
}
355-
time.Sleep(1 * time.Second)
356-
}
357-
358-
} else {
359-
// wallet is not scanning but we need to
360-
// catch up with history so we need to rescan the
361-
// wallet from the last time satstack was shut down
362-
363-
startHeight, err := getPreviousRescanBlock()
364-
340+
err := b.AbortRescan()
365341
if err != nil {
366-
// no rescanning necessary
367-
log.Info("In case you run satstack for the first this error can be ignored: ", err)
368-
return
342+
log.WithFields(log.Fields{
343+
"error": err,
344+
}).Error("Failed to abort rescan")
369345
}
346+
}
370347

371-
endHeight, _ := b.GetBlockCount()
348+
endHeight, _ := b.GetBlockCount()
372349

373-
// Begin Starting rescan, this is a blocking call
374-
err = b.rescanWallet(startHeight, endHeight)
375-
if err != nil {
376-
log.WithFields(log.Fields{
377-
"prefix": "worker",
378-
"error": err,
379-
}).Error("Failed to rescan blocks")
380-
sendInterruptSignal()
381-
return
382-
}
350+
// Begin Starting rescan, this is a blocking call
351+
err = b.rescanWallet(startHeight, endHeight)
352+
if err != nil {
353+
log.WithFields(log.Fields{
354+
"prefix": "worker",
355+
"error": err,
356+
}).Error("Failed to rescan blocks")
357+
sendInterruptSignal()
358+
return
383359
}
384360
}
385-
err := b.DumpLatestRescanTime()
361+
362+
err = b.DumpLatestRescanTime()
386363
if err != nil {
387364
log.WithFields(log.Fields{
388365
"prefix": "worker",

config/loader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ func configLookupPaths() ([]string, error) {
148148
return []string{
149149
path.Join(liveUserDataFolder(home), "lss.json"),
150150
"lss.json",
151+
path.Join(home, ".satstack", "lss.json"),
151152
path.Join(home, "lss.json"),
152153
}, nil
153154
}
@@ -161,6 +162,7 @@ func configRescanLookupPaths() ([]string, error) {
161162
return []string{
162163
path.Join(liveUserDataFolder(home), "lss_rescan.json"),
163164
"lss_rescan.json",
165+
path.Join(home, ".satstack", "lss_rescan.json"),
164166
path.Join(home, "lss_rescan.json"),
165167
}, nil
166168
}

config/writer..go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
log "github.com/sirupsen/logrus"
88
)
99

10+
// WriteRescanConf writes the rescan information into a file
11+
// when it does not exist it saves it to the same location
12+
// where the lss.json is stored
1013
func WriteRescanConf(data *ConfigurationRescan) error {
1114
paths, err := configRescanLookupPaths()
1215
if err != nil {
@@ -24,7 +27,7 @@ func WriteRescanConf(data *ConfigurationRescan) error {
2427
if configPath == "" {
2528
// if the file does not exist, save to home dir
2629
// check where the lss.json lies and take the same path
27-
lssPath, err := configRescanLookupPaths()
30+
lssPath, err := configLookupPaths()
2831
if err != nil {
2932
return err
3033
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/btcsuite/btcd/btcutil v1.1.2
88
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
99
github.com/gin-gonic/gin v1.8.1
10-
github.com/magefile/mage v1.13.0
10+
github.com/magefile/mage v1.14.0
1111
github.com/mattn/go-runewidth v0.0.13
1212
github.com/mitchellh/go-homedir v1.1.0
1313
github.com/mitchellh/go-wordwrap v1.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
9595
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
9696
github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M=
9797
github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
98+
github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo=
99+
github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A=
98100
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
99101
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
100102
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=

httpd/svc/explorer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func (s *Service) GetStatus() *bus.ExplorerStatus {
4444
}
4545

4646
// Case 1: satstack is running the numbers.
47+
// or rescanning the wallet
4748
if s.Bus.IsPendingScan {
4849
status.Status = bus.PendingScan
4950
return &status

0 commit comments

Comments
 (0)