-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(*): use proper retry #29
Changes from 2 commits
939ce13
27175b5
ef39512
2a6c985
ba3699e
f7c96e3
402f310
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ package monitor | |
import ( | ||
"fmt" | ||
|
||
"github.com/babylonlabs-io/babylon/types/retry" | ||
"github.com/avast/retry-go/v4" | ||
btclctypes "github.com/babylonlabs-io/babylon/x/btclightclient/types" | ||
ckpttypes "github.com/babylonlabs-io/babylon/x/checkpointing/types" | ||
epochingtypes "github.com/babylonlabs-io/babylon/x/epoching/types" | ||
|
@@ -61,15 +61,18 @@ func (m *Monitor) FindTipConfirmedEpoch() (uint64, error) { | |
func (m *Monitor) queryCurrentEpochWithRetry() (*epochingtypes.QueryCurrentEpochResponse, error) { | ||
var currentEpochRes epochingtypes.QueryCurrentEpochResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.CurrentEpoch() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
currentEpochRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the current epoch", zap.Error(err)) | ||
|
||
|
@@ -82,15 +85,18 @@ func (m *Monitor) queryCurrentEpochWithRetry() (*epochingtypes.QueryCurrentEpoch | |
func (m *Monitor) queryRawCheckpointWithRetry(epoch uint64) (*ckpttypes.QueryRawCheckpointResponse, error) { | ||
var rawCheckpointRes ckpttypes.QueryRawCheckpointResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.RawCheckpoint(epoch) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rawCheckpointRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the raw checkpoint", zap.Error(err)) | ||
|
||
|
@@ -103,15 +109,18 @@ func (m *Monitor) queryRawCheckpointWithRetry(epoch uint64) (*ckpttypes.QueryRaw | |
func (m *Monitor) queryBlsPublicKeyListWithRetry(epoch uint64) (*ckpttypes.QueryBlsPublicKeyListResponse, error) { | ||
var blsPublicKeyListRes ckpttypes.QueryBlsPublicKeyListResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.BlsPublicKeyList(epoch, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
blsPublicKeyListRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the BLS public key list", zap.Error(err)) | ||
|
||
|
@@ -124,15 +133,18 @@ func (m *Monitor) queryBlsPublicKeyListWithRetry(epoch uint64) (*ckpttypes.Query | |
func (m *Monitor) queryEndedEpochBTCHeightWithRetry(epoch uint64) (*monitortypes.QueryEndedEpochBtcHeightResponse, error) { | ||
var endedEpochBTCHeightRes monitortypes.QueryEndedEpochBtcHeightResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.EndedEpochBTCHeight(epoch) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
endedEpochBTCHeightRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the ended epoch BTC height", zap.Error(err)) | ||
|
||
|
@@ -145,15 +157,25 @@ func (m *Monitor) queryEndedEpochBTCHeightWithRetry(epoch uint64) (*monitortypes | |
func (m *Monitor) queryReportedCheckpointBTCHeightWithRetry(hashStr string) (*monitortypes.QueryReportedCheckpointBtcHeightResponse, error) { | ||
var reportedCheckpointBtcHeightRes monitortypes.QueryReportedCheckpointBtcHeightResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
retryOptions := []retry.Option{ | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
} | ||
|
||
if m.ComCfg.TestMode { | ||
retryOptions = append(retryOptions, retry.Attempts(1)) | ||
Lazar955 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.ReportedCheckpointBTCHeight(hashStr) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
reportedCheckpointBtcHeightRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retryOptions...); err != nil { | ||
m.logger.Debug( | ||
"failed to query the reported checkpoint BTC height", zap.Error(err)) | ||
|
||
|
@@ -166,15 +188,18 @@ func (m *Monitor) queryReportedCheckpointBTCHeightWithRetry(hashStr string) (*mo | |
func (m *Monitor) queryBTCHeaderChainTipWithRetry() (*btclctypes.QueryTipResponse, error) { | ||
var btcHeaderChainTipRes btclctypes.QueryTipResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.BTCHeaderChainTip() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
btcHeaderChainTipRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say we need to pass attempts config to every method, it would pretty wierd that some methods do not respect config value. |
||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the BTC header chain tip", zap.Error(err)) | ||
|
||
|
@@ -187,15 +212,18 @@ func (m *Monitor) queryBTCHeaderChainTipWithRetry() (*btclctypes.QueryTipRespons | |
func (m *Monitor) queryContainsBTCBlockWithRetry(blockHash *chainhash.Hash) (*btclctypes.QueryContainsBytesResponse, error) { | ||
var containsBTCBlockRes btclctypes.QueryContainsBytesResponse | ||
|
||
if err := retry.Do(m.ComCfg.RetrySleepTime, m.ComCfg.MaxRetrySleepTime, func() error { | ||
if err := retry.Do(func() error { | ||
res, err := m.BBNQuerier.ContainsBTCBlock(blockHash) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
containsBTCBlockRes = *res | ||
return nil | ||
}); err != nil { | ||
}, | ||
retry.Delay(m.ComCfg.RetrySleepTime), | ||
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime), | ||
); err != nil { | ||
m.logger.Debug( | ||
"failed to query the contains BTC block", zap.Error(err)) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,8 @@ import ( | |
"sync" | ||
"time" | ||
|
||
"github.com/avast/retry-go/v4" | ||
"github.com/babylonlabs-io/babylon/btctxformatter" | ||
"github.com/babylonlabs-io/babylon/types/retry" | ||
btcctypes "github.com/babylonlabs-io/babylon/x/btccheckpoint/types" | ||
"github.com/babylonlabs-io/vigilante/btcclient" | ||
"github.com/babylonlabs-io/vigilante/config" | ||
|
@@ -57,10 +57,13 @@ func New( | |
btccParamsRes *btcctypes.QueryParamsResponse | ||
err error | ||
) | ||
err = retry.Do(retrySleepTime, maxRetrySleepTime, func() error { | ||
err = retry.Do(func() error { | ||
btccParamsRes, err = babylonClient.BTCCheckpointParams() | ||
return err | ||
}) | ||
}, | ||
retry.Delay(retrySleepTime), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would say that, given There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed added it in f7c96e3 |
||
retry.MaxDelay(maxRetrySleepTime), | ||
) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get BTC Checkpoint parameters: %w", err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those those options ever set in
btclient
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed in f7c96e3