From e917cab4f23da3f10213e42c222276eb4cedf299 Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Fri, 28 Jun 2024 15:45:26 +0300 Subject: [PATCH 1/2] doc:improve header.Verify godoc (#208) --- header.go | 1 + 1 file changed, 1 insertion(+) diff --git a/header.go b/header.go index 02e391e4..010ab2ca 100644 --- a/header.go +++ b/header.go @@ -27,6 +27,7 @@ type Header[H any] interface { // Time returns time when header was created. Time() time.Time // Verify validates given untrusted Header against trusted Header. + // Verify should be able to validate both adjacent and non-adjacent headers. Verify(H) error // Validate performs stateless validation to check for missed/incorrect fields. Validate() error From 8f539799611e85b73a7f2a6dc3e6e1e3eb97472d Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Fri, 26 Jul 2024 17:25:19 +0200 Subject: [PATCH 2/2] feat(store): flush loop retries and backoff (#211) ## Overview Before this PR when we fail to write a batch we just ignore it. Adding retries + backoff to try a few times. Fixes #209 --- store/store.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/store/store.go b/store/store.go index 657a22c7..6ea126ff 100644 --- a/store/store.go +++ b/store/store.go @@ -397,14 +397,22 @@ func (s *Store[H]) flushLoop() { startTime := time.Now() toFlush := s.pending.GetAll() - err := s.flush(ctx, toFlush...) - if err != nil { + + for i := 0; ; i++ { + err := s.flush(ctx, toFlush...) + if err == nil { + break + } + from, to := toFlush[0].Height(), toFlush[len(toFlush)-1].Height() - // TODO(@Wondertan): Should this be a fatal error case with os.Exit? - log.Errorw("writing header batch", "from", from, "to", to, "err", err) + log.Errorw("writing header batch", "try", i+1, "from", from, "to", to, "err", err) s.metrics.flush(ctx, time.Since(startTime), s.pending.Len(), true) - continue + + const maxRetrySleep = time.Second + sleep := min(10*time.Duration(i+1)*time.Millisecond, maxRetrySleep) + time.Sleep(sleep) } + s.metrics.flush(ctx, time.Since(startTime), s.pending.Len(), false) // reset pending s.pending.Reset()