From 1375bd399623274e29923cc797f6a5656469dc09 Mon Sep 17 00:00:00 2001 From: Oleg Kovalov Date: Mon, 27 Jan 2025 16:14:21 +0100 Subject: [PATCH] even better names --- store/heightsub.go | 18 +++++++++--------- store/store.go | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/store/heightsub.go b/store/heightsub.go index 148cb32d..7ca90194 100644 --- a/store/heightsub.go +++ b/store/heightsub.go @@ -34,7 +34,7 @@ func newHeightSub[H header.Header[H]]() *heightSub[H] { } // Init the heightSub with a given height. -// Unblocks all awaiting [Wait] calls lower than height. +// Notifies all awaiting [Wait] calls lower than height. func (hs *heightSub[H]) Init(height uint64) { hs.height.Store(height) @@ -43,7 +43,7 @@ func (hs *heightSub[H]) Init(height uint64) { for h := range hs.heightSubs { if h < height { - hs.unblockHeight(h, true) + hs.notifyHeight(h, true) } } } @@ -54,7 +54,7 @@ func (hs *heightSub[H]) Height() uint64 { } // SetHeight sets the new head height for heightSub. -// Unblocks all awaiting [Wait] calls in range from [heightSub.Height] to height. +// Notifies all awaiting [Wait] calls in range from [heightSub.Height] to height. func (hs *heightSub[H]) SetHeight(height uint64) { for { curr := hs.height.Load() @@ -69,7 +69,7 @@ func (hs *heightSub[H]) SetHeight(height uint64) { defer hs.heightSubsLk.Unlock() //nolint:gocritic we have a return below for ; curr <= height; curr++ { - hs.unblockHeight(curr, true) + hs.notifyHeight(curr, true) } return } @@ -108,22 +108,22 @@ func (hs *heightSub[H]) Wait(ctx context.Context, height uint64) error { case <-ctx.Done(): // no need to keep the request, if the op has canceled hs.heightSubsLk.Lock() - hs.unblockHeight(height, false) + hs.notifyHeight(height, false) hs.heightSubsLk.Unlock() return ctx.Err() } } -// UnblockHeight and release the waiters in [Wait]. +// NotifyHeight and release the waiters in [Wait]. // Note: do not advance heightSub's height. -func (hs *heightSub[H]) UnblockHeight(height uint64) { +func (hs *heightSub[H]) NotifyHeight(height uint64) { hs.heightSubsLk.Lock() defer hs.heightSubsLk.Unlock() - hs.unblockHeight(height, true) + hs.notifyHeight(height, true) } -func (hs *heightSub[H]) unblockHeight(height uint64, all bool) { +func (hs *heightSub[H]) notifyHeight(height uint64, all bool) { sac, ok := hs.heightSubs[height] if !ok { return diff --git a/store/store.go b/store/store.go index c36a835c..93a34ee3 100644 --- a/store/store.go +++ b/store/store.go @@ -379,7 +379,7 @@ func (s *Store[H]) flushLoop() { s.pending.Append(headers...) // notify waiters in heightSub and advance contiguousHead // if we don't have gaps. - s.unblockAndAdvance(ctx, headers...) + s.notifyAndAdvance(ctx, headers...) // don't flush and continue if pending batch is not grown enough, // and Store is not stopping(headers == nil) if s.pending.Len() < s.Params.WriteBatchSize && headers != nil { @@ -506,12 +506,12 @@ func (s *Store[H]) get(ctx context.Context, hash header.Hash) ([]byte, error) { return data, nil } -// unblockAndAdvance will notify waiters in heightSub and advance contiguousHead +// notifyAndAdvance will notify waiters in heightSub and advance contiguousHead // based on already written headers. -func (s *Store[H]) unblockAndAdvance(ctx context.Context, headers ...H) { +func (s *Store[H]) notifyAndAdvance(ctx context.Context, headers ...H) { // always inform heightSub about new headers seen for _, h := range headers { - s.heightSub.UnblockHeight(h.Height()) + s.heightSub.NotifyHeight(h.Height()) } currHead := s.contiguousHead.Load()