Skip to content
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

Merged
merged 7 commits into from
Sep 4, 2024
Merged

chore(*): use proper retry #29

merged 7 commits into from
Sep 4, 2024

Conversation

Lazar955
Copy link
Member

@Lazar955 Lazar955 commented Sep 2, 2024

Replaces usage of retry.do from babylon with avast/retry-go

References issue

monitor/query.go Outdated Show resolved Hide resolved
@Lazar955 Lazar955 changed the base branch from dev to main September 3, 2024 07:20
@Lazar955 Lazar955 marked this pull request as ready for review September 3, 2024 09:14
Copy link
Collaborator

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note, babylon retry library have hardcoded errors which should/should not be retries:

var unrecoverableErrors = []error{
	btclctypes.ErrHeaderParentDoesNotExist,
	btclctypes.ErrChainWithNotEnoughWork,
	btclctypes.ErrInvalidHeader,
	btcctypes.ErrProvidedHeaderDoesNotHaveAncestor,
	btcctypes.ErrInvalidHeader,
	btcctypes.ErrNoCheckpointsForPreviousEpoch,
	btcctypes.ErrInvalidCheckpointProof,
	checkpointingtypes.ErrBlsPrivKeyDoesNotExist,
	// TODO Add more errors here
}

// expectedErrors is a list of errors which can safely be ignored and should not be retried.
var expectedErrors = []error{
	btcctypes.ErrDuplicatedSubmission,
	btcctypes.ErrInvalidHeader,
	// TODO Add more errors here
}

could you double check that this errors are relevant in this context ?

}); err != nil {
},
retry.Delay(m.ComCfg.RetrySleepTime),
retry.MaxDelay(m.ComCfg.MaxRetrySleepTime),
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

opts = append(opts, opt)

err := retry.Do(retryableFunc, opts...)
if containsErr(expectedErrors, err) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we check the expected errors twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RafilxTenfen when retryif returns false, that means that Do is returning an error, we want to check if this error is expected and ignore it (return nil), as we don't want to keep retrying on expected errors or unrecoverable but in that case we do return an error. This is matching behavior of retry implementation in Babylon repo

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it, thanks for explaining

Copy link
Contributor

@RafilxTenfen RafilxTenfen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

Copy link
Collaborator

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, few minor comments.

One note for the future, for now it is fine to have this global list of errors, to not change behaviour, but ultimately this errors (unrecorevable/expected) should be set at call site by each caller. Then we know what call can return, what error and each caller knows what to do with each error. Maybe you could create task to get rid of those global error lists ?

blockHash, err = c.GetBestBlockHash()
if err != nil {
return err
}
return nil
}); err != nil {
},
retry.Delay(c.retrySleepTime),
Copy link
Collaborator

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 ?

Copy link
Member Author

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

btccParamsRes, err = babylonClient.BTCCheckpointParams()
return err
})
},
retry.Delay(retrySleepTime),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say that, given max-attempts is in common potion of the config it should probably set in every program, otherwise we risk seeing some wierd behaviour only to learn some toold respect this config option and some does not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed added it in f7c96e3

@Lazar955 Lazar955 mentioned this pull request Sep 4, 2024
@Lazar955 Lazar955 merged commit 3b8378d into main Sep 4, 2024
8 checks passed
@Lazar955 Lazar955 deleted the lazar/fix-retry-usage branch September 4, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants