Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cristaloleg committed Oct 7, 2024
1 parent 61a6b31 commit 964e86f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ func (s *Store[H]) tryAdvanceHead(ctx context.Context, headers ...H) {
if headers[i].Height() != currHeight+1 {
break
}
s.writeHead.Store(&headers[i])
newHead := headers[i]
s.writeHead.Store(&newHead)
currHeight++
}

Expand All @@ -528,10 +529,11 @@ func (s *Store[H]) tryAdvanceHead(ctx context.Context, headers ...H) {

// advance based on already written headers.
for {
newHead, err := s.GetByHeight(ctx, currHeight+1)
h, err := s.GetByHeight(ctx, currHeight+1)
if err != nil {
break
}
newHead := h
s.writeHead.Store(&newHead)
currHeight++
}
Expand Down
5 changes: 4 additions & 1 deletion store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ func TestStore_Append(t *testing.T) {
}

// wait for batch to be written.
time.Sleep(100 * time.Millisecond)
time.Sleep(2 * time.Second)

head, err = store.Head(ctx)
assert.NoError(t, err)
assert.Equal(t, head.Height(), headers[len(headers)-1].Height())
assert.Equal(t, head.Hash(), headers[len(headers)-1].Hash())
}

Expand Down Expand Up @@ -222,6 +223,7 @@ func TestStore_Append_stableHeadWhenGaps(t *testing.T) {
// head is advanced to the last known header.
head, err := store.Head(ctx)
require.NoError(t, err)
assert.Equal(t, head.Height(), wantHead.Height())
assert.Equal(t, head.Hash(), wantHead.Hash())

// check that store height is aligned with the head.
Expand Down Expand Up @@ -253,6 +255,7 @@ func TestStore_Append_stableHeadWhenGaps(t *testing.T) {
// after appending missing headers we're on the latest header.
head, err := store.Head(ctx)
require.NoError(t, err)
assert.Equal(t, head.Height(), latestHead.Height())
assert.Equal(t, head.Hash(), latestHead.Hash())

// check that store height is aligned with the head.
Expand Down

0 comments on commit 964e86f

Please sign in to comment.