Skip to content

Commit

Permalink
even better names
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jan 27, 2025
1 parent 8194f52 commit 1375bd3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions store/heightsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}
}
Expand All @@ -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()
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 1375bd3

Please sign in to comment.