cleanup: Reduce and normalize import path aliasing. (#6975)

The code in the Tendermint repository makes heavy use of import aliasing.
This is made necessary by our extensive reuse of common base package names, and
by repetition of similar names across different subdirectories.

Unfortunately we have not been very consistent about which packages we alias in
various circumstances, and the aliases we use vary. In the spirit of the advice
in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports,
his change makes an effort to clean up and normalize import aliasing.

This change makes no API or behavioral changes. It is a pure cleanup intended
o help make the code more readable to developers (including myself) trying to
understand what is being imported where.

Only unexported names have been modified, and the changes were generated and
applied mechanically with gofmt -r and comby, respecting the lexical and
syntactic rules of Go.  Even so, I did not fix every inconsistency. Where the
changes would be too disruptive, I left it alone.

The principles I followed in this cleanup are:

- Remove aliases that restate the package name.
- Remove aliases where the base package name is unambiguous.
- Move overly-terse abbreviations from the import to the usage site.
- Fix lexical issues (remove underscores, remove capitalization).
- Fix import groupings to more closely match the style guide.
- Group blank (side-effecting) imports and ensure they are commented.
- Add aliases to multiple imports with the same base package name.
This commit is contained in:
M. J. Fromberger
2021-09-23 07:52:07 -07:00
committed by GitHub
parent c9beef796d
commit cf7537ea5f
127 changed files with 1473 additions and 1473 deletions
+6 -6
View File
@@ -7,9 +7,9 @@ import (
"time"
abci "github.com/tendermint/tendermint/abci/types"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/internal/libs/fail"
mempl "github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/internal/proxy"
"github.com/tendermint/tendermint/libs/log"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
@@ -37,7 +37,7 @@ type BlockExecutor struct {
// manage the mempool lock during commit
// and update both with block results after commit.
mempool mempl.Mempool
mempool mempool.Mempool
evpool EvidencePool
logger log.Logger
@@ -61,7 +61,7 @@ func NewBlockExecutor(
stateStore Store,
logger log.Logger,
proxyApp proxy.AppConnConsensus,
mempool mempl.Mempool,
pool mempool.Mempool,
evpool EvidencePool,
blockStore BlockStore,
options ...BlockExecutorOption,
@@ -70,7 +70,7 @@ func NewBlockExecutor(
store: stateStore,
proxyApp: proxyApp,
eventBus: types.NopEventBus{},
mempool: mempool,
mempool: pool,
evpool: evpool,
logger: logger,
metrics: NopMetrics(),
@@ -424,7 +424,7 @@ func validateValidatorUpdates(abciUpdates []abci.ValidatorUpdate,
}
// Check if validator's pubkey matches an ABCI type in the consensus params
pk, err := cryptoenc.PubKeyFromProto(valUpdate.PubKey)
pk, err := encoding.PubKeyFromProto(valUpdate.PubKey)
if err != nil {
return err
}
+8 -8
View File
@@ -8,12 +8,13 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abciclient "github.com/tendermint/tendermint/abci/client"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/tmhash"
mmock "github.com/tendermint/tendermint/internal/mempool/mock"
"github.com/tendermint/tendermint/internal/proxy"
@@ -25,7 +26,6 @@ import (
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
dbm "github.com/tendermint/tm-db"
)
var (
@@ -218,9 +218,9 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
func TestValidateValidatorUpdates(t *testing.T) {
pubkey1 := ed25519.GenPrivKey().PubKey()
pubkey2 := ed25519.GenPrivKey().PubKey()
pk1, err := cryptoenc.PubKeyToProto(pubkey1)
pk1, err := encoding.PubKeyToProto(pubkey1)
assert.NoError(t, err)
pk2, err := cryptoenc.PubKeyToProto(pubkey2)
pk2, err := encoding.PubKeyToProto(pubkey2)
assert.NoError(t, err)
defaultValidatorParams := types.ValidatorParams{PubKeyTypes: []string{types.ABCIPubKeyTypeEd25519}}
@@ -278,9 +278,9 @@ func TestUpdateValidators(t *testing.T) {
pubkey2 := ed25519.GenPrivKey().PubKey()
val2 := types.NewValidator(pubkey2, 20)
pk, err := cryptoenc.PubKeyToProto(pubkey1)
pk, err := encoding.PubKeyToProto(pubkey1)
require.NoError(t, err)
pk2, err := cryptoenc.PubKeyToProto(pubkey2)
pk2, err := encoding.PubKeyToProto(pubkey2)
require.NoError(t, err)
testCases := []struct {
@@ -385,7 +385,7 @@ func TestEndBlockValidatorUpdates(t *testing.T) {
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
pubkey := ed25519.GenPrivKey().PubKey()
pk, err := cryptoenc.PubKeyToProto(pubkey)
pk, err := encoding.PubKeyToProto(pubkey)
require.NoError(t, err)
app.ValidatorUpdates = []abci.ValidatorUpdate{
{PubKey: pk, Power: 10},
@@ -442,7 +442,7 @@ func TestEndBlockValidatorUpdatesResultingInEmptySet(t *testing.T) {
block := sf.MakeBlock(state, 1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
vp, err := cryptoenc.PubKeyToProto(state.Validators.Validators[0].PubKey)
vp, err := encoding.PubKeyToProto(state.Validators.Validators[0].PubKey)
require.NoError(t, err)
// Remove the only validator
app.ValidatorUpdates = []abci.ValidatorUpdate{
+4 -4
View File
@@ -11,7 +11,7 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/internal/proxy"
sm "github.com/tendermint/tendermint/internal/state"
sf "github.com/tendermint/tendermint/internal/state/test/factory"
@@ -148,11 +148,11 @@ func makeHeaderPartsResponsesValPubKeyChange(
// If the pubkey is new, remove the old and add the new.
_, val := state.NextValidators.GetByIndex(0)
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
vPbPk, err := cryptoenc.PubKeyToProto(val.PubKey)
vPbPk, err := encoding.PubKeyToProto(val.PubKey)
if err != nil {
panic(err)
}
pbPk, err := cryptoenc.PubKeyToProto(pubkey)
pbPk, err := encoding.PubKeyToProto(pubkey)
if err != nil {
panic(err)
}
@@ -181,7 +181,7 @@ func makeHeaderPartsResponsesValPowerChange(
// If the pubkey is new, remove the old and add the new.
_, val := state.NextValidators.GetByIndex(0)
if val.VotingPower != power {
vPbPk, err := cryptoenc.PubKeyToProto(val.PubKey)
vPbPk, err := encoding.PubKeyToProto(val.PubKey)
if err != nil {
panic(err)
}
+3 -2
View File
@@ -6,15 +6,16 @@ import (
"testing"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
blockidxkv "github.com/tendermint/tendermint/internal/state/indexer/block/kv"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
db "github.com/tendermint/tm-db"
)
func TestBlockIndexer(t *testing.T) {
store := db.NewPrefixDB(db.NewMemDB(), []byte("block_events"))
store := dbm.NewPrefixDB(dbm.NewMemDB(), []byte("block_events"))
indexer := blockidxkv.New(store)
require.NoError(t, indexer.Index(types.EventDataNewBlockHeader{
@@ -9,11 +9,11 @@ import (
"time"
"github.com/adlio/schema"
_ "github.com/lib/pq"
dockertest "github.com/ory/dockertest"
"github.com/ory/dockertest/docker"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
indexer "github.com/tendermint/tendermint/internal/state/indexer"
@@ -21,7 +21,9 @@ import (
psql "github.com/tendermint/tendermint/internal/state/indexer/sink/psql"
tmlog "github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/types"
db "github.com/tendermint/tm-db"
// Register the Postgre database driver.
_ "github.com/lib/pq"
)
var psqldb *sql.DB
@@ -55,7 +57,7 @@ func TestIndexerServiceIndexesBlocks(t *testing.T) {
pool, err := setupDB(t)
assert.Nil(t, err)
store := db.NewMemDB()
store := dbm.NewMemDB()
eventSinks := []indexer.EventSink{kv.NewEventSink(store), pSink}
assert.True(t, indexer.KVSinkEnabled(eventSinks))
assert.True(t, indexer.IndexingEnabled(eventSinks))
+2 -1
View File
@@ -3,13 +3,14 @@ package kv
import (
"context"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/internal/state/indexer"
kvb "github.com/tendermint/tendermint/internal/state/indexer/block/kv"
kvt "github.com/tendermint/tendermint/internal/state/indexer/tx/kv"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)
var _ indexer.EventSink = (*EventSink)(nil)
+9 -8
View File
@@ -5,6 +5,8 @@ import (
"fmt"
"testing"
dbm "github.com/tendermint/tm-db"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -13,21 +15,20 @@ import (
kvtx "github.com/tendermint/tendermint/internal/state/indexer/tx/kv"
"github.com/tendermint/tendermint/libs/pubsub/query"
"github.com/tendermint/tendermint/types"
db "github.com/tendermint/tm-db"
)
func TestType(t *testing.T) {
kvSink := NewEventSink(db.NewMemDB())
kvSink := NewEventSink(dbm.NewMemDB())
assert.Equal(t, indexer.KV, kvSink.Type())
}
func TestStop(t *testing.T) {
kvSink := NewEventSink(db.NewMemDB())
kvSink := NewEventSink(dbm.NewMemDB())
assert.Nil(t, kvSink.Stop())
}
func TestBlockFuncs(t *testing.T) {
store := db.NewPrefixDB(db.NewMemDB(), []byte("block_events"))
store := dbm.NewPrefixDB(dbm.NewMemDB(), []byte("block_events"))
indexer := NewEventSink(store)
require.NoError(t, indexer.IndexBlockEvents(types.EventDataNewBlockHeader{
@@ -158,7 +159,7 @@ func TestBlockFuncs(t *testing.T) {
}
func TestTxSearchWithCancelation(t *testing.T) {
indexer := NewEventSink(db.NewMemDB())
indexer := NewEventSink(dbm.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
@@ -180,7 +181,7 @@ func TestTxSearchWithCancelation(t *testing.T) {
}
func TestTxSearchDeprecatedIndexing(t *testing.T) {
esdb := db.NewMemDB()
esdb := dbm.NewMemDB()
indexer := NewEventSink(esdb)
// index tx using events indexing (composite key)
@@ -260,7 +261,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) {
}
func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
indexer := NewEventSink(db.NewMemDB())
indexer := NewEventSink(dbm.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
@@ -282,7 +283,7 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
}
func TestTxSearchMultipleTxs(t *testing.T) {
indexer := NewEventSink(db.NewMemDB())
indexer := NewEventSink(dbm.NewMemDB())
// indexed first, but bigger height (to test the order of transactions)
txResult := txResultWithEvents([]abci.Event{
+8 -9
View File
@@ -10,8 +10,7 @@ import (
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
db "github.com/tendermint/tm-db"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
indexer "github.com/tendermint/tendermint/internal/state/indexer"
@@ -21,7 +20,7 @@ import (
)
func TestTxIndex(t *testing.T) {
txIndexer := NewTxIndex(db.NewMemDB())
txIndexer := NewTxIndex(dbm.NewMemDB())
tx := types.Tx("HELLO WORLD")
txResult := &abci.TxResult{
@@ -67,7 +66,7 @@ func TestTxIndex(t *testing.T) {
}
func TestTxSearch(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
indexer := NewTxIndex(dbm.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
@@ -147,7 +146,7 @@ func TestTxSearch(t *testing.T) {
}
func TestTxSearchWithCancelation(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
indexer := NewTxIndex(dbm.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
@@ -165,7 +164,7 @@ func TestTxSearchWithCancelation(t *testing.T) {
}
func TestTxSearchDeprecatedIndexing(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
indexer := NewTxIndex(dbm.NewMemDB())
// index tx using events indexing (composite key)
txResult1 := txResultWithEvents([]abci.Event{
@@ -244,7 +243,7 @@ func TestTxSearchDeprecatedIndexing(t *testing.T) {
}
func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
indexer := NewTxIndex(dbm.NewMemDB())
txResult := txResultWithEvents([]abci.Event{
{Type: "account", Attributes: []abci.EventAttribute{{Key: "number", Value: "1", Index: true}}},
@@ -266,7 +265,7 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
}
func TestTxSearchMultipleTxs(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
indexer := NewTxIndex(dbm.NewMemDB())
// indexed first, but bigger height (to test the order of transactions)
txResult := txResultWithEvents([]abci.Event{
@@ -339,7 +338,7 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) {
require.NoError(b, err)
defer os.RemoveAll(dir)
store, err := db.NewDB("tx_index", "goleveldb", dir)
store, err := dbm.NewDB("tx_index", "goleveldb", dir)
require.NoError(b, err)
txIndexer := NewTxIndex(store)
+25 -26
View File
@@ -12,36 +12,35 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/encoding"
sm "github.com/tendermint/tendermint/internal/state"
sf "github.com/tendermint/tendermint/internal/state/test/factory"
statefactory "github.com/tendermint/tendermint/internal/state/test/factory"
tmstate "github.com/tendermint/tendermint/proto/tendermint/state"
"github.com/tendermint/tendermint/types"
)
// setupTestCase does setup common to all test cases.
func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, sm.State) {
config := cfg.ResetTestRoot("state_")
dbType := dbm.BackendType(config.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, config.DBDir())
cfg := config.ResetTestRoot("state_")
dbType := dbm.BackendType(cfg.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, cfg.DBDir())
require.NoError(t, err)
stateStore := sm.NewStore(stateDB)
state, err := stateStore.Load()
require.NoError(t, err)
require.Empty(t, state)
state, err = sm.MakeGenesisStateFromFile(config.GenesisFile())
state, err = sm.MakeGenesisStateFromFile(cfg.GenesisFile())
assert.NoError(t, err)
assert.NotNil(t, state)
err = stateStore.Save(state)
require.NoError(t, err)
tearDown := func(t *testing.T) { os.RemoveAll(config.RootDir) }
tearDown := func(t *testing.T) { os.RemoveAll(cfg.RootDir) }
return tearDown, stateDB, state
}
@@ -106,7 +105,7 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
state.LastBlockHeight++
// Build mock responses.
block := sf.MakeBlock(state, 2, new(types.Commit))
block := statefactory.MakeBlock(state, 2, new(types.Commit))
abciResponses := new(tmstate.ABCIResponses)
dtxs := make([]*abci.ResponseDeliverTx, 2)
@@ -114,7 +113,7 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
abciResponses.DeliverTxs[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Events: nil}
abciResponses.DeliverTxs[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Events: nil}
pbpk, err := cryptoenc.PubKeyToProto(ed25519.GenPrivKey().PubKey())
pbpk, err := encoding.PubKeyToProto(ed25519.GenPrivKey().PubKey())
require.NoError(t, err)
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{{PubKey: pbpk, Power: 10}}}
@@ -448,7 +447,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) {
// NewValidatorSet calls IncrementProposerPriority but uses on a copy of val1
assert.EqualValues(t, 0, val1.ProposerPriority)
block := sf.MakeBlock(state, state.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(state, state.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
abciResponses := &tmstate.ABCIResponses{
BeginBlock: &abci.ResponseBeginBlock{},
@@ -465,7 +464,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) {
// add a validator
val2PubKey := ed25519.GenPrivKey().PubKey()
val2VotingPower := int64(100)
fvp, err := cryptoenc.PubKeyToProto(val2PubKey)
fvp, err := encoding.PubKeyToProto(val2PubKey)
require.NoError(t, err)
updateAddVal := abci.ValidatorUpdate{PubKey: fvp, Power: val2VotingPower}
@@ -562,7 +561,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
// we only have one validator:
assert.Equal(t, val1PubKey.Address(), state.Validators.Proposer.Address)
block := sf.MakeBlock(state, state.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(state, state.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
// no updates:
abciResponses := &tmstate.ABCIResponses{
@@ -583,7 +582,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) {
// add a validator with the same voting power as the first
val2PubKey := ed25519.GenPrivKey().PubKey()
fvp, err := cryptoenc.PubKeyToProto(val2PubKey)
fvp, err := encoding.PubKeyToProto(val2PubKey)
require.NoError(t, err)
updateAddVal := abci.ValidatorUpdate{PubKey: fvp, Power: val1VotingPower}
validatorUpdates, err = types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{updateAddVal})
@@ -749,7 +748,7 @@ func TestLargeGenesisValidator(t *testing.T) {
validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
require.NoError(t, err)
block := sf.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
updatedState, err := sm.UpdateState(oldState, blockID, &block.Header, abciResponses, validatorUpdates)
@@ -769,7 +768,7 @@ func TestLargeGenesisValidator(t *testing.T) {
// see: https://github.com/tendermint/tendermint/issues/2960
firstAddedValPubKey := ed25519.GenPrivKey().PubKey()
firstAddedValVotingPower := int64(10)
fvp, err := cryptoenc.PubKeyToProto(firstAddedValPubKey)
fvp, err := encoding.PubKeyToProto(firstAddedValPubKey)
require.NoError(t, err)
firstAddedVal := abci.ValidatorUpdate{PubKey: fvp, Power: firstAddedValVotingPower}
validatorUpdates, err := types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{firstAddedVal})
@@ -778,7 +777,7 @@ func TestLargeGenesisValidator(t *testing.T) {
BeginBlock: &abci.ResponseBeginBlock{},
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{firstAddedVal}},
}
block := sf.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
updatedState, err := sm.UpdateState(oldState, blockID, &block.Header, abciResponses, validatorUpdates)
require.NoError(t, err)
@@ -793,7 +792,7 @@ func TestLargeGenesisValidator(t *testing.T) {
validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
require.NoError(t, err)
block := sf.MakeBlock(lastState, lastState.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(lastState, lastState.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
updatedStateInner, err := sm.UpdateState(lastState, blockID, &block.Header, abciResponses, validatorUpdates)
@@ -816,7 +815,7 @@ func TestLargeGenesisValidator(t *testing.T) {
// add 10 validators with the same voting power as the one added directly after genesis:
for i := 0; i < 10; i++ {
addedPubKey := ed25519.GenPrivKey().PubKey()
ap, err := cryptoenc.PubKeyToProto(addedPubKey)
ap, err := encoding.PubKeyToProto(addedPubKey)
require.NoError(t, err)
addedVal := abci.ValidatorUpdate{PubKey: ap, Power: firstAddedValVotingPower}
validatorUpdates, err := types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{addedVal})
@@ -826,7 +825,7 @@ func TestLargeGenesisValidator(t *testing.T) {
BeginBlock: &abci.ResponseBeginBlock{},
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{addedVal}},
}
block := sf.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
state, err = sm.UpdateState(state, blockID, &block.Header, abciResponses, validatorUpdates)
require.NoError(t, err)
@@ -834,14 +833,14 @@ func TestLargeGenesisValidator(t *testing.T) {
require.Equal(t, 10+2, len(state.NextValidators.Validators))
// remove genesis validator:
gp, err := cryptoenc.PubKeyToProto(genesisPubKey)
gp, err := encoding.PubKeyToProto(genesisPubKey)
require.NoError(t, err)
removeGenesisVal := abci.ValidatorUpdate{PubKey: gp, Power: 0}
abciResponses = &tmstate.ABCIResponses{
BeginBlock: &abci.ResponseBeginBlock{},
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{removeGenesisVal}},
}
block = sf.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
block = statefactory.MakeBlock(oldState, oldState.LastBlockHeight+1, new(types.Commit))
blockID = types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
validatorUpdates, err = types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
require.NoError(t, err)
@@ -862,7 +861,7 @@ func TestLargeGenesisValidator(t *testing.T) {
}
validatorUpdates, err = types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
require.NoError(t, err)
block = sf.MakeBlock(curState, curState.LastBlockHeight+1, new(types.Commit))
block = statefactory.MakeBlock(curState, curState.LastBlockHeight+1, new(types.Commit))
blockID = types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
curState, err = sm.UpdateState(curState, blockID, &block.Header, abciResponses, validatorUpdates)
require.NoError(t, err)
@@ -887,7 +886,7 @@ func TestLargeGenesisValidator(t *testing.T) {
validatorUpdates, err := types.PB2TM.ValidatorUpdates(abciResponses.EndBlock.ValidatorUpdates)
require.NoError(t, err)
block := sf.MakeBlock(updatedState, updatedState.LastBlockHeight+1, new(types.Commit))
block := statefactory.MakeBlock(updatedState, updatedState.LastBlockHeight+1, new(types.Commit))
blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: block.MakePartSet(testPartSize).Header()}
updatedState, err = sm.UpdateState(updatedState, blockID, &block.Header, abciResponses, validatorUpdates)
@@ -982,7 +981,7 @@ func TestStateMakeBlock(t *testing.T) {
proposerAddress := state.Validators.GetProposer().Address
stateVersion := state.Version.Consensus
block := sf.MakeBlock(state, 2, new(types.Commit))
block := statefactory.MakeBlock(state, 2, new(types.Commit))
// test we set some fields
assert.Equal(t, stateVersion, block.Version)
+6 -7
View File
@@ -7,11 +7,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
sm "github.com/tendermint/tendermint/internal/state"
@@ -102,13 +101,13 @@ func TestStoreLoadValidators(t *testing.T) {
func BenchmarkLoadValidators(b *testing.B) {
const valSetSize = 100
config := cfg.ResetTestRoot("state_")
defer os.RemoveAll(config.RootDir)
dbType := dbm.BackendType(config.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, config.DBDir())
cfg := config.ResetTestRoot("state_")
defer os.RemoveAll(cfg.RootDir)
dbType := dbm.BackendType(cfg.DBBackend)
stateDB, err := dbm.NewDB("state", dbType, cfg.DBDir())
require.NoError(b, err)
stateStore := sm.NewStore(stateDB)
state, err := sm.MakeGenesisStateFromFile(config.GenesisFile())
state, err := sm.MakeGenesisStateFromFile(cfg.GenesisFile())
if err != nil {
b.Fatal(err)
}
+5 -5
View File
@@ -1,22 +1,22 @@
package state
import (
mempl "github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/internal/mempool"
"github.com/tendermint/tendermint/types"
)
// TxPreCheck returns a function to filter transactions before processing.
// The function limits the size of a transaction to the block's maximum data size.
func TxPreCheck(state State) mempl.PreCheckFunc {
func TxPreCheck(state State) mempool.PreCheckFunc {
maxDataBytes := types.MaxDataBytesNoEvidence(
state.ConsensusParams.Block.MaxBytes,
state.Validators.Size(),
)
return mempl.PreCheckMaxBytes(maxDataBytes)
return mempool.PreCheckMaxBytes(maxDataBytes)
}
// TxPostCheck returns a function to filter transactions after processing.
// The function limits the gas wanted by a transaction to the block's maximum total gas.
func TxPostCheck(state State) mempl.PostCheckFunc {
return mempl.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)
func TxPostCheck(state State) mempool.PostCheckFunc {
return mempool.PostCheckMaxGas(state.ConsensusParams.Block.MaxGas)
}
+10 -10
View File
@@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
dbm "github.com/tendermint/tm-db"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
@@ -15,14 +16,13 @@ import (
memmock "github.com/tendermint/tendermint/internal/mempool/mock"
sm "github.com/tendermint/tendermint/internal/state"
"github.com/tendermint/tendermint/internal/state/mocks"
sf "github.com/tendermint/tendermint/internal/state/test/factory"
"github.com/tendermint/tendermint/internal/test/factory"
statefactory "github.com/tendermint/tendermint/internal/state/test/factory"
testfactory "github.com/tendermint/tendermint/internal/test/factory"
"github.com/tendermint/tendermint/libs/log"
tmtime "github.com/tendermint/tendermint/libs/time"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/store"
"github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)
const validationTestsStopHeight int64 = 10
@@ -90,7 +90,7 @@ func TestValidateBlockHeader(t *testing.T) {
Invalid blocks don't pass
*/
for _, tc := range testCases {
block := sf.MakeBlock(state, height, lastCommit)
block := statefactory.MakeBlock(state, height, lastCommit)
tc.malleateBlock(block)
err := blockExec.ValidateBlock(state, block)
t.Logf("%s: %v", tc.name, err)
@@ -107,7 +107,7 @@ func TestValidateBlockHeader(t *testing.T) {
}
nextHeight := validationTestsStopHeight
block := sf.MakeBlock(state, nextHeight, lastCommit)
block := statefactory.MakeBlock(state, nextHeight, lastCommit)
state.InitialHeight = nextHeight + 1
err := blockExec.ValidateBlock(state, block)
require.Error(t, err, "expected an error when state is ahead of block")
@@ -141,7 +141,7 @@ func TestValidateBlockCommit(t *testing.T) {
#2589: ensure state.LastValidators.VerifyCommit fails here
*/
// should be height-1 instead of height
wrongHeightVote, err := factory.MakeVote(
wrongHeightVote, err := testfactory.MakeVote(
privVals[proposerAddr.String()],
chainID,
1,
@@ -158,7 +158,7 @@ func TestValidateBlockCommit(t *testing.T) {
state.LastBlockID,
[]types.CommitSig{wrongHeightVote.CommitSig()},
)
block := sf.MakeBlock(state, height, wrongHeightCommit)
block := statefactory.MakeBlock(state, height, wrongHeightCommit)
err = blockExec.ValidateBlock(state, block)
_, isErrInvalidCommitHeight := err.(types.ErrInvalidCommitHeight)
require.True(t, isErrInvalidCommitHeight, "expected ErrInvalidCommitHeight at height %d but got: %v", height, err)
@@ -166,7 +166,7 @@ func TestValidateBlockCommit(t *testing.T) {
/*
#2589: test len(block.LastCommit.Signatures) == state.LastValidators.Size()
*/
block = sf.MakeBlock(state, height, wrongSigsCommit)
block = statefactory.MakeBlock(state, height, wrongSigsCommit)
err = blockExec.ValidateBlock(state, block)
_, isErrInvalidCommitSignatures := err.(types.ErrInvalidCommitSignatures)
require.True(t, isErrInvalidCommitSignatures,
@@ -195,7 +195,7 @@ func TestValidateBlockCommit(t *testing.T) {
/*
wrongSigsCommit is fine except for the extra bad precommit
*/
goodVote, err := factory.MakeVote(
goodVote, err := testfactory.MakeVote(
privVals[proposerAddr.String()],
chainID,
1,
@@ -278,7 +278,7 @@ func TestValidateBlockEvidence(t *testing.T) {
evidence = append(evidence, newEv)
currentBytes += int64(len(newEv.Bytes()))
}
block, _ := state.MakeBlock(height, factory.MakeTenTxs(height), lastCommit, evidence, proposerAddr)
block, _ := state.MakeBlock(height, testfactory.MakeTenTxs(height), lastCommit, evidence, proposerAddr)
err := blockExec.ValidateBlock(state, block)
if assert.Error(t, err) {
_, ok := err.(*types.ErrEvidenceOverflow)