diff --git a/bus/infrastructure.go b/bus/infrastructure.go index 398a8b4..68bb1cb 100644 --- a/bus/infrastructure.go +++ b/bus/infrastructure.go @@ -492,7 +492,7 @@ func (b *Bus) DumpLatestRescanTime() error { if err != nil { log.WithFields(log.Fields{ "prefix": "worker", - }).Error("Error savng last timestamp to file: %s", err) + }).Errorf("Error saving last timestamp to file: %s", err) return err } diff --git a/bus/workers.go b/bus/workers.go index af10a5e..5ef5a3f 100644 --- a/bus/workers.go +++ b/bus/workers.go @@ -126,7 +126,6 @@ func getPreviousRescanBlock() (int64, error) { configRescan, err := config.LoadRescanConf() if err != nil { - log.Errorf("loading rescan config: %s", err) return -1, err } @@ -270,15 +269,21 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool, } + // We check whether the lss_rescan.json exists + startHeight, err := getPreviousRescanBlock() + if err != nil { + // no rescanning necessary + log.Debugf("No lss_rescan.json file found, scanning the whole wallet: %s", err) + } + // We allow the user to force an import of all descriptors // which will trigger a rescan automatically using the timestamp // in the importDescriptorRequest - if forceImportDesc || isNewWallet { + if forceImportDesc || isNewWallet || startHeight == -1 { - // updates status of the wallet - // if wallet is syncing we do not want - // to kill the syncing otherwise the importDescriptor call - // will fail + // Check whether the wallet is syncing in the background + // if so, the sync is aborted so that we can import the + // descriptors in the next step if forceImportDesc { err := b.checkWalletSyncStatus() @@ -320,7 +325,7 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool, b.IsPendingScan = false } else { - // wallet is loaded + // wallet is loaded and exists in the backend err := b.checkWalletSyncStatus() if err != nil { log.WithFields(log.Fields{ @@ -333,56 +338,29 @@ func (b *Bus) Worker(config *config.Configuration, skipCirculationCheck bool, } if b.IsPendingScan { - - for { - err := b.checkWalletSyncStatus() - if err != nil { - log.WithFields(log.Fields{ - "prefix": "worker", - "error": err, - }).Error("failed to check wallet status") - - sendInterruptSignal() - return - } - - if !b.IsPendingScan { - log.WithFields(log.Fields{ - "prefix": "worker", - }).Info("Wallet Rescan finished") - break - } - time.Sleep(1 * time.Second) - } - - } else { - // wallet is not scanning but we need to - // catch up with history so we need to rescan the - // wallet from the last time satstack was shut down - - startHeight, err := getPreviousRescanBlock() - + err := b.AbortRescan() if err != nil { - // no rescanning necessary - log.Info("In case you run satstack for the first this error can be ignored: ", err) - return + log.WithFields(log.Fields{ + "error": err, + }).Error("Failed to abort rescan") } + } - endHeight, _ := b.GetBlockCount() + endHeight, _ := b.GetBlockCount() - // Begin Starting rescan, this is a blocking call - err = b.rescanWallet(startHeight, endHeight) - if err != nil { - log.WithFields(log.Fields{ - "prefix": "worker", - "error": err, - }).Error("Failed to rescan blocks") - sendInterruptSignal() - return - } + // Begin Starting rescan, this is a blocking call + err = b.rescanWallet(startHeight, endHeight) + if err != nil { + log.WithFields(log.Fields{ + "prefix": "worker", + "error": err, + }).Error("Failed to rescan blocks") + sendInterruptSignal() + return } } - err := b.DumpLatestRescanTime() + + err = b.DumpLatestRescanTime() if err != nil { log.WithFields(log.Fields{ "prefix": "worker", diff --git a/config/loader.go b/config/loader.go index eea64ff..6139483 100644 --- a/config/loader.go +++ b/config/loader.go @@ -148,6 +148,7 @@ func configLookupPaths() ([]string, error) { return []string{ path.Join(liveUserDataFolder(home), "lss.json"), "lss.json", + path.Join(home, ".satstack", "lss.json"), path.Join(home, "lss.json"), }, nil } @@ -161,6 +162,7 @@ func configRescanLookupPaths() ([]string, error) { return []string{ path.Join(liveUserDataFolder(home), "lss_rescan.json"), "lss_rescan.json", + path.Join(home, ".satstack", "lss_rescan.json"), path.Join(home, "lss_rescan.json"), }, nil } diff --git a/config/writer..go b/config/writer..go index 65b6995..3978998 100644 --- a/config/writer..go +++ b/config/writer..go @@ -7,6 +7,9 @@ import ( log "github.com/sirupsen/logrus" ) +// WriteRescanConf writes the rescan information into a file +// when it does not exist it saves it to the same location +// where the lss.json is stored func WriteRescanConf(data *ConfigurationRescan) error { paths, err := configRescanLookupPaths() if err != nil { @@ -24,7 +27,7 @@ func WriteRescanConf(data *ConfigurationRescan) error { if configPath == "" { // if the file does not exist, save to home dir // check where the lss.json lies and take the same path - lssPath, err := configRescanLookupPaths() + lssPath, err := configLookupPaths() if err != nil { return err } diff --git a/go.mod b/go.mod index 33feadb..b5cb839 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/btcsuite/btcd/btcutil v1.1.2 github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 github.com/gin-gonic/gin v1.8.1 - github.com/magefile/mage v1.13.0 + github.com/magefile/mage v1.14.0 github.com/mattn/go-runewidth v0.0.13 github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-wordwrap v1.0.1 diff --git a/go.sum b/go.sum index 3b58cff..dc44134 100644 --- a/go.sum +++ b/go.sum @@ -95,6 +95,8 @@ github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w= github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY= github.com/magefile/mage v1.13.0 h1:XtLJl8bcCM7EFoO8FyH8XK3t7G5hQAeK+i4tq+veT9M= github.com/magefile/mage v1.13.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= +github.com/magefile/mage v1.14.0 h1:6QDX3g6z1YvJ4olPhT1wksUcSa/V0a1B+pJb73fBjyo= +github.com/magefile/mage v1.14.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= diff --git a/httpd/svc/explorer.go b/httpd/svc/explorer.go index 5f0d9a0..15cbe49 100644 --- a/httpd/svc/explorer.go +++ b/httpd/svc/explorer.go @@ -44,6 +44,7 @@ func (s *Service) GetStatus() *bus.ExplorerStatus { } // Case 1: satstack is running the numbers. + // or rescanning the wallet if s.Bus.IsPendingScan { status.Status = bus.PendingScan return &status