Skip to content

Commit

Permalink
fix race in monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Lazar955 committed Sep 10, 2024
1 parent 42e287c commit ac80078
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions monitor/btcscanner/btc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Scanner interface {
}

type BtcScanner struct {
mu sync.Mutex
logger *zap.SugaredLogger

// connect to BTC node
Expand Down Expand Up @@ -94,7 +95,7 @@ func (bs *BtcScanner) Start(startHeight uint64) {
return
}

bs.BaseHeight = startHeight
bs.SetBaseHeight(startHeight)

bs.Started.Store(true)
bs.logger.Info("the BTC scanner is started")
Expand Down Expand Up @@ -143,7 +144,7 @@ func (bs *BtcScanner) Bootstrap() {
if bs.confirmedTipBlock != nil {
firstUnconfirmedHeight = uint64(bs.confirmedTipBlock.Height + 1)
} else {
firstUnconfirmedHeight = bs.BaseHeight
firstUnconfirmedHeight = bs.GetBaseHeight()
}

bs.logger.Infof("the bootstrapping starts at %d", firstUnconfirmedHeight)
Expand Down Expand Up @@ -283,5 +284,13 @@ func (bs *BtcScanner) Stop() {
}

func (bs *BtcScanner) GetBaseHeight() uint64 {
bs.mu.Lock()
defer bs.mu.Unlock()
return bs.BaseHeight
}

func (bs *BtcScanner) SetBaseHeight(h uint64) {
bs.mu.Lock()
defer bs.mu.Unlock()
bs.BaseHeight = h
}

0 comments on commit ac80078

Please sign in to comment.