Skip to content

Commit

Permalink
add useful comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gusin13 committed Oct 1, 2022
1 parent 00845d4 commit 04e571e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion btcclient/client_block_subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func (c *Client) mustSubscribeBlocksByWebSocket() {
panic(err)
}

err = types.Retry(initialInterval, maxInterval, func() error { // TODO: make retry parameters universal and accessible here
err = types.Retry(initialInterval, maxInterval, func() error {
return c.subscribeBlocksByWebSocket()
})

Expand Down
4 changes: 2 additions & 2 deletions reporter/btc_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (r *Reporter) submitHeader(signer sdk.AccAddress, header *wire.BlockHeader)
return err
}

//TODO implement retry mechanism in mustSubmitHeader and keep submitHeader as it is
err = types.Retry(initialInterval, maxInterval, func() error {
//TODO implement retry mechanism in mustSubmitHeader and keep submitHeader as it is
msgInsertHeader := types.NewMsgInsertHeader(r.babylonClient.Cfg.AccountPrefix, signer, header)
res, err = r.babylonClient.InsertHeader(msgInsertHeader)
if err != nil {
Expand Down Expand Up @@ -222,8 +222,8 @@ func (r *Reporter) matchAndSubmitCkpts(signer sdk.AccAddress) error {
continue
}

//TODO implement retry mechanism in mustInsertBTCSpvProof and keep InsertBTCSpvProof as it is
err = types.Retry(initialInterval, maxInterval, func() error {
//TODO implement retry mechanism in mustInsertBTCSpvProof and keep InsertBTCSpvProof as it is
res, err = r.babylonClient.InsertBTCSpvProof(msgInsertBTCSpvProof)
return err
})
Expand Down
7 changes: 3 additions & 4 deletions types/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ func GetWrappedTxs(msg *wire.MsgBlock) []*btcutil.Tx {
}

// Retry retries the retryableFunc. In each iteration it will exponentially increase the sleep
// time and will stop retrying once maxSleepTime is reached. isUnrecoverableErr identifies
// if an error is unsafe. It will stop retry execution and return error to caller.
// isExpectedErr is used to identify if an error can be safely ignored, retry will
// stop execution but will return nil to caller.
// time and will stop retrying once maxSleepTime is reached.
// - isUnrecoverableErr identifies if an error is unsafe. It will stop retry execution and return error to caller.
// - isExpectedErr is used to identify if an error can be safely ignored, retry will stop execution but will return nil to caller.
func Retry(sleep time.Duration, maxSleepTime time.Duration, retryableFunc func() error) error {
if err := retryableFunc(); err != nil {
if isUnrecoverableErr(err) {
Expand Down

0 comments on commit 04e571e

Please sign in to comment.