Skip to content

Commit be8cb57

Browse files
committed
feat(store): add tail header (#200)
## Overview Add `tailHeader` as a part of backward sync. Currently it's initialized to initial header and isn't exported. Harmless addition to simplify future PRs.
1 parent 816cf0e commit be8cb57

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

store/store.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type Store[H header.Header[H]] struct {
5151
writesDn chan struct{}
5252
// writeHead maintains the current write head
5353
writeHead atomic.Pointer[H]
54+
// tailHeader maintains the current tail header.
55+
tailHeader atomic.Pointer[H]
5456
// pending keeps headers pending to be written in one batch
5557
pending *batch[H]
5658

@@ -121,6 +123,8 @@ func (s *Store[H]) Init(ctx context.Context, initial H) error {
121123
return err
122124
}
123125

126+
s.tailHeader.Store(&initial)
127+
124128
log.Infow("initialized head", "height", initial.Height(), "hash", initial.Hash())
125129
s.heightSub.Pub(initial)
126130
return nil

store/store_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ func TestStore(t *testing.T) {
2222
ds := sync.MutexWrap(datastore.NewMapDatastore())
2323
store := NewTestStore(t, ctx, ds, suite.Head())
2424

25+
assert.Equal(t, *store.tailHeader.Load(), suite.Head())
26+
2527
head, err := store.Head(ctx)
2628
require.NoError(t, err)
2729
assert.EqualValues(t, suite.Head().Hash(), head.Hash())

0 commit comments

Comments
 (0)