Skip to content

Commit

Permalink
chore(pruner): remove SpacedHeaderGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
ronething-bot committed Jan 6, 2025
1 parent 4d3d3c2 commit c5b6089
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
19 changes: 16 additions & 3 deletions header/headertest/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"

"github.com/celestiaorg/celestia-app/v3/pkg/da"
libhead "github.com/celestiaorg/go-header"
Expand All @@ -40,6 +39,7 @@ type TestSuite struct {
// blockTime is optional - if set, the test suite will generate
// blocks timestamped at the specified interval
blockTime time.Duration
startTime time.Time
}

func NewStore(t *testing.T) libhead.Store[*header.ExtendedHeader] {
Expand All @@ -62,6 +62,18 @@ func NewTestSuite(t *testing.T, numValidators int, blockTime time.Duration) *Tes
vals: vals,
valSet: valSet,
blockTime: blockTime,
startTime: time.Now(),
}
}

func NewTestSuiteWithStartTime(t *testing.T, startTime time.Time, blockTime time.Duration) *TestSuite {
valSet, vals := RandValidatorSet(3, 1)
return &TestSuite{
t: t,
vals: vals,
valSet: valSet,
blockTime: blockTime,
startTime: startTime,
}
}

Expand All @@ -74,10 +86,11 @@ func (s *TestSuite) genesis() *header.ExtendedHeader {
gen.ValidatorsHash = s.valSet.Hash()
gen.NextValidatorsHash = s.valSet.Hash()
gen.Height = 1
gen.Time = s.startTime
voteSet := types.NewVoteSet(gen.ChainID, gen.Height, 0, tmproto.PrecommitType, s.valSet)
blockID := RandBlockID(s.t)
blockID.Hash = gen.Hash()
commit, err := MakeCommit(blockID, gen.Height, 0, voteSet, s.vals, time.Now())
commit, err := MakeCommit(blockID, gen.Height, 0, voteSet, s.vals, s.startTime)
require.NoError(s.t, err)

eh := &header.ExtendedHeader{
Expand Down Expand Up @@ -199,7 +212,7 @@ func (s *TestSuite) Commit(h *header.RawHeader) *types.Commit {
ValidatorIndex: int32(i),
Height: h.Height,
Round: round,
Timestamp: tmtime.Now().UTC(),
Timestamp: h.Time,
Type: tmproto.PrecommitType,
BlockID: bid,
}
Expand Down
33 changes: 2 additions & 31 deletions pruner/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ func TestFindPruneableHeaders(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)

headerGenerator := NewSpacedHeaderGenerator(t, tc.startTime, tc.blockTime)
store := headertest.NewCustomStore(t, headerGenerator, tc.headerAmount)
suite := headertest.NewTestSuiteWithStartTime(t, tc.startTime, tc.blockTime)
store := headertest.NewCustomStore(t, suite, tc.headerAmount)

mp := &mockPruner{}

Expand Down Expand Up @@ -317,32 +317,3 @@ func (mp *mockPruner) Prune(_ context.Context, h *header.ExtendedHeader) error {
mp.deletedHeaderHashes = append(mp.deletedHeaderHashes, pruned{hash: h.Hash().String(), height: h.Height()})
return nil
}

// TODO @renaynay @distractedm1nd: Deduplicate via headertest utility.
// https://github.com/celestiaorg/celestia-node/issues/3278.
type SpacedHeaderGenerator struct {
t *testing.T
TimeBetweenHeaders time.Duration
currentTime time.Time
currentHeight int64
}

func NewSpacedHeaderGenerator(
t *testing.T, startTime time.Time, timeBetweenHeaders time.Duration,
) *SpacedHeaderGenerator {
return &SpacedHeaderGenerator{
t: t,
TimeBetweenHeaders: timeBetweenHeaders,
currentTime: startTime,
currentHeight: 1,
}
}

func (shg *SpacedHeaderGenerator) NextHeader() *header.ExtendedHeader {
h := headertest.RandExtendedHeaderAtTimestamp(shg.t, shg.currentTime)
h.RawHeader.Height = shg.currentHeight
h.RawHeader.Time = shg.currentTime
shg.currentHeight++
shg.currentTime = shg.currentTime.Add(shg.TimeBetweenHeaders)
return h
}

0 comments on commit c5b6089

Please sign in to comment.