Skip to content

Commit

Permalink
bugfix when intial wallet configuartion
Browse files Browse the repository at this point in the history
  • Loading branch information
ziggie1984 committed Jan 10, 2023
1 parent 55f3690 commit dfef163
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bus/infrastructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
80 changes: 29 additions & 51 deletions bus/workers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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{
Expand All @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
5 changes: 4 additions & 1 deletion config/writer..go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
1 change: 1 addition & 0 deletions httpd/svc/explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dfef163

Please sign in to comment.