Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Jul 31, 2024
1 parent 1d53e1a commit da710eb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ func (s *Store[H]) HasAt(_ context.Context, height uint64) bool {

// Append the given headers to the store. Real write to the disk happens
// asynchronously and might fail without reporting error (just logging).
// TODO(cristaloleg): add retries to the flush worker.
func (s *Store[H]) Append(ctx context.Context, headers ...H) error {
lh := len(headers)
if lh == 0 {
Expand Down Expand Up @@ -521,28 +520,29 @@ func (s *Store[H]) tryAdvanceHead(headers ...H) {
s.knownHeaders[h.Height()] = h
}

head := *headPtr
height := head.Height()
currHead := head
currHead := *headPtr
height := currHead.Height()
newHead := currHead

// try to move to the next height.
for len(s.knownHeaders) > 0 {
h, ok := s.knownHeaders[height+1]
if !ok {
break
}
head = h
newHead = h
delete(s.knownHeaders, height+1)
height++
}

// we found higher continuous header, so update.
if currHead.Height() < head.Height() {
// we found higher continuous header - update.
if currHead.Height() < newHead.Height() {
// we don't need CAS here because that's the only place
// where writeHead is updated, knownHeadersLk ensures 1 goroutine.
s.writeHead.Store(&head)
log.Infow("new head", "height", head.Height(), "hash", head.Hash())
s.metrics.newHead(head.Height())
// NOTE: Store[H].Head also updates writeHead but only once when it's nil.
s.writeHead.Store(&newHead)
log.Infow("new head", "height", newHead.Height(), "hash", newHead.Hash())
s.metrics.newHead(newHead.Height())
}
}

Expand Down

0 comments on commit da710eb

Please sign in to comment.