mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
eth/borfinality: handle errors to prevent access logging (#8372)
This PR adds a few checks on top of https://github.com/ledgerwatch/erigon/pull/8364 to prevent access logging. Moreover, fixes a bug which sent wrong error to parent function.
This commit is contained in:
parent
47690db676
commit
b107a97e49
@ -94,7 +94,7 @@ func startNoAckMilestoneByIDService(config *config) {
|
||||
RetryHeimdallHandler(handleNoAckMilestoneByID, config, tickerDuration, noAckMilestoneTimeout, fnName)
|
||||
}
|
||||
|
||||
type heimdallHandler func(ctx context.Context, heimdall heimdall.IHeimdallClient, config *config) error
|
||||
type heimdallHandler func(ctx context.Context, heimdallClient heimdall.IHeimdallClient, config *config) error
|
||||
|
||||
func RetryHeimdallHandler(fn heimdallHandler, config *config, tickerDuration time.Duration, timeout time.Duration, fnName string) {
|
||||
retryHeimdallHandler(fn, config, tickerDuration, timeout, fnName)
|
||||
@ -144,12 +144,12 @@ func retryHeimdallHandler(fn heimdallHandler, config *config, tickerDuration tim
|
||||
}
|
||||
|
||||
// handleWhitelistCheckpoint handles the checkpoint whitelist mechanism.
|
||||
func handleWhitelistCheckpoint(ctx context.Context, heimdall heimdall.IHeimdallClient, config *config) error {
|
||||
func handleWhitelistCheckpoint(ctx context.Context, heimdallClient heimdall.IHeimdallClient, config *config) error {
|
||||
service := whitelist.GetWhitelistingService()
|
||||
|
||||
// Create a new bor verifier, which will be used to verify checkpoints and milestones
|
||||
verifier := newBorVerifier()
|
||||
blockNum, blockHash, err := fetchWhitelistCheckpoint(ctx, heimdall, verifier, config)
|
||||
blockNum, blockHash, err := fetchWhitelistCheckpoint(ctx, heimdallClient, verifier, config)
|
||||
|
||||
// If the array is empty, we're bound to receive an error. Non-nill error and non-empty array
|
||||
// means that array has partial elements and it failed for some block. We'll add those partial
|
||||
@ -164,12 +164,12 @@ func handleWhitelistCheckpoint(ctx context.Context, heimdall heimdall.IHeimdallC
|
||||
}
|
||||
|
||||
// handleMilestone handles the milestone mechanism.
|
||||
func handleMilestone(ctx context.Context, heimdall heimdall.IHeimdallClient, config *config) error {
|
||||
func handleMilestone(ctx context.Context, heimdallClient heimdall.IHeimdallClient, config *config) error {
|
||||
service := whitelist.GetWhitelistingService()
|
||||
|
||||
// Create a new bor verifier, which will be used to verify checkpoints and milestones
|
||||
verifier := newBorVerifier()
|
||||
num, hash, err := fetchWhitelistMilestone(ctx, heimdall, verifier, config)
|
||||
num, hash, err := fetchWhitelistMilestone(ctx, heimdallClient, verifier, config)
|
||||
|
||||
// If the current chain head is behind the received milestone, add it to the future milestone
|
||||
// list. Also, the hash mismatch (end block hash) error will lead to rewind so also
|
||||
@ -178,6 +178,10 @@ func handleMilestone(ctx context.Context, heimdall heimdall.IHeimdallClient, con
|
||||
service.ProcessFutureMilestone(num, hash)
|
||||
}
|
||||
|
||||
if errors.Is(err, heimdall.ErrServiceUnavailable) {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -187,11 +191,14 @@ func handleMilestone(ctx context.Context, heimdall heimdall.IHeimdallClient, con
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNoAckMilestone(ctx context.Context, heimdall heimdall.IHeimdallClient, config *config) error {
|
||||
func handleNoAckMilestone(ctx context.Context, heimdallClient heimdall.IHeimdallClient, config *config) error {
|
||||
service := whitelist.GetWhitelistingService()
|
||||
milestoneID, err := fetchNoAckMilestone(ctx, heimdall, config.logger)
|
||||
milestoneID, err := fetchNoAckMilestone(ctx, heimdallClient, config.logger)
|
||||
|
||||
if errors.Is(err, heimdall.ErrServiceUnavailable) {
|
||||
return nil
|
||||
}
|
||||
|
||||
//If failed to fetch the no-ack milestone then it give the error.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -201,12 +208,12 @@ func handleNoAckMilestone(ctx context.Context, heimdall heimdall.IHeimdallClient
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleNoAckMilestoneByID(ctx context.Context, heimdall heimdall.IHeimdallClient, config *config) error {
|
||||
func handleNoAckMilestoneByID(ctx context.Context, heimdallClient heimdall.IHeimdallClient, config *config) error {
|
||||
service := whitelist.GetWhitelistingService()
|
||||
milestoneIDs := service.GetMilestoneIDsList()
|
||||
|
||||
for _, milestoneID := range milestoneIDs {
|
||||
err := fetchNoAckMilestoneByID(ctx, heimdall, milestoneID, config.logger)
|
||||
err := fetchNoAckMilestoneByID(ctx, heimdallClient, milestoneID, config.logger)
|
||||
if err == nil {
|
||||
service.RemoveMilestoneID(milestoneID)
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ func fetchWhitelistMilestone(ctx context.Context, heimdallClient heimdall.IHeimd
|
||||
milestone, err := heimdallClient.FetchMilestone(ctx)
|
||||
if errors.Is(err, heimdall.ErrServiceUnavailable) {
|
||||
config.logger.Debug("Failed to fetch latest milestone for whitelisting", "err", err)
|
||||
return num, hash, errMilestone
|
||||
return num, hash, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@ -99,7 +99,7 @@ func fetchNoAckMilestone(ctx context.Context, heimdallClient heimdall.IHeimdallC
|
||||
milestoneID, err := heimdallClient.FetchLastNoAckMilestone(ctx)
|
||||
if errors.Is(err, heimdall.ErrServiceUnavailable) {
|
||||
logger.Debug("Failed to fetch latest no-ack milestone", "err", err)
|
||||
return milestoneID, errMilestone
|
||||
return milestoneID, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user