Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(pruner): remove SpacedHeaderGenerator #4032

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 NewTestSuiteWithGenesisTime(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.NewTestSuiteWithGenesisTime(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
}
Loading