Skip to content

Commit

Permalink
chore: stop to sync once the FP is started
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Sep 17, 2024
1 parent 94b8ff6 commit d3216f1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions finality-provider/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,16 +240,16 @@ func (app *FinalityProviderApp) getFpPrivKey(fpPk []byte) (*btcec.PrivateKey, er
return record.PrivKey, nil
}

// SyncFinalityProviderStatus syncs the status of the finality-providers
func (app *FinalityProviderApp) SyncFinalityProviderStatus() error {
// SyncFinalityProviderStatus syncs the status of the finality-providers with the chain.
func (app *FinalityProviderApp) SyncFinalityProviderStatus() (fpInstanceStarted bool, err error) {
latestBlock, err := app.cc.QueryBestBlock()
if err != nil {
return err
return false, err
}

fps, err := app.fps.GetAllStoredFinalityProviders()
if err != nil {
return err
return false, err
}

for _, fp := range fps {
Expand Down Expand Up @@ -277,7 +277,7 @@ func (app *FinalityProviderApp) SyncFinalityProviderStatus() error {
oldStatus := fp.Status
newStatus, err := app.fps.UpdateFpStatusFromVotingPower(vp, fp)
if err != nil {
return err
return false, err
}

app.logger.Info(
Expand All @@ -293,11 +293,12 @@ func (app *FinalityProviderApp) SyncFinalityProviderStatus() error {
}

if err := app.fpManager.StartFinalityProvider(bip340PubKey, ""); err != nil {
return err
return false, err
}
fpInstanceStarted = true
}

return nil
return fpInstanceStarted, nil
}

// Start starts only the finality-provider daemon without any finality-provider instances
Expand Down Expand Up @@ -691,9 +692,13 @@ func (app *FinalityProviderApp) syncChainFpStatusLoop() {
for {
select {
case <-syncFpStatusTicker.C:
if err := app.SyncFinalityProviderStatus(); err != nil {
fpInstanceStarted, err := app.SyncFinalityProviderStatus()
if err != nil {
app.Logger().Error("failed to sync finality-provider status", zap.Error(err))
}
if fpInstanceStarted {
return
}

case <-app.quit:
syncFpStatusTicker.Stop()
Expand Down

0 comments on commit d3216f1

Please sign in to comment.