Skip to content

Commit

Permalink
Merge pull request #249 from SiaFoundation/nate/improve-rescan-logging
Browse files Browse the repository at this point in the history
Make rescan logging clearer
  • Loading branch information
n8maninger committed Dec 30, 2023
2 parents f2e88c3 + 3c36550 commit 7a86b99
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
13 changes: 7 additions & 6 deletions host/contracts/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"math"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -541,13 +542,13 @@ func NewManager(store ContractStore, alerts Alerts, storage StorageManager, c Ch
// blocking startup
go func() {
err := cm.chain.Subscribe(cm, changeID, cm.tg.Done())
if err != nil {
cm.log.Error("failed to subscribe to consensus set", zap.Error(err))
if errors.Is(err, chain.ErrInvalidChangeID) {
if err := cm.chain.Subscribe(cm, modules.ConsensusChangeBeginning, cm.tg.Done()); err != nil {
cm.log.Fatal("failed to reset consensus change subscription", zap.Error(err))
}
if errors.Is(err, chain.ErrInvalidChangeID) {
cm.log.Warn("rescanning blockchain due to unknown consensus change ID")
if err := cm.chain.Subscribe(cm, modules.ConsensusChangeBeginning, cm.tg.Done()); err != nil {
cm.log.Fatal("failed to reset consensus change subscription", zap.Error(err))
}
} else if err != nil && !strings.Contains(err.Error(), "ThreadGroup already stopped") {
cm.log.Fatal("failed to subscribe to consensus changes", zap.Error(err))
}
}()

Expand Down
1 change: 1 addition & 0 deletions host/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ func NewConfigManager(dir string, hostKey types.PrivateKey, rhp2Addr string, sto
// subscribe to consensus changes
err := cm.Subscribe(m, lastChange, m.tg.Done())
if errors.Is(err, chain.ErrInvalidChangeID) {
m.log.Warn("rescanning blockchain due to unknown consensus change ID")
// reset change ID and subscribe again
if err := store.RevertLastAnnouncement(); err != nil {
m.log.Fatal("failed to reset wallet", zap.Error(err))
Expand Down
20 changes: 11 additions & 9 deletions wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"sort"
"strings"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -824,16 +825,17 @@ func NewSingleAddressWallet(priv types.PrivateKey, cm ChainManager, tp Transacti

go func() {
// note: start in goroutine to avoid blocking startup
if err := cm.Subscribe(sw, changeID, sw.tg.Done()); err != nil {
sw.log.Error("failed to subscribe to consensus changes", zap.Error(err))
if errors.Is(err, chain.ErrInvalidChangeID) {
// reset change ID and subscribe again
if err := store.ResetWallet(seedHash); err != nil {
sw.log.Fatal("failed to reset wallet", zap.Error(err))
} else if err = cm.Subscribe(sw, modules.ConsensusChangeBeginning, sw.tg.Done()); err != nil {
sw.log.Fatal("failed to reset consensus change subscription", zap.Error(err))
}
err := cm.Subscribe(sw, changeID, sw.tg.Done())
if errors.Is(err, chain.ErrInvalidChangeID) {
sw.log.Warn("rescanning blockchain due to unknown consensus change ID")
// reset change ID and subscribe again
if err := store.ResetWallet(seedHash); err != nil {
sw.log.Fatal("failed to reset wallet", zap.Error(err))
} else if err = cm.Subscribe(sw, modules.ConsensusChangeBeginning, sw.tg.Done()); err != nil {
sw.log.Fatal("failed to reset consensus change subscription", zap.Error(err))
}
} else if err != nil && !strings.Contains(err.Error(), "ThreadGroup already stopped") {
sw.log.Fatal("failed to subscribe to consensus set", zap.Error(err))
}
}()
tp.Subscribe(sw)
Expand Down

0 comments on commit 7a86b99

Please sign in to comment.