Skip to content

Commit 20d578b

Browse files
committed
add store to store adapter
1 parent 8ddde04 commit 20d578b

2 files changed

Lines changed: 14 additions & 29 deletions

File tree

block/internal/submitting/submitter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ func (s *Submitter) processDAInclusionLoop() {
379379
s.logger.Error().Err(err).Msg("failed to get store height for pruning")
380380
continue
381381
}
382-
if storeHeight <= lastPruned+uint64(s.config.Node.PruningInterval) {
382+
if storeHeight <= lastPruned+s.config.Node.PruningInterval {
383383
continue
384384
}
385385

pkg/store/store_adapter.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,6 @@ type EntityWithDAHint[H any] interface {
4747
DAHint() uint64
4848
}
4949

50-
// lastPrunedHeightGetter is an optional interface that store getters can
51-
// implement to expose the last pruned block height.
52-
type lastPrunedHeightGetter interface {
53-
LastPrunedHeight(ctx context.Context) (uint64, bool)
54-
}
55-
5650
// heightSub provides a mechanism for waiting on a specific height to be stored.
5751
// This is critical for go-header syncer which expects GetByHeight to block until
5852
// the requested height is available.
@@ -134,6 +128,7 @@ func (hs *heightSub) notifyUpTo(h uint64) {
134128
// a block, it writes to the underlying store, and subsequent reads will come from the store.
135129
type StoreAdapter[H EntityWithDAHint[H]] struct {
136130
getter StoreGetter[H]
131+
store Store
137132
genesisInitialHeight uint64
138133

139134
// heightSub tracks the current height and allows waiting for specific heights.
@@ -275,10 +270,12 @@ func (a *StoreAdapter[H]) Tail(ctx context.Context) (H, error) {
275270
// genesis initial height, but if pruning metadata is available we can
276271
// skip directly past fully-pruned ranges.
277272
startHeight := a.genesisInitialHeight
278-
if getter, ok := a.getter.(lastPrunedHeightGetter); ok {
279-
if lastPruned, ok := getter.LastPrunedHeight(ctx); ok {
280-
if lastPruned < ^uint64(0) {
281-
startHeight = lastPruned + 1
273+
if a.store != nil {
274+
if meta, err := a.store.GetMetadata(ctx, LastPrunedBlockHeightKey); err == nil && len(meta) == heightLength {
275+
if lastPruned, err := decodeHeight(meta); err == nil {
276+
if candidate := lastPruned + 1; candidate > startHeight {
277+
startHeight = candidate
278+
}
282279
}
283280
}
284281
}
@@ -728,34 +725,22 @@ func (g *DataStoreGetter) HasAt(ctx context.Context, height uint64) bool {
728725
return err == nil
729726
}
730727

731-
// LastPrunedHeight implements lastPrunedHeightGetter for DataStoreGetter by
732-
// reading the pruning metadata from the underlying store.
733-
func (g *DataStoreGetter) LastPrunedHeight(ctx context.Context) (uint64, bool) {
734-
meta, err := g.store.GetMetadata(ctx, LastPrunedBlockHeightKey)
735-
if err != nil || len(meta) != heightLength {
736-
return 0, false
737-
}
738-
739-
height, err := decodeHeight(meta)
740-
if err != nil {
741-
return 0, false
742-
}
743-
744-
return height, true
745-
}
746-
747728
// Type aliases for convenience
748729
type HeaderStoreAdapter = StoreAdapter[*types.P2PSignedHeader]
749730
type DataStoreAdapter = StoreAdapter[*types.P2PData]
750731

751732
// NewHeaderStoreAdapter creates a new StoreAdapter for headers.
752733
// The genesis is used to determine the initial height for efficient Tail lookups.
753734
func NewHeaderStoreAdapter(store Store, gen genesis.Genesis) *HeaderStoreAdapter {
754-
return NewStoreAdapter(NewHeaderStoreGetter(store), gen)
735+
adapter := NewStoreAdapter(NewHeaderStoreGetter(store), gen)
736+
adapter.store = store
737+
return adapter
755738
}
756739

757740
// NewDataStoreAdapter creates a new StoreAdapter for data.
758741
// The genesis is used to determine the initial height for efficient Tail lookups.
759742
func NewDataStoreAdapter(store Store, gen genesis.Genesis) *DataStoreAdapter {
760-
return NewStoreAdapter(NewDataStoreGetter(store), gen)
743+
adapter := NewStoreAdapter(NewDataStoreGetter(store), gen)
744+
adapter.store = store
745+
return adapter
761746
}

0 commit comments

Comments
 (0)