From e2ec93350e7997f7bbd2245eb5dff8862bb433cb Mon Sep 17 00:00:00 2001 From: William Banfield Date: Thu, 20 Jan 2022 17:35:05 -0500 Subject: [PATCH] context position fixup --- internal/blocksync/reactor_test.go | 10 +++++----- internal/consensus/byzantine_test.go | 2 +- internal/consensus/common_test.go | 10 +++++----- internal/consensus/mempool_test.go | 10 +++++----- internal/consensus/pbts_test.go | 2 +- internal/consensus/reactor_test.go | 2 +- internal/consensus/types/height_vote_set_test.go | 2 +- internal/evidence/pool_test.go | 2 +- internal/evidence/verify_test.go | 10 +++++----- internal/state/rollback_test.go | 2 +- internal/statesync/block_queue_test.go | 2 +- internal/statesync/reactor_test.go | 8 ++++---- internal/test/factory/validator.go | 2 +- light/client_test.go | 4 ++-- light/store/db/db_test.go | 16 ++++++++-------- node/node_test.go | 2 +- 16 files changed, 43 insertions(+), 43 deletions(-) diff --git a/internal/blocksync/reactor_test.go b/internal/blocksync/reactor_test.go index c8cd359bc..25814a2ea 100644 --- a/internal/blocksync/reactor_test.go +++ b/internal/blocksync/reactor_test.go @@ -207,7 +207,7 @@ func TestReactor_AbruptDisconnect(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(cfg.RootDir) - valSet, privVals := factory.ValidatorSet(t, ctx, 1, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) maxBlockHeight := int64(64) @@ -247,7 +247,7 @@ func TestReactor_SyncTime(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(cfg.RootDir) - valSet, privVals := factory.ValidatorSet(t, ctx, 1, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) maxBlockHeight := int64(101) @@ -275,7 +275,7 @@ func TestReactor_NoBlockResponse(t *testing.T) { require.NoError(t, err) defer os.RemoveAll(cfg.RootDir) - valSet, privVals := factory.ValidatorSet(t, ctx, 1, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) maxBlockHeight := int64(65) @@ -328,7 +328,7 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) { defer os.RemoveAll(cfg.RootDir) maxBlockHeight := int64(48) - valSet, privVals := factory.ValidatorSet(t, ctx, 1, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, 1, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) rts := setup(ctx, t, genDoc, privVals[0], []int64{maxBlockHeight, 0, 0, 0, 0}, 1000) @@ -363,7 +363,7 @@ func TestReactor_BadBlockStopsPeer(t *testing.T) { // // XXX: This causes a potential race condition. // See: https://github.com/tendermint/tendermint/issues/6005 - valSet, otherPrivVals := factory.ValidatorSet(t, ctx, 1, 30) + valSet, otherPrivVals := factory.ValidatorSet(ctx, t, 1, 30) otherGenDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) newNode := rts.network.MakeNode(ctx, t, p2ptest.NodeOptions{ MaxPeers: uint16(len(rts.nodes) + 1), diff --git a/internal/consensus/byzantine_test.go b/internal/consensus/byzantine_test.go index 73ade8cec..8a0840d39 100644 --- a/internal/consensus/byzantine_test.go +++ b/internal/consensus/byzantine_test.go @@ -46,7 +46,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { tickerFunc := newMockTickerFunc(true) appFunc := newKVStore - valSet, privVals := factory.ValidatorSet(t, ctx, nValidators, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, 30) genDoc := factory.GenesisDoc(config, time.Now(), valSet.Validators, nil) states := make([]*State, nValidators) diff --git a/internal/consensus/common_test.go b/internal/consensus/common_test.go index 8a7967acf..4c1d0c4da 100644 --- a/internal/consensus/common_test.go +++ b/internal/consensus/common_test.go @@ -522,7 +522,7 @@ func loadPrivValidator(t *testing.T, cfg *config.Config) *privval.FilePV { func makeState(ctx context.Context, t *testing.T, cfg *config.Config, logger log.Logger, nValidators int) (*State, []*validatorStub) { t.Helper() // Get State - state, privVals := makeGenesisState(t, ctx, cfg, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, cfg, genesisStateArgs{ Validators: nValidators, }) @@ -734,7 +734,7 @@ func makeConsensusState( ) ([]*State, cleanupFunc) { t.Helper() - valSet, privVals := factory.ValidatorSet(t, ctx, nValidators, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) css := make([]*State, nValidators) logger := consensusLogger() @@ -795,7 +795,7 @@ func randConsensusNetWithPeers( ) ([]*State, *types.GenesisDoc, *config.Config, cleanupFunc) { t.Helper() - valSet, privVals := factory.ValidatorSet(t, ctx, nValidators, testMinPower) + valSet, privVals := factory.ValidatorSet(ctx, t, nValidators, testMinPower) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) css := make([]*State, nPeers) t.Helper() @@ -853,7 +853,7 @@ type genesisStateArgs struct { Time time.Time } -func makeGenesisState(t *testing.T, ctx context.Context, cfg *config.Config, args genesisStateArgs) (sm.State, []types.PrivValidator) { +func makeGenesisState(ctx context.Context, t *testing.T, cfg *config.Config, args genesisStateArgs) (sm.State, []types.PrivValidator) { t.Helper() if args.Power == 0 { args.Power = 1 @@ -861,7 +861,7 @@ func makeGenesisState(t *testing.T, ctx context.Context, cfg *config.Config, arg if args.Validators == 0 { args.Power = 4 } - valSet, privValidators := factory.ValidatorSet(t, ctx, args.Validators, args.Power) + valSet, privValidators := factory.ValidatorSet(ctx, t, args.Validators, args.Power) if args.Params == nil { args.Params = types.DefaultConsensusParams() } diff --git a/internal/consensus/mempool_test.go b/internal/consensus/mempool_test.go index a96b36466..0ae0d2d9c 100644 --- a/internal/consensus/mempool_test.go +++ b/internal/consensus/mempool_test.go @@ -40,7 +40,7 @@ func TestMempoolNoProgressUntilTxsAvailable(t *testing.T) { t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) }) config.Consensus.CreateEmptyBlocks = false - state, privVals := makeGenesisState(t, ctx, baseConfig, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{ Validators: 1, Power: 10}) cs := newStateWithConfig(ctx, t, log.TestingLogger(), config, state, privVals[0], NewCounterApplication()) @@ -67,7 +67,7 @@ func TestMempoolProgressAfterCreateEmptyBlocksInterval(t *testing.T) { t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) }) config.Consensus.CreateEmptyBlocksInterval = ensureTimeout - state, privVals := makeGenesisState(t, ctx, baseConfig, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{ Validators: 1, Power: 10}) cs := newStateWithConfig(ctx, t, log.TestingLogger(), config, state, privVals[0], NewCounterApplication()) @@ -92,7 +92,7 @@ func TestMempoolProgressInHigherRound(t *testing.T) { t.Cleanup(func() { _ = os.RemoveAll(config.RootDir) }) config.Consensus.CreateEmptyBlocks = false - state, privVals := makeGenesisState(t, ctx, baseConfig, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, baseConfig, genesisStateArgs{ Validators: 1, Power: 10}) cs := newStateWithConfig(ctx, t, log.TestingLogger(), config, state, privVals[0], NewCounterApplication()) @@ -143,7 +143,7 @@ func TestMempoolTxConcurrentWithCommit(t *testing.T) { config := configSetup(t) logger := log.TestingLogger() - state, privVals := makeGenesisState(t, ctx, config, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, config, genesisStateArgs{ Validators: 1, Power: 10}) stateStore := sm.NewStore(dbm.NewMemDB()) @@ -178,7 +178,7 @@ func TestMempoolRmBadTx(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - state, privVals := makeGenesisState(t, ctx, config, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, config, genesisStateArgs{ Validators: 1, Power: 10}) app := NewCounterApplication() diff --git a/internal/consensus/pbts_test.go b/internal/consensus/pbts_test.go index 2efc92535..0f8122991 100644 --- a/internal/consensus/pbts_test.go +++ b/internal/consensus/pbts_test.go @@ -104,7 +104,7 @@ func newPBTSTestHarness(ctx context.Context, t *testing.T, tc pbtsTestConfigurat consensusParams := types.DefaultConsensusParams() consensusParams.Synchrony = tc.synchronyParams - state, privVals := makeGenesisState(t, ctx, cfg, genesisStateArgs{ + state, privVals := makeGenesisState(ctx, t, cfg, genesisStateArgs{ Params: consensusParams, Time: tc.genesisTime, Validators: validators, diff --git a/internal/consensus/reactor_test.go b/internal/consensus/reactor_test.go index 52db6eb9e..00e8d73f3 100644 --- a/internal/consensus/reactor_test.go +++ b/internal/consensus/reactor_test.go @@ -383,7 +383,7 @@ func TestReactorWithEvidence(t *testing.T) { tickerFunc := newMockTickerFunc(true) appFunc := newKVStore - valSet, privVals := factory.ValidatorSet(t, ctx, n, 30) + valSet, privVals := factory.ValidatorSet(ctx, t, n, 30) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) states := make([]*State, n) logger := consensusLogger() diff --git a/internal/consensus/types/height_vote_set_test.go b/internal/consensus/types/height_vote_set_test.go index 31ebe8fe3..3ebfcf2ee 100644 --- a/internal/consensus/types/height_vote_set_test.go +++ b/internal/consensus/types/height_vote_set_test.go @@ -33,7 +33,7 @@ func TestPeerCatchupRounds(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - valSet, privVals := factory.ValidatorSet(t, ctx, 10, 1) + valSet, privVals := factory.ValidatorSet(ctx, t, 10, 1) hvs := NewHeightVoteSet(cfg.ChainID(), 1, valSet) diff --git a/internal/evidence/pool_test.go b/internal/evidence/pool_test.go index 129932e9c..36431d49d 100644 --- a/internal/evidence/pool_test.go +++ b/internal/evidence/pool_test.go @@ -41,7 +41,7 @@ func TestEvidencePoolBasic(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - valSet, privVals := factory.ValidatorSet(t, ctx, 1, 10) + valSet, privVals := factory.ValidatorSet(ctx, t, 1, 10) blockStore.On("LoadBlockMeta", mock.AnythingOfType("int64")).Return( &types.BlockMeta{Header: types.Header{Time: defaultEvidenceTime}}, ) diff --git a/internal/evidence/verify_test.go b/internal/evidence/verify_test.go index 1a6bb9640..159cc7518 100644 --- a/internal/evidence/verify_test.go +++ b/internal/evidence/verify_test.go @@ -201,7 +201,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - conflictingVals, conflictingPrivVals := factory.ValidatorSet(t, ctx, 5, 10) + conflictingVals, conflictingPrivVals := factory.ValidatorSet(ctx, t, 5, 10) conflictingHeader := factory.MakeHeader(t, &types.Header{ ChainID: evidenceChainID, @@ -295,7 +295,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { func TestVerifyLightClientAttack_Amnesia(t *testing.T) { var height int64 = 10 - conflictingVals, conflictingPrivVals := factory.ValidatorSet(t, ctx, 5, 10) + conflictingVals, conflictingPrivVals := factory.ValidatorSet(ctx, t, 5, 10) ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -495,14 +495,14 @@ func makeLunaticEvidence( ) (ev *types.LightClientAttackEvidence, trusted *types.LightBlock, common *types.LightBlock) { t.Helper() - commonValSet, commonPrivVals := factory.ValidatorSet(t, ctx, totalVals, defaultVotingPower) + commonValSet, commonPrivVals := factory.ValidatorSet(ctx, t, totalVals, defaultVotingPower) require.Greater(t, totalVals, byzVals) // extract out the subset of byzantine validators in the common validator set byzValSet, byzPrivVals := commonValSet.Validators[:byzVals], commonPrivVals[:byzVals] - phantomValSet, phantomPrivVals := factory.ValidatorSet(t, ctx, phantomVals, defaultVotingPower) + phantomValSet, phantomPrivVals := factory.ValidatorSet(ctx, t, phantomVals, defaultVotingPower) conflictingVals := phantomValSet.Copy() require.NoError(t, conflictingVals.UpdateWithChangeSet(byzValSet)) @@ -557,7 +557,7 @@ func makeLunaticEvidence( ValidatorSet: commonValSet, } trustedBlockID := factory.MakeBlockIDWithHash(trustedHeader.Hash()) - trustedVals, privVals := factory.ValidatorSet(t, ctx, totalVals, defaultVotingPower) + trustedVals, privVals := factory.ValidatorSet(ctx, t, totalVals, defaultVotingPower) trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), trustedVals) trustedCommit, err := factory.MakeCommit(ctx, trustedBlockID, height, 1, trustedVoteSet, privVals, defaultEvidenceTime) require.NoError(t, err) diff --git a/internal/state/rollback_test.go b/internal/state/rollback_test.go index d3bbaf009..d74889ed0 100644 --- a/internal/state/rollback_test.go +++ b/internal/state/rollback_test.go @@ -106,7 +106,7 @@ func setupStateStore(t *testing.T, height int64) state.Store { stateStore := state.NewStore(dbm.NewMemDB()) ctx, cancel := context.WithCancel(context.Background()) defer cancel() - valSet, _ := factory.ValidatorSet(t, ctx, 5, 10) + valSet, _ := factory.ValidatorSet(ctx, t, 5, 10) params := types.DefaultConsensusParams() params.Version.AppVersion = 10 diff --git a/internal/statesync/block_queue_test.go b/internal/statesync/block_queue_test.go index cc61591c5..1093b1cd9 100644 --- a/internal/statesync/block_queue_test.go +++ b/internal/statesync/block_queue_test.go @@ -293,7 +293,7 @@ loop: } func mockLBResp(ctx context.Context, t *testing.T, peer types.NodeID, height int64, time time.Time) lightBlockResponse { - vals, pv := factory.ValidatorSet(t, ctx, 3, 10) + vals, pv := factory.ValidatorSet(ctx, t, 3, 10) _, _, lb := mockLB(ctx, t, height, time, factory.MakeBlockID(), vals, pv) return lightBlockResponse{ block: lb, diff --git a/internal/statesync/reactor_test.go b/internal/statesync/reactor_test.go index 7692ba94b..62900133c 100644 --- a/internal/statesync/reactor_test.go +++ b/internal/statesync/reactor_test.go @@ -442,7 +442,7 @@ func TestReactor_LightBlockResponse(t *testing.T) { h := factory.MakeHeader(t, &types.Header{}) h.Height = height blockID := factory.MakeBlockIDWithHash(h.Hash()) - vals, pv := factory.ValidatorSet(t, ctx, 1, 10) + vals, pv := factory.ValidatorSet(ctx, t, 1, 10) vote, err := factory.MakeVote(ctx, pv[0], h.ChainID, 0, h.Height, 0, 2, blockID, factory.DefaultTestTime) require.NoError(t, err) @@ -733,7 +733,7 @@ func handleLightBlockRequests( } else { switch errorCount % 3 { case 0: // send a different block - vals, pv := factory.ValidatorSet(t, ctx, 3, 10) + vals, pv := factory.ValidatorSet(ctx, t, 3, 10) _, _, lb := mockLB(ctx, t, int64(msg.Height), factory.DefaultTestTime, factory.MakeBlockID(), vals, pv) differntLB, err := lb.ToProto() require.NoError(t, err) @@ -802,7 +802,7 @@ func buildLightBlockChain(ctx context.Context, t *testing.T, fromHeight, toHeigh chain := make(map[int64]*types.LightBlock, toHeight-fromHeight) lastBlockID := factory.MakeBlockID() blockTime := startTime.Add(time.Duration(fromHeight-toHeight) * time.Minute) - vals, pv := factory.ValidatorSet(t, ctx, 3, 10) + vals, pv := factory.ValidatorSet(ctx, t, 3, 10) for height := fromHeight; height < toHeight; height++ { vals, pv, chain[height] = mockLB(ctx, t, height, blockTime, lastBlockID, vals, pv) lastBlockID = factory.MakeBlockIDWithHash(chain[height].Header.Hash()) @@ -822,7 +822,7 @@ func mockLB(ctx context.Context, t *testing.T, height int64, time time.Time, las }) header.Version.App = testAppVersion - nextVals, nextPrivVals := factory.ValidatorSet(t, ctx, 3, 10) + nextVals, nextPrivVals := factory.ValidatorSet(ctx, t, 3, 10) header.ValidatorsHash = currentVals.Hash() header.NextValidatorsHash = nextVals.Hash() header.ConsensusHash = types.DefaultConsensusParams().HashConsensusParams() diff --git a/internal/test/factory/validator.go b/internal/test/factory/validator.go index 6d7f543f3..383ba7536 100644 --- a/internal/test/factory/validator.go +++ b/internal/test/factory/validator.go @@ -20,7 +20,7 @@ func Validator(ctx context.Context, votingPower int64) (*types.Validator, types. return val, privVal, nil } -func ValidatorSet(t *testing.T, ctx context.Context, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) { +func ValidatorSet(ctx context.Context, t *testing.T, numValidators int, votingPower int64) (*types.ValidatorSet, []types.PrivValidator) { var ( valz = make([]*types.Validator, numValidators) privValidators = make([]types.PrivValidator, numValidators) diff --git a/light/client_test.go b/light/client_test.go index 05a8e08ab..352b38b60 100644 --- a/light/client_test.go +++ b/light/client_test.go @@ -122,7 +122,7 @@ func TestClient(t *testing.T) { t.Run("SequentialVerification", func(t *testing.T) { newKeys := genPrivKeys(4) newVals := newKeys.ToValidators(10, 1) - differentVals, _ := factory.ValidatorSet(t, ctx, 10, 100) + differentVals, _ := factory.ValidatorSet(ctx, t, 10, 100) testCases := []struct { name string @@ -940,7 +940,7 @@ func TestClient(t *testing.T) { logger := log.NewTestingLogger(t) - differentVals, _ := factory.ValidatorSet(t, ctx, 10, 100) + differentVals, _ := factory.ValidatorSet(ctx, t, 10, 100) mockBadValSetNode := mockNodeFromHeadersAndVals( map[int64]*types.SignedHeader{ 1: h1, diff --git a/light/store/db/db_test.go b/light/store/db/db_test.go index aa9539f99..7069eb11d 100644 --- a/light/store/db/db_test.go +++ b/light/store/db/db_test.go @@ -33,7 +33,7 @@ func TestLast_FirstLightBlockHeight(t *testing.T) { assert.EqualValues(t, -1, height) // 1 key - err = dbStore.SaveLightBlock(randLightBlock(t, ctx, int64(1))) + err = dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(1))) require.NoError(t, err) height, err = dbStore.LastLightBlockHeight() @@ -56,7 +56,7 @@ func Test_SaveLightBlock(t *testing.T) { assert.Nil(t, h) // 1 key - err = dbStore.SaveLightBlock(randLightBlock(t, ctx, 1)) + err = dbStore.SaveLightBlock(randLightBlock(ctx, t, 1)) require.NoError(t, err) size := dbStore.Size() @@ -87,7 +87,7 @@ func Test_LightBlockBefore(t *testing.T) { _, _ = dbStore.LightBlockBefore(100) }) - err := dbStore.SaveLightBlock(randLightBlock(t, ctx, int64(2))) + err := dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(2))) require.NoError(t, err) h, err := dbStore.LightBlockBefore(3) @@ -111,7 +111,7 @@ func Test_Prune(t *testing.T) { require.NoError(t, err) // One header - err = dbStore.SaveLightBlock(randLightBlock(t, ctx, 2)) + err = dbStore.SaveLightBlock(randLightBlock(ctx, t, 2)) require.NoError(t, err) assert.EqualValues(t, 1, dbStore.Size()) @@ -126,7 +126,7 @@ func Test_Prune(t *testing.T) { // Multiple headers for i := 1; i <= 10; i++ { - err = dbStore.SaveLightBlock(randLightBlock(t, ctx, int64(i))) + err = dbStore.SaveLightBlock(randLightBlock(ctx, t, int64(i))) require.NoError(t, err) } @@ -151,7 +151,7 @@ func Test_Concurrency(t *testing.T) { go func(i int64) { defer wg.Done() - err := dbStore.SaveLightBlock(randLightBlock(t, ctx, i)) + err := dbStore.SaveLightBlock(randLightBlock(ctx, t, i)) require.NoError(t, err) _, err = dbStore.LightBlock(i) @@ -194,9 +194,9 @@ func Test_Concurrency(t *testing.T) { wg.Wait() } -func randLightBlock(t *testing.T, ctx context.Context, height int64) *types.LightBlock { +func randLightBlock(ctx context.Context, t *testing.T, height int64) *types.LightBlock { t.Helper() - vals, _ := factory.ValidatorSet(t, ctx, 2, 1) + vals, _ := factory.ValidatorSet(ctx, t, 2, 1) return &types.LightBlock{ SignedHeader: &types.SignedHeader{ Header: &types.Header{ diff --git a/node/node_test.go b/node/node_test.go index 1ab1e3351..99ea4aa50 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -728,7 +728,7 @@ func loadStatefromGenesis(ctx context.Context, t *testing.T) sm.State { require.NoError(t, err) require.True(t, loadedState.IsEmpty()) - valSet, _ := factory.ValidatorSet(t, ctx, 0, 10) + valSet, _ := factory.ValidatorSet(ctx, t, 0, 10) genDoc := factory.GenesisDoc(cfg, time.Now(), valSet.Validators, nil) state, err := loadStateFromDBOrGenesisDocProvider(