Skip to content

Commit 8de6a71

Browse files
committed
proof: fix re-try mechanism
The re-try mechanism introduced in a previous PR didn't work properly, because the re-try only happens if the callback returns an error. This fixes the behavior by returning a temporary error to trigger the re-try.
1 parent a7b40ad commit 8de6a71

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

proof/archive.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,8 @@ func (m *MultiArchiver) HasProof(ctx context.Context,
912912
// the other ones are in the process of importing it right now. So we
913913
// re-try a couple of times to see if the proof becomes available
914914
// eventually.
915-
return fn.RetryFuncN(
915+
errNeedRetry := errors.New("need to re-try")
916+
result, err := fn.RetryFuncN(
916917
ctx, fn.DefaultRetryConfig(), func() (bool, error) {
917918
allHaveProof = true
918919
for _, archive := range m.backends {
@@ -924,9 +925,23 @@ func (m *MultiArchiver) HasProof(ctx context.Context,
924925
allHaveProof = allHaveProof && ok
925926
}
926927

927-
return allHaveProof, nil
928+
if !allHaveProof {
929+
// If not all backends have the proof, we
930+
// return an error to indicate that we need
931+
// to retry. This error is only for RetryFuncN
932+
// and will never reach the caller.
933+
return false, errNeedRetry
934+
}
935+
936+
return true, nil
928937
},
929938
)
939+
if err != nil && !errors.Is(err, errNeedRetry) {
940+
return false, fmt.Errorf("error checking if proof exists: %w",
941+
err)
942+
}
943+
944+
return result, nil
930945
}
931946

932947
// FetchProofs fetches all proofs for assets uniquely identified by the passed

0 commit comments

Comments
 (0)