From 88cbf477e789882dbc43bb3e92935ce24a0e118a Mon Sep 17 00:00:00 2001 From: Lasaro Date: Mon, 16 Jan 2023 11:43:31 -0300 Subject: [PATCH] replace tm for cmt (#101) * Renaming of variables and aliases prefixed with tm to use prefix cmt * Update assert to reflect new alias * More renaming * updating the Style guide to reflect new aliases * Replacing references to alias in the documentation --- STYLE_GUIDE.md | 12 +- abci/client/client.go | 4 +- abci/client/grpc_client.go | 8 +- abci/client/local_client.go | 8 +- abci/client/socket_client.go | 8 +- abci/client/socket_client_test.go | 4 +- abci/cmd/abci-cli/abci-cli.go | 4 +- abci/example/example_test.go | 4 +- abci/example/kvstore/helpers.go | 6 +- abci/example/kvstore/kvstore_test.go | 6 +- abci/server/grpc_server.go | 4 +- abci/server/socket_server.go | 14 +- abci/tests/benchmarks/parallel/parallel.go | 4 +- abci/tests/benchmarks/simple/simple.go | 4 +- abci/tests/server/client.go | 6 +- abci/types/messages_test.go | 6 +- blocksync/pool.go | 6 +- blocksync/pool_test.go | 6 +- blocksync/reactor_test.go | 4 +- cmd/priv_val_server/main.go | 8 +- cmd/tendermint/commands/gen_node_key.go | 4 +- cmd/tendermint/commands/gen_validator.go | 4 +- cmd/tendermint/commands/init.go | 16 +- cmd/tendermint/commands/light.go | 8 +- cmd/tendermint/commands/probe_upnp.go | 4 +- cmd/tendermint/commands/reindex_event.go | 4 +- cmd/tendermint/commands/reindex_event_test.go | 6 +- cmd/tendermint/commands/reset.go | 16 +- cmd/tendermint/commands/root.go | 4 +- cmd/tendermint/commands/root_test.go | 4 +- cmd/tendermint/commands/run_node.go | 4 +- cmd/tendermint/commands/show_validator.go | 8 +- cmd/tendermint/commands/testnet.go | 10 +- cmd/tendermint/commands/version.go | 8 +- config/toml.go | 12 +- consensus/byzantine_test.go | 28 +-- consensus/common_test.go | 84 ++++----- consensus/invalid_test.go | 14 +- consensus/metrics.go | 6 +- consensus/msgs.go | 86 ++++----- consensus/msgs_test.go | 114 ++++++------ consensus/reactor.go | 122 ++++++------- consensus/reactor_test.go | 30 ++-- consensus/replay_file.go | 24 +-- consensus/replay_stubs.go | 6 +- consensus/replay_test.go | 34 ++-- consensus/state.go | 76 ++++---- consensus/state_test.go | 168 +++++++++--------- consensus/types/height_vote_set.go | 28 +-- consensus/types/height_vote_set_test.go | 12 +- consensus/wal.go | 22 +-- consensus/wal_generator.go | 8 +- consensus/wal_test.go | 14 +- crypto/ed25519/ed25519.go | 6 +- crypto/merkle/proof.go | 8 +- crypto/merkle/proof_op.go | 16 +- crypto/merkle/proof_test.go | 8 +- crypto/merkle/proof_value.go | 12 +- crypto/merkle/tree_test.go | 10 +- crypto/secp256k1/secp256k1.go | 6 +- crypto/sr25519/encoding.go | 6 +- docs/tutorials/go-built-in.md | 8 +- docs/tutorials/go.md | 4 +- evidence/pool.go | 8 +- evidence/pool_test.go | 4 +- evidence/reactor.go | 12 +- evidence/reactor_test.go | 8 +- evidence/verify_test.go | 20 +-- inspect/inspect.go | 4 +- inspect/inspect_test.go | 2 +- internal/test/commit.go | 8 +- internal/test/config.go | 10 +- internal/test/vote.go | 4 +- libs/autofile/autofile.go | 4 +- libs/autofile/autofile_test.go | 6 +- libs/autofile/cmd/logjack.go | 4 +- libs/autofile/group_test.go | 18 +- libs/bits/bit_array.go | 22 +-- libs/bits/bit_array_test.go | 4 +- libs/cli/flags/log_level_test.go | 6 +- libs/clist/clist.go | 6 +- libs/clist/clist_test.go | 8 +- libs/cmap/cmap.go | 4 +- libs/events/events.go | 8 +- libs/flowrate/flowrate.go | 4 +- libs/json/structs.go | 4 +- libs/json/types.go | 4 +- libs/log/lazy.go | 4 +- libs/pubsub/pubsub.go | 4 +- libs/pubsub/subscription.go | 4 +- libs/rand/random.go | 4 +- libs/tempfile/tempfile.go | 4 +- libs/tempfile/tempfile_test.go | 6 +- libs/test/mutate.go | 8 +- libs/timer/throttle_timer.go | 4 +- libs/timer/throttle_timer_test.go | 4 +- light/client.go | 10 +- light/helpers_test.go | 12 +- light/proxy/proxy.go | 4 +- light/rpc/client.go | 12 +- light/store/db/db.go | 8 +- light/store/db/db_test.go | 8 +- light/verifier.go | 10 +- light/verifier_test.go | 24 +-- mempool/cache.go | 4 +- mempool/v0/clist_mempool.go | 10 +- mempool/v0/clist_mempool_test.go | 8 +- mempool/v0/reactor.go | 4 +- mempool/v0/reactor_test.go | 6 +- mempool/v1/reactor.go | 4 +- node/node.go | 8 +- node/node_test.go | 14 +- node/setup.go | 6 +- p2p/conn/connection.go | 12 +- p2p/conn/secret_connection.go | 6 +- p2p/conn/secret_connection_test.go | 26 +-- p2p/conn_set.go | 4 +- p2p/fuzz.go | 10 +- p2p/key.go | 10 +- p2p/key_test.go | 8 +- p2p/node_info.go | 16 +- p2p/peer.go | 22 +-- p2p/peer_set.go | 4 +- p2p/peer_test.go | 10 +- p2p/pex/addrbook.go | 28 +-- p2p/pex/addrbook_test.go | 22 +-- p2p/pex/pex_reactor.go | 14 +- p2p/switch_test.go | 4 +- p2p/test_util.go | 16 +- privval/file.go | 60 +++---- privval/file_test.go | 40 ++--- privval/msgs_test.go | 10 +- privval/retry_signer_client.go | 6 +- privval/signer_client.go | 6 +- privval/signer_client_test.go | 48 ++--- privval/signer_endpoint.go | 4 +- privval/signer_listener_endpoint.go | 4 +- privval/signer_listener_endpoint_test.go | 10 +- privval/signer_requestHandler.go | 10 +- privval/signer_server.go | 4 +- privval/socket_dialers.go | 4 +- privval/utils.go | 6 +- proxy/app_conn_test.go | 8 +- proxy/client.go | 6 +- proxy/multi_app_conn.go | 8 +- proxy/multi_app_conn_test.go | 2 +- rpc/client/event_test.go | 6 +- rpc/client/evidence_test.go | 10 +- rpc/client/http/http.go | 12 +- rpc/client/local/local.go | 14 +- rpc/client/rpc_test.go | 8 +- rpc/core/blocks.go | 14 +- rpc/core/blocks_test.go | 4 +- rpc/core/consensus.go | 4 +- rpc/core/env.go | 4 +- rpc/core/events.go | 10 +- rpc/core/status.go | 10 +- rpc/core/tx.go | 8 +- rpc/core/types/responses.go | 4 +- rpc/grpc/client_server.go | 4 +- rpc/jsonrpc/client/decode.go | 6 +- rpc/jsonrpc/client/encode.go | 4 +- rpc/jsonrpc/client/http_json_client.go | 6 +- rpc/jsonrpc/client/ws_client.go | 8 +- rpc/jsonrpc/client/ws_client_test.go | 4 +- rpc/jsonrpc/jsonrpc_test.go | 22 +-- rpc/jsonrpc/server/http_json_handler.go | 6 +- rpc/jsonrpc/server/http_uri_handler.go | 6 +- rpc/jsonrpc/test/main.go | 8 +- rpc/jsonrpc/types/types.go | 8 +- rpc/test/helpers.go | 4 +- scripts/json2wal/main.go | 4 +- scripts/wal2json/main.go | 4 +- state/execution.go | 10 +- state/execution_test.go | 8 +- state/export_test.go | 4 +- state/helpers_test.go | 26 +-- state/rollback.go | 8 +- state/rollback_test.go | 16 +- state/state.go | 24 +-- state/state_test.go | 40 ++--- state/store.go | 62 +++---- state/store_test.go | 14 +- state/tx_filter_test.go | 8 +- state/txindex/kv/kv_test.go | 4 +- state/validation_test.go | 8 +- statesync/chunks.go | 4 +- statesync/messages_test.go | 4 +- statesync/reactor.go | 4 +- statesync/snapshots.go | 4 +- statesync/stateprovider.go | 12 +- statesync/syncer.go | 4 +- statesync/syncer_test.go | 12 +- store/store.go | 32 ++-- store/store_test.go | 64 +++---- test/app/grpc_client.go | 4 +- test/e2e/node/main.go | 62 +++---- test/e2e/runner/evidence.go | 12 +- test/fuzz/tests/mempool_test.go | 4 +- .../internal/test_harness.go | 14 +- tools/tm-signer-harness/main.go | 16 +- types/block.go | 124 ++++++------- types/block_meta.go | 8 +- types/block_meta_test.go | 10 +- types/block_test.go | 56 +++--- types/canonical.go | 26 +-- types/canonical_test.go | 26 +-- types/event_bus.go | 22 +-- types/event_bus_test.go | 26 +-- types/events.go | 34 ++-- types/evidence.go | 46 ++--- types/evidence_test.go | 18 +- types/genesis.go | 18 +- types/genesis_test.go | 12 +- types/light.go | 14 +- types/light_test.go | 4 +- types/params.go | 20 +-- types/params_test.go | 16 +- types/part_set.go | 44 ++--- types/part_set_test.go | 14 +- types/priv_validator.go | 14 +- types/proposal.go | 26 +-- types/proposal_test.go | 12 +- types/protobuf.go | 20 +-- types/protobuf_test.go | 24 +-- types/signable.go | 4 +- types/signed_msg_type.go | 6 +- types/test_util.go | 10 +- types/tx.go | 18 +- types/tx_test.go | 10 +- types/validation.go | 4 +- types/validation_test.go | 26 +-- types/validator.go | 14 +- types/validator_set.go | 16 +- types/validator_set_test.go | 40 ++--- types/vote.go | 42 ++--- types/vote_set.go | 18 +- types/vote_set_test.go | 62 +++---- types/vote_test.go | 26 +-- 239 files changed, 1819 insertions(+), 1819 deletions(-) diff --git a/STYLE_GUIDE.md b/STYLE_GUIDE.md index 0ed354f6b80..945d19745ad 100644 --- a/STYLE_GUIDE.md +++ b/STYLE_GUIDE.md @@ -76,13 +76,13 @@ Sometimes it's necessary to rename libraries to avoid naming collisions or ambig * Use [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports) * Separate imports into blocks - one for the standard lib, one for external libs and one for application libs. * Here are some common library labels for consistency: - * dbm "github.com/tendermint/tm-db" - * tmcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" - * tmcfg "github.com/tendermint/tendermint/config/tendermint" - * tmtypes "github.com/tendermint/tendermint/types" + * dbm "github.com/cometbft/cometbft-db" + * cmtcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" + * cmtcfg "github.com/tendermint/tendermint/config/tendermint" + * cmttypes "github.com/tendermint/tendermint/types" * Never use anonymous imports (the `.`), for example, `tmlibs/common` or anything else. -* When importing a pkg from the `tendermint/libs` directory, prefix the pkg alias with tm. - * tmbits "github.com/tendermint/tendermint/libs/bits" +* When importing a pkg from the `tendermint/libs` directory, prefix the pkg alias with cmt. + * cmtbits "github.com/tendermint/tendermint/libs/bits" * tip: Use the `_` library import to import a library for initialization effects (side effects) ## Dependencies diff --git a/abci/client/client.go b/abci/client/client.go index cffb62f1240..8553204e4d0 100644 --- a/abci/client/client.go +++ b/abci/client/client.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) const ( @@ -85,7 +85,7 @@ type ReqRes struct { *sync.WaitGroup *types.Response // Not set atomically, so be sure to use WaitGroup. - mtx tmsync.Mutex + mtx cmtsync.Mutex // callbackInvoked as a variable to track if the callback was already // invoked during the regular execution of the request. This variable diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go index 1258f013f9f..ed8f7be2be4 100644 --- a/abci/client/grpc_client.go +++ b/abci/client/grpc_client.go @@ -10,9 +10,9 @@ import ( "google.golang.org/grpc" "github.com/tendermint/tendermint/abci/types" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) var _ Client = (*grpcClient)(nil) @@ -27,7 +27,7 @@ type grpcClient struct { conn *grpc.ClientConn chReqRes chan *ReqRes // dispatches "async" responses to callbacks *in order*, needed by mempool - mtx tmsync.Mutex + mtx cmtsync.Mutex addr string err error resCb func(*types.Request, *types.Response) // listens to all callbacks @@ -50,7 +50,7 @@ func NewGRPCClient(addr string, mustConnect bool) Client { } func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { - return tmnet.Connect(addr) + return cmtnet.Connect(addr) } func (cli *grpcClient) OnStart() error { diff --git a/abci/client/local_client.go b/abci/client/local_client.go index a49b2c86872..28c8f197292 100644 --- a/abci/client/local_client.go +++ b/abci/client/local_client.go @@ -3,7 +3,7 @@ package abcicli import ( types "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // NOTE: use defer to unlock mutex because Application might panic (e.g., in @@ -13,7 +13,7 @@ import ( type localClient struct { service.BaseService - mtx *tmsync.Mutex + mtx *cmtsync.Mutex types.Application Callback } @@ -22,9 +22,9 @@ var _ Client = (*localClient)(nil) // NewLocalClient creates a local client, which will be directly calling the // methods of the given app. -func NewLocalClient(mtx *tmsync.Mutex, app types.Application) Client { +func NewLocalClient(mtx *cmtsync.Mutex, app types.Application) Client { if mtx == nil { - mtx = new(tmsync.Mutex) + mtx = new(cmtsync.Mutex) } cli := &localClient{ mtx: mtx, diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 3df6007d2f1..c04a34ab965 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -11,9 +11,9 @@ import ( "time" "github.com/tendermint/tendermint/abci/types" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/libs/timer" ) @@ -34,7 +34,7 @@ type socketClient struct { reqQueue chan *ReqRes flushTimer *timer.ThrottleTimer - mtx tmsync.Mutex + mtx cmtsync.Mutex err error reqSent *list.List // list of requests sent, waiting for response resCb func(*types.Request, *types.Response) // called on all requests, if set. @@ -68,7 +68,7 @@ func (cli *socketClient) OnStart() error { ) for { - conn, err = tmnet.Connect(cli.addr) + conn, err = cmtnet.Connect(cli.addr) if err != nil { if cli.mustConnect { return err diff --git a/abci/client/socket_client_test.go b/abci/client/socket_client_test.go index 9bf28fe128c..e20fd1bb1c4 100644 --- a/abci/client/socket_client_test.go +++ b/abci/client/socket_client_test.go @@ -12,7 +12,7 @@ import ( abcicli "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/server" "github.com/tendermint/tendermint/abci/types" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" ) @@ -96,7 +96,7 @@ func TestHangingSyncCalls(t *testing.T) { func setupClientServer(t *testing.T, app types.Application) ( service.Service, abcicli.Client) { // some port between 20k and 30k - port := 20000 + tmrand.Int32()%10000 + port := 20000 + cmtrand.Int32()%10000 addr := fmt.Sprintf("localhost:%d", port) s, err := server.NewServer(addr, "socket", app) diff --git a/abci/cmd/abci-cli/abci-cli.go b/abci/cmd/abci-cli/abci-cli.go index ab0d521566f..54810d3af44 100644 --- a/abci/cmd/abci-cli/abci-cli.go +++ b/abci/cmd/abci-cli/abci-cli.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" abcicli "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/example/code" @@ -690,7 +690,7 @@ func cmdKVStore(cmd *cobra.Command, args []string) error { } // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(logger, func() { + cmtos.TrapSignal(logger, func() { // Cleanup if err := srv.Stop(); err != nil { logger.Error("Error while stopping server", "err", err) diff --git a/abci/example/example_test.go b/abci/example/example_test.go index e5c99b1cd38..0bd172eb25f 100644 --- a/abci/example/example_test.go +++ b/abci/example/example_test.go @@ -16,7 +16,7 @@ import ( "golang.org/x/net/context" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" abcicli "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/example/code" @@ -125,7 +125,7 @@ func testStream(t *testing.T, app types.Application) { // test grpc func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { - return tmnet.Connect(addr) + return cmtnet.Connect(addr) } func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) { diff --git a/abci/example/kvstore/helpers.go b/abci/example/kvstore/helpers.go index e59fee279c0..725745dcf11 100644 --- a/abci/example/kvstore/helpers.go +++ b/abci/example/kvstore/helpers.go @@ -2,14 +2,14 @@ package kvstore import ( "github.com/tendermint/tendermint/abci/types" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) // RandVal creates one random validator, with a key derived // from the input value func RandVal(i int) types.ValidatorUpdate { - pubkey := tmrand.Bytes(32) - power := tmrand.Uint16() + 1 + pubkey := cmtrand.Bytes(32) + power := cmtrand.Uint16() + 1 v := types.UpdateValidator(pubkey, int64(power), "") return v } diff --git a/abci/example/kvstore/kvstore_test.go b/abci/example/kvstore/kvstore_test.go index 77d6e933fb6..73dffecf7f8 100644 --- a/abci/example/kvstore/kvstore_test.go +++ b/abci/example/kvstore/kvstore_test.go @@ -15,7 +15,7 @@ import ( "github.com/tendermint/tendermint/abci/example/code" abciserver "github.com/tendermint/tendermint/abci/server" "github.com/tendermint/tendermint/abci/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) const ( @@ -121,7 +121,7 @@ func TestPersistentKVStoreInfo(t *testing.T) { // make and apply block height = int64(1) hash := []byte("foo") - header := tmproto.Header{ + header := cmtproto.Header{ Height: height, } kvstore.BeginBlock(types.RequestBeginBlock{Hash: hash, Header: header}) @@ -211,7 +211,7 @@ func makeApplyBlock( // make and apply block height := int64(heightInt) hash := []byte("foo") - header := tmproto.Header{ + header := cmtproto.Header{ Height: height, } diff --git a/abci/server/grpc_server.go b/abci/server/grpc_server.go index 503f0b64f11..913520ab36d 100644 --- a/abci/server/grpc_server.go +++ b/abci/server/grpc_server.go @@ -6,7 +6,7 @@ import ( "google.golang.org/grpc" "github.com/tendermint/tendermint/abci/types" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" ) @@ -23,7 +23,7 @@ type GRPCServer struct { // NewGRPCServer returns a new gRPC ABCI server func NewGRPCServer(protoAddr string, app types.ABCIApplicationServer) service.Service { - proto, addr := tmnet.ProtocolAndAddress(protoAddr) + proto, addr := cmtnet.ProtocolAndAddress(protoAddr) s := &GRPCServer{ proto: proto, addr: addr, diff --git a/abci/server/socket_server.go b/abci/server/socket_server.go index 5da8bf5bac9..bf35720ec31 100644 --- a/abci/server/socket_server.go +++ b/abci/server/socket_server.go @@ -9,10 +9,10 @@ import ( "runtime" "github.com/tendermint/tendermint/abci/types" - tmlog "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtlog "github.com/tendermint/tendermint/libs/log" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // var maxNumberConnections = 2 @@ -25,16 +25,16 @@ type SocketServer struct { addr string listener net.Listener - connsMtx tmsync.Mutex + connsMtx cmtsync.Mutex conns map[int]net.Conn nextConnID int - appMtx tmsync.Mutex + appMtx cmtsync.Mutex app types.Application } func NewSocketServer(protoAddr string, app types.Application) service.Service { - proto, addr := tmnet.ProtocolAndAddress(protoAddr) + proto, addr := cmtnet.ProtocolAndAddress(protoAddr) s := &SocketServer{ proto: proto, addr: addr, @@ -46,7 +46,7 @@ func NewSocketServer(protoAddr string, app types.Application) service.Service { return s } -func (s *SocketServer) SetLogger(l tmlog.Logger) { +func (s *SocketServer) SetLogger(l cmtlog.Logger) { s.BaseService.SetLogger(l) s.isLoggerSet = true } diff --git a/abci/tests/benchmarks/parallel/parallel.go b/abci/tests/benchmarks/parallel/parallel.go index fe213313d4d..06d3851b280 100644 --- a/abci/tests/benchmarks/parallel/parallel.go +++ b/abci/tests/benchmarks/parallel/parallel.go @@ -6,12 +6,12 @@ import ( "log" "github.com/tendermint/tendermint/abci/types" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" ) func main() { - conn, err := tmnet.Connect("unix://test.sock") + conn, err := cmtnet.Connect("unix://test.sock") if err != nil { log.Fatal(err.Error()) } diff --git a/abci/tests/benchmarks/simple/simple.go b/abci/tests/benchmarks/simple/simple.go index b18eaa580b3..c7308f590b7 100644 --- a/abci/tests/benchmarks/simple/simple.go +++ b/abci/tests/benchmarks/simple/simple.go @@ -8,12 +8,12 @@ import ( "reflect" "github.com/tendermint/tendermint/abci/types" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" ) func main() { - conn, err := tmnet.Connect("unix://test.sock") + conn, err := cmtnet.Connect("unix://test.sock") if err != nil { log.Fatal(err.Error()) } diff --git a/abci/tests/server/client.go b/abci/tests/server/client.go index 76d315216aa..617148424ee 100644 --- a/abci/tests/server/client.go +++ b/abci/tests/server/client.go @@ -7,15 +7,15 @@ import ( abcicli "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/types" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func InitChain(client abcicli.Client) error { total := 10 vals := make([]types.ValidatorUpdate, total) for i := 0; i < total; i++ { - pubkey := tmrand.Bytes(33) - power := tmrand.Int() + pubkey := cmtrand.Bytes(33) + power := cmtrand.Int() vals[i] = types.UpdateValidator(pubkey, int64(power), "") } _, err := client.InitChainSync(types.RequestInitChain{ diff --git a/abci/types/messages_test.go b/abci/types/messages_test.go index 17613769f84..d052dbc53e6 100644 --- a/abci/types/messages_test.go +++ b/abci/types/messages_test.go @@ -9,7 +9,7 @@ import ( "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/assert" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func TestMarshalJSON(t *testing.T) { @@ -61,7 +61,7 @@ func TestWriteReadMessageSimple(t *testing.T) { func TestWriteReadMessage(t *testing.T) { cases := []proto.Message{ - &tmproto.Header{ + &cmtproto.Header{ Height: 4, ChainID: "test", }, @@ -73,7 +73,7 @@ func TestWriteReadMessage(t *testing.T) { err := WriteMessage(c, buf) assert.Nil(t, err) - msg := new(tmproto.Header) + msg := new(cmtproto.Header) err = ReadMessage(buf, msg) assert.Nil(t, err) diff --git a/blocksync/pool.go b/blocksync/pool.go index 57ba94ce835..f508e770e4b 100644 --- a/blocksync/pool.go +++ b/blocksync/pool.go @@ -10,7 +10,7 @@ import ( flow "github.com/tendermint/tendermint/libs/flowrate" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" ) @@ -64,7 +64,7 @@ type BlockPool struct { service.BaseService startTime time.Time - mtx tmsync.Mutex + mtx cmtsync.Mutex // block requests requesters map[int64]*bpRequester height int64 // the lowest key in requesters. @@ -513,7 +513,7 @@ type bpRequester struct { gotBlockCh chan struct{} redoCh chan p2p.ID // redo may send multitime, add peerId to identify repeat - mtx tmsync.Mutex + mtx cmtsync.Mutex peerID p2p.ID block *types.Block } diff --git a/blocksync/pool_test.go b/blocksync/pool_test.go index 9fcc9dde4e8..f031f091876 100644 --- a/blocksync/pool_test.go +++ b/blocksync/pool_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" ) @@ -66,8 +66,8 @@ func (ps testPeers) stop() { func makePeers(numPeers int, minHeight, maxHeight int64) testPeers { peers := make(testPeers, numPeers) for i := 0; i < numPeers; i++ { - peerID := p2p.ID(tmrand.Str(12)) - height := minHeight + tmrand.Int63n(maxHeight-minHeight) + peerID := p2p.ID(cmtrand.Str(12)) + height := minHeight + cmtrand.Int63n(maxHeight-minHeight) base := minHeight + int64(i) if base > height { base = height diff --git a/blocksync/reactor_test.go b/blocksync/reactor_test.go index 0ab127b5306..2bd66aab1d0 100644 --- a/blocksync/reactor_test.go +++ b/blocksync/reactor_test.go @@ -23,7 +23,7 @@ import ( sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) var config *cfg.Config @@ -42,7 +42,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G sort.Sort(types.PrivValidatorsByAddress(privValidators)) return &types.GenesisDoc{ - GenesisTime: tmtime.Now(), + GenesisTime: cmttime.Now(), ChainID: test.DefaultTestChainID, Validators: validators, }, privValidators diff --git a/cmd/priv_val_server/main.go b/cmd/priv_val_server/main.go index 813ce6b1404..1c7183852ac 100644 --- a/cmd/priv_val_server/main.go +++ b/cmd/priv_val_server/main.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" - tmos "github.com/tendermint/tendermint/libs/os" + cmtnet "github.com/tendermint/tendermint/libs/net" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/privval" ) @@ -37,7 +37,7 @@ func main() { pv := privval.LoadFilePV(*privValKeyPath, *privValStatePath) var dialer privval.SocketDialer - protocol, address := tmnet.ProtocolAndAddress(*addr) + protocol, address := cmtnet.ProtocolAndAddress(*addr) switch protocol { case "unix": dialer = privval.DialUnixFn(address) @@ -58,7 +58,7 @@ func main() { } // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(logger, func() { + cmtos.TrapSignal(logger, func() { err := ss.Stop() if err != nil { panic(err) diff --git a/cmd/tendermint/commands/gen_node_key.go b/cmd/tendermint/commands/gen_node_key.go index dd4eee74033..4993e147a96 100644 --- a/cmd/tendermint/commands/gen_node_key.go +++ b/cmd/tendermint/commands/gen_node_key.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/p2p" ) @@ -21,7 +21,7 @@ var GenNodeKeyCmd = &cobra.Command{ func genNodeKey(cmd *cobra.Command, args []string) error { nodeKeyFile := config.NodeKeyFile() - if tmos.FileExists(nodeKeyFile) { + if cmtos.FileExists(nodeKeyFile) { return fmt.Errorf("node key at %s already exists", nodeKeyFile) } diff --git a/cmd/tendermint/commands/gen_validator.go b/cmd/tendermint/commands/gen_validator.go index 3b3336fcdd8..11539efe3ab 100644 --- a/cmd/tendermint/commands/gen_validator.go +++ b/cmd/tendermint/commands/gen_validator.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/privval" ) @@ -21,7 +21,7 @@ var GenValidatorCmd = &cobra.Command{ func genValidator(cmd *cobra.Command, args []string) { pv := privval.GenFilePV("", "") - jsbz, err := tmjson.Marshal(pv) + jsbz, err := cmtjson.Marshal(pv) if err != nil { panic(err) } diff --git a/cmd/tendermint/commands/init.go b/cmd/tendermint/commands/init.go index e2eae6eef6c..facaee41f01 100644 --- a/cmd/tendermint/commands/init.go +++ b/cmd/tendermint/commands/init.go @@ -6,12 +6,12 @@ import ( "github.com/spf13/cobra" cfg "github.com/tendermint/tendermint/config" - tmos "github.com/tendermint/tendermint/libs/os" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) // InitFilesCmd initializes a fresh Tendermint Core instance. @@ -30,7 +30,7 @@ func initFilesWithConfig(config *cfg.Config) error { privValKeyFile := config.PrivValidatorKeyFile() privValStateFile := config.PrivValidatorStateFile() var pv *privval.FilePV - if tmos.FileExists(privValKeyFile) { + if cmtos.FileExists(privValKeyFile) { pv = privval.LoadFilePV(privValKeyFile, privValStateFile) logger.Info("Found private validator", "keyFile", privValKeyFile, "stateFile", privValStateFile) @@ -42,7 +42,7 @@ func initFilesWithConfig(config *cfg.Config) error { } nodeKeyFile := config.NodeKeyFile() - if tmos.FileExists(nodeKeyFile) { + if cmtos.FileExists(nodeKeyFile) { logger.Info("Found node key", "path", nodeKeyFile) } else { if _, err := p2p.LoadOrGenNodeKey(nodeKeyFile); err != nil { @@ -53,12 +53,12 @@ func initFilesWithConfig(config *cfg.Config) error { // genesis file genFile := config.GenesisFile() - if tmos.FileExists(genFile) { + if cmtos.FileExists(genFile) { logger.Info("Found genesis file", "path", genFile) } else { genDoc := types.GenesisDoc{ - ChainID: fmt.Sprintf("test-chain-%v", tmrand.Str(6)), - GenesisTime: tmtime.Now(), + ChainID: fmt.Sprintf("test-chain-%v", cmtrand.Str(6)), + GenesisTime: cmttime.Now(), ConsensusParams: types.DefaultConsensusParams(), } pubKey, err := pv.GetPubKey() diff --git a/cmd/tendermint/commands/light.go b/cmd/tendermint/commands/light.go index 2bab772130c..721d2aa89e1 100644 --- a/cmd/tendermint/commands/light.go +++ b/cmd/tendermint/commands/light.go @@ -16,8 +16,8 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmos "github.com/tendermint/tendermint/libs/os" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/light" lproxy "github.com/tendermint/tendermint/light/proxy" lrpc "github.com/tendermint/tendermint/light/rpc" @@ -141,7 +141,7 @@ func runProxy(cmd *cobra.Command, args []string) error { } } - trustLevel, err := tmmath.ParseFraction(trustLevelStr) + trustLevel, err := cmtmath.ParseFraction(trustLevelStr) if err != nil { return fmt.Errorf("can't parse trust level: %w", err) } @@ -218,7 +218,7 @@ func runProxy(cmd *cobra.Command, args []string) error { } // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(logger, func() { + cmtos.TrapSignal(logger, func() { p.Listener.Close() }) diff --git a/cmd/tendermint/commands/probe_upnp.go b/cmd/tendermint/commands/probe_upnp.go index 7d0193c841b..17b310bc0d8 100644 --- a/cmd/tendermint/commands/probe_upnp.go +++ b/cmd/tendermint/commands/probe_upnp.go @@ -5,7 +5,7 @@ import ( "github.com/spf13/cobra" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/p2p/upnp" ) @@ -24,7 +24,7 @@ func probeUpnp(cmd *cobra.Command, args []string) error { fmt.Println("Probe failed: ", err) } else { fmt.Println("Probe success!") - jsonBytes, err := tmjson.Marshal(capabilities) + jsonBytes, err := cmtjson.Marshal(capabilities) if err != nil { return err } diff --git a/cmd/tendermint/commands/reindex_event.go b/cmd/tendermint/commands/reindex_event.go index 976224f962a..b9ad7227564 100644 --- a/cmd/tendermint/commands/reindex_event.go +++ b/cmd/tendermint/commands/reindex_event.go @@ -9,7 +9,7 @@ import ( dbm "github.com/tendermint/tm-db" abcitypes "github.com/tendermint/tendermint/abci/types" - tmcfg "github.com/tendermint/tendermint/config" + cmtcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/progressbar" "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/indexer" @@ -100,7 +100,7 @@ func init() { ReIndexEventCmd.Flags().Int64Var(&endHeight, "end-height", 0, "the block height would like to finish for re-index") } -func loadEventSinks(cfg *tmcfg.Config, chainID string) (indexer.BlockIndexer, txindex.TxIndexer, error) { +func loadEventSinks(cfg *cmtcfg.Config, chainID string) (indexer.BlockIndexer, txindex.TxIndexer, error) { switch strings.ToLower(cfg.TxIndex.Indexer) { case "null": return nil, nil, errors.New("found null event sink, please check the tx-index section in the config.toml") diff --git a/cmd/tendermint/commands/reindex_event_test.go b/cmd/tendermint/commands/reindex_event_test.go index 336f61a6144..dfc053265ea 100644 --- a/cmd/tendermint/commands/reindex_event_test.go +++ b/cmd/tendermint/commands/reindex_event_test.go @@ -12,7 +12,7 @@ import ( dbm "github.com/tendermint/tm-db" abcitypes "github.com/tendermint/tendermint/abci/types" - tmcfg "github.com/tendermint/tendermint/config" + cmtcfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/internal/test" prototmstate "github.com/tendermint/tendermint/proto/tendermint/state" blockmocks "github.com/tendermint/tendermint/state/indexer/mocks" @@ -96,7 +96,7 @@ func TestLoadEventSink(t *testing.T) { } for idx, tc := range testCases { - cfg := tmcfg.TestConfig() + cfg := cmtcfg.TestConfig() cfg.TxIndex.Indexer = tc.sinks cfg.TxIndex.PsqlConn = tc.connURL _, _, err := loadEventSinks(cfg, test.DefaultTestChainID) @@ -109,7 +109,7 @@ func TestLoadEventSink(t *testing.T) { } func TestLoadBlockStore(t *testing.T) { - cfg := tmcfg.TestConfig() + cfg := cmtcfg.TestConfig() cfg.DBPath = t.TempDir() _, _, err := loadStateAndBlockStore(cfg) require.Error(t, err) diff --git a/cmd/tendermint/commands/reset.go b/cmd/tendermint/commands/reset.go index 86beb6a56f2..a32fba8bbde 100644 --- a/cmd/tendermint/commands/reset.go +++ b/cmd/tendermint/commands/reset.go @@ -7,7 +7,7 @@ import ( "github.com/spf13/cobra" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/privval" ) @@ -94,7 +94,7 @@ func resetAll(dbDir, addrBookFile, privValKeyFile, privValStateFile string, logg logger.Error("Error removing all blockchain history", "dir", dbDir, "err", err) } - if err := tmos.EnsureDir(dbDir, 0700); err != nil { + if err := cmtos.EnsureDir(dbDir, 0700); err != nil { logger.Error("unable to recreate dbDir", "err", err) } @@ -111,7 +111,7 @@ func resetState(dbDir string, logger log.Logger) error { evidence := filepath.Join(dbDir, "evidence.db") txIndex := filepath.Join(dbDir, "tx_index.db") - if tmos.FileExists(blockdb) { + if cmtos.FileExists(blockdb) { if err := os.RemoveAll(blockdb); err == nil { logger.Info("Removed all blockstore.db", "dir", blockdb) } else { @@ -119,7 +119,7 @@ func resetState(dbDir string, logger log.Logger) error { } } - if tmos.FileExists(state) { + if cmtos.FileExists(state) { if err := os.RemoveAll(state); err == nil { logger.Info("Removed all state.db", "dir", state) } else { @@ -127,7 +127,7 @@ func resetState(dbDir string, logger log.Logger) error { } } - if tmos.FileExists(wal) { + if cmtos.FileExists(wal) { if err := os.RemoveAll(wal); err == nil { logger.Info("Removed all cs.wal", "dir", wal) } else { @@ -135,7 +135,7 @@ func resetState(dbDir string, logger log.Logger) error { } } - if tmos.FileExists(evidence) { + if cmtos.FileExists(evidence) { if err := os.RemoveAll(evidence); err == nil { logger.Info("Removed all evidence.db", "dir", evidence) } else { @@ -143,7 +143,7 @@ func resetState(dbDir string, logger log.Logger) error { } } - if tmos.FileExists(txIndex) { + if cmtos.FileExists(txIndex) { if err := os.RemoveAll(txIndex); err == nil { logger.Info("Removed tx_index.db", "dir", txIndex) } else { @@ -151,7 +151,7 @@ func resetState(dbDir string, logger log.Logger) error { } } - if err := tmos.EnsureDir(dbDir, 0700); err != nil { + if err := cmtos.EnsureDir(dbDir, 0700); err != nil { logger.Error("unable to recreate dbDir", "err", err) } return nil diff --git a/cmd/tendermint/commands/root.go b/cmd/tendermint/commands/root.go index 16ea8a391d2..0d1cc054f5a 100644 --- a/cmd/tendermint/commands/root.go +++ b/cmd/tendermint/commands/root.go @@ -10,7 +10,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/cli" - tmflags "github.com/tendermint/tendermint/libs/cli/flags" + cmtflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" ) @@ -79,7 +79,7 @@ var RootCmd = &cobra.Command{ logger = log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)) } - logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel) + logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel) if err != nil { return err } diff --git a/cmd/tendermint/commands/root_test.go b/cmd/tendermint/commands/root_test.go index ed9d4c73f85..a5dc4d842ed 100644 --- a/cmd/tendermint/commands/root_test.go +++ b/cmd/tendermint/commands/root_test.go @@ -14,7 +14,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/cli" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" ) var ( @@ -139,7 +139,7 @@ func TestRootConfig(t *testing.T) { // XXX: path must match cfg.defaultConfigPath configFilePath := filepath.Join(defaultRoot, "config") - err := tmos.EnsureDir(configFilePath, 0700) + err := cmtos.EnsureDir(configFilePath, 0700) require.Nil(t, err) // write the non-defaults to a different path diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 5bb2a6d4529..80d0f03cf3a 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" cfg "github.com/tendermint/tendermint/config" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" nm "github.com/tendermint/tendermint/node" ) @@ -119,7 +119,7 @@ func NewRunNodeCmd(nodeProvider nm.Provider) *cobra.Command { logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo()) // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(logger, func() { + cmtos.TrapSignal(logger, func() { if n.IsRunning() { if err := n.Stop(); err != nil { logger.Error("unable to stop the node", "error", err) diff --git a/cmd/tendermint/commands/show_validator.go b/cmd/tendermint/commands/show_validator.go index f29976bb3a4..83e0101d706 100644 --- a/cmd/tendermint/commands/show_validator.go +++ b/cmd/tendermint/commands/show_validator.go @@ -5,8 +5,8 @@ import ( "github.com/spf13/cobra" - tmjson "github.com/tendermint/tendermint/libs/json" - tmos "github.com/tendermint/tendermint/libs/os" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/privval" ) @@ -21,7 +21,7 @@ var ShowValidatorCmd = &cobra.Command{ func showValidator(cmd *cobra.Command, args []string) error { keyFilePath := config.PrivValidatorKeyFile() - if !tmos.FileExists(keyFilePath) { + if !cmtos.FileExists(keyFilePath) { return fmt.Errorf("private validator file %s does not exist", keyFilePath) } @@ -32,7 +32,7 @@ func showValidator(cmd *cobra.Command, args []string) error { return fmt.Errorf("can't get pubkey: %w", err) } - bz, err := tmjson.Marshal(pubKey) + bz, err := cmtjson.Marshal(pubKey) if err != nil { return fmt.Errorf("failed to marshal private validator pubkey: %w", err) } diff --git a/cmd/tendermint/commands/testnet.go b/cmd/tendermint/commands/testnet.go index d5e71b94092..702dfa8a653 100644 --- a/cmd/tendermint/commands/testnet.go +++ b/cmd/tendermint/commands/testnet.go @@ -12,11 +12,11 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/bytes" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) var ( @@ -179,9 +179,9 @@ func testnetFiles(cmd *cobra.Command, args []string) error { // Generate genesis doc from generated validators genDoc := &types.GenesisDoc{ - ChainID: "chain-" + tmrand.Str(6), + ChainID: "chain-" + cmtrand.Str(6), ConsensusParams: types.DefaultConsensusParams(), - GenesisTime: tmtime.Now(), + GenesisTime: cmttime.Now(), InitialHeight: initialHeight, Validators: genVals, } @@ -274,5 +274,5 @@ func moniker(i int) string { } func randomMoniker() string { - return bytes.HexBytes(tmrand.Bytes(8)).String() + return bytes.HexBytes(cmtrand.Bytes(8)).String() } diff --git a/cmd/tendermint/commands/version.go b/cmd/tendermint/commands/version.go index 16fb878c977..ea57af0d276 100644 --- a/cmd/tendermint/commands/version.go +++ b/cmd/tendermint/commands/version.go @@ -14,9 +14,9 @@ var VersionCmd = &cobra.Command{ Use: "version", Short: "Show version info", Run: func(cmd *cobra.Command, args []string) { - tmVersion := version.TMCoreSemVer + cmtVersion := version.TMCoreSemVer if version.TMGitCommitHash != "" { - tmVersion += "+" + version.TMGitCommitHash + cmtVersion += "+" + version.TMGitCommitHash } if verbose { @@ -26,14 +26,14 @@ var VersionCmd = &cobra.Command{ BlockProtocol uint64 `json:"block_protocol"` P2PProtocol uint64 `json:"p2p_protocol"` }{ - Tendermint: tmVersion, + Tendermint: cmtVersion, ABCI: version.ABCISemVer, BlockProtocol: version.BlockProtocol, P2PProtocol: version.P2PProtocol, }, "", " ") fmt.Println(string(values)) } else { - fmt.Println(tmVersion) + fmt.Println(cmtVersion) } }, } diff --git a/config/toml.go b/config/toml.go index 6041b92c323..fb57843806c 100644 --- a/config/toml.go +++ b/config/toml.go @@ -6,7 +6,7 @@ import ( "strings" "text/template" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" ) // DefaultDirPerm is the default permissions used when creating directories. @@ -29,20 +29,20 @@ func init() { // EnsureRoot creates the root, config, and data directories if they don't exist, // and panics if it fails. func EnsureRoot(rootDir string) { - if err := tmos.EnsureDir(rootDir, DefaultDirPerm); err != nil { + if err := cmtos.EnsureDir(rootDir, DefaultDirPerm); err != nil { panic(err.Error()) } - if err := tmos.EnsureDir(filepath.Join(rootDir, DefaultConfigDir), DefaultDirPerm); err != nil { + if err := cmtos.EnsureDir(filepath.Join(rootDir, DefaultConfigDir), DefaultDirPerm); err != nil { panic(err.Error()) } - if err := tmos.EnsureDir(filepath.Join(rootDir, DefaultDataDir), DefaultDirPerm); err != nil { + if err := cmtos.EnsureDir(filepath.Join(rootDir, DefaultDataDir), DefaultDirPerm); err != nil { panic(err.Error()) } configFilePath := filepath.Join(rootDir, defaultConfigFilePath) // Write default config file if missing. - if !tmos.FileExists(configFilePath) { + if !cmtos.FileExists(configFilePath) { writeDefaultConfigFile(configFilePath) } } @@ -61,7 +61,7 @@ func WriteConfigFile(configFilePath string, config *Config) { panic(err) } - tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644) + cmtos.MustWriteFile(configFilePath, buffer.Bytes(), 0644) } // Note: any changes to the comments/variables/mapstructure diff --git a/consensus/byzantine_test.go b/consensus/byzantine_test.go index 850584a8c07..47d6c76c7e6 100644 --- a/consensus/byzantine_test.go +++ b/consensus/byzantine_test.go @@ -19,15 +19,15 @@ import ( "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" mempl "github.com/tendermint/tendermint/mempool" cfg "github.com/tendermint/tendermint/config" mempoolv0 "github.com/tendermint/tendermint/mempool/v0" mempoolv1 "github.com/tendermint/tendermint/mempool/v1" "github.com/tendermint/tendermint/p2p" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" @@ -65,7 +65,7 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { blockDB := dbm.NewMemDB() blockStore := store.NewBlockStore(blockDB) - mtx := new(tmsync.Mutex) + mtx := new(cmtsync.Mutex) // one for mempool, one for consensus proxyAppConnCon := abcicli.NewLocalClient(mtx, app) proxyAppConnConMem := abcicli.NewLocalClient(mtx, app) @@ -156,9 +156,9 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { // allow first height to happen normally so that byzantine validator is no longer proposer if height == prevoteHeight { bcs.Logger.Info("Sending two votes") - prevote1, err := bcs.signVote(tmproto.PrevoteType, bcs.ProposalBlock.Hash(), bcs.ProposalBlockParts.Header()) + prevote1, err := bcs.signVote(cmtproto.PrevoteType, bcs.ProposalBlock.Hash(), bcs.ProposalBlockParts.Header()) require.NoError(t, err) - prevote2, err := bcs.signVote(tmproto.PrevoteType, nil, types.PartSetHeader{}) + prevote2, err := bcs.signVote(cmtproto.PrevoteType, nil, types.PartSetHeader{}) require.NoError(t, err) peerList := reactors[byzantineNode].Switch.Peers().List() bcs.Logger.Info("Getting peer list", "peers", peerList) @@ -167,13 +167,13 @@ func TestByzantinePrevoteEquivocation(t *testing.T) { if i < len(peerList)/2 { bcs.Logger.Info("Signed and pushed vote", "vote", prevote1, "peer", peer) peer.Send(p2p.Envelope{ - Message: &tmcons.Vote{Vote: prevote1.ToProto()}, + Message: &cmtcons.Vote{Vote: prevote1.ToProto()}, ChannelID: VoteChannel, }) } else { bcs.Logger.Info("Signed and pushed vote", "vote", prevote2, "peer", peer) peer.Send(p2p.Envelope{ - Message: &tmcons.Vote{Vote: prevote2.ToProto()}, + Message: &cmtcons.Vote{Vote: prevote2.ToProto()}, ChannelID: VoteChannel, }) } @@ -529,7 +529,7 @@ func sendProposalAndParts( // proposal peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.Proposal{Proposal: *proposal.ToProto()}, + Message: &cmtcons.Proposal{Proposal: *proposal.ToProto()}, }) // parts @@ -541,7 +541,7 @@ func sendProposalAndParts( } peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.BlockPart{ + Message: &cmtcons.BlockPart{ Height: height, // This tells peer that this part applies to us. Round: round, // This tells peer that this part applies to us. Part: *pp, @@ -551,16 +551,16 @@ func sendProposalAndParts( // votes cs.mtx.Lock() - prevote, _ := cs.signVote(tmproto.PrevoteType, blockHash, parts.Header()) - precommit, _ := cs.signVote(tmproto.PrecommitType, blockHash, parts.Header()) + prevote, _ := cs.signVote(cmtproto.PrevoteType, blockHash, parts.Header()) + precommit, _ := cs.signVote(cmtproto.PrecommitType, blockHash, parts.Header()) cs.mtx.Unlock() peer.Send(p2p.Envelope{ ChannelID: VoteChannel, - Message: &tmcons.Vote{Vote: prevote.ToProto()}, + Message: &cmtcons.Vote{Vote: prevote.ToProto()}, }) peer.Send(p2p.Envelope{ ChannelID: VoteChannel, - Message: &tmcons.Vote{Vote: precommit.ToProto()}, + Message: &cmtcons.Vote{Vote: precommit.ToProto()}, }) } diff --git a/consensus/common_test.go b/consensus/common_test.go index fee218198ff..0f768d24e9e 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -25,21 +25,21 @@ import ( cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/internal/test" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtsync "github.com/tendermint/tendermint/libs/sync" mempl "github.com/tendermint/tendermint/mempool" mempoolv0 "github.com/tendermint/tendermint/mempool/v0" mempoolv1 "github.com/tendermint/tendermint/mempool/v1" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) const ( @@ -58,7 +58,7 @@ var ( ) func ensureDir(dir string, mode os.FileMode) { - if err := tmos.EnsureDir(dir, mode); err != nil { + if err := cmtos.EnsureDir(dir, mode); err != nil { panic(err) } } @@ -90,7 +90,7 @@ func newValidatorStub(privValidator types.PrivValidator, valIndex int32) *valida } func (vs *validatorStub) signVote( - voteType tmproto.SignedMsgType, + voteType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader) (*types.Vote, error) { @@ -104,7 +104,7 @@ func (vs *validatorStub) signVote( ValidatorAddress: pubKey.Address(), Height: vs.Height, Round: vs.Round, - Timestamp: tmtime.Now(), + Timestamp: cmttime.Now(), Type: voteType, BlockID: types.BlockID{Hash: hash, PartSetHeader: header}, } @@ -126,7 +126,7 @@ func (vs *validatorStub) signVote( } // Sign vote for type/hash/header -func signVote(vs *validatorStub, voteType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote { +func signVote(vs *validatorStub, voteType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote { v, err := vs.signVote(voteType, hash, header) if err != nil { panic(fmt.Errorf("failed to sign vote: %v", err)) @@ -138,7 +138,7 @@ func signVote(vs *validatorStub, voteType tmproto.SignedMsgType, hash []byte, he } func signVotes( - voteType tmproto.SignedMsgType, + voteType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader, vss ...*validatorStub) []*types.Vote { @@ -240,7 +240,7 @@ func addVotes(to *State, votes ...*types.Vote) { func signAddVotes( to *State, - voteType tmproto.SignedMsgType, + voteType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader, vss ...*validatorStub, @@ -348,12 +348,12 @@ func validatePrevoteAndPrecommit( cs.mtx.Unlock() } -func subscribeToVoter(cs *State, addr []byte) <-chan tmpubsub.Message { +func subscribeToVoter(cs *State, addr []byte) <-chan cmtpubsub.Message { votesSub, err := cs.eventBus.SubscribeUnbuffered(context.Background(), testSubscriber, types.EventQueryVote) if err != nil { panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, types.EventQueryVote)) } - ch := make(chan tmpubsub.Message) + ch := make(chan cmtpubsub.Message) go func() { for msg := range votesSub.Out() { vote := msg.Data().(types.EventDataVote) @@ -395,7 +395,7 @@ func newStateWithConfigAndBlockStore( blockStore := store.NewBlockStore(blockDB) // one for mempool, one for consensus - mtx := new(tmsync.Mutex) + mtx := new(cmtsync.Mutex) proxyAppConnCon := abcicli.NewLocalClient(mtx, app) proxyAppConnConMem := abcicli.NewLocalClient(mtx, app) @@ -486,7 +486,7 @@ func randStateWithApp(nValidators int, app abci.Application) (*State, []*validat //------------------------------------------------------------------------------- -func ensureNoNewEvent(ch <-chan tmpubsub.Message, timeout time.Duration, +func ensureNoNewEvent(ch <-chan cmtpubsub.Message, timeout time.Duration, errorMessage string) { select { case <-time.After(timeout): @@ -496,28 +496,28 @@ func ensureNoNewEvent(ch <-chan tmpubsub.Message, timeout time.Duration, } } -func ensureNoNewEventOnChannel(ch <-chan tmpubsub.Message) { +func ensureNoNewEventOnChannel(ch <-chan cmtpubsub.Message) { ensureNoNewEvent( ch, ensureTimeout, "We should be stuck waiting, not receiving new event on the channel") } -func ensureNoNewRoundStep(stepCh <-chan tmpubsub.Message) { +func ensureNoNewRoundStep(stepCh <-chan cmtpubsub.Message) { ensureNoNewEvent( stepCh, ensureTimeout, "We should be stuck waiting, not receiving NewRoundStep event") } -func ensureNoNewUnlock(unlockCh <-chan tmpubsub.Message) { +func ensureNoNewUnlock(unlockCh <-chan cmtpubsub.Message) { ensureNoNewEvent( unlockCh, ensureTimeout, "We should be stuck waiting, not receiving Unlock event") } -func ensureNoNewTimeout(stepCh <-chan tmpubsub.Message, timeout int64) { +func ensureNoNewTimeout(stepCh <-chan cmtpubsub.Message, timeout int64) { timeoutDuration := time.Duration(timeout*10) * time.Nanosecond ensureNoNewEvent( stepCh, @@ -525,7 +525,7 @@ func ensureNoNewTimeout(stepCh <-chan tmpubsub.Message, timeout int64) { "We should be stuck waiting, not receiving NewTimeout event") } -func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int32, timeout time.Duration, errorMessage string) { +func ensureNewEvent(ch <-chan cmtpubsub.Message, height int64, round int32, timeout time.Duration, errorMessage string) { select { case <-time.After(timeout): panic(errorMessage) @@ -545,7 +545,7 @@ func ensureNewEvent(ch <-chan tmpubsub.Message, height int64, round int32, timeo } } -func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewRound(roundCh <-chan cmtpubsub.Message, height int64, round int32) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewRound event") @@ -564,13 +564,13 @@ func ensureNewRound(roundCh <-chan tmpubsub.Message, height int64, round int32) } } -func ensureNewTimeout(timeoutCh <-chan tmpubsub.Message, height int64, round int32, timeout int64) { +func ensureNewTimeout(timeoutCh <-chan cmtpubsub.Message, height int64, round int32, timeout int64) { timeoutDuration := time.Duration(timeout*10) * time.Nanosecond ensureNewEvent(timeoutCh, height, round, timeoutDuration, "Timeout expired while waiting for NewTimeout event") } -func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewProposal(proposalCh <-chan cmtpubsub.Message, height int64, round int32) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewProposal event") @@ -589,12 +589,12 @@ func ensureNewProposal(proposalCh <-chan tmpubsub.Message, height int64, round i } } -func ensureNewValidBlock(validBlockCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewValidBlock(validBlockCh <-chan cmtpubsub.Message, height int64, round int32) { ensureNewEvent(validBlockCh, height, round, ensureTimeout, "Timeout expired while waiting for NewValidBlock event") } -func ensureNewBlock(blockCh <-chan tmpubsub.Message, height int64) { +func ensureNewBlock(blockCh <-chan cmtpubsub.Message, height int64) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewBlock event") @@ -610,7 +610,7 @@ func ensureNewBlock(blockCh <-chan tmpubsub.Message, height int64) { } } -func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash tmbytes.HexBytes) { +func ensureNewBlockHeader(blockCh <-chan cmtpubsub.Message, height int64, blockHash cmtbytes.HexBytes) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewBlockHeader event") @@ -629,12 +629,12 @@ func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHa } } -func ensureNewUnlock(unlockCh <-chan tmpubsub.Message, height int64, round int32) { +func ensureNewUnlock(unlockCh <-chan cmtpubsub.Message, height int64, round int32) { ensureNewEvent(unlockCh, height, round, ensureTimeout, "Timeout expired while waiting for NewUnlock event") } -func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int32, propID types.BlockID) { +func ensureProposal(proposalCh <-chan cmtpubsub.Message, height int64, round int32, propID types.BlockID) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewProposal event") @@ -656,16 +656,16 @@ func ensureProposal(proposalCh <-chan tmpubsub.Message, height int64, round int3 } } -func ensurePrecommit(voteCh <-chan tmpubsub.Message, height int64, round int32) { - ensureVote(voteCh, height, round, tmproto.PrecommitType) +func ensurePrecommit(voteCh <-chan cmtpubsub.Message, height int64, round int32) { + ensureVote(voteCh, height, round, cmtproto.PrecommitType) } -func ensurePrevote(voteCh <-chan tmpubsub.Message, height int64, round int32) { - ensureVote(voteCh, height, round, tmproto.PrevoteType) +func ensurePrevote(voteCh <-chan cmtpubsub.Message, height int64, round int32) { + ensureVote(voteCh, height, round, cmtproto.PrevoteType) } -func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int32, - voteType tmproto.SignedMsgType) { +func ensureVote(voteCh <-chan cmtpubsub.Message, height int64, round int32, + voteType cmtproto.SignedMsgType) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewVote event") @@ -688,12 +688,12 @@ func ensureVote(voteCh <-chan tmpubsub.Message, height int64, round int32, } } -func ensurePrevoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte) { +func ensurePrevoteMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte) { t.Helper() - ensureVoteMatch(t, voteCh, height, round, hash, tmproto.PrevoteType) + ensureVoteMatch(t, voteCh, height, round, hash, cmtproto.PrevoteType) } -func ensureVoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, round int32, hash []byte, voteType tmproto.SignedMsgType) { +func ensureVoteMatch(t *testing.T, voteCh <-chan cmtpubsub.Message, height int64, round int32, hash []byte, voteType cmtproto.SignedMsgType) { t.Helper() select { case <-time.After(ensureTimeout): @@ -715,7 +715,7 @@ func ensureVoteMatch(t *testing.T, voteCh <-chan tmpubsub.Message, height int64, } } -func ensurePrecommitTimeout(ch <-chan tmpubsub.Message) { +func ensurePrecommitTimeout(ch <-chan cmtpubsub.Message) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for the Precommit to Timeout") @@ -723,7 +723,7 @@ func ensurePrecommitTimeout(ch <-chan tmpubsub.Message) { } } -func ensureNewEventOnChannel(ch <-chan tmpubsub.Message) { +func ensureNewEventOnChannel(ch <-chan cmtpubsub.Message) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for new activity on the channel") @@ -867,7 +867,7 @@ func randGenesisDoc(numValidators int, randPower bool, minPower int64) (*types.G sort.Sort(types.PrivValidatorsByAddress(privValidators)) return &types.GenesisDoc{ - GenesisTime: tmtime.Now(), + GenesisTime: cmttime.Now(), InitialHeight: 1, ChainID: test.DefaultTestChainID, Validators: validators, @@ -944,7 +944,7 @@ func newPersistentKVStoreWithPath(dbDir string) abci.Application { return kvstore.NewPersistentKVStoreApplication(dbDir) } -func signDataIsEqual(v1 *types.Vote, v2 *tmproto.Vote) bool { +func signDataIsEqual(v1 *types.Vote, v2 *cmtproto.Vote) bool { if v1 == nil || v2 == nil { return false } diff --git a/consensus/invalid_test.go b/consensus/invalid_test.go index 4e6f39bab47..7985a40d8f2 100644 --- a/consensus/invalid_test.go +++ b/consensus/invalid_test.go @@ -5,10 +5,10 @@ import ( "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -71,17 +71,17 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw valIndex, _ := cs.Validators.GetByAddress(addr) // precommit a random block - blockHash := bytes.HexBytes(tmrand.Bytes(32)) + blockHash := bytes.HexBytes(cmtrand.Bytes(32)) precommit := &types.Vote{ ValidatorAddress: addr, ValidatorIndex: valIndex, Height: cs.Height, Round: cs.Round, Timestamp: cs.voteTime(), - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: types.BlockID{ Hash: blockHash, - PartSetHeader: types.PartSetHeader{Total: 1, Hash: tmrand.Bytes(32)}}, + PartSetHeader: types.PartSetHeader{Total: 1, Hash: cmtrand.Bytes(32)}}, } p := precommit.ToProto() err = cs.privValidator.SignVote(cs.state.ChainID, p) @@ -96,7 +96,7 @@ func invalidDoPrevoteFunc(t *testing.T, height int64, round int32, cs *State, sw for _, peer := range peers { cs.Logger.Info("Sending bad vote", "block", blockHash, "peer", peer) peer.Send(p2p.Envelope{ - Message: &tmcons.Vote{Vote: precommit.ToProto()}, + Message: &cmtcons.Vote{Vote: precommit.ToProto()}, ChannelID: VoteChannel, }) } diff --git a/consensus/metrics.go b/consensus/metrics.go index f8262d3916c..c55d3209bb5 100644 --- a/consensus/metrics.go +++ b/consensus/metrics.go @@ -7,7 +7,7 @@ import ( "github.com/go-kit/kit/metrics" cstypes "github.com/tendermint/tendermint/consensus/types" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -128,7 +128,7 @@ func (m *Metrics) MarkProposalProcessed(accepted bool) { m.ProposalReceiveCount.With("status", status).Add(1) } -func (m *Metrics) MarkVoteReceived(vt tmproto.SignedMsgType, power, totalPower int64) { +func (m *Metrics) MarkVoteReceived(vt cmtproto.SignedMsgType, power, totalPower int64) { p := float64(power) / float64(totalPower) n := strings.ToLower(strings.TrimPrefix(vt.String(), "SIGNED_MSG_TYPE_")) m.RoundVotingPowerPercent.With("vote_type", n).Add(p) @@ -140,7 +140,7 @@ func (m *Metrics) MarkRound(r int32, st time.Time) { m.RoundDurationSeconds.Observe(roundTime) } -func (m *Metrics) MarkLateVote(vt tmproto.SignedMsgType) { +func (m *Metrics) MarkLateVote(vt cmtproto.SignedMsgType) { n := strings.ToLower(strings.TrimPrefix(vt.String(), "SIGNED_MSG_TYPE_")) m.LateVotes.With("vote_type", n).Add(1) } diff --git a/consensus/msgs.go b/consensus/msgs.go index 4631e1e5368..02c9cbc3d63 100644 --- a/consensus/msgs.go +++ b/consensus/msgs.go @@ -8,10 +8,10 @@ import ( cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/libs/bits" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/p2p" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -26,7 +26,7 @@ func MsgToProto(msg Message) (proto.Message, error) { switch msg := msg.(type) { case *NewRoundStepMessage: - pb = &tmcons.NewRoundStep{ + pb = &cmtcons.NewRoundStep{ Height: msg.Height, Round: msg.Round, Step: uint32(msg.Step), @@ -37,7 +37,7 @@ func MsgToProto(msg Message) (proto.Message, error) { case *NewValidBlockMessage: pbPartSetHeader := msg.BlockPartSetHeader.ToProto() pbBits := msg.BlockParts.ToProto() - pb = &tmcons.NewValidBlock{ + pb = &cmtcons.NewValidBlock{ Height: msg.Height, Round: msg.Round, BlockPartSetHeader: pbPartSetHeader, @@ -47,13 +47,13 @@ func MsgToProto(msg Message) (proto.Message, error) { case *ProposalMessage: pbP := msg.Proposal.ToProto() - pb = &tmcons.Proposal{ + pb = &cmtcons.Proposal{ Proposal: *pbP, } case *ProposalPOLMessage: pbBits := msg.ProposalPOL.ToProto() - pb = &tmcons.ProposalPOL{ + pb = &cmtcons.ProposalPOL{ Height: msg.Height, ProposalPolRound: msg.ProposalPOLRound, ProposalPol: *pbBits, @@ -64,7 +64,7 @@ func MsgToProto(msg Message) (proto.Message, error) { if err != nil { return nil, fmt.Errorf("msg to proto error: %w", err) } - pb = &tmcons.BlockPart{ + pb = &cmtcons.BlockPart{ Height: msg.Height, Round: msg.Round, Part: *parts, @@ -72,12 +72,12 @@ func MsgToProto(msg Message) (proto.Message, error) { case *VoteMessage: vote := msg.Vote.ToProto() - pb = &tmcons.Vote{ + pb = &cmtcons.Vote{ Vote: vote, } case *HasVoteMessage: - pb = &tmcons.HasVote{ + pb = &cmtcons.HasVote{ Height: msg.Height, Round: msg.Round, Type: msg.Type, @@ -86,7 +86,7 @@ func MsgToProto(msg Message) (proto.Message, error) { case *VoteSetMaj23Message: bi := msg.BlockID.ToProto() - pb = &tmcons.VoteSetMaj23{ + pb = &cmtcons.VoteSetMaj23{ Height: msg.Height, Round: msg.Round, Type: msg.Type, @@ -97,7 +97,7 @@ func MsgToProto(msg Message) (proto.Message, error) { bi := msg.BlockID.ToProto() bits := msg.Votes.ToProto() - vsb := &tmcons.VoteSetBits{ + vsb := &cmtcons.VoteSetBits{ Height: msg.Height, Round: msg.Round, Type: msg.Type, @@ -125,8 +125,8 @@ func MsgFromProto(p proto.Message) (Message, error) { var pb Message switch msg := p.(type) { - case *tmcons.NewRoundStep: - rs, err := tmmath.SafeConvertUint8(int64(msg.Step)) + case *cmtcons.NewRoundStep: + rs, err := cmtmath.SafeConvertUint8(int64(msg.Step)) // deny message based on possible overflow if err != nil { return nil, fmt.Errorf("denying message due to possible overflow: %w", err) @@ -138,7 +138,7 @@ func MsgFromProto(p proto.Message) (Message, error) { SecondsSinceStartTime: msg.SecondsSinceStartTime, LastCommitRound: msg.LastCommitRound, } - case *tmcons.NewValidBlock: + case *cmtcons.NewValidBlock: pbPartSetHeader, err := types.PartSetHeaderFromProto(&msg.BlockPartSetHeader) if err != nil { return nil, fmt.Errorf("parts to proto error: %w", err) @@ -154,7 +154,7 @@ func MsgFromProto(p proto.Message) (Message, error) { BlockParts: pbBits, IsCommit: msg.IsCommit, } - case *tmcons.Proposal: + case *cmtcons.Proposal: pbP, err := types.ProposalFromProto(&msg.Proposal) if err != nil { return nil, fmt.Errorf("proposal msg to proto error: %w", err) @@ -163,7 +163,7 @@ func MsgFromProto(p proto.Message) (Message, error) { pb = &ProposalMessage{ Proposal: pbP, } - case *tmcons.ProposalPOL: + case *cmtcons.ProposalPOL: pbBits := new(bits.BitArray) pbBits.FromProto(&msg.ProposalPol) pb = &ProposalPOLMessage{ @@ -171,7 +171,7 @@ func MsgFromProto(p proto.Message) (Message, error) { ProposalPOLRound: msg.ProposalPolRound, ProposalPOL: pbBits, } - case *tmcons.BlockPart: + case *cmtcons.BlockPart: parts, err := types.PartFromProto(&msg.Part) if err != nil { return nil, fmt.Errorf("blockpart msg to proto error: %w", err) @@ -181,7 +181,7 @@ func MsgFromProto(p proto.Message) (Message, error) { Round: msg.Round, Part: parts, } - case *tmcons.Vote: + case *cmtcons.Vote: vote, err := types.VoteFromProto(msg.Vote) if err != nil { return nil, fmt.Errorf("vote msg to proto error: %w", err) @@ -190,14 +190,14 @@ func MsgFromProto(p proto.Message) (Message, error) { pb = &VoteMessage{ Vote: vote, } - case *tmcons.HasVote: + case *cmtcons.HasVote: pb = &HasVoteMessage{ Height: msg.Height, Round: msg.Round, Type: msg.Type, Index: msg.Index, } - case *tmcons.VoteSetMaj23: + case *cmtcons.VoteSetMaj23: bi, err := types.BlockIDFromProto(&msg.BlockID) if err != nil { return nil, fmt.Errorf("voteSetMaj23 msg to proto error: %w", err) @@ -208,7 +208,7 @@ func MsgFromProto(p proto.Message) (Message, error) { Type: msg.Type, BlockID: *bi, } - case *tmcons.VoteSetBits: + case *cmtcons.VoteSetBits: bi, err := types.BlockIDFromProto(&msg.BlockID) if err != nil { return nil, fmt.Errorf("voteSetBits msg to proto error: %w", err) @@ -235,14 +235,14 @@ func MsgFromProto(p proto.Message) (Message, error) { } // WALToProto takes a WAL message and return a proto walMessage and error -func WALToProto(msg WALMessage) (*tmcons.WALMessage, error) { - var pb tmcons.WALMessage +func WALToProto(msg WALMessage) (*cmtcons.WALMessage, error) { + var pb cmtcons.WALMessage switch msg := msg.(type) { case types.EventDataRoundState: - pb = tmcons.WALMessage{ - Sum: &tmcons.WALMessage_EventDataRoundState{ - EventDataRoundState: &tmproto.EventDataRoundState{ + pb = cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_EventDataRoundState{ + EventDataRoundState: &cmtproto.EventDataRoundState{ Height: msg.Height, Round: msg.Round, Step: msg.Step, @@ -257,19 +257,19 @@ func WALToProto(msg WALMessage) (*tmcons.WALMessage, error) { if w, ok := consMsg.(p2p.Wrapper); ok { consMsg = w.Wrap() } - cm := consMsg.(*tmcons.Message) - pb = tmcons.WALMessage{ - Sum: &tmcons.WALMessage_MsgInfo{ - MsgInfo: &tmcons.MsgInfo{ + cm := consMsg.(*cmtcons.Message) + pb = cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_MsgInfo{ + MsgInfo: &cmtcons.MsgInfo{ Msg: *cm, PeerID: string(msg.PeerID), }, }, } case timeoutInfo: - pb = tmcons.WALMessage{ - Sum: &tmcons.WALMessage_TimeoutInfo{ - TimeoutInfo: &tmcons.TimeoutInfo{ + pb = cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_TimeoutInfo{ + TimeoutInfo: &cmtcons.TimeoutInfo{ Duration: msg.Duration, Height: msg.Height, Round: msg.Round, @@ -278,9 +278,9 @@ func WALToProto(msg WALMessage) (*tmcons.WALMessage, error) { }, } case EndHeightMessage: - pb = tmcons.WALMessage{ - Sum: &tmcons.WALMessage_EndHeight{ - EndHeight: &tmcons.EndHeight{ + pb = cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_EndHeight{ + EndHeight: &cmtcons.EndHeight{ Height: msg.Height, }, }, @@ -293,20 +293,20 @@ func WALToProto(msg WALMessage) (*tmcons.WALMessage, error) { } // WALFromProto takes a proto wal message and return a consensus walMessage and error -func WALFromProto(msg *tmcons.WALMessage) (WALMessage, error) { +func WALFromProto(msg *cmtcons.WALMessage) (WALMessage, error) { if msg == nil { return nil, errors.New("nil WAL message") } var pb WALMessage switch msg := msg.Sum.(type) { - case *tmcons.WALMessage_EventDataRoundState: + case *cmtcons.WALMessage_EventDataRoundState: pb = types.EventDataRoundState{ Height: msg.EventDataRoundState.Height, Round: msg.EventDataRoundState.Round, Step: msg.EventDataRoundState.Step, } - case *tmcons.WALMessage_MsgInfo: + case *cmtcons.WALMessage_MsgInfo: um, err := msg.MsgInfo.Msg.Unwrap() if err != nil { return nil, fmt.Errorf("unwrap message: %w", err) @@ -320,8 +320,8 @@ func WALFromProto(msg *tmcons.WALMessage) (WALMessage, error) { PeerID: p2p.ID(msg.MsgInfo.PeerID), } - case *tmcons.WALMessage_TimeoutInfo: - tis, err := tmmath.SafeConvertUint8(int64(msg.TimeoutInfo.Step)) + case *cmtcons.WALMessage_TimeoutInfo: + tis, err := cmtmath.SafeConvertUint8(int64(msg.TimeoutInfo.Step)) // deny message based on possible overflow if err != nil { return nil, fmt.Errorf("denying message due to possible overflow: %w", err) @@ -333,7 +333,7 @@ func WALFromProto(msg *tmcons.WALMessage) (WALMessage, error) { Step: cstypes.RoundStepType(tis), } return pb, nil - case *tmcons.WALMessage_EndHeight: + case *cmtcons.WALMessage_EndHeight: pb := EndHeightMessage{ Height: msg.EndHeight.Height, } diff --git a/consensus/msgs_test.go b/consensus/msgs_test.go index 122a2a4112b..5d24698a135 100644 --- a/consensus/msgs_test.go +++ b/consensus/msgs_test.go @@ -12,21 +12,21 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/libs/bits" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) func TestMsgToProto(t *testing.T) { psh := types.PartSetHeader{ Total: 1, - Hash: tmrand.Bytes(32), + Hash: cmtrand.Bytes(32), } pbPsh := psh.ToProto() bi := types.BlockID{ - Hash: tmrand.Bytes(32), + Hash: cmtrand.Bytes(32), PartSetHeader: psh, } pbBi := bi.ToProto() @@ -39,7 +39,7 @@ func TestMsgToProto(t *testing.T) { Proof: merkle.Proof{ Total: 1, Index: 1, - LeafHash: tmrand.Bytes(32), + LeafHash: cmtrand.Bytes(32), Aunts: [][]byte{}, }, } @@ -47,13 +47,13 @@ func TestMsgToProto(t *testing.T) { require.NoError(t, err) proposal := types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 1, Round: 1, POLRound: 1, BlockID: bi, Timestamp: time.Now(), - Signature: tmrand.Bytes(20), + Signature: cmtrand.Bytes(20), } pbProposal := proposal.ToProto() @@ -80,7 +80,7 @@ func TestMsgToProto(t *testing.T) { Step: 1, SecondsSinceStartTime: 1, LastCommitRound: 2, - }, &tmcons.NewRoundStep{ + }, &cmtcons.NewRoundStep{ Height: 2, Round: 1, Step: 1, @@ -96,7 +96,7 @@ func TestMsgToProto(t *testing.T) { BlockPartSetHeader: psh, BlockParts: bits, IsCommit: false, - }, &tmcons.NewValidBlock{ + }, &cmtcons.NewValidBlock{ Height: 1, Round: 1, BlockPartSetHeader: pbPsh, @@ -109,7 +109,7 @@ func TestMsgToProto(t *testing.T) { Height: 100, Round: 1, Part: &parts, - }, &tmcons.BlockPart{ + }, &cmtcons.BlockPart{ Height: 100, Round: 1, Part: *pbParts, @@ -120,7 +120,7 @@ func TestMsgToProto(t *testing.T) { Height: 1, ProposalPOLRound: 1, ProposalPOL: bits, - }, &tmcons.ProposalPOL{ + }, &cmtcons.ProposalPOL{ Height: 1, ProposalPolRound: 1, ProposalPol: *pbBits, @@ -128,14 +128,14 @@ func TestMsgToProto(t *testing.T) { false}, {"successful ProposalMessage", &ProposalMessage{ Proposal: &proposal, - }, &tmcons.Proposal{ + }, &cmtcons.Proposal{ Proposal: *pbProposal, }, false}, {"successful VoteMessage", &VoteMessage{ Vote: vote, - }, &tmcons.Vote{ + }, &cmtcons.Vote{ Vote: pbVote, }, @@ -145,7 +145,7 @@ func TestMsgToProto(t *testing.T) { Round: 1, Type: 1, BlockID: bi, - }, &tmcons.VoteSetMaj23{ + }, &cmtcons.VoteSetMaj23{ Height: 1, Round: 1, Type: 1, @@ -159,7 +159,7 @@ func TestMsgToProto(t *testing.T) { Type: 1, BlockID: bi, Votes: bits, - }, &tmcons.VoteSetBits{ + }, &cmtcons.VoteSetBits{ Height: 1, Round: 1, Type: 1, @@ -168,7 +168,7 @@ func TestMsgToProto(t *testing.T) { }, false}, - {"failure", nil, &tmcons.Message{}, true}, + {"failure", nil, &cmtcons.Message{}, true}, } for _, tt := range testsCases { tt := tt @@ -201,7 +201,7 @@ func TestWALMsgProto(t *testing.T) { Proof: merkle.Proof{ Total: 1, Index: 1, - LeafHash: tmrand.Bytes(32), + LeafHash: cmtrand.Bytes(32), Aunts: [][]byte{}, }, } @@ -211,16 +211,16 @@ func TestWALMsgProto(t *testing.T) { testsCases := []struct { testName string msg WALMessage - want *tmcons.WALMessage + want *cmtcons.WALMessage wantErr bool }{ {"successful EventDataRoundState", types.EventDataRoundState{ Height: 2, Round: 1, Step: "ronies", - }, &tmcons.WALMessage{ - Sum: &tmcons.WALMessage_EventDataRoundState{ - EventDataRoundState: &tmproto.EventDataRoundState{ + }, &cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_EventDataRoundState{ + EventDataRoundState: &cmtproto.EventDataRoundState{ Height: 2, Round: 1, Step: "ronies", @@ -234,12 +234,12 @@ func TestWALMsgProto(t *testing.T) { Part: &parts, }, PeerID: p2p.ID("string"), - }, &tmcons.WALMessage{ - Sum: &tmcons.WALMessage_MsgInfo{ - MsgInfo: &tmcons.MsgInfo{ - Msg: tmcons.Message{ - Sum: &tmcons.Message_BlockPart{ - BlockPart: &tmcons.BlockPart{ + }, &cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_MsgInfo{ + MsgInfo: &cmtcons.MsgInfo{ + Msg: cmtcons.Message{ + Sum: &cmtcons.Message_BlockPart{ + BlockPart: &cmtcons.BlockPart{ Height: 100, Round: 1, Part: *pbParts, @@ -255,9 +255,9 @@ func TestWALMsgProto(t *testing.T) { Height: 1, Round: 1, Step: 1, - }, &tmcons.WALMessage{ - Sum: &tmcons.WALMessage_TimeoutInfo{ - TimeoutInfo: &tmcons.TimeoutInfo{ + }, &cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_TimeoutInfo{ + TimeoutInfo: &cmtcons.TimeoutInfo{ Duration: time.Duration(100), Height: 1, Round: 1, @@ -267,14 +267,14 @@ func TestWALMsgProto(t *testing.T) { }, false}, {"successful EndHeightMessage", EndHeightMessage{ Height: 1, - }, &tmcons.WALMessage{ - Sum: &tmcons.WALMessage_EndHeight{ - EndHeight: &tmcons.EndHeight{ + }, &cmtcons.WALMessage{ + Sum: &cmtcons.WALMessage_EndHeight{ + EndHeight: &cmtcons.EndHeight{ Height: 1, }, }, }, false}, - {"failure", nil, &tmcons.WALMessage{}, true}, + {"failure", nil, &cmtcons.WALMessage{}, true}, } for _, tt := range testsCases { tt := tt @@ -329,7 +329,7 @@ func TestConsMsgsVectors(t *testing.T) { require.NoError(t, err) proposal := types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 1, Round: 1, POLRound: 1, @@ -345,7 +345,7 @@ func TestConsMsgsVectors(t *testing.T) { Height: 1, Round: 0, Timestamp: date, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: bi, } vpb := v.ToProto() @@ -355,47 +355,47 @@ func TestConsMsgsVectors(t *testing.T) { cMsg proto.Message expBytes string }{ - {"NewRoundStep", &tmcons.Message{Sum: &tmcons.Message_NewRoundStep{NewRoundStep: &tmcons.NewRoundStep{ + {"NewRoundStep", &cmtcons.Message{Sum: &cmtcons.Message_NewRoundStep{NewRoundStep: &cmtcons.NewRoundStep{ Height: 1, Round: 1, Step: 1, SecondsSinceStartTime: 1, LastCommitRound: 1, }}}, "0a0a08011001180120012801"}, - {"NewRoundStep Max", &tmcons.Message{Sum: &tmcons.Message_NewRoundStep{NewRoundStep: &tmcons.NewRoundStep{ + {"NewRoundStep Max", &cmtcons.Message{Sum: &cmtcons.Message_NewRoundStep{NewRoundStep: &cmtcons.NewRoundStep{ Height: math.MaxInt64, Round: math.MaxInt32, Step: math.MaxUint32, SecondsSinceStartTime: math.MaxInt64, LastCommitRound: math.MaxInt32, }}}, "0a2608ffffffffffffffff7f10ffffffff0718ffffffff0f20ffffffffffffffff7f28ffffffff07"}, - {"NewValidBlock", &tmcons.Message{Sum: &tmcons.Message_NewValidBlock{ - NewValidBlock: &tmcons.NewValidBlock{ + {"NewValidBlock", &cmtcons.Message{Sum: &cmtcons.Message_NewValidBlock{ + NewValidBlock: &cmtcons.NewValidBlock{ Height: 1, Round: 1, BlockPartSetHeader: pbPsh, BlockParts: pbBits, IsCommit: false}}}, "1231080110011a24080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d22050801120100"}, - {"Proposal", &tmcons.Message{Sum: &tmcons.Message_Proposal{Proposal: &tmcons.Proposal{Proposal: *pbProposal}}}, + {"Proposal", &cmtcons.Message{Sum: &cmtcons.Message_Proposal{Proposal: &cmtcons.Proposal{Proposal: *pbProposal}}}, "1a720a7008201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e"}, - {"ProposalPol", &tmcons.Message{Sum: &tmcons.Message_ProposalPol{ - ProposalPol: &tmcons.ProposalPOL{Height: 1, ProposalPolRound: 1}}}, + {"ProposalPol", &cmtcons.Message{Sum: &cmtcons.Message_ProposalPol{ + ProposalPol: &cmtcons.ProposalPOL{Height: 1, ProposalPolRound: 1}}}, "2206080110011a00"}, - {"BlockPart", &tmcons.Message{Sum: &tmcons.Message_BlockPart{ - BlockPart: &tmcons.BlockPart{Height: 1, Round: 1, Part: *pbParts}}}, + {"BlockPart", &cmtcons.Message{Sum: &cmtcons.Message_BlockPart{ + BlockPart: &cmtcons.BlockPart{Height: 1, Round: 1, Part: *pbParts}}}, "2a36080110011a3008011204746573741a26080110011a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d"}, - {"Vote", &tmcons.Message{Sum: &tmcons.Message_Vote{ - Vote: &tmcons.Vote{Vote: vpb}}}, + {"Vote", &cmtcons.Message{Sum: &cmtcons.Message_Vote{ + Vote: &cmtcons.Vote{Vote: vpb}}}, "32700a6e0802100122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a0608c0b89fdc0532146164645f6d6f72655f6578636c616d6174696f6e3801"}, - {"HasVote", &tmcons.Message{Sum: &tmcons.Message_HasVote{ - HasVote: &tmcons.HasVote{Height: 1, Round: 1, Type: tmproto.PrevoteType, Index: 1}}}, + {"HasVote", &cmtcons.Message{Sum: &cmtcons.Message_HasVote{ + HasVote: &cmtcons.HasVote{Height: 1, Round: 1, Type: cmtproto.PrevoteType, Index: 1}}}, "3a080801100118012001"}, - {"HasVote", &tmcons.Message{Sum: &tmcons.Message_HasVote{ - HasVote: &tmcons.HasVote{Height: math.MaxInt64, Round: math.MaxInt32, - Type: tmproto.PrevoteType, Index: math.MaxInt32}}}, + {"HasVote", &cmtcons.Message{Sum: &cmtcons.Message_HasVote{ + HasVote: &cmtcons.HasVote{Height: math.MaxInt64, Round: math.MaxInt32, + Type: cmtproto.PrevoteType, Index: math.MaxInt32}}}, "3a1808ffffffffffffffff7f10ffffffff07180120ffffffff07"}, - {"VoteSetMaj23", &tmcons.Message{Sum: &tmcons.Message_VoteSetMaj23{ - VoteSetMaj23: &tmcons.VoteSetMaj23{Height: 1, Round: 1, Type: tmproto.PrevoteType, BlockID: pbBi}}}, + {"VoteSetMaj23", &cmtcons.Message{Sum: &cmtcons.Message_VoteSetMaj23{ + VoteSetMaj23: &cmtcons.VoteSetMaj23{Height: 1, Round: 1, Type: cmtproto.PrevoteType, BlockID: pbBi}}}, "425008011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d"}, - {"VoteSetBits", &tmcons.Message{Sum: &tmcons.Message_VoteSetBits{ - VoteSetBits: &tmcons.VoteSetBits{Height: 1, Round: 1, Type: tmproto.PrevoteType, BlockID: pbBi, Votes: *pbBits}}}, + {"VoteSetBits", &cmtcons.Message{Sum: &cmtcons.Message_VoteSetBits{ + VoteSetBits: &cmtcons.VoteSetBits{Height: 1, Round: 1, Type: cmtproto.PrevoteType, BlockID: pbBi, Votes: *pbBits}}}, "4a5708011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a050801120100"}, } diff --git a/consensus/reactor.go b/consensus/reactor.go index 6a6d95f38ec..883996c4929 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -9,16 +9,16 @@ import ( cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/libs/bits" - tmevents "github.com/tendermint/tendermint/libs/events" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtevents "github.com/tendermint/tendermint/libs/events" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) const ( @@ -41,7 +41,7 @@ type Reactor struct { conS *State - mtx tmsync.RWMutex + mtx cmtsync.RWMutex waitSync bool eventBus *types.EventBus rs *cstypes.RoundState @@ -144,7 +144,7 @@ func (conR *Reactor) GetChannels() []*p2p.ChannelDescriptor { Priority: 6, SendQueueCapacity: 100, RecvMessageCapacity: maxMsgSize, - MessageType: &tmcons.Message{}, + MessageType: &cmtcons.Message{}, }, { ID: DataChannel, // maybe split between gossiping current block and catchup stuff @@ -153,7 +153,7 @@ func (conR *Reactor) GetChannels() []*p2p.ChannelDescriptor { SendQueueCapacity: 100, RecvBufferCapacity: 50 * 4096, RecvMessageCapacity: maxMsgSize, - MessageType: &tmcons.Message{}, + MessageType: &cmtcons.Message{}, }, { ID: VoteChannel, @@ -161,7 +161,7 @@ func (conR *Reactor) GetChannels() []*p2p.ChannelDescriptor { SendQueueCapacity: 100, RecvBufferCapacity: 100 * 100, RecvMessageCapacity: maxMsgSize, - MessageType: &tmcons.Message{}, + MessageType: &cmtcons.Message{}, }, { ID: VoteSetBitsChannel, @@ -169,7 +169,7 @@ func (conR *Reactor) GetChannels() []*p2p.ChannelDescriptor { SendQueueCapacity: 2, RecvBufferCapacity: 1024, RecvMessageCapacity: maxMsgSize, - MessageType: &tmcons.Message{}, + MessageType: &cmtcons.Message{}, }, } } @@ -284,14 +284,14 @@ func (conR *Reactor) Receive(e p2p.Envelope) { // (and consequently shows which we don't have) var ourVotes *bits.BitArray switch msg.Type { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID) - case tmproto.PrecommitType: + case cmtproto.PrecommitType: ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID) default: panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?") } - eMsg := &tmcons.VoteSetBits{ + eMsg := &cmtcons.VoteSetBits{ Height: msg.Height, Round: msg.Round, Type: msg.Type, @@ -364,9 +364,9 @@ func (conR *Reactor) Receive(e p2p.Envelope) { if height == msg.Height { var ourVotes *bits.BitArray switch msg.Type { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: ourVotes = votes.Prevotes(msg.Round).BitArrayByBlockID(msg.BlockID) - case tmproto.PrecommitType: + case cmtproto.PrecommitType: ourVotes = votes.Precommits(msg.Round).BitArrayByBlockID(msg.BlockID) default: panic("Bad VoteSetBitsMessage field Type. Forgot to add a check in ValidateBasic?") @@ -406,21 +406,21 @@ func (conR *Reactor) WaitSync() bool { func (conR *Reactor) subscribeToBroadcastEvents() { const subscriber = "consensus-reactor" if err := conR.conS.evsw.AddListenerForEvent(subscriber, types.EventNewRoundStep, - func(data tmevents.EventData) { + func(data cmtevents.EventData) { conR.broadcastNewRoundStepMessage(data.(*cstypes.RoundState)) }); err != nil { conR.Logger.Error("Error adding listener for events", "err", err) } if err := conR.conS.evsw.AddListenerForEvent(subscriber, types.EventValidBlock, - func(data tmevents.EventData) { + func(data cmtevents.EventData) { conR.broadcastNewValidBlockMessage(data.(*cstypes.RoundState)) }); err != nil { conR.Logger.Error("Error adding listener for events", "err", err) } if err := conR.conS.evsw.AddListenerForEvent(subscriber, types.EventVote, - func(data tmevents.EventData) { + func(data cmtevents.EventData) { conR.broadcastHasVoteMessage(data.(*types.Vote)) }); err != nil { conR.Logger.Error("Error adding listener for events", "err", err) @@ -443,7 +443,7 @@ func (conR *Reactor) broadcastNewRoundStepMessage(rs *cstypes.RoundState) { func (conR *Reactor) broadcastNewValidBlockMessage(rs *cstypes.RoundState) { psh := rs.ProposalBlockParts.Header() - csMsg := &tmcons.NewValidBlock{ + csMsg := &cmtcons.NewValidBlock{ Height: rs.Height, Round: rs.Round, BlockPartSetHeader: psh.ToProto(), @@ -458,7 +458,7 @@ func (conR *Reactor) broadcastNewValidBlockMessage(rs *cstypes.RoundState) { // Broadcasts HasVoteMessage to peers that care. func (conR *Reactor) broadcastHasVoteMessage(vote *types.Vote) { - msg := &tmcons.HasVote{ + msg := &cmtcons.HasVote{ Height: vote.Height, Round: vote.Round, Type: vote.Type, @@ -492,8 +492,8 @@ func (conR *Reactor) broadcastHasVoteMessage(vote *types.Vote) { */ } -func makeRoundStepMessage(rs *cstypes.RoundState) (nrsMsg *tmcons.NewRoundStep) { - nrsMsg = &tmcons.NewRoundStep{ +func makeRoundStepMessage(rs *cstypes.RoundState) (nrsMsg *cmtcons.NewRoundStep) { + nrsMsg = &cmtcons.NewRoundStep{ Height: rs.Height, Round: rs.Round, Step: uint32(rs.Step), @@ -555,7 +555,7 @@ OUTER_LOOP: logger.Debug("Sending block part", "height", prs.Height, "round", prs.Round) if peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.BlockPart{ + Message: &cmtcons.BlockPart{ Height: rs.Height, // This tells peer that this part applies to us. Round: rs.Round, // This tells peer that this part applies to us. Part: *parts, @@ -609,7 +609,7 @@ OUTER_LOOP: logger.Debug("Sending proposal", "height", prs.Height, "round", prs.Round) if peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.Proposal{Proposal: *rs.Proposal.ToProto()}, + Message: &cmtcons.Proposal{Proposal: *rs.Proposal.ToProto()}, }) { // NOTE[ZM]: A peer might have received different proposal msg so this Proposal msg will be rejected! ps.SetHasProposal(rs.Proposal) @@ -623,7 +623,7 @@ OUTER_LOOP: logger.Debug("Sending POL", "height", prs.Height, "round", prs.Round) peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.ProposalPOL{ + Message: &cmtcons.ProposalPOL{ Height: rs.Height, ProposalPolRound: rs.Proposal.POLRound, ProposalPol: *rs.Votes.Prevotes(rs.Proposal.POLRound).BitArray().ToProto(), @@ -673,7 +673,7 @@ func (conR *Reactor) gossipDataForCatchup(logger log.Logger, rs *cstypes.RoundSt } if peer.Send(p2p.Envelope{ ChannelID: DataChannel, - Message: &tmcons.BlockPart{ + Message: &cmtcons.BlockPart{ Height: prs.Height, // Not our height, so it doesn't matter. Round: prs.Round, // Not our height, so it doesn't matter. Part: *pp, @@ -840,10 +840,10 @@ OUTER_LOOP: peer.TrySend(p2p.Envelope{ ChannelID: StateChannel, - Message: &tmcons.VoteSetMaj23{ + Message: &cmtcons.VoteSetMaj23{ Height: prs.Height, Round: prs.Round, - Type: tmproto.PrevoteType, + Type: cmtproto.PrevoteType, BlockID: maj23.ToProto(), }, }) @@ -860,10 +860,10 @@ OUTER_LOOP: if maj23, ok := rs.Votes.Precommits(prs.Round).TwoThirdsMajority(); ok { peer.TrySend(p2p.Envelope{ ChannelID: StateChannel, - Message: &tmcons.VoteSetMaj23{ + Message: &cmtcons.VoteSetMaj23{ Height: prs.Height, Round: prs.Round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: maj23.ToProto(), }, }) @@ -881,10 +881,10 @@ OUTER_LOOP: peer.TrySend(p2p.Envelope{ ChannelID: StateChannel, - Message: &tmcons.VoteSetMaj23{ + Message: &cmtcons.VoteSetMaj23{ Height: prs.Height, Round: prs.ProposalPOLRound, - Type: tmproto.PrevoteType, + Type: cmtproto.PrevoteType, BlockID: maj23.ToProto(), }, }) @@ -904,10 +904,10 @@ OUTER_LOOP: if commit := conR.conS.LoadCommit(prs.Height); commit != nil { peer.TrySend(p2p.Envelope{ ChannelID: StateChannel, - Message: &tmcons.VoteSetMaj23{ + Message: &cmtcons.VoteSetMaj23{ Height: prs.Height, Round: commit.Round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: commit.BlockID.ToProto(), }, }) @@ -1058,7 +1058,7 @@ func (ps *PeerState) ToJSON() ([]byte, error) { ps.mtx.Lock() defer ps.mtx.Unlock() - return tmjson.Marshal(ps) + return cmtjson.Marshal(ps) } // GetHeight returns an atomic snapshot of the PeerRoundState's height @@ -1127,7 +1127,7 @@ func (ps *PeerState) PickSendVote(votes types.VoteSetReader) bool { ps.logger.Debug("Sending vote message", "ps", ps, "vote", vote) if ps.peer.Send(p2p.Envelope{ ChannelID: VoteChannel, - Message: &tmcons.Vote{ + Message: &cmtcons.Vote{ Vote: vote.ToProto(), }, }) { @@ -1151,7 +1151,7 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote } height, round, votesType, size := - votes.GetHeight(), votes.GetRound(), tmproto.SignedMsgType(votes.Type()), votes.Size() + votes.GetHeight(), votes.GetRound(), cmtproto.SignedMsgType(votes.Type()), votes.Size() // Lazily set data using 'votes'. if votes.IsCommit() { @@ -1169,7 +1169,7 @@ func (ps *PeerState) PickVoteToSend(votes types.VoteSetReader) (vote *types.Vote return nil, false } -func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType tmproto.SignedMsgType) *bits.BitArray { +func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType cmtproto.SignedMsgType) *bits.BitArray { if !types.IsVoteTypeValid(votesType) { return nil } @@ -1177,25 +1177,25 @@ func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType tmprot if ps.PRS.Height == height { if ps.PRS.Round == round { switch votesType { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return ps.PRS.Prevotes - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return ps.PRS.Precommits } } if ps.PRS.CatchupCommitRound == round { switch votesType { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return nil - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return ps.PRS.CatchupCommit } } if ps.PRS.ProposalPOLRound == round { switch votesType { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return ps.PRS.ProposalPOL - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return nil } } @@ -1204,9 +1204,9 @@ func (ps *PeerState) getVoteBitArray(height int64, round int32, votesType tmprot if ps.PRS.Height == height+1 { if ps.PRS.LastCommitRound == round { switch votesType { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return nil - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return ps.PRS.LastCommit } } @@ -1321,7 +1321,7 @@ func (ps *PeerState) SetHasVote(vote *types.Vote) { ps.setHasVote(vote.Height, vote.Round, vote.Type, vote.ValidatorIndex) } -func (ps *PeerState) setHasVote(height int64, round int32, voteType tmproto.SignedMsgType, index int32) { +func (ps *PeerState) setHasVote(height int64, round int32, voteType cmtproto.SignedMsgType, index int32) { ps.logger.Debug("setHasVote", "peerH/R", log.NewLazySprintf("%d/%d", ps.PRS.Height, ps.PRS.Round), @@ -1353,7 +1353,7 @@ func (ps *PeerState) ApplyNewRoundStepMessage(msg *NewRoundStepMessage) { psCatchupCommit := ps.PRS.CatchupCommit lastPrecommits := ps.PRS.Precommits - startTime := tmtime.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second) + startTime := cmttime.Now().Add(-1 * time.Duration(msg.SecondsSinceStartTime) * time.Second) ps.PRS.Height = msg.Height ps.PRS.Round = msg.Round ps.PRS.Step = msg.Step @@ -1486,15 +1486,15 @@ type Message interface { } func init() { - tmjson.RegisterType(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage") - tmjson.RegisterType(&NewValidBlockMessage{}, "tendermint/NewValidBlockMessage") - tmjson.RegisterType(&ProposalMessage{}, "tendermint/Proposal") - tmjson.RegisterType(&ProposalPOLMessage{}, "tendermint/ProposalPOL") - tmjson.RegisterType(&BlockPartMessage{}, "tendermint/BlockPart") - tmjson.RegisterType(&VoteMessage{}, "tendermint/Vote") - tmjson.RegisterType(&HasVoteMessage{}, "tendermint/HasVote") - tmjson.RegisterType(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23") - tmjson.RegisterType(&VoteSetBitsMessage{}, "tendermint/VoteSetBits") + cmtjson.RegisterType(&NewRoundStepMessage{}, "tendermint/NewRoundStepMessage") + cmtjson.RegisterType(&NewValidBlockMessage{}, "tendermint/NewValidBlockMessage") + cmtjson.RegisterType(&ProposalMessage{}, "tendermint/Proposal") + cmtjson.RegisterType(&ProposalPOLMessage{}, "tendermint/ProposalPOL") + cmtjson.RegisterType(&BlockPartMessage{}, "tendermint/BlockPart") + cmtjson.RegisterType(&VoteMessage{}, "tendermint/Vote") + cmtjson.RegisterType(&HasVoteMessage{}, "tendermint/HasVote") + cmtjson.RegisterType(&VoteSetMaj23Message{}, "tendermint/VoteSetMaj23") + cmtjson.RegisterType(&VoteSetBitsMessage{}, "tendermint/VoteSetBits") } //------------------------------------- @@ -1699,7 +1699,7 @@ func (m *VoteMessage) String() string { type HasVoteMessage struct { Height int64 Round int32 - Type tmproto.SignedMsgType + Type cmtproto.SignedMsgType Index int32 } @@ -1731,7 +1731,7 @@ func (m *HasVoteMessage) String() string { type VoteSetMaj23Message struct { Height int64 Round int32 - Type tmproto.SignedMsgType + Type cmtproto.SignedMsgType BlockID types.BlockID } @@ -1763,7 +1763,7 @@ func (m *VoteSetMaj23Message) String() string { type VoteSetBitsMessage struct { Height int64 Round int32 - Type tmproto.SignedMsgType + Type cmtproto.SignedMsgType BlockID types.BlockID Votes *bits.BitArray } diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index f0cdc5f9dd3..62858c0e4d0 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -27,14 +27,14 @@ import ( "github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" mempl "github.com/tendermint/tendermint/mempool" mempoolv0 "github.com/tendermint/tendermint/mempool/v0" mempoolv1 "github.com/tendermint/tendermint/mempool/v1" "github.com/tendermint/tendermint/p2p" p2pmock "github.com/tendermint/tendermint/p2p/mock" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" statemocks "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/store" @@ -55,7 +55,7 @@ func startConsensusNet(t *testing.T, css []*State, n int) ( blocksSubs := make([]types.Subscription, 0) eventBuses := make([]*types.EventBus, n) for i := 0; i < n; i++ { - /*logger, err := tmflags.ParseLogLevel("consensus:info,*:error", logger, "info") + /*logger, err := cmtflags.ParseLogLevel("consensus:info,*:error", logger, "info") if err != nil { t.Fatal(err)}*/ reactors[i] = NewReactor(css[i], true) // so we dont start the consensus states reactors[i].SetLogger(css[i].Logger) @@ -157,7 +157,7 @@ func TestReactorWithEvidence(t *testing.T) { blockDB := dbm.NewMemDB() blockStore := store.NewBlockStore(blockDB) - mtx := new(tmsync.Mutex) + mtx := new(cmtsync.Mutex) memplMetrics := mempl.NopMetrics() // one for mempool, one for consensus proxyAppConnCon := abcicli.NewLocalClient(mtx, app) @@ -275,8 +275,8 @@ func TestReactorReceiveDoesNotPanicIfAddPeerHasntBeenCalledYet(t *testing.T) { reactor.Receive(p2p.Envelope{ ChannelID: StateChannel, Src: peer, - Message: &tmcons.HasVote{Height: 1, - Round: 1, Index: 1, Type: tmproto.PrevoteType}, + Message: &cmtcons.HasVote{Height: 1, + Round: 1, Index: 1, Type: cmtproto.PrevoteType}, }) reactor.AddPeer(peer) }) @@ -301,8 +301,8 @@ func TestReactorReceivePanicsIfInitPeerHasntBeenCalledYet(t *testing.T) { reactor.Receive(p2p.Envelope{ ChannelID: StateChannel, Src: peer, - Message: &tmcons.HasVote{Height: 1, - Round: 1, Index: 1, Type: tmproto.PrevoteType}, + Message: &cmtcons.HasVote{Height: 1, + Round: 1, Index: 1, Type: cmtproto.PrevoteType}, }) }) } @@ -884,8 +884,8 @@ func TestBlockPartMessageValidateBasic(t *testing.T) { func TestHasVoteMessageValidateBasic(t *testing.T) { const ( - validSignedMsgType tmproto.SignedMsgType = 0x01 - invalidSignedMsgType tmproto.SignedMsgType = 0x03 + validSignedMsgType cmtproto.SignedMsgType = 0x01 + invalidSignedMsgType cmtproto.SignedMsgType = 0x03 ) testCases := []struct { //nolint: maligned @@ -894,7 +894,7 @@ func TestHasVoteMessageValidateBasic(t *testing.T) { messageIndex int32 messageHeight int64 testName string - messageType tmproto.SignedMsgType + messageType cmtproto.SignedMsgType }{ {false, 0, 0, 0, "Valid Message", validSignedMsgType}, {true, -1, 0, 0, "Invalid Message", validSignedMsgType}, @@ -920,8 +920,8 @@ func TestHasVoteMessageValidateBasic(t *testing.T) { func TestVoteSetMaj23MessageValidateBasic(t *testing.T) { const ( - validSignedMsgType tmproto.SignedMsgType = 0x01 - invalidSignedMsgType tmproto.SignedMsgType = 0x03 + validSignedMsgType cmtproto.SignedMsgType = 0x01 + invalidSignedMsgType cmtproto.SignedMsgType = 0x03 ) validBlockID := types.BlockID{} @@ -938,7 +938,7 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) { messageRound int32 messageHeight int64 testName string - messageType tmproto.SignedMsgType + messageType cmtproto.SignedMsgType messageBlockID types.BlockID }{ {false, 0, 0, "Valid Message", validSignedMsgType, validBlockID}, diff --git a/consensus/replay_file.go b/consensus/replay_file.go index c342c32bde7..64f5164470b 100644 --- a/consensus/replay_file.go +++ b/consensus/replay_file.go @@ -14,7 +14,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" @@ -34,7 +34,7 @@ func RunReplayFile(config cfg.BaseConfig, csConfig *cfg.ConsensusConfig, console consensusState := newConsensusStateForReplay(config, csConfig) if err := consensusState.ReplayFile(csConfig.WalFile(), console); err != nil { - tmos.Exit(fmt.Sprintf("Error during consensus replay: %v", err)) + cmtos.Exit(fmt.Sprintf("Error during consensus replay: %v", err)) } } @@ -185,9 +185,9 @@ func (pb *playback) replayConsoleLoop() int { bufReader := bufio.NewReader(os.Stdin) line, more, err := bufReader.ReadLine() if more { - tmos.Exit("input is too long") + cmtos.Exit("input is too long") } else if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } tokens := strings.Split(string(line), " ") @@ -222,7 +222,7 @@ func (pb *playback) replayConsoleLoop() int { newStepSub, err := pb.cs.eventBus.Subscribe(ctx, subscriber, types.EventQueryNewRoundStep) if err != nil { - tmos.Exit(fmt.Sprintf("failed to subscribe %s to %v", subscriber, types.EventQueryNewRoundStep)) + cmtos.Exit(fmt.Sprintf("failed to subscribe %s to %v", subscriber, types.EventQueryNewRoundStep)) } defer func() { if err := pb.cs.eventBus.Unsubscribe(ctx, subscriber, types.EventQueryNewRoundStep); err != nil { @@ -288,25 +288,25 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo // Get BlockStore blockStoreDB, err := dbm.NewDB("blockstore", dbType, config.DBDir()) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } blockStore := store.NewBlockStore(blockStoreDB) // Get State stateDB, err := dbm.NewDB("state", dbType, config.DBDir()) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } stateStore := sm.NewStore(stateDB, sm.StoreOptions{ DiscardABCIResponses: false, }) gdoc, err := sm.MakeGenesisDocFromFile(config.GenesisFile()) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } state, err := sm.MakeGenesisState(gdoc) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } // Create proxyAppConn connection (consensus, mempool, query) @@ -314,19 +314,19 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo proxyApp := proxy.NewAppConns(clientCreator, proxy.NopMetrics()) err = proxyApp.Start() if err != nil { - tmos.Exit(fmt.Sprintf("Error starting proxy app conns: %v", err)) + cmtos.Exit(fmt.Sprintf("Error starting proxy app conns: %v", err)) } eventBus := types.NewEventBus() if err := eventBus.Start(); err != nil { - tmos.Exit(fmt.Sprintf("Failed to start event bus: %v", err)) + cmtos.Exit(fmt.Sprintf("Failed to start event bus: %v", err)) } handshaker := NewHandshaker(stateStore, state, blockStore, gdoc) handshaker.SetEventBus(eventBus) err = handshaker.Handshake(proxyApp) if err != nil { - tmos.Exit(fmt.Sprintf("Error on handshake: %v", err)) + cmtos.Exit(fmt.Sprintf("Error on handshake: %v", err)) } mempool, evpool := emptyMempool{}, sm.EmptyEvidencePool{} diff --git a/consensus/replay_stubs.go b/consensus/replay_stubs.go index aa74f942059..a40fe2b5a7f 100644 --- a/consensus/replay_stubs.go +++ b/consensus/replay_stubs.go @@ -4,7 +4,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/clist" mempl "github.com/tendermint/tendermint/mempool" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" ) @@ -56,7 +56,7 @@ func (emptyMempool) CloseWAL() {} // Useful because we don't want to call Commit() twice for the same block on // the real app. -func newMockProxyApp(appHash []byte, abciResponses *tmstate.ABCIResponses) proxy.AppConnConsensus { +func newMockProxyApp(appHash []byte, abciResponses *cmtstate.ABCIResponses) proxy.AppConnConsensus { clientCreator := proxy.NewLocalClientCreator(&mockProxyApp{ appHash: appHash, abciResponses: abciResponses, @@ -74,7 +74,7 @@ type mockProxyApp struct { appHash []byte txCount int - abciResponses *tmstate.ABCIResponses + abciResponses *cmtstate.ABCIResponses } func (mock *mockProxyApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { diff --git a/consensus/replay_test.go b/consensus/replay_test.go index f4c4e14e8cf..d604378ea69 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -24,11 +24,11 @@ import ( cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" mempl "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/privval" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -352,7 +352,7 @@ func TestSimulateValidatorsChange(t *testing.T) { ensureNewRound(newRoundCh, height, 0) ensureNewProposal(proposalCh, height, round) rs := css[0].GetRoundState() - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) ensureNewRound(newRoundCh, height+1, 0) // HEIGHT 2 @@ -384,7 +384,7 @@ func TestSimulateValidatorsChange(t *testing.T) { } ensureNewProposal(proposalCh, height, round) rs = css[0].GetRoundState() - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) ensureNewRound(newRoundCh, height+1, 0) // HEIGHT 3 @@ -416,7 +416,7 @@ func TestSimulateValidatorsChange(t *testing.T) { } ensureNewProposal(proposalCh, height, round) rs = css[0].GetRoundState() - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:nVals]...) ensureNewRound(newRoundCh, height+1, 0) // HEIGHT 4 @@ -484,7 +484,7 @@ func TestSimulateValidatorsChange(t *testing.T) { if i == selfIndex { continue } - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) } ensureNewRound(newRoundCh, height+1, 0) @@ -503,7 +503,7 @@ func TestSimulateValidatorsChange(t *testing.T) { if i == selfIndex { continue } - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) } ensureNewRound(newRoundCh, height+1, 0) @@ -540,7 +540,7 @@ func TestSimulateValidatorsChange(t *testing.T) { if i == selfIndex { continue } - signAddVotes(css[0], tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) + signAddVotes(css[0], cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), newVss[i]) } ensureNewRound(newRoundCh, height+1, 0) @@ -600,14 +600,14 @@ func TestMockProxyApp(t *testing.T) { txIndex := 0 assert.NotPanics(t, func() { - abciResWithEmptyDeliverTx := new(tmstate.ABCIResponses) + abciResWithEmptyDeliverTx := new(cmtstate.ABCIResponses) abciResWithEmptyDeliverTx.DeliverTxs = make([]*abci.ResponseDeliverTx, 0) abciResWithEmptyDeliverTx.DeliverTxs = append(abciResWithEmptyDeliverTx.DeliverTxs, &abci.ResponseDeliverTx{}) // called when saveABCIResponses: bytes, err := proto.Marshal(abciResWithEmptyDeliverTx) require.NoError(t, err) - loadedAbciRes := new(tmstate.ABCIResponses) + loadedAbciRes := new(cmtstate.ABCIResponses) // this also happens sm.LoadABCIResponses err = proto.Unmarshal(bytes, loadedAbciRes) @@ -615,7 +615,7 @@ func TestMockProxyApp(t *testing.T) { mock := newMockProxyApp([]byte("mock_hash"), loadedAbciRes) - abciRes := new(tmstate.ABCIResponses) + abciRes := new(cmtstate.ABCIResponses) abciRes.DeliverTxs = make([]*abci.ResponseDeliverTx, len(loadedAbciRes.DeliverTxs)) // Execute transactions and get hash. proxyCb := func(req *abci.Request, res *abci.Response) { @@ -979,11 +979,11 @@ func (app *badApp) Commit() abci.ResponseCommit { app.height++ if app.onlyLastHashIsWrong { if app.height == app.numBlocks { - return abci.ResponseCommit{Data: tmrand.Bytes(8)} + return abci.ResponseCommit{Data: cmtrand.Bytes(8)} } return abci.ResponseCommit{Data: []byte{app.height}} } else if app.allHashesAreWrong { - return abci.ResponseCommit{Data: tmrand.Bytes(8)} + return abci.ResponseCommit{Data: cmtrand.Bytes(8)} } panic("either allHashesAreWrong or onlyLastHashIsWrong must be set") @@ -1032,7 +1032,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) { case EndHeightMessage: // if its not the first one, we have a full block if thisBlockParts != nil { - var pbb = new(tmproto.Block) + var pbb = new(cmtproto.Block) bz, err := io.ReadAll(thisBlockParts.GetReader()) if err != nil { panic(err) @@ -1065,7 +1065,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) { return nil, nil, err } case *types.Vote: - if p.Type == tmproto.PrecommitType { + if p.Type == cmtproto.PrecommitType { thisBlockCommit = types.NewCommit(p.Height, p.Round, p.BlockID, []types.CommitSig{p.CommitSig()}) } @@ -1076,7 +1076,7 @@ func makeBlockchainFromWAL(wal WAL) ([]*types.Block, []*types.Commit, error) { if err != nil { panic(err) } - var pbb = new(tmproto.Block) + var pbb = new(cmtproto.Block) err = proto.Unmarshal(bz, pbb) if err != nil { panic(err) diff --git a/consensus/state.go b/consensus/state.go index b1b64d7ef04..93a9f735bf7 100644 --- a/consensus/state.go +++ b/consensus/state.go @@ -15,19 +15,19 @@ import ( cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/crypto" - tmevents "github.com/tendermint/tendermint/libs/events" + cmtevents "github.com/tendermint/tendermint/libs/events" "github.com/tendermint/tendermint/libs/fail" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmos "github.com/tendermint/tendermint/libs/os" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) // Consensus sentinel errors @@ -96,7 +96,7 @@ type State struct { evpool evidencePool // internal state - mtx tmsync.RWMutex + mtx cmtsync.RWMutex cstypes.RoundState state sm.State // State until height-1. // privValidator pubkey, memoized for the duration of one block @@ -136,7 +136,7 @@ type State struct { // synchronous pubsub between consensus state and reactor. // state only emits EventNewRoundStep and EventVote - evsw tmevents.EventSwitch + evsw cmtevents.EventSwitch // for reporting metrics metrics *Metrics @@ -168,7 +168,7 @@ func NewState( doWALCatchup: true, wal: nilWAL{}, evpool: evpool, - evsw: tmevents.NewEventSwitch(), + evsw: cmtevents.NewEventSwitch(), metrics: NopMetrics(), } @@ -244,14 +244,14 @@ func (cs *State) GetRoundState() *cstypes.RoundState { func (cs *State) GetRoundStateJSON() ([]byte, error) { cs.mtx.RLock() defer cs.mtx.RUnlock() - return tmjson.Marshal(cs.RoundState) + return cmtjson.Marshal(cs.RoundState) } // GetRoundStateSimpleJSON returns a json of RoundStateSimple func (cs *State) GetRoundStateSimpleJSON() ([]byte, error) { cs.mtx.RLock() defer cs.mtx.RUnlock() - return tmjson.Marshal(cs.RoundState.RoundStateSimple()) + return cmtjson.Marshal(cs.RoundState.RoundStateSimple()) } // GetValidators returns a copy of the current validators. @@ -345,7 +345,7 @@ func (cs *State) OnStart() error { // 2) backup original WAL file corruptedFile := fmt.Sprintf("%s.CORRUPTED", cs.config.WalFile()) - if err := tmos.CopyFile(cs.config.WalFile(), corruptedFile); err != nil { + if err := cmtos.CopyFile(cs.config.WalFile(), corruptedFile); err != nil { return err } @@ -537,8 +537,8 @@ func (cs *State) updateRoundStep(round int32, step cstypes.RoundStepType) { // enterNewRound(height, 0) at cs.StartTime. func (cs *State) scheduleRound0(rs *cstypes.RoundState) { - // cs.Logger.Info("scheduleRound0", "now", tmtime.Now(), "startTime", cs.StartTime) - sleepDuration := rs.StartTime.Sub(tmtime.Now()) + // cs.Logger.Info("scheduleRound0", "now", cmttime.Now(), "startTime", cs.StartTime) + sleepDuration := rs.StartTime.Sub(cmttime.Now()) cs.scheduleTimeout(sleepDuration, rs.Height, 0, cstypes.RoundStepNewHeight) } @@ -663,7 +663,7 @@ func (cs *State) updateToState(state sm.State) { // to be gathered for the first block. // And alternative solution that relies on clocks: // cs.StartTime = state.LastBlockTime.Add(timeoutCommit) - cs.StartTime = cs.config.Commit(tmtime.Now()) + cs.StartTime = cs.config.Commit(cmttime.Now()) } else { cs.StartTime = cs.config.Commit(cs.CommitTime) } @@ -965,7 +965,7 @@ func (cs *State) handleTxsAvailable() { } // +1ms to ensure RoundStepNewRound timeout always happens after RoundStepNewHeight - timeoutCommit := cs.StartTime.Sub(tmtime.Now()) + 1*time.Millisecond + timeoutCommit := cs.StartTime.Sub(cmttime.Now()) + 1*time.Millisecond cs.scheduleTimeout(timeoutCommit, cs.Height, 0, cstypes.RoundStepNewRound) case cstypes.RoundStepNewRound: // after timeoutCommit @@ -996,7 +996,7 @@ func (cs *State) enterNewRound(height int64, round int32) { return } - if now := tmtime.Now(); cs.StartTime.After(now) { + if now := cmttime.Now(); cs.StartTime.After(now) { logger.Debug("need to set a buffer and log message here for sanity", "start_time", cs.StartTime, "now", now) } @@ -1006,7 +1006,7 @@ func (cs *State) enterNewRound(height int64, round int32) { validators := cs.Validators if cs.Round < round { validators = validators.Copy() - validators.IncrementProposerPriority(tmmath.SafeSubInt32(round, cs.Round)) + validators.IncrementProposerPriority(cmtmath.SafeSubInt32(round, cs.Round)) } // Setup new round @@ -1025,7 +1025,7 @@ func (cs *State) enterNewRound(height int64, round int32) { cs.ProposalBlockParts = nil } - cs.Votes.SetRound(tmmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping + cs.Votes.SetRound(cmtmath.SafeAddInt32(round, 1)) // also track next round (round+1) to allow round-skipping cs.TriggeredTimeoutPrecommit = false if err := cs.eventBus.PublishEventNewRound(cs.NewRoundEvent()); err != nil { @@ -1277,14 +1277,14 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { // If a block is locked, prevote that. if cs.LockedBlock != nil { logger.Debug("prevote step; already locked on a block; prevoting locked block") - cs.signAddVote(tmproto.PrevoteType, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header()) + cs.signAddVote(cmtproto.PrevoteType, cs.LockedBlock.Hash(), cs.LockedBlockParts.Header()) return } // If ProposalBlock is nil, prevote nil. if cs.ProposalBlock == nil { logger.Debug("prevote step: ProposalBlock is nil") - cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrevoteType, nil, types.PartSetHeader{}) return } @@ -1294,7 +1294,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { // ProposalBlock is invalid, prevote nil. logger.Error("prevote step: consensus deems this block invalid; prevoting nil", "err", err) - cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrevoteType, nil, types.PartSetHeader{}) return } @@ -1319,7 +1319,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { if !isAppValid { logger.Error("prevote step: state machine rejected a proposed block; this should not happen:"+ "the proposer may be misbehaving; prevoting nil", "err", err) - cs.signAddVote(tmproto.PrevoteType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrevoteType, nil, types.PartSetHeader{}) return } @@ -1327,7 +1327,7 @@ func (cs *State) defaultDoPrevote(height int64, round int32) { // NOTE: the proposal signature is validated when it is received, // and the proposal block parts are validated as they are received (against the merkle hash in the proposal) logger.Debug("prevote step: ProposalBlock is valid") - cs.signAddVote(tmproto.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header()) + cs.signAddVote(cmtproto.PrevoteType, cs.ProposalBlock.Hash(), cs.ProposalBlockParts.Header()) } // Enter: any +2/3 prevotes at next round. @@ -1397,7 +1397,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Debug("precommit step; no +2/3 prevotes during enterPrecommit; precommitting nil") } - cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrecommitType, nil, types.PartSetHeader{}) return } @@ -1427,7 +1427,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { } } - cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrecommitType, nil, types.PartSetHeader{}) return } @@ -1442,7 +1442,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Error("failed publishing event relock", "err", err) } - cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader) + cs.signAddVote(cmtproto.PrecommitType, blockID.Hash, blockID.PartSetHeader) return } @@ -1463,7 +1463,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Error("failed publishing event lock", "err", err) } - cs.signAddVote(tmproto.PrecommitType, blockID.Hash, blockID.PartSetHeader) + cs.signAddVote(cmtproto.PrecommitType, blockID.Hash, blockID.PartSetHeader) return } @@ -1485,7 +1485,7 @@ func (cs *State) enterPrecommit(height int64, round int32) { logger.Error("failed publishing event unlock", "err", err) } - cs.signAddVote(tmproto.PrecommitType, nil, types.PartSetHeader{}) + cs.signAddVote(cmtproto.PrecommitType, nil, types.PartSetHeader{}) } // Enter: any +2/3 precommits for next round. @@ -1539,7 +1539,7 @@ func (cs *State) enterCommit(height int64, commitRound int32) { // keep cs.Round the same, commitRound points to the right Precommits set. cs.updateRoundStep(cs.Round, cstypes.RoundStepCommit) cs.CommitRound = commitRound - cs.CommitTime = tmtime.Now() + cs.CommitTime = cmttime.Now() cs.newStep() // Maybe finalize immediately. @@ -1910,7 +1910,7 @@ func (cs *State) addProposalBlockPart(msg *BlockPartMessage, peerID p2p.ID) (add return added, err } - var pbb = new(tmproto.Block) + var pbb = new(cmtproto.Block) err = proto.Unmarshal(bz, pbb) if err != nil { return added, err @@ -2032,7 +2032,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error // A precommit for the previous height? // These come in while we wait timeoutCommit - if vote.Height+1 == cs.Height && vote.Type == tmproto.PrecommitType { + if vote.Height+1 == cs.Height && vote.Type == cmtproto.PrecommitType { if cs.Step != cstypes.RoundStepNewHeight { // Late precommit at prior height is ignored cs.Logger.Debug("precommit vote came in after commit timeout and has been ignored", "vote", vote) @@ -2086,7 +2086,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error cs.evsw.FireEvent(types.EventVote, vote) switch vote.Type { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: prevotes := cs.Votes.Prevotes(vote.Round) cs.Logger.Debug("added vote to prevote", "vote", vote, "prevotes", prevotes.StringShort()) @@ -2165,7 +2165,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error } } - case tmproto.PrecommitType: + case cmtproto.PrecommitType: precommits := cs.Votes.Precommits(vote.Round) cs.Logger.Debug("added vote to precommit", "height", vote.Height, @@ -2202,7 +2202,7 @@ func (cs *State) addVote(vote *types.Vote, peerID p2p.ID) (added bool, err error // CONTRACT: cs.privValidator is not nil. func (cs *State) signVote( - msgType tmproto.SignedMsgType, + msgType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader, ) (*types.Vote, error) { @@ -2238,7 +2238,7 @@ func (cs *State) signVote( } func (cs *State) voteTime() time.Time { - now := tmtime.Now() + now := cmttime.Now() minVoteTime := now // Minimum time increment between blocks const timeIota = time.Millisecond @@ -2259,7 +2259,7 @@ func (cs *State) voteTime() time.Time { } // sign the vote and publish on internalMsgQueue -func (cs *State) signAddVote(msgType tmproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote { +func (cs *State) signAddVote(msgType cmtproto.SignedMsgType, hash []byte, header types.PartSetHeader) *types.Vote { if cs.privValidator == nil { // the node does not have a key return nil } diff --git a/consensus/state_test.go b/consensus/state_test.go index e8001513559..678c9b48758 100644 --- a/consensus/state_test.go +++ b/consensus/state_test.go @@ -16,12 +16,12 @@ import ( abcimocks "github.com/tendermint/tendermint/abci/types/mocks" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/crypto/tmhash" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtrand "github.com/tendermint/tendermint/libs/rand" p2pmock "github.com/tendermint/tendermint/p2p/mock" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -84,7 +84,7 @@ func TestStateProposerSelection0(t *testing.T) { ensureNewProposal(proposalCh, height, round) rs := cs1.GetRoundState() - signAddVotes(cs1, tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...) + signAddVotes(cs1, cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vss[1:]...) // Wait for new round so next validator is set. ensureNewRound(newRoundCh, height+1, 0) @@ -128,7 +128,7 @@ func TestStateProposerSelection2(t *testing.T) { } rs := cs1.GetRoundState() - signAddVotes(cs1, tmproto.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...) + signAddVotes(cs1, cmtproto.PrecommitType, nil, rs.ProposalBlockParts.Header(), vss[1:]...) ensureNewRound(newRoundCh, height, i+round+1) // wait for the new round event each round incrementRound(vss[1:]...) } @@ -239,7 +239,7 @@ func TestStateBadProposal(t *testing.T) { bps, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2) ensurePrevote(voteCh, height, round) // wait for precommit @@ -248,7 +248,7 @@ func TestStateBadProposal(t *testing.T) { bps2, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrecommitType, propBlock.Hash(), bps2.Header(), vs2) + signAddVotes(cs1, cmtproto.PrecommitType, propBlock.Hash(), bps2.Header(), vs2) } func TestStateOversizedBlock(t *testing.T) { @@ -264,7 +264,7 @@ func TestStateOversizedBlock(t *testing.T) { propBlock, err := cs1.createProposalBlock() require.NoError(t, err) - propBlock.Data.Txs = []types.Tx{tmrand.Bytes(2001)} + propBlock.Data.Txs = []types.Tx{cmtrand.Bytes(2001)} propBlock.Header.DataHash = propBlock.Data.Hash() // make the second validator the proposer by incrementing round @@ -308,14 +308,14 @@ func TestStateOversizedBlock(t *testing.T) { bps, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2) ensurePrevote(voteCh, height, round) ensurePrecommit(voteCh, height, round) validatePrecommit(t, cs1, round, -1, vss[0], nil, nil) bps2, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrecommitType, propBlock.Hash(), bps2.Header(), vs2) + signAddVotes(cs1, cmtproto.PrecommitType, propBlock.Hash(), bps2.Header(), vs2) } //---------------------------------------------------------------------------------------------------- @@ -398,7 +398,7 @@ func TestStateFullRound2(t *testing.T) { propBlockHash, propPartSetHeader := rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header() // prevote arrives from vs2: - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propPartSetHeader, vs2) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propPartSetHeader, vs2) ensurePrevote(voteCh, height, round) // prevote ensurePrecommit(voteCh, height, round) // precommit @@ -408,7 +408,7 @@ func TestStateFullRound2(t *testing.T) { // we should be stuck in limbo waiting for more precommits // precommit arrives from vs2: - signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propPartSetHeader, vs2) + signAddVotes(cs1, cmtproto.PrecommitType, propBlockHash, propPartSetHeader, vs2) ensurePrecommit(voteCh, height, round) // wait to finish commit, propose in next height @@ -452,7 +452,7 @@ func TestStateLockNoPOL(t *testing.T) { // we should now be stuck in limbo forever, waiting for more prevotes // prevote arrives from vs2: - signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, thePartSetHeader, vs2) + signAddVotes(cs1, cmtproto.PrevoteType, theBlockHash, thePartSetHeader, vs2) ensurePrevote(voteCh, height, round) // prevote ensurePrecommit(voteCh, height, round) // precommit @@ -464,7 +464,7 @@ func TestStateLockNoPOL(t *testing.T) { hash := make([]byte, len(theBlockHash)) copy(hash, theBlockHash) hash[0] = (hash[0] + 1) % 255 - signAddVotes(cs1, tmproto.PrecommitType, hash, thePartSetHeader, vs2) + signAddVotes(cs1, cmtproto.PrecommitType, hash, thePartSetHeader, vs2) ensurePrecommit(voteCh, height, round) // precommit // (note we're entering precommit for a second time this round) @@ -498,7 +498,7 @@ func TestStateLockNoPOL(t *testing.T) { bps, err := rs.LockedBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, hash, bps.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, hash, bps.Header(), vs2) ensurePrevote(voteCh, height, round) // now we're going to enter prevote again, but with invalid args @@ -513,7 +513,7 @@ func TestStateLockNoPOL(t *testing.T) { // add conflicting precommit from vs2 bps2, err := rs.LockedBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrecommitType, hash, bps2.Header(), vs2) + signAddVotes(cs1, cmtproto.PrecommitType, hash, bps2.Header(), vs2) ensurePrecommit(voteCh, height, round) // (note we're entering precommit for a second time this round, but with invalid args @@ -545,7 +545,7 @@ func TestStateLockNoPOL(t *testing.T) { bps0, err := rs.ProposalBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, hash, bps0.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, hash, bps0.Header(), vs2) ensurePrevote(voteCh, height, round) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -557,7 +557,7 @@ func TestStateLockNoPOL(t *testing.T) { require.NoError(t, err) signAddVotes( cs1, - tmproto.PrecommitType, + cmtproto.PrecommitType, hash, bps1.Header(), vs2) // NOTE: conflicting precommits at same height @@ -598,7 +598,7 @@ func TestStateLockNoPOL(t *testing.T) { bps4, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), bps4.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, propBlock.Hash(), bps4.Header(), vs2) ensurePrevote(voteCh, height, round) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -609,7 +609,7 @@ func TestStateLockNoPOL(t *testing.T) { require.NoError(t, err) signAddVotes( cs1, - tmproto.PrecommitType, + cmtproto.PrecommitType, propBlock.Hash(), bps5.Header(), vs2) // NOTE: conflicting precommits at same height @@ -655,14 +655,14 @@ func TestStateLockPOLRelock(t *testing.T) { ensurePrevote(voteCh, height, round) // prevote - signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // our precommit // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash) // add precommits from the rest - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal cs2 := newState(cs1.state, vs2, kvstore.NewApplication()) @@ -705,14 +705,14 @@ func TestStateLockPOLRelock(t *testing.T) { validatePrevote(t, cs1, round, vss[0], theBlockHash) // now lets add prevotes from everyone else for the new block - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // we should have unlocked and locked on the new block, sending a precommit for this new block validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash) // more prevote creating a majority on the new block and this is then committed - signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3) + signAddVotes(cs1, cmtproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3) ensureNewBlockHeader(newBlockCh, height, propBlockHash) ensureNewRound(newRoundCh, height+1, 0) @@ -754,15 +754,15 @@ func TestStateLockPOLUnlock(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], theBlockHash) - signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash) // add precommits from the rest - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) - signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, theBlockHash, theBlockParts, vs3) // before we time out into new round, set next proposal block prop, propBlock := decideProposal(t, cs1, vs2, vs2.Height, vs2.Round+1) @@ -794,7 +794,7 @@ func TestStateLockPOLUnlock(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], lockedBlockHash) // now lets add prevotes from everyone else for nil (a polka!) - signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // the polka makes us unlock and precommit nil ensureNewUnlock(unlockCh, height, round) @@ -804,7 +804,7 @@ func TestStateLockPOLUnlock(t *testing.T) { // NOTE: since we don't relock on nil, the lock round is -1 validatePrecommit(t, cs1, round, -1, vss[0], nil, nil) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3) ensureNewRound(newRoundCh, height, round+1) } @@ -843,14 +843,14 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { ensurePrevote(voteCh, height, round) // prevote - signAddVotes(cs1, tmproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, firstBlockHash, firstBlockParts, vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // our precommit // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], firstBlockHash, firstBlockHash) // add precommits from the rest - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal cs2 := newState(cs1.state, vs2, kvstore.NewApplication()) @@ -885,7 +885,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { validatePrevote(t, cs1, round, vss[0], firstBlockHash) // now lets add prevotes from everyone else for the new block - signAddVotes(cs1, tmproto.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, secondBlockHash, secondBlockParts.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // we should have unlocked and locked on the new block, sending a precommit for this new block @@ -896,7 +896,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { } // more prevote creating a majority on the new block and this is then committed - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // before we timeout to the new round set the new proposal cs3 := newState(cs1.state, vs3, kvstore.NewApplication()) @@ -930,7 +930,7 @@ func TestStateLockPOLUnlockOnUnknownBlock(t *testing.T) { // we are no longer locked to the first block so we should be able to prevote validatePrevote(t, cs1, round, vss[0], thirdPropBlockHash) - signAddVotes(cs1, tmproto.PrevoteType, thirdPropBlockHash, thirdPropBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, thirdPropBlockHash, thirdPropBlockParts.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // we have a majority, now vs1 can change lock to the third block @@ -972,12 +972,12 @@ func TestStateLockPOLSafety1(t *testing.T) { bps, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - prevotes := signVotes(tmproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2, vs3, vs4) + prevotes := signVotes(cmtproto.PrevoteType, propBlock.Hash(), bps.Header(), vs2, vs3, vs4) t.Logf("old prop hash %v", fmt.Sprintf("%X", propBlock.Hash())) // we do see them precommit nil - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) // cs1 precommit nil ensurePrecommit(voteCh, height, round) @@ -1018,13 +1018,13 @@ func TestStateLockPOLSafety1(t *testing.T) { validatePrevote(t, cs1, round, vss[0], propBlockHash) // now we see the others prevote for it, so we should lock on it - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // we should have precommitted validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1089,7 +1089,7 @@ func TestStateLockPOLSafety2(t *testing.T) { propBlockID0 := types.BlockID{Hash: propBlockHash0, PartSetHeader: propBlockParts0.Header()} // the others sign a polka but we don't see it - prevotes := signVotes(tmproto.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4) + prevotes := signVotes(cmtproto.PrevoteType, propBlockHash0, propBlockParts0.Header(), vs2, vs3, vs4) // the block for round 1 prop1, propBlock1 := decideProposal(t, cs1, vs2, vs2.Height, vs2.Round+1) @@ -1113,15 +1113,15 @@ func TestStateLockPOLSafety2(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], propBlockHash1) - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash1, propBlockParts1.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], propBlockHash1, propBlockHash1) // add precommits from the rest - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) - signAddVotes(cs1, tmproto.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, propBlockHash1, propBlockParts1.Header(), vs3) incrementRound(vs2, vs3, vs4) @@ -1195,13 +1195,13 @@ func TestProposeValidBlock(t *testing.T) { // the others sign a polka bps, err := propBlock.MakePartSet(partSize) require.NoError(t, err) - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, bps.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, bps.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // we should have precommitted validatePrecommit(t, cs1, round, round, vss[0], propBlockHash, propBlockHash) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) @@ -1218,7 +1218,7 @@ func TestProposeValidBlock(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], propBlockHash) - signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) ensureNewUnlock(unlockCh, height, round) @@ -1229,7 +1229,7 @@ func TestProposeValidBlock(t *testing.T) { incrementRound(vs2, vs3, vs4) incrementRound(vs2, vs3, vs4) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) round += 2 // moving to the next round @@ -1286,10 +1286,10 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { validatePrevote(t, cs1, round, vss[0], propBlockHash) // vs2 send prevote for propBlock - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2) // vs3 send prevote nil - signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs3) + signAddVotes(cs1, cmtproto.PrevoteType, nil, types.PartSetHeader{}, vs3) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -1304,7 +1304,7 @@ func TestSetValidBlockOnDelayedPrevote(t *testing.T) { assert.True(t, rs.ValidRound == -1) // vs2 send (delayed) prevote for propBlock - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs4) ensureNewValidBlock(validBlockCh, height, round) @@ -1352,7 +1352,7 @@ func TestSetValidBlockOnDelayedProposal(t *testing.T) { require.NoError(t, err) // vs2, vs3 and vs4 send prevote for propBlock - signAddVotes(cs1, tmproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) ensureNewValidBlock(validBlockCh, height, round) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Prevote(round).Nanoseconds()) @@ -1412,7 +1412,7 @@ func TestProcessProposalAccept(t *testing.T) { ensureNewProposal(proposalCh, height, round) rs := cs1.GetRoundState() - var prevoteHash tmbytes.HexBytes + var prevoteHash cmtbytes.HexBytes if !testCase.expectedNilPrevote { prevoteHash = rs.ProposalBlock.Hash() } @@ -1436,7 +1436,7 @@ func TestWaitingTimeoutOnNilPolka(t *testing.T) { startTestRound(cs1, height, round) ensureNewRound(newRoundCh, height, round) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) ensureNewTimeout(timeoutWaitCh, height, round, cs1.config.Precommit(round).Nanoseconds()) ensureNewRound(newRoundCh, height, round+1) @@ -1464,7 +1464,7 @@ func TestWaitingTimeoutProposeOnNewRound(t *testing.T) { ensurePrevote(voteCh, height, round) incrementRound(vss[1:]...) - signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) round++ // moving to the next round ensureNewRound(newRoundCh, height, round) @@ -1500,7 +1500,7 @@ func TestRoundSkipOnNilPolkaFromHigherRound(t *testing.T) { ensurePrevote(voteCh, height, round) incrementRound(vss[1:]...) - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2, vs3, vs4) round++ // moving to the next round ensureNewRound(newRoundCh, height, round) @@ -1534,7 +1534,7 @@ func TestWaitTimeoutProposeOnNilPolkaForTheCurrentRound(t *testing.T) { ensureNewRound(newRoundCh, height, round) incrementRound(vss[1:]...) - signAddVotes(cs1, tmproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, nil, types.PartSetHeader{}, vs2, vs3, vs4) ensureNewTimeout(timeoutProposeCh, height, round, cs1.config.Propose(round).Nanoseconds()) @@ -1566,7 +1566,7 @@ func TestEmitNewValidBlockEventOnCommitWithoutBlock(t *testing.T) { ensureNewRound(newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock - signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) ensureNewValidBlock(validBlockCh, height, round) rs := cs1.GetRoundState() @@ -1600,7 +1600,7 @@ func TestCommitFromPreviousRound(t *testing.T) { ensureNewRound(newRoundCh, height, round) // vs2, vs3 and vs4 send precommit for propBlock for the previous round - signAddVotes(cs1, tmproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, propBlockHash, propBlockParts.Header(), vs2, vs3, vs4) ensureNewValidBlock(validBlockCh, height, round) @@ -1664,15 +1664,15 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], theBlockHash) - signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash) // add precommits - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) - signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2) + signAddVotes(cs1, cmtproto.PrecommitType, theBlockHash, theBlockParts, vs3) // wait till timeout occurs ensurePrecommitTimeout(precommitTimeoutCh) @@ -1680,7 +1680,7 @@ func TestStartNextHeightCorrectlyAfterTimeout(t *testing.T) { ensureNewRound(newRoundCh, height, round+1) // majority is now reached - signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, theBlockHash, theBlockParts, vs4) ensureNewBlockHeader(newBlockHeader, height, theBlockHash) @@ -1724,15 +1724,15 @@ func TestResetTimeoutPrecommitUponNewHeight(t *testing.T) { ensurePrevote(voteCh, height, round) validatePrevote(t, cs1, round, vss[0], theBlockHash) - signAddVotes(cs1, tmproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, theBlockHash, theBlockParts, vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) validatePrecommit(t, cs1, round, round, vss[0], theBlockHash, theBlockHash) // add precommits - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) - signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs3) - signAddVotes(cs1, tmproto.PrecommitType, theBlockHash, theBlockParts, vs4) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2) + signAddVotes(cs1, cmtproto.PrecommitType, theBlockHash, theBlockParts, vs3) + signAddVotes(cs1, cmtproto.PrecommitType, theBlockHash, theBlockParts, vs4) ensureNewBlockHeader(newBlockHeader, height, theBlockHash) @@ -1779,7 +1779,7 @@ func TestStateSlashingPrevotes(t *testing.T) { // add one for a different block should cause us to go into prevote wait hash := rs.ProposalBlock.Hash() hash[0] = byte(hash[0]+1) % 255 - signAddVotes(cs1, tmproto.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, hash, rs.ProposalBlockParts.Header(), vs2) <-timeoutWaitCh @@ -1787,7 +1787,7 @@ func TestStateSlashingPrevotes(t *testing.T) { // away and ignore more prevotes (and thus fail to slash!) // add the conflicting vote - signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) // XXX: Check for existence of Dupeout info } @@ -1809,7 +1809,7 @@ func TestStateSlashingPrecommits(t *testing.T) { <-voteCh // prevote // add prevote from vs2 - signAddVotes(cs1, tmproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrevoteType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) <-voteCh // precommit @@ -1817,13 +1817,13 @@ func TestStateSlashingPrecommits(t *testing.T) { // add one for a different block should cause us to go into prevote wait hash := rs.ProposalBlock.Hash() hash[0] = byte(hash[0]+1) % 255 - signAddVotes(cs1, tmproto.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrecommitType, hash, rs.ProposalBlockParts.Header(), vs2) // NOTE: we have to send the vote for different block first so we don't just go into precommit round right // away and ignore more prevotes (and thus fail to slash!) // add precommit from vs2 - signAddVotes(cs1, tmproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) + signAddVotes(cs1, cmtproto.PrecommitType, rs.ProposalBlock.Hash(), rs.ProposalBlockParts.Header(), vs2) // XXX: Check for existence of Dupeout info } @@ -1864,17 +1864,17 @@ func TestStateHalt1(t *testing.T) { ensurePrevote(voteCh, height, round) - signAddVotes(cs1, tmproto.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4) + signAddVotes(cs1, cmtproto.PrevoteType, propBlock.Hash(), propBlockParts.Header(), vs2, vs3, vs4) ensurePrecommit(voteCh, height, round) // the proposed block should now be locked and our precommit added validatePrecommit(t, cs1, round, round, vss[0], propBlock.Hash(), propBlock.Hash()) // add precommits from the rest - signAddVotes(cs1, tmproto.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal - signAddVotes(cs1, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3) + signAddVotes(cs1, cmtproto.PrecommitType, nil, types.PartSetHeader{}, vs2) // didnt receive proposal + signAddVotes(cs1, cmtproto.PrecommitType, propBlock.Hash(), propBlockParts.Header(), vs3) // we receive this later, but vs3 might receive it earlier and with ours will go to commit! - precommit4 := signVote(vs4, tmproto.PrecommitType, propBlock.Hash(), propBlockParts.Header()) + precommit4 := signVote(vs4, cmtproto.PrecommitType, propBlock.Hash(), propBlockParts.Header()) incrementRound(vs2, vs3, vs4) @@ -1911,7 +1911,7 @@ func TestStateOutputsBlockPartsStats(t *testing.T) { peer := p2pmock.NewPeer(nil) // 1) new block part - parts := types.NewPartSetFromData(tmrand.Bytes(100), 10) + parts := types.NewPartSetFromData(cmtrand.Bytes(100), 10) msg := &BlockPartMessage{ Height: 1, Round: 0, @@ -1953,9 +1953,9 @@ func TestStateOutputVoteStats(t *testing.T) { // create dummy peer peer := p2pmock.NewPeer(nil) - randBytes := tmrand.Bytes(tmhash.Size) + randBytes := cmtrand.Bytes(tmhash.Size) - vote := signVote(vss[1], tmproto.PrecommitType, randBytes, types.PartSetHeader{}) + vote := signVote(vss[1], cmtproto.PrecommitType, randBytes, types.PartSetHeader{}) voteMessage := &VoteMessage{vote} cs.handleMsg(msgInfo{voteMessage, peer.ID()}) @@ -1969,7 +1969,7 @@ func TestStateOutputVoteStats(t *testing.T) { // sending the vote for the bigger height incrementHeight(vss[1]) - vote = signVote(vss[1], tmproto.PrecommitType, randBytes, types.PartSetHeader{}) + vote = signVote(vss[1], cmtproto.PrecommitType, randBytes, types.PartSetHeader{}) cs.handleMsg(msgInfo{&VoteMessage{vote}, peer.ID()}) @@ -1984,16 +1984,16 @@ func TestStateOutputVoteStats(t *testing.T) { func TestSignSameVoteTwice(t *testing.T) { _, vss := randState(2) - randBytes := tmrand.Bytes(tmhash.Size) + randBytes := cmtrand.Bytes(tmhash.Size) vote := signVote(vss[1], - tmproto.PrecommitType, + cmtproto.PrecommitType, randBytes, types.PartSetHeader{Total: 10, Hash: randBytes}, ) vote2 := signVote(vss[1], - tmproto.PrecommitType, + cmtproto.PrecommitType, randBytes, types.PartSetHeader{Total: 10, Hash: randBytes}, ) @@ -2002,7 +2002,7 @@ func TestSignSameVoteTwice(t *testing.T) { } // subscribe subscribes test client to the given query and returns a channel with cap = 1. -func subscribe(eventBus *types.EventBus, q tmpubsub.Query) <-chan tmpubsub.Message { +func subscribe(eventBus *types.EventBus, q cmtpubsub.Query) <-chan cmtpubsub.Message { sub, err := eventBus.Subscribe(context.Background(), testSubscriber, q) if err != nil { panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, q)) @@ -2011,7 +2011,7 @@ func subscribe(eventBus *types.EventBus, q tmpubsub.Query) <-chan tmpubsub.Messa } // subscribe subscribes test client to the given query and returns a channel with cap = 0. -func subscribeUnBuffered(eventBus *types.EventBus, q tmpubsub.Query) <-chan tmpubsub.Message { +func subscribeUnBuffered(eventBus *types.EventBus, q cmtpubsub.Query) <-chan cmtpubsub.Message { sub, err := eventBus.SubscribeUnbuffered(context.Background(), testSubscriber, q) if err != nil { panic(fmt.Sprintf("failed to subscribe %s to %v", testSubscriber, q)) diff --git a/consensus/types/height_vote_set.go b/consensus/types/height_vote_set.go index 6a5c0b49529..7bf05433aae 100644 --- a/consensus/types/height_vote_set.go +++ b/consensus/types/height_vote_set.go @@ -6,10 +6,10 @@ import ( "strings" "sync" - tmjson "github.com/tendermint/tendermint/libs/json" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/p2p" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -86,7 +86,7 @@ func (hvs *HeightVoteSet) Round() int32 { func (hvs *HeightVoteSet) SetRound(round int32) { hvs.mtx.Lock() defer hvs.mtx.Unlock() - newRound := tmmath.SafeSubInt32(hvs.round, 1) + newRound := cmtmath.SafeSubInt32(hvs.round, 1) if hvs.round != 0 && (round < newRound) { panic("SetRound() must increment hvs.round") } @@ -104,8 +104,8 @@ func (hvs *HeightVoteSet) addRound(round int32) { panic("addRound() for an existing round") } // log.Debug("addRound(round)", "round", round) - prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrevoteType, hvs.valSet) - precommits := types.NewVoteSet(hvs.chainID, hvs.height, round, tmproto.PrecommitType, hvs.valSet) + prevotes := types.NewVoteSet(hvs.chainID, hvs.height, round, cmtproto.PrevoteType, hvs.valSet) + precommits := types.NewVoteSet(hvs.chainID, hvs.height, round, cmtproto.PrecommitType, hvs.valSet) hvs.roundVoteSets[round] = RoundVoteSet{ Prevotes: prevotes, Precommits: precommits, @@ -139,13 +139,13 @@ func (hvs *HeightVoteSet) AddVote(vote *types.Vote, peerID p2p.ID) (added bool, func (hvs *HeightVoteSet) Prevotes(round int32) *types.VoteSet { hvs.mtx.Lock() defer hvs.mtx.Unlock() - return hvs.getVoteSet(round, tmproto.PrevoteType) + return hvs.getVoteSet(round, cmtproto.PrevoteType) } func (hvs *HeightVoteSet) Precommits(round int32) *types.VoteSet { hvs.mtx.Lock() defer hvs.mtx.Unlock() - return hvs.getVoteSet(round, tmproto.PrecommitType) + return hvs.getVoteSet(round, cmtproto.PrecommitType) } // Last round and blockID that has +2/3 prevotes for a particular block or nil. @@ -154,7 +154,7 @@ func (hvs *HeightVoteSet) POLInfo() (polRound int32, polBlockID types.BlockID) { hvs.mtx.Lock() defer hvs.mtx.Unlock() for r := hvs.round; r >= 0; r-- { - rvs := hvs.getVoteSet(r, tmproto.PrevoteType) + rvs := hvs.getVoteSet(r, cmtproto.PrevoteType) polBlockID, ok := rvs.TwoThirdsMajority() if ok { return r, polBlockID @@ -163,15 +163,15 @@ func (hvs *HeightVoteSet) POLInfo() (polRound int32, polBlockID types.BlockID) { return -1, types.BlockID{} } -func (hvs *HeightVoteSet) getVoteSet(round int32, voteType tmproto.SignedMsgType) *types.VoteSet { +func (hvs *HeightVoteSet) getVoteSet(round int32, voteType cmtproto.SignedMsgType) *types.VoteSet { rvs, ok := hvs.roundVoteSets[round] if !ok { return nil } switch voteType { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return rvs.Prevotes - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return rvs.Precommits default: panic(fmt.Sprintf("Unexpected vote type %X", voteType)) @@ -184,7 +184,7 @@ func (hvs *HeightVoteSet) getVoteSet(round int32, voteType tmproto.SignedMsgType // TODO: implement ability to remove peers too func (hvs *HeightVoteSet) SetPeerMaj23( round int32, - voteType tmproto.SignedMsgType, + voteType cmtproto.SignedMsgType, peerID p2p.ID, blockID types.BlockID) error { hvs.mtx.Lock() @@ -238,7 +238,7 @@ func (hvs *HeightVoteSet) StringIndented(indent string) string { func (hvs *HeightVoteSet) MarshalJSON() ([]byte, error) { hvs.mtx.Lock() defer hvs.mtx.Unlock() - return tmjson.Marshal(hvs.toAllRoundVotes()) + return cmtjson.Marshal(hvs.toAllRoundVotes()) } func (hvs *HeightVoteSet) toAllRoundVotes() []roundVotes { diff --git a/consensus/types/height_vote_set_test.go b/consensus/types/height_vote_set_test.go index ccbdbed9dc7..9318e3e18ea 100644 --- a/consensus/types/height_vote_set_test.go +++ b/consensus/types/height_vote_set_test.go @@ -8,10 +8,10 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/internal/test" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) var config *cfg.Config // NOTE: must be reset for each _test.go file @@ -63,15 +63,15 @@ func makeVoteHR(t *testing.T, height int64, valIndex, round int32, privVals []ty panic(err) } - randBytes := tmrand.Bytes(tmhash.Size) + randBytes := cmtrand.Bytes(tmhash.Size) vote := &types.Vote{ ValidatorAddress: pubKey.Address(), ValidatorIndex: valIndex, Height: height, Round: round, - Timestamp: tmtime.Now(), - Type: tmproto.PrecommitType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrecommitType, BlockID: types.BlockID{Hash: randBytes, PartSetHeader: types.PartSetHeader{}}, } diff --git a/consensus/wal.go b/consensus/wal.go index adbcaa64b9c..67cb29146df 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -12,12 +12,12 @@ import ( "github.com/cosmos/gogoproto/proto" auto "github.com/tendermint/tendermint/libs/autofile" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/service" - tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" - tmtime "github.com/tendermint/tendermint/types/time" + cmtcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + cmttime "github.com/tendermint/tendermint/types/time" ) const ( @@ -46,9 +46,9 @@ type EndHeightMessage struct { type WALMessage interface{} func init() { - tmjson.RegisterType(msgInfo{}, "tendermint/wal/MsgInfo") - tmjson.RegisterType(timeoutInfo{}, "tendermint/wal/TimeoutInfo") - tmjson.RegisterType(EndHeightMessage{}, "tendermint/wal/EndHeightMessage") + cmtjson.RegisterType(msgInfo{}, "tendermint/wal/MsgInfo") + cmtjson.RegisterType(timeoutInfo{}, "tendermint/wal/TimeoutInfo") + cmtjson.RegisterType(EndHeightMessage{}, "tendermint/wal/EndHeightMessage") } //-------------------------------------------------------- @@ -89,7 +89,7 @@ var _ WAL = &BaseWAL{} // NewWAL returns a new write-ahead logger based on `baseWAL`, which implements // WAL. It's flushed and synced to disk every 2s and once when stopped. func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*BaseWAL, error) { - err := tmos.EnsureDir(filepath.Dir(walFile), 0700) + err := cmtos.EnsureDir(filepath.Dir(walFile), 0700) if err != nil { return nil, fmt.Errorf("failed to ensure WAL directory is in place: %w", err) } @@ -186,7 +186,7 @@ func (wal *BaseWAL) Write(msg WALMessage) error { return nil } - if err := wal.enc.Encode(&TimedWALMessage{tmtime.Now(), msg}); err != nil { + if err := wal.enc.Encode(&TimedWALMessage{cmttime.Now(), msg}); err != nil { wal.Logger.Error("Error writing msg to consensus wal. WARNING: recover may not be possible for the current height", "err", err, "msg", msg) return err @@ -302,7 +302,7 @@ func (enc *WALEncoder) Encode(v *TimedWALMessage) error { if err != nil { return err } - pv := tmcons.TimedWALMessage{ + pv := cmtcons.TimedWALMessage{ Time: v.Time, Msg: pbMsg, } @@ -400,7 +400,7 @@ func (dec *WALDecoder) Decode() (*TimedWALMessage, error) { return nil, DataCorruptionError{fmt.Errorf("checksums do not match: read: %v, actual: %v", crc, actualCRC)} } - var res = new(tmcons.TimedWALMessage) + var res = new(cmtcons.TimedWALMessage) err = proto.Unmarshal(data, res) if err != nil { return nil, DataCorruptionError{fmt.Errorf("failed to decode data: %v", err)} diff --git a/consensus/wal_generator.go b/consensus/wal_generator.go index 96a0d485c27..ccabf68787c 100644 --- a/consensus/wal_generator.go +++ b/consensus/wal_generator.go @@ -15,7 +15,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/privval" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" @@ -138,7 +138,7 @@ func WALWithNBlocks(t *testing.T, numBlocks int) (data []byte, err error) { func randPort() int { // returns between base and base + spread base, spread := 20000, 20000 - return base + tmrand.Intn(spread) + return base + cmtrand.Intn(spread) } func makeAddrs() (string, string, string) { @@ -153,8 +153,8 @@ func getConfig(t *testing.T) *cfg.Config { c := test.ResetTestRoot(t.Name()) // and we use random ports to run in parallel - tm, rpc, grpc := makeAddrs() - c.P2P.ListenAddress = tm + cmt, rpc, grpc := makeAddrs() + c.P2P.ListenAddress = cmt c.RPC.ListenAddress = rpc c.RPC.GRPCListenAddress = grpc return c diff --git a/consensus/wal_test.go b/consensus/wal_test.go index 12b775b413d..881fb8d0f05 100644 --- a/consensus/wal_test.go +++ b/consensus/wal_test.go @@ -17,8 +17,8 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/libs/autofile" "github.com/tendermint/tendermint/libs/log" - tmtypes "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttypes "github.com/tendermint/tendermint/types" + cmttime "github.com/tendermint/tendermint/types/time" ) const ( @@ -75,17 +75,17 @@ func TestWALTruncate(t *testing.T) { dec := NewWALDecoder(gr) msg, err := dec.Decode() assert.NoError(t, err, "expected to decode a message") - rs, ok := msg.Msg.(tmtypes.EventDataRoundState) + rs, ok := msg.Msg.(cmttypes.EventDataRoundState) assert.True(t, ok, "expected message of type EventDataRoundState") assert.Equal(t, rs.Height, h+1, "wrong height") } func TestWALEncoderDecoder(t *testing.T) { - now := tmtime.Now() + now := cmttime.Now() msgs := []TimedWALMessage{ {Time: now, Msg: EndHeightMessage{0}}, {Time: now, Msg: timeoutInfo{Duration: time.Second, Height: 1, Round: 1, Step: types.RoundStepPropose}}, - {Time: now, Msg: tmtypes.EventDataRoundState{Height: 1, Round: 1, Step: ""}}, + {Time: now, Msg: cmttypes.EventDataRoundState{Height: 1, Round: 1, Step: ""}}, } b := new(bytes.Buffer) @@ -130,7 +130,7 @@ func TestWALWrite(t *testing.T) { msg := &BlockPartMessage{ Height: 1, Round: 1, - Part: &tmtypes.Part{ + Part: &cmttypes.Part{ Index: 1, Bytes: make([]byte, 1), Proof: merkle.Proof{ @@ -170,7 +170,7 @@ func TestWALSearchForEndHeight(t *testing.T) { dec := NewWALDecoder(gr) msg, err := dec.Decode() assert.NoError(t, err, "expected to decode a message") - rs, ok := msg.Msg.(tmtypes.EventDataRoundState) + rs, ok := msg.Msg.(cmttypes.EventDataRoundState) assert.True(t, ok, "expected message of type EventDataRoundState") assert.Equal(t, rs.Height, h+1, "wrong height") } diff --git a/crypto/ed25519/ed25519.go b/crypto/ed25519/ed25519.go index 1447ab273be..00fb389a904 100644 --- a/crypto/ed25519/ed25519.go +++ b/crypto/ed25519/ed25519.go @@ -12,7 +12,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" ) //------------------------------------- @@ -57,8 +57,8 @@ const ( ) func init() { - tmjson.RegisterType(PubKey{}, PubKeyName) - tmjson.RegisterType(PrivKey{}, PrivKeyName) + cmtjson.RegisterType(PubKey{}, PubKeyName) + cmtjson.RegisterType(PrivKey{}, PrivKeyName) } // PrivKey implements crypto.PrivKey. diff --git a/crypto/merkle/proof.go b/crypto/merkle/proof.go index 2994e804871..97094dcfd36 100644 --- a/crypto/merkle/proof.go +++ b/crypto/merkle/proof.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/tendermint/tendermint/crypto/tmhash" - tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + cmtcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) const ( @@ -116,11 +116,11 @@ func (sp *Proof) ValidateBasic() error { return nil } -func (sp *Proof) ToProto() *tmcrypto.Proof { +func (sp *Proof) ToProto() *cmtcrypto.Proof { if sp == nil { return nil } - pb := new(tmcrypto.Proof) + pb := new(cmtcrypto.Proof) pb.Total = sp.Total pb.Index = sp.Index @@ -130,7 +130,7 @@ func (sp *Proof) ToProto() *tmcrypto.Proof { return pb } -func ProofFromProto(pb *tmcrypto.Proof) (*Proof, error) { +func ProofFromProto(pb *cmtcrypto.Proof) (*Proof, error) { if pb == nil { return nil, errors.New("nil proof") } diff --git a/crypto/merkle/proof_op.go b/crypto/merkle/proof_op.go index 038037cf539..2731df692db 100644 --- a/crypto/merkle/proof_op.go +++ b/crypto/merkle/proof_op.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + cmtcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) //---------------------------------------- @@ -21,7 +21,7 @@ import ( type ProofOperator interface { Run([][]byte) ([][]byte, error) GetKey() []byte - ProofOp() tmcrypto.ProofOp + ProofOp() cmtcrypto.ProofOp } //---------------------------------------- @@ -71,7 +71,7 @@ func (poz ProofOperators) Verify(root []byte, keypath string, args [][]byte) (er //---------------------------------------- // ProofRuntime - main entrypoint -type OpDecoder func(tmcrypto.ProofOp) (ProofOperator, error) +type OpDecoder func(cmtcrypto.ProofOp) (ProofOperator, error) type ProofRuntime struct { decoders map[string]OpDecoder @@ -91,7 +91,7 @@ func (prt *ProofRuntime) RegisterOpDecoder(typ string, dec OpDecoder) { prt.decoders[typ] = dec } -func (prt *ProofRuntime) Decode(pop tmcrypto.ProofOp) (ProofOperator, error) { +func (prt *ProofRuntime) Decode(pop cmtcrypto.ProofOp) (ProofOperator, error) { decoder := prt.decoders[pop.Type] if decoder == nil { return nil, fmt.Errorf("unrecognized proof type %v", pop.Type) @@ -99,7 +99,7 @@ func (prt *ProofRuntime) Decode(pop tmcrypto.ProofOp) (ProofOperator, error) { return decoder(pop) } -func (prt *ProofRuntime) DecodeProof(proof *tmcrypto.ProofOps) (ProofOperators, error) { +func (prt *ProofRuntime) DecodeProof(proof *cmtcrypto.ProofOps) (ProofOperators, error) { poz := make(ProofOperators, 0, len(proof.Ops)) for _, pop := range proof.Ops { operator, err := prt.Decode(pop) @@ -111,17 +111,17 @@ func (prt *ProofRuntime) DecodeProof(proof *tmcrypto.ProofOps) (ProofOperators, return poz, nil } -func (prt *ProofRuntime) VerifyValue(proof *tmcrypto.ProofOps, root []byte, keypath string, value []byte) (err error) { +func (prt *ProofRuntime) VerifyValue(proof *cmtcrypto.ProofOps, root []byte, keypath string, value []byte) (err error) { return prt.Verify(proof, root, keypath, [][]byte{value}) } // TODO In the long run we'll need a method of classifcation of ops, // whether existence or absence or perhaps a third? -func (prt *ProofRuntime) VerifyAbsence(proof *tmcrypto.ProofOps, root []byte, keypath string) (err error) { +func (prt *ProofRuntime) VerifyAbsence(proof *cmtcrypto.ProofOps, root []byte, keypath string) (err error) { return prt.Verify(proof, root, keypath, nil) } -func (prt *ProofRuntime) Verify(proof *tmcrypto.ProofOps, root []byte, keypath string, args [][]byte) (err error) { +func (prt *ProofRuntime) Verify(proof *cmtcrypto.ProofOps, root []byte, keypath string, args [][]byte) (err error) { poz, err := prt.DecodeProof(proof) if err != nil { return fmt.Errorf("decoding proof: %w", err) diff --git a/crypto/merkle/proof_test.go b/crypto/merkle/proof_test.go index f0d2f868969..f787d5a4045 100644 --- a/crypto/merkle/proof_test.go +++ b/crypto/merkle/proof_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + cmtcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) const ProofOpDomino = "test:domino" @@ -29,8 +29,8 @@ func NewDominoOp(key, input, output string) DominoOp { } } -func (dop DominoOp) ProofOp() tmcrypto.ProofOp { - dopb := tmcrypto.DominoOp{ +func (dop DominoOp) ProofOp() cmtcrypto.ProofOp { + dopb := cmtcrypto.DominoOp{ Key: dop.key, Input: dop.Input, Output: dop.Output, @@ -40,7 +40,7 @@ func (dop DominoOp) ProofOp() tmcrypto.ProofOp { panic(err) } - return tmcrypto.ProofOp{ + return cmtcrypto.ProofOp{ Type: ProofOpDomino, Key: []byte(dop.key), Data: bz, diff --git a/crypto/merkle/proof_value.go b/crypto/merkle/proof_value.go index 842dc820182..6471b33337a 100644 --- a/crypto/merkle/proof_value.go +++ b/crypto/merkle/proof_value.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/tendermint/tendermint/crypto/tmhash" - tmcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" + cmtcrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" ) const ProofOpValue = "simple:v" @@ -37,11 +37,11 @@ func NewValueOp(key []byte, proof *Proof) ValueOp { } } -func ValueOpDecoder(pop tmcrypto.ProofOp) (ProofOperator, error) { +func ValueOpDecoder(pop cmtcrypto.ProofOp) (ProofOperator, error) { if pop.Type != ProofOpValue { return nil, fmt.Errorf("unexpected ProofOp.Type; got %v, want %v", pop.Type, ProofOpValue) } - var pbop tmcrypto.ValueOp // a bit strange as we'll discard this, but it works. + var pbop cmtcrypto.ValueOp // a bit strange as we'll discard this, but it works. err := pbop.Unmarshal(pop.Data) if err != nil { return nil, fmt.Errorf("decoding ProofOp.Data into ValueOp: %w", err) @@ -54,8 +54,8 @@ func ValueOpDecoder(pop tmcrypto.ProofOp) (ProofOperator, error) { return NewValueOp(pop.Key, sp), nil } -func (op ValueOp) ProofOp() tmcrypto.ProofOp { - pbval := tmcrypto.ValueOp{ +func (op ValueOp) ProofOp() cmtcrypto.ProofOp { + pbval := cmtcrypto.ValueOp{ Key: op.key, Proof: op.Proof.ToProto(), } @@ -63,7 +63,7 @@ func (op ValueOp) ProofOp() tmcrypto.ProofOp { if err != nil { panic(err) } - return tmcrypto.ProofOp{ + return cmtcrypto.ProofOp{ Type: ProofOpValue, Key: op.key, Data: bz, diff --git a/crypto/merkle/tree_test.go b/crypto/merkle/tree_test.go index bdf46983615..4c05b7ae0ae 100644 --- a/crypto/merkle/tree_test.go +++ b/crypto/merkle/tree_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" . "github.com/tendermint/tendermint/libs/test" "github.com/tendermint/tendermint/crypto/tmhash" @@ -54,7 +54,7 @@ func TestProof(t *testing.T) { items := make([][]byte, total) for i := 0; i < total; i++ { - items[i] = testItem(tmrand.Bytes(tmhash.Size)) + items[i] = testItem(cmtrand.Bytes(tmhash.Size)) } rootHash = HashFromByteSlices(items) @@ -78,7 +78,7 @@ func TestProof(t *testing.T) { // Trail too long should make it fail origAunts := proof.Aunts - proof.Aunts = append(proof.Aunts, tmrand.Bytes(32)) + proof.Aunts = append(proof.Aunts, cmtrand.Bytes(32)) err = proof.Verify(rootHash, item) require.Error(t, err, "Expected verification to fail for wrong trail length") @@ -107,7 +107,7 @@ func TestHashAlternatives(t *testing.T) { items := make([][]byte, total) for i := 0; i < total; i++ { - items[i] = testItem(tmrand.Bytes(tmhash.Size)) + items[i] = testItem(cmtrand.Bytes(tmhash.Size)) } rootHash1 := HashFromByteSlicesIterative(items) @@ -120,7 +120,7 @@ func BenchmarkHashAlternatives(b *testing.B) { items := make([][]byte, total) for i := 0; i < total; i++ { - items[i] = testItem(tmrand.Bytes(tmhash.Size)) + items[i] = testItem(cmtrand.Bytes(tmhash.Size)) } b.ResetTimer() diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index 18fb41f0198..0cc5d1ad95e 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -13,7 +13,7 @@ import ( "golang.org/x/crypto/ripemd160" //nolint: staticcheck // necessary for Bitcoin address format "github.com/tendermint/tendermint/crypto" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" ) // ------------------------------------- @@ -26,8 +26,8 @@ const ( ) func init() { - tmjson.RegisterType(PubKey{}, PubKeyName) - tmjson.RegisterType(PrivKey{}, PrivKeyName) + cmtjson.RegisterType(PubKey{}, PubKeyName) + cmtjson.RegisterType(PrivKey{}, PrivKeyName) } var _ crypto.PrivKey = PrivKey{} diff --git a/crypto/sr25519/encoding.go b/crypto/sr25519/encoding.go index c0a8a7925e7..70615195ca1 100644 --- a/crypto/sr25519/encoding.go +++ b/crypto/sr25519/encoding.go @@ -1,6 +1,6 @@ package sr25519 -import tmjson "github.com/tendermint/tendermint/libs/json" +import cmtjson "github.com/tendermint/tendermint/libs/json" const ( PrivKeyName = "tendermint/PrivKeySr25519" @@ -8,6 +8,6 @@ const ( ) func init() { - tmjson.RegisterType(PubKey{}, PubKeyName) - tmjson.RegisterType(PrivKey{}, PrivKeyName) + cmtjson.RegisterType(PubKey{}, PubKeyName) + cmtjson.RegisterType(PrivKey{}, PrivKeyName) } diff --git a/docs/tutorials/go-built-in.md b/docs/tutorials/go-built-in.md index f979fa81c04..492bd92794b 100644 --- a/docs/tutorials/go-built-in.md +++ b/docs/tutorials/go-built-in.md @@ -515,8 +515,8 @@ import ( "github.com/dgraph-io/badger/v3" "github.com/spf13/viper" cfg "github.com/tendermint/tendermint/config" - tmflags "github.com/tendermint/tendermint/libs/cli/flags" - tmlog "github.com/tendermint/tendermint/libs/log" + cmtflags "github.com/tendermint/tendermint/libs/cli/flags" + cmtlog "github.com/tendermint/tendermint/libs/log" nm "github.com/tendermint/tendermint/node" ) @@ -569,8 +569,8 @@ func main() { log.Fatalf("failed to load node's key: %v", err) } - logger := tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)) - logger, err = tmflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel) + logger := cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)) + logger, err = cmtflags.ParseLogLevel(config.LogLevel, logger, cfg.DefaultLogLevel) if err != nil { log.Fatalf("failed to parse log level: %v", err) } diff --git a/docs/tutorials/go.md b/docs/tutorials/go.md index df430962eac..534a21e2bae 100644 --- a/docs/tutorials/go.md +++ b/docs/tutorials/go.md @@ -510,7 +510,7 @@ import ( "syscall" "github.com/dgraph-io/badger/v3" - tmlog "github.com/tendermint/tendermint/libs/log" + cmtlog "github.com/tendermint/tendermint/libs/log" ) var homeDir string @@ -540,7 +540,7 @@ func main() { app := NewKVStoreApplication(db) - logger := tmlog.NewTMLogger(tmlog.NewSyncWriter(os.Stdout)) + logger := cmtlog.NewTMLogger(cmtlog.NewSyncWriter(os.Stdout)) server := abciserver.NewSocketServer(socketAddr, app) server.SetLogger(logger) diff --git a/evidence/pool.go b/evidence/pool.go index 6bec0159820..731c2b36ebd 100644 --- a/evidence/pool.go +++ b/evidence/pool.go @@ -14,7 +14,7 @@ import ( clist "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -362,7 +362,7 @@ func (evpool *Pool) listEvidence(prefixKey byte, maxBytes int64) ([]types.Eviden evSize int64 totalSize int64 evidence []types.Evidence - evList tmproto.EvidenceList // used for calculating the bytes size + evList cmtproto.EvidenceList // used for calculating the bytes size ) iter, err := dbm.IteratePrefix(evpool.evidenceStore, []byte{prefixKey}) @@ -371,7 +371,7 @@ func (evpool *Pool) listEvidence(prefixKey byte, maxBytes int64) ([]types.Eviden } defer iter.Close() for ; iter.Valid(); iter.Next() { - var evpb tmproto.Evidence + var evpb cmtproto.Evidence err := evpb.Unmarshal(iter.Value()) if err != nil { return evidence, totalSize, err @@ -542,7 +542,7 @@ type duplicateVoteSet struct { } func bytesToEv(evBytes []byte) (types.Evidence, error) { - var evpb tmproto.Evidence + var evpb cmtproto.Evidence err := evpb.Unmarshal(evBytes) if err != nil { return &types.DuplicateVoteEvidence{}, err diff --git a/evidence/pool_test.go b/evidence/pool_test.go index 8283bb2f943..e623d784143 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -15,7 +15,7 @@ import ( "github.com/tendermint/tendermint/evidence/mocks" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" sm "github.com/tendermint/tendermint/state" smmocks "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/store" @@ -417,7 +417,7 @@ func initializeBlockStore(db dbm.DB, state sm.State, valAddr []byte) (*store.Blo lastCommit := makeCommit(i-1, valAddr) block := state.MakeBlock(i, test.MakeNTxs(i, 1), lastCommit, nil, state.Validators.Proposer.Address) block.Header.Time = defaultEvidenceTime.Add(time.Duration(i) * time.Minute) - block.Header.Version = tmversion.Consensus{Block: version.BlockProtocol, App: 1} + block.Header.Version = cmtversion.Consensus{Block: version.BlockProtocol, App: 1} const parts = 1 partSet, err := block.MakePartSet(parts) if err != nil { diff --git a/evidence/reactor.go b/evidence/reactor.go index 4211dcc8faa..db151bea129 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -9,7 +9,7 @@ import ( clist "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/p2p" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -57,7 +57,7 @@ func (evR *Reactor) GetChannels() []*p2p.ChannelDescriptor { ID: EvidenceChannel, Priority: 6, RecvMessageCapacity: maxMsgSize, - MessageType: &tmproto.EvidenceList{}, + MessageType: &cmtproto.EvidenceList{}, }, } } @@ -217,8 +217,8 @@ type PeerState interface { // encodemsg takes a array of evidence // returns the byte encoding of the List Message -func evidenceListToProto(evis []types.Evidence) (*tmproto.EvidenceList, error) { - evi := make([]tmproto.Evidence, len(evis)) +func evidenceListToProto(evis []types.Evidence) (*cmtproto.EvidenceList, error) { + evi := make([]cmtproto.Evidence, len(evis)) for i := 0; i < len(evis); i++ { ev, err := types.EvidenceToProto(evis[i]) if err != nil { @@ -226,14 +226,14 @@ func evidenceListToProto(evis []types.Evidence) (*tmproto.EvidenceList, error) { } evi[i] = *ev } - epl := tmproto.EvidenceList{ + epl := cmtproto.EvidenceList{ Evidence: evi, } return &epl, nil } func evidenceListFromProto(m proto.Message) ([]types.Evidence, error) { - lm := m.(*tmproto.EvidenceList) + lm := m.(*cmtproto.EvidenceList) evis := make([]types.Evidence, len(lm.Evidence)) for i := 0; i < len(lm.Evidence); i++ { diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 0d7d1110dae..1dbd3a65fa8 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -23,7 +23,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/p2p" p2pmocks "github.com/tendermint/tendermint/p2p/mocks" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -356,7 +356,7 @@ func exampleVote(t byte) *types.Vote { } return &types.Vote{ - Type: tmproto.SignedMsgType(t), + Type: cmtproto.SignedMsgType(t), Height: 3, Round: 2, Timestamp: stamp, @@ -401,14 +401,14 @@ func TestEvidenceVectors(t *testing.T) { for _, tc := range testCases { tc := tc - evi := make([]tmproto.Evidence, len(tc.evidenceList)) + evi := make([]cmtproto.Evidence, len(tc.evidenceList)) for i := 0; i < len(tc.evidenceList); i++ { ev, err := types.EvidenceToProto(tc.evidenceList[i]) require.NoError(t, err, tc.testName) evi[i] = *ev } - epl := tmproto.EvidenceList{ + epl := cmtproto.EvidenceList{ Evidence: evi, } diff --git a/evidence/verify_test.go b/evidence/verify_test.go index f8021f4363f..bb7aab01893 100644 --- a/evidence/verify_test.go +++ b/evidence/verify_test.go @@ -15,8 +15,8 @@ import ( "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/evidence/mocks" "github.com/tendermint/tendermint/libs/log" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" sm "github.com/tendermint/tendermint/state" smmocks "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/types" @@ -206,7 +206,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { // we are simulating a duplicate vote attack where all the validators in the conflictingVals set // except the last validator vote twice blockID := makeBlockID(conflictingHeader.Hash(), 1000, []byte("partshash")) - voteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals) + voteSet := types.NewVoteSet(evidenceChainID, 10, 1, cmtproto.SignedMsgType(2), conflictingVals) commit, err := types.MakeCommit(blockID, 10, 1, voteSet, conflictingPrivVals[:4], defaultEvidenceTime) require.NoError(t, err) ev := &types.LightClientAttackEvidence{ @@ -224,7 +224,7 @@ func TestVerifyLightClientAttack_Equivocation(t *testing.T) { } trustedBlockID := makeBlockID(trustedHeader.Hash(), 1000, []byte("partshash")) - trustedVoteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals) + trustedVoteSet := types.NewVoteSet(evidenceChainID, 10, 1, cmtproto.SignedMsgType(2), conflictingVals) trustedCommit, err := types.MakeCommit(trustedBlockID, 10, 1, trustedVoteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) trustedSignedHeader := &types.SignedHeader{ @@ -290,7 +290,7 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) { // we are simulating an amnesia attack where all the validators in the conflictingVals set // except the last validator vote twice. However this time the commits are of different rounds. blockID := makeBlockID(conflictingHeader.Hash(), 1000, []byte("partshash")) - voteSet := types.NewVoteSet(evidenceChainID, 10, 0, tmproto.SignedMsgType(2), conflictingVals) + voteSet := types.NewVoteSet(evidenceChainID, 10, 0, cmtproto.SignedMsgType(2), conflictingVals) commit, err := types.MakeCommit(blockID, 10, 0, voteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) ev := &types.LightClientAttackEvidence{ @@ -308,7 +308,7 @@ func TestVerifyLightClientAttack_Amnesia(t *testing.T) { } trustedBlockID := makeBlockID(trustedHeader.Hash(), 1000, []byte("partshash")) - trustedVoteSet := types.NewVoteSet(evidenceChainID, 10, 1, tmproto.SignedMsgType(2), conflictingVals) + trustedVoteSet := types.NewVoteSet(evidenceChainID, 10, 1, cmtproto.SignedMsgType(2), conflictingVals) trustedCommit, err := types.MakeCommit(trustedBlockID, 10, 1, trustedVoteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) trustedSignedHeader := &types.SignedHeader{ @@ -482,7 +482,7 @@ func makeLunaticEvidence( conflictingHeader.ValidatorsHash = conflictingVals.Hash() blockID := makeBlockID(conflictingHeader.Hash(), 1000, []byte("partshash")) - voteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), conflictingVals) + voteSet := types.NewVoteSet(evidenceChainID, height, 1, cmtproto.SignedMsgType(2), conflictingVals) commit, err := types.MakeCommit(blockID, height, 1, voteSet, conflictingPrivVals, defaultEvidenceTime) require.NoError(t, err) ev = &types.LightClientAttackEvidence{ @@ -509,7 +509,7 @@ func makeLunaticEvidence( } trustedBlockID := makeBlockID(trustedHeader.Hash(), 1000, []byte("partshash")) trustedVals, privVals := types.RandValidatorSet(totalVals, defaultVotingPower) - trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, tmproto.SignedMsgType(2), trustedVals) + trustedVoteSet := types.NewVoteSet(evidenceChainID, height, 1, cmtproto.SignedMsgType(2), trustedVals) trustedCommit, err := types.MakeCommit(trustedBlockID, height, 1, trustedVoteSet, privVals, defaultEvidenceTime) require.NoError(t, err) trusted = &types.LightBlock{ @@ -540,7 +540,7 @@ func makeVote( ValidatorIndex: valIndex, Height: height, Round: round, - Type: tmproto.SignedMsgType(step), + Type: cmtproto.SignedMsgType(step), BlockID: blockID, Timestamp: time, } @@ -556,7 +556,7 @@ func makeVote( func makeHeaderRandom(height int64) *types.Header { return &types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: evidenceChainID, Height: height, Time: defaultEvidenceTime, diff --git a/inspect/inspect.go b/inspect/inspect.go index 71c44f7bbd3..3a9a087368f 100644 --- a/inspect/inspect.go +++ b/inspect/inspect.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/inspect/rpc" "github.com/tendermint/tendermint/libs/log" - tmstrings "github.com/tendermint/tendermint/libs/strings" + cmtstrings "github.com/tendermint/tendermint/libs/strings" rpccore "github.com/tendermint/tendermint/rpc/core" "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/indexer" @@ -98,7 +98,7 @@ func (ins *Inspector) Run(ctx context.Context) error { func startRPCServers(ctx context.Context, cfg *config.RPCConfig, logger log.Logger, routes rpccore.RoutesMap) error { g, tctx := errgroup.WithContext(ctx) - listenAddrs := tmstrings.SplitAndTrimEmpty(cfg.ListenAddress, ",", " ") + listenAddrs := cmtstrings.SplitAndTrimEmpty(cfg.ListenAddress, ",", " ") rh := rpc.Handler(cfg, routes, logger) for _, listenerAddr := range listenAddrs { server := rpc.Server{ diff --git a/inspect/inspect_test.go b/inspect/inspect_test.go index c4ad7a5e44b..d314bc0fb21 100644 --- a/inspect/inspect_test.go +++ b/inspect/inspect_test.go @@ -263,7 +263,7 @@ func TestBlockResults(t *testing.T) { testGasUsed := int64(100) stateStoreMock := &statemocks.Store{} stateStoreMock.On("Close").Return(nil) - // tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + // cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" stateStoreMock.On("LoadABCIResponses", testHeight).Return(&state.ABCIResponses{ DeliverTxs: []*abcitypes.ResponseDeliverTx{ { diff --git a/internal/test/commit.go b/internal/test/commit.go index fd3a8ac5aae..14f21b9907f 100644 --- a/internal/test/commit.go +++ b/internal/test/commit.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -21,7 +21,7 @@ func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, valida ValidatorIndex: int32(i), Height: voteSet.GetHeight(), Round: voteSet.GetRound(), - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: blockID, Timestamp: now, } @@ -41,7 +41,7 @@ func MakeCommitFromVoteSet(blockID types.BlockID, voteSet *types.VoteSet, valida } func MakeVoteSet(lastState sm.State, round int32) *types.VoteSet { - return types.NewVoteSet(lastState.ChainID, lastState.LastBlockHeight+1, round, tmproto.PrecommitType, lastState.NextValidators) + return types.NewVoteSet(lastState.ChainID, lastState.LastBlockHeight+1, round, cmtproto.PrecommitType, lastState.NextValidators) } func MakeCommit(blockID types.BlockID, height int64, round int32, valSet *types.ValidatorSet, privVals []types.PrivValidator, chainID string, now time.Time) (*types.Commit, error) { @@ -67,7 +67,7 @@ func MakeCommit(blockID types.BlockID, height int64, round int32, valSet *types. ValidatorIndex: idx, Height: height, Round: round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: blockID, Timestamp: now, } diff --git a/internal/test/config.go b/internal/test/config.go index 85a84cec200..fab633f9427 100644 --- a/internal/test/config.go +++ b/internal/test/config.go @@ -6,7 +6,7 @@ import ( "path/filepath" "github.com/tendermint/tendermint/config" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" ) func ResetTestRoot(testName string) *config.Config { @@ -27,16 +27,16 @@ func ResetTestRootWithChainID(testName string, chainID string) *config.Config { privKeyFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorKey) privStateFilePath := filepath.Join(rootDir, baseConfig.PrivValidatorState) - if !tmos.FileExists(genesisFilePath) { + if !cmtos.FileExists(genesisFilePath) { if chainID == "" { chainID = DefaultTestChainID } testGenesis := fmt.Sprintf(testGenesisFmt, chainID) - tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) + cmtos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644) } // we always overwrite the priv val - tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644) - tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644) + cmtos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644) + cmtos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644) config := config.TestConfig().SetRoot(rootDir) return config diff --git a/internal/test/vote.go b/internal/test/vote.go index 180cb943de1..d70fe991d67 100644 --- a/internal/test/vote.go +++ b/internal/test/vote.go @@ -3,7 +3,7 @@ package test import ( "time" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -27,7 +27,7 @@ func MakeVote( ValidatorIndex: valIndex, Height: height, Round: round, - Type: tmproto.SignedMsgType(step), + Type: cmtproto.SignedMsgType(step), BlockID: blockID, Timestamp: time, } diff --git a/libs/autofile/autofile.go b/libs/autofile/autofile.go index 10cc04a28ff..f652420ed8c 100644 --- a/libs/autofile/autofile.go +++ b/libs/autofile/autofile.go @@ -8,7 +8,7 @@ import ( "syscall" "time" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) /* AutoFile usage @@ -64,7 +64,7 @@ func OpenAutoFile(path string) (*AutoFile, error) { return nil, err } af := &AutoFile{ - ID: tmrand.Str(12) + ":" + path, + ID: cmtrand.Str(12) + ":" + path, Path: path, closeTicker: time.NewTicker(autoFileClosePeriod), closeTickerStopc: make(chan struct{}), diff --git a/libs/autofile/autofile_test.go b/libs/autofile/autofile_test.go index ff6056fc56e..7c8e011cfaa 100644 --- a/libs/autofile/autofile_test.go +++ b/libs/autofile/autofile_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" ) func TestSIGHUP(t *testing.T) { @@ -70,10 +70,10 @@ func TestSIGHUP(t *testing.T) { require.NoError(t, err) // Both files should exist - if body := tmos.MustReadFile(filepath.Join(dir, name+"_old")); string(body) != "Line 1\nLine 2\n" { + if body := cmtos.MustReadFile(filepath.Join(dir, name+"_old")); string(body) != "Line 1\nLine 2\n" { t.Errorf("unexpected body %s", body) } - if body := tmos.MustReadFile(filepath.Join(dir, name)); string(body) != "Line 3\nLine 4\n" { + if body := cmtos.MustReadFile(filepath.Join(dir, name)); string(body) != "Line 3\nLine 4\n" { t.Errorf("unexpected body %s", body) } diff --git a/libs/autofile/cmd/logjack.go b/libs/autofile/cmd/logjack.go index 46eaf71eed4..d6ef7cc38c2 100644 --- a/libs/autofile/cmd/logjack.go +++ b/libs/autofile/cmd/logjack.go @@ -9,7 +9,7 @@ import ( "strings" auto "github.com/tendermint/tendermint/libs/autofile" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" ) const Version = "0.0.1" @@ -44,7 +44,7 @@ func (fmtLogger) Info(msg string, keyvals ...interface{}) { func main() { // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(fmtLogger{}, func() { + cmtos.TrapSignal(fmtLogger{}, func() { fmt.Println("logjack shutting down") }) diff --git a/libs/autofile/group_test.go b/libs/autofile/group_test.go index ffdb7001393..80a8e33b9e7 100644 --- a/libs/autofile/group_test.go +++ b/libs/autofile/group_test.go @@ -9,14 +9,14 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmos "github.com/tendermint/tendermint/libs/os" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func createTestGroupWithHeadSizeLimit(t *testing.T, headSizeLimit int64) *Group { - testID := tmrand.Str(12) + testID := cmtrand.Str(12) testDir := "_test_" + testID - err := tmos.EnsureDir(testDir, 0700) + err := cmtos.EnsureDir(testDir, 0700) require.NoError(t, err, "Error creating dir") headPath := testDir + "/myfile" @@ -49,7 +49,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { // Write 1000 bytes 999 times. for i := 0; i < 999; i++ { - err := g.WriteLine(tmrand.Str(999)) + err := g.WriteLine(cmtrand.Str(999)) require.NoError(t, err, "Error appending to head") } err := g.FlushAndSync() @@ -61,7 +61,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { assertGroupInfo(t, g.ReadGroupInfo(), 0, 0, 999000, 999000) // Write 1000 more bytes. - err = g.WriteLine(tmrand.Str(999)) + err = g.WriteLine(cmtrand.Str(999)) require.NoError(t, err, "Error appending to head") err = g.FlushAndSync() require.NoError(t, err) @@ -71,7 +71,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { assertGroupInfo(t, g.ReadGroupInfo(), 0, 1, 1000000, 0) // Write 1000 more bytes. - err = g.WriteLine(tmrand.Str(999)) + err = g.WriteLine(cmtrand.Str(999)) require.NoError(t, err, "Error appending to head") err = g.FlushAndSync() require.NoError(t, err) @@ -82,7 +82,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { // Write 1000 bytes 999 times. for i := 0; i < 999; i++ { - err = g.WriteLine(tmrand.Str(999)) + err = g.WriteLine(cmtrand.Str(999)) require.NoError(t, err, "Error appending to head") } err = g.FlushAndSync() @@ -94,7 +94,7 @@ func TestCheckHeadSizeLimit(t *testing.T) { assertGroupInfo(t, g.ReadGroupInfo(), 0, 2, 2000000, 0) // Write 1000 more bytes. - _, err = g.Head.Write([]byte(tmrand.Str(999) + "\n")) + _, err = g.Head.Write([]byte(cmtrand.Str(999) + "\n")) require.NoError(t, err, "Error appending to head") err = g.FlushAndSync() require.NoError(t, err) diff --git a/libs/bits/bit_array.go b/libs/bits/bit_array.go index 9d69014602d..6f12bd39bd5 100644 --- a/libs/bits/bit_array.go +++ b/libs/bits/bit_array.go @@ -7,9 +7,9 @@ import ( "strings" "sync" - tmmath "github.com/tendermint/tendermint/libs/math" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmprotobits "github.com/tendermint/tendermint/proto/tendermint/libs/bits" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtprotobits "github.com/tendermint/tendermint/proto/tendermint/libs/bits" ) // BitArray is a thread-safe implementation of a bit array. @@ -123,8 +123,8 @@ func (bA *BitArray) Or(o *BitArray) *BitArray { } bA.mtx.Lock() o.mtx.Lock() - c := bA.copyBits(tmmath.MaxInt(bA.Bits, o.Bits)) - smaller := tmmath.MinInt(len(bA.Elems), len(o.Elems)) + c := bA.copyBits(cmtmath.MaxInt(bA.Bits, o.Bits)) + smaller := cmtmath.MinInt(len(bA.Elems), len(o.Elems)) for i := 0; i < smaller; i++ { c.Elems[i] |= o.Elems[i] } @@ -150,7 +150,7 @@ func (bA *BitArray) And(o *BitArray) *BitArray { } func (bA *BitArray) and(o *BitArray) *BitArray { - c := bA.copyBits(tmmath.MinInt(bA.Bits, o.Bits)) + c := bA.copyBits(cmtmath.MinInt(bA.Bits, o.Bits)) for i := 0; i < len(c.Elems); i++ { c.Elems[i] &= o.Elems[i] } @@ -192,7 +192,7 @@ func (bA *BitArray) Sub(o *BitArray) *BitArray { // If o is longer, those bits are ignored. // If bA is longer, then skipping those iterations is equivalent // to right padding with 0's - smaller := tmmath.MinInt(len(bA.Elems), len(o.Elems)) + smaller := cmtmath.MinInt(len(bA.Elems), len(o.Elems)) for i := 0; i < smaller; i++ { // &^ is and not in golang c.Elems[i] &^= o.Elems[i] @@ -254,7 +254,7 @@ func (bA *BitArray) PickRandom() (int, bool) { return 0, false } - return trueIndices[tmrand.Intn(len(trueIndices))], true + return trueIndices[cmtrand.Intn(len(trueIndices))], true } func (bA *BitArray) getTrueIndices() []int { @@ -419,19 +419,19 @@ func (bA *BitArray) UnmarshalJSON(bz []byte) error { } // ToProto converts BitArray to protobuf -func (bA *BitArray) ToProto() *tmprotobits.BitArray { +func (bA *BitArray) ToProto() *cmtprotobits.BitArray { if bA == nil || len(bA.Elems) == 0 { return nil } - return &tmprotobits.BitArray{ + return &cmtprotobits.BitArray{ Bits: int64(bA.Bits), Elems: bA.Elems, } } // FromProto sets a protobuf BitArray to the given pointer. -func (bA *BitArray) FromProto(protoBitArray *tmprotobits.BitArray) { +func (bA *BitArray) FromProto(protoBitArray *cmtprotobits.BitArray) { if protoBitArray == nil { bA = nil return diff --git a/libs/bits/bit_array_test.go b/libs/bits/bit_array_test.go index e4306ecf209..7a5aae4383b 100644 --- a/libs/bits/bit_array_test.go +++ b/libs/bits/bit_array_test.go @@ -9,11 +9,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func randBitArray(bits int) (*BitArray, []byte) { - src := tmrand.Bytes((bits + 7) / 8) + src := cmtrand.Bytes((bits + 7) / 8) bA := NewBitArray(bits) for i := 0; i < len(src); i++ { for j := 0; j < 8; j++ { diff --git a/libs/cli/flags/log_level_test.go b/libs/cli/flags/log_level_test.go index 9d1b240095e..1a0c2abfb5e 100644 --- a/libs/cli/flags/log_level_test.go +++ b/libs/cli/flags/log_level_test.go @@ -5,7 +5,7 @@ import ( "strings" "testing" - tmflags "github.com/tendermint/tendermint/libs/cli/flags" + cmtflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" ) @@ -44,7 +44,7 @@ func TestParseLogLevel(t *testing.T) { } for _, c := range correctLogLevels { - logger, err := tmflags.ParseLogLevel(c.lvl, jsonLogger, defaultLogLevelValue) + logger, err := cmtflags.ParseLogLevel(c.lvl, jsonLogger, defaultLogLevelValue) if err != nil { t.Fatal(err) } @@ -87,7 +87,7 @@ func TestParseLogLevel(t *testing.T) { incorrectLogLevel := []string{"some", "mempool:some", "*:some,mempool:error"} for _, lvl := range incorrectLogLevel { - if _, err := tmflags.ParseLogLevel(lvl, jsonLogger, defaultLogLevelValue); err == nil { + if _, err := cmtflags.ParseLogLevel(lvl, jsonLogger, defaultLogLevelValue); err == nil { t.Fatalf("Expected %s to produce error", lvl) } } diff --git a/libs/clist/clist.go b/libs/clist/clist.go index 2e4171b1c79..8f27743e802 100644 --- a/libs/clist/clist.go +++ b/libs/clist/clist.go @@ -15,7 +15,7 @@ import ( "fmt" "sync" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // MaxLength is the max allowed number of elements a linked list is @@ -42,7 +42,7 @@ and there's no reason to serialize that condition for goroutines waiting on NextWait() (since it's just a read operation). */ type CElement struct { - mtx tmsync.RWMutex + mtx cmtsync.RWMutex prev *CElement prevWg *sync.WaitGroup prevWaitCh chan struct{} @@ -218,7 +218,7 @@ func (e *CElement) SetRemoved() { // Operations are goroutine-safe. // Panics if length grows beyond the max. type CList struct { - mtx tmsync.RWMutex + mtx cmtsync.RWMutex wg *sync.WaitGroup waitCh chan struct{} head *CElement // first element diff --git a/libs/clist/clist_test.go b/libs/clist/clist_test.go index ccb50ca8392..2224e6052d0 100644 --- a/libs/clist/clist_test.go +++ b/libs/clist/clist_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestPanicOnMaxLength(t *testing.T) { @@ -150,7 +150,7 @@ func _TestGCRandom(t *testing.T) { els = append(els, el) } - for _, i := range tmrand.Perm(numElements) { + for _, i := range cmtrand.Perm(numElements) { el := els[i] l.Remove(el) _ = el.Next() @@ -208,7 +208,7 @@ func TestScanRightDeleteRandom(t *testing.T) { // Remove an element, push back an element. for i := 0; i < numTimes; i++ { // Pick an element to remove - rmElIdx := tmrand.Intn(len(els)) + rmElIdx := cmtrand.Intn(len(els)) rmEl := els[rmElIdx] // Remove it @@ -262,7 +262,7 @@ func TestWaitChan(t *testing.T) { for i := 1; i < 100; i++ { l.PushBack(i) pushed++ - time.Sleep(time.Duration(tmrand.Intn(25)) * time.Millisecond) + time.Sleep(time.Duration(cmtrand.Intn(25)) * time.Millisecond) } // apply a deterministic pause so the counter has time to catch up time.Sleep(25 * time.Millisecond) diff --git a/libs/cmap/cmap.go b/libs/cmap/cmap.go index d16631d31cd..5e0e2b988a4 100644 --- a/libs/cmap/cmap.go +++ b/libs/cmap/cmap.go @@ -1,13 +1,13 @@ package cmap import ( - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // CMap is a goroutine-safe map type CMap struct { m map[string]interface{} - l tmsync.Mutex + l cmtsync.Mutex } func NewCMap() *CMap { diff --git a/libs/events/events.go b/libs/events/events.go index ffc06cc0233..7cd5add8f0c 100644 --- a/libs/events/events.go +++ b/libs/events/events.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // ErrListenerWasRemoved is returned by AddEvent if the listener was removed. @@ -54,7 +54,7 @@ type EventSwitch interface { type eventSwitch struct { service.BaseService - mtx tmsync.RWMutex + mtx cmtsync.RWMutex eventCells map[string]*eventCell listeners map[string]*eventListener } @@ -162,7 +162,7 @@ func (evsw *eventSwitch) FireEvent(event string, data EventData) { // eventCell handles keeping track of listener callbacks for a given event. type eventCell struct { - mtx tmsync.RWMutex + mtx cmtsync.RWMutex listeners map[string]EventCallback } @@ -206,7 +206,7 @@ type EventCallback func(data EventData) type eventListener struct { id string - mtx tmsync.RWMutex + mtx cmtsync.RWMutex removed bool events []string } diff --git a/libs/flowrate/flowrate.go b/libs/flowrate/flowrate.go index fdc168d18d2..b71cffca168 100644 --- a/libs/flowrate/flowrate.go +++ b/libs/flowrate/flowrate.go @@ -10,12 +10,12 @@ import ( "math" "time" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // Monitor monitors and limits the transfer rate of a data stream. type Monitor struct { - mu tmsync.Mutex // Mutex guarding access to all internal fields + mu cmtsync.Mutex // Mutex guarding access to all internal fields active bool // Flag indicating an active transfer start time.Duration // Transfer start time (clock() value) bytes int64 // Total number of bytes transferred diff --git a/libs/json/structs.go b/libs/json/structs.go index 2037cdad975..d4f84788c54 100644 --- a/libs/json/structs.go +++ b/libs/json/structs.go @@ -6,7 +6,7 @@ import ( "strings" "unicode" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) var ( @@ -16,7 +16,7 @@ var ( // structCache is a cache of struct info. type structInfoCache struct { - tmsync.RWMutex + cmtsync.RWMutex structInfos map[reflect.Type]*structInfo } diff --git a/libs/json/types.go b/libs/json/types.go index 13f20d2bc99..8617ad831c5 100644 --- a/libs/json/types.go +++ b/libs/json/types.go @@ -5,7 +5,7 @@ import ( "fmt" "reflect" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) var ( @@ -39,7 +39,7 @@ type typeInfo struct { // types is a type registry. It is safe for concurrent use. type types struct { - tmsync.RWMutex + cmtsync.RWMutex byType map[reflect.Type]*typeInfo byName map[string]*typeInfo } diff --git a/libs/log/lazy.go b/libs/log/lazy.go index 521fa19521a..124d841599e 100644 --- a/libs/log/lazy.go +++ b/libs/log/lazy.go @@ -3,7 +3,7 @@ package log import ( "fmt" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" ) type LazySprintf struct { @@ -27,7 +27,7 @@ type LazyBlockHash struct { } type hashable interface { - Hash() tmbytes.HexBytes + Hash() cmtbytes.HexBytes } // NewLazyBlockHash defers block Hash until the Stringer interface is invoked. diff --git a/libs/pubsub/pubsub.go b/libs/pubsub/pubsub.go index 3a1d66b3749..9a4c3e38811 100644 --- a/libs/pubsub/pubsub.go +++ b/libs/pubsub/pubsub.go @@ -39,7 +39,7 @@ import ( "fmt" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) type operation int @@ -95,7 +95,7 @@ type Server struct { // check if we have subscription before // subscribing or unsubscribing - mtx tmsync.RWMutex + mtx cmtsync.RWMutex subscriptions map[string]map[string]struct{} // subscriber -> query (string) -> empty struct } diff --git a/libs/pubsub/subscription.go b/libs/pubsub/subscription.go index d07abd86da7..f172f1338f9 100644 --- a/libs/pubsub/subscription.go +++ b/libs/pubsub/subscription.go @@ -3,7 +3,7 @@ package pubsub import ( "errors" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) var ( @@ -24,7 +24,7 @@ type Subscription struct { out chan Message canceled chan struct{} - mtx tmsync.RWMutex + mtx cmtsync.RWMutex err error } diff --git a/libs/rand/random.go b/libs/rand/random.go index 7d2410ee944..871832a2ec6 100644 --- a/libs/rand/random.go +++ b/libs/rand/random.go @@ -5,7 +5,7 @@ import ( mrand "math/rand" "time" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) const ( @@ -20,7 +20,7 @@ const ( // All of the methods here are suitable for concurrent use. // This is achieved by using a mutex lock on all of the provided methods. type Rand struct { - tmsync.Mutex + cmtsync.Mutex rand *mrand.Rand } diff --git a/libs/tempfile/tempfile.go b/libs/tempfile/tempfile.go index 922ed572210..a72a4381b5c 100644 --- a/libs/tempfile/tempfile.go +++ b/libs/tempfile/tempfile.go @@ -9,7 +9,7 @@ import ( "strings" "time" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) const ( @@ -32,7 +32,7 @@ const ( var ( atomicWriteFileRand uint64 - atomicWriteFileRandMu tmsync.Mutex + atomicWriteFileRandMu cmtsync.Mutex ) func writeFileRandReseed() uint64 { diff --git a/libs/tempfile/tempfile_test.go b/libs/tempfile/tempfile_test.go index 6ccdb22dd0e..86fa3930f2c 100644 --- a/libs/tempfile/tempfile_test.go +++ b/libs/tempfile/tempfile_test.go @@ -10,13 +10,13 @@ import ( "github.com/stretchr/testify/require" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestWriteFileAtomic(t *testing.T) { var ( - data = []byte(tmrand.Str(tmrand.Intn(2048))) - old = tmrand.Bytes(tmrand.Intn(2048)) + data = []byte(cmtrand.Str(cmtrand.Intn(2048))) + old = cmtrand.Bytes(cmtrand.Intn(2048)) perm os.FileMode = 0600 ) diff --git a/libs/test/mutate.go b/libs/test/mutate.go index f90600f5aed..7b98ee9b288 100644 --- a/libs/test/mutate.go +++ b/libs/test/mutate.go @@ -1,7 +1,7 @@ package test import ( - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) // Contract: !bytes.Equal(input, output) && len(input) >= len(output) @@ -17,11 +17,11 @@ func MutateByteSlice(bytez []byte) []byte { bytez = mBytez // Try a random mutation - switch tmrand.Int() % 2 { + switch cmtrand.Int() % 2 { case 0: // Mutate a single byte - bytez[tmrand.Int()%len(bytez)] += byte(tmrand.Int()%255 + 1) + bytez[cmtrand.Int()%len(bytez)] += byte(cmtrand.Int()%255 + 1) case 1: // Remove an arbitrary byte - pos := tmrand.Int() % len(bytez) + pos := cmtrand.Int() % len(bytez) bytez = append(bytez[:pos], bytez[pos+1:]...) } return bytez diff --git a/libs/timer/throttle_timer.go b/libs/timer/throttle_timer.go index 7f5660c059b..a6d6a8974f6 100644 --- a/libs/timer/throttle_timer.go +++ b/libs/timer/throttle_timer.go @@ -3,7 +3,7 @@ package timer import ( "time" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) /* @@ -18,7 +18,7 @@ type ThrottleTimer struct { quit chan struct{} dur time.Duration - mtx tmsync.Mutex + mtx cmtsync.Mutex timer *time.Timer isSet bool } diff --git a/libs/timer/throttle_timer_test.go b/libs/timer/throttle_timer_test.go index af990fc6d26..74434bbbbf8 100644 --- a/libs/timer/throttle_timer_test.go +++ b/libs/timer/throttle_timer_test.go @@ -8,12 +8,12 @@ import ( asrt "github.com/stretchr/testify/assert" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) type thCounter struct { input chan struct{} - mtx tmsync.Mutex + mtx cmtsync.Mutex count int } diff --git a/light/client.go b/light/client.go index 39f80a9827b..8f787a520d3 100644 --- a/light/client.go +++ b/light/client.go @@ -10,8 +10,8 @@ import ( "time" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/light/provider" "github.com/tendermint/tendermint/light/store" "github.com/tendermint/tendermint/types" @@ -62,7 +62,7 @@ func SequentialVerification() Option { // which must sign the new header in order for us to trust it. NOTE this only // applies to non-adjacent headers. For adjacent headers, sequential // verification is used. -func SkippingVerification(trustLevel tmmath.Fraction) Option { +func SkippingVerification(trustLevel cmtmath.Fraction) Option { return func(c *Client) { c.verificationMode = skipping c.trustLevel = trustLevel @@ -134,13 +134,13 @@ type Client struct { chainID string trustingPeriod time.Duration // see TrustOptions.Period verificationMode mode - trustLevel tmmath.Fraction + trustLevel cmtmath.Fraction maxRetryAttempts uint16 // see MaxRetryAttempts option maxClockDrift time.Duration maxBlockLag time.Duration // Mutex for locking during changes of the light clients providers - providerMutex tmsync.Mutex + providerMutex cmtsync.Mutex // Primary provider of new headers. primary provider.Provider // Providers used to "witness" new headers. diff --git a/light/helpers_test.go b/light/helpers_test.go index 980ded9562f..13bd09740cb 100644 --- a/light/helpers_test.go +++ b/light/helpers_test.go @@ -6,10 +6,10 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/tmhash" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" ) @@ -103,8 +103,8 @@ func makeVote(header *types.Header, valset *types.ValidatorSet, ValidatorIndex: idx, Height: header.Height, Round: 1, - Timestamp: tmtime.Now(), - Type: tmproto.PrecommitType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrecommitType, BlockID: blockID, } @@ -125,7 +125,7 @@ func genHeader(chainID string, height int64, bTime time.Time, txs types.Txs, valset, nextValset *types.ValidatorSet, appHash, consHash, resHash []byte) *types.Header { return &types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 0}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 0}, ChainID: chainID, Height: height, Time: bTime, diff --git a/light/proxy/proxy.go b/light/proxy/proxy.go index 70dca1c1077..fad4e97ca59 100644 --- a/light/proxy/proxy.go +++ b/light/proxy/proxy.go @@ -7,7 +7,7 @@ import ( "net/http" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/light" lrpc "github.com/tendermint/tendermint/light/rpc" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -96,7 +96,7 @@ func (p *Proxy) listen() (net.Listener, *http.ServeMux, error) { wm := rpcserver.NewWebsocketManager(r, rpcserver.OnDisconnect(func(remoteAddr string) { err := p.Client.UnsubscribeAll(context.Background(), remoteAddr) - if err != nil && err != tmpubsub.ErrSubscriptionNotFound { + if err != nil && err != cmtpubsub.ErrSubscriptionNotFound { wmLogger.Error("Failed to unsubscribe addr from events", "addr", remoteAddr, "err", err) } }), diff --git a/light/rpc/client.go b/light/rpc/client.go index 779ec9cc84b..aa667ac8c27 100644 --- a/light/rpc/client.go +++ b/light/rpc/client.go @@ -12,8 +12,8 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtmath "github.com/tendermint/tendermint/libs/math" service "github.com/tendermint/tendermint/libs/service" rpcclient "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -125,12 +125,12 @@ func (c *Client) ABCIInfo(ctx context.Context) (*ctypes.ResultABCIInfo, error) { } // ABCIQuery requests proof by default. -func (c *Client) ABCIQuery(ctx context.Context, path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (c *Client) ABCIQuery(ctx context.Context, path string, data cmtbytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQueryWithOptions(ctx, path, data, rpcclient.DefaultABCIQueryOptions) } // ABCIQueryWithOptions returns an error if opts.Prove is false. -func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data tmbytes.HexBytes, +func (c *Client) ABCIQueryWithOptions(ctx context.Context, path string, data cmtbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { // always request the proof @@ -452,7 +452,7 @@ func (c *Client) Header(ctx context.Context, height *int64) (*ctypes.ResultHeade } // HeaderByHash calls rpcclient#HeaderByHash and updates the client if it's falling behind. -func (c *Client) HeaderByHash(ctx context.Context, hash tmbytes.HexBytes) (*ctypes.ResultHeader, error) { +func (c *Client) HeaderByHash(ctx context.Context, hash cmtbytes.HexBytes) (*ctypes.ResultHeader, error) { res, err := c.next.HeaderByHash(ctx, hash) if err != nil { return nil, err @@ -553,7 +553,7 @@ func (c *Client) Validators( } skipCount := validateSkipCount(page, perPage) - v := l.ValidatorSet.Validators[skipCount : skipCount+tmmath.MinInt(perPage, totalCount-skipCount)] + v := l.ValidatorSet.Validators[skipCount : skipCount+cmtmath.MinInt(perPage, totalCount-skipCount)] return &ctypes.ResultValidators{ BlockHeight: l.Height, diff --git a/light/store/db/db.go b/light/store/db/db.go index 8e24a630e5e..fed75277871 100644 --- a/light/store/db/db.go +++ b/light/store/db/db.go @@ -8,9 +8,9 @@ import ( dbm "github.com/tendermint/tm-db" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/light/store" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -22,7 +22,7 @@ type dbs struct { db dbm.DB prefix string - mtx tmsync.RWMutex + mtx cmtsync.RWMutex size uint16 } @@ -120,7 +120,7 @@ func (s *dbs) LightBlock(height int64) (*types.LightBlock, error) { return nil, store.ErrLightBlockNotFound } - var lbpb tmproto.LightBlock + var lbpb cmtproto.LightBlock err = lbpb.Unmarshal(bz) if err != nil { return nil, fmt.Errorf("unmarshal error: %w", err) diff --git a/light/store/db/db_test.go b/light/store/db/db_test.go index ef9710694f7..c45533df76e 100644 --- a/light/store/db/db_test.go +++ b/light/store/db/db_test.go @@ -12,8 +12,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" ) @@ -175,8 +175,8 @@ func randLightBlock(height int64) *types.LightBlock { return &types.LightBlock{ SignedHeader: &types.SignedHeader{ Header: &types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 0}, - ChainID: tmrand.Str(12), + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 0}, + ChainID: cmtrand.Str(12), Height: height, Time: time.Now(), LastBlockID: types.BlockID{}, diff --git a/light/verifier.go b/light/verifier.go index 2ec02e8773c..e0ad91c2b6f 100644 --- a/light/verifier.go +++ b/light/verifier.go @@ -6,14 +6,14 @@ import ( "fmt" "time" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/types" ) var ( // DefaultTrustLevel - new header can be trusted if at least one correct // validator signed it. - DefaultTrustLevel = tmmath.Fraction{Numerator: 1, Denominator: 3} + DefaultTrustLevel = cmtmath.Fraction{Numerator: 1, Denominator: 3} ) // VerifyNonAdjacent verifies non-adjacent untrustedHeader against @@ -37,7 +37,7 @@ func VerifyNonAdjacent( trustingPeriod time.Duration, now time.Time, maxClockDrift time.Duration, - trustLevel tmmath.Fraction) error { + trustLevel cmtmath.Fraction) error { if untrustedHeader.Height == trustedHeader.Height+1 { return errors.New("headers must be non adjacent in height") @@ -140,7 +140,7 @@ func Verify( trustingPeriod time.Duration, now time.Time, maxClockDrift time.Duration, - trustLevel tmmath.Fraction) error { + trustLevel cmtmath.Fraction) error { if untrustedHeader.Height != trustedHeader.Height+1 { return VerifyNonAdjacent(trustedHeader, trustedVals, untrustedHeader, untrustedVals, @@ -194,7 +194,7 @@ func verifyNewHeaderAndVals( // ValidateTrustLevel checks that trustLevel is within the allowed range [1/3, // 1]. If not, it returns an error. 1/3 is the minimum amount of trust needed // which does not break the security model. -func ValidateTrustLevel(lvl tmmath.Fraction) error { +func ValidateTrustLevel(lvl cmtmath.Fraction) error { if lvl.Numerator*3 < lvl.Denominator || // < 1/3 lvl.Numerator > lvl.Denominator || // > 1 lvl.Denominator == 0 { diff --git a/light/verifier_test.go b/light/verifier_test.go index 9e10810b234..cd2049ee8e4 100644 --- a/light/verifier_test.go +++ b/light/verifier_test.go @@ -7,7 +7,7 @@ import ( "github.com/stretchr/testify/assert" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/types" ) @@ -301,27 +301,27 @@ func TestVerifyReturnsErrorIfTrustLevelIsInvalid(t *testing.T) { ) err := light.Verify(header, vals, header, vals, 2*time.Hour, time.Now(), maxClockDrift, - tmmath.Fraction{Numerator: 2, Denominator: 1}) + cmtmath.Fraction{Numerator: 2, Denominator: 1}) assert.Error(t, err) } func TestValidateTrustLevel(t *testing.T) { testCases := []struct { - lvl tmmath.Fraction + lvl cmtmath.Fraction valid bool }{ // valid - 0: {tmmath.Fraction{Numerator: 1, Denominator: 1}, true}, - 1: {tmmath.Fraction{Numerator: 1, Denominator: 3}, true}, - 2: {tmmath.Fraction{Numerator: 2, Denominator: 3}, true}, - 3: {tmmath.Fraction{Numerator: 3, Denominator: 3}, true}, - 4: {tmmath.Fraction{Numerator: 4, Denominator: 5}, true}, + 0: {cmtmath.Fraction{Numerator: 1, Denominator: 1}, true}, + 1: {cmtmath.Fraction{Numerator: 1, Denominator: 3}, true}, + 2: {cmtmath.Fraction{Numerator: 2, Denominator: 3}, true}, + 3: {cmtmath.Fraction{Numerator: 3, Denominator: 3}, true}, + 4: {cmtmath.Fraction{Numerator: 4, Denominator: 5}, true}, // invalid - 5: {tmmath.Fraction{Numerator: 6, Denominator: 5}, false}, - 6: {tmmath.Fraction{Numerator: 0, Denominator: 1}, false}, - 7: {tmmath.Fraction{Numerator: 0, Denominator: 0}, false}, - 8: {tmmath.Fraction{Numerator: 1, Denominator: 0}, false}, + 5: {cmtmath.Fraction{Numerator: 6, Denominator: 5}, false}, + 6: {cmtmath.Fraction{Numerator: 0, Denominator: 1}, false}, + 7: {cmtmath.Fraction{Numerator: 0, Denominator: 0}, false}, + 8: {cmtmath.Fraction{Numerator: 1, Denominator: 0}, false}, } for _, tc := range testCases { diff --git a/mempool/cache.go b/mempool/cache.go index 722607553f7..3c8748ff431 100644 --- a/mempool/cache.go +++ b/mempool/cache.go @@ -3,7 +3,7 @@ package mempool import ( "container/list" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/types" ) @@ -33,7 +33,7 @@ var _ TxCache = (*LRUTxCache)(nil) // LRUTxCache maintains a thread-safe LRU cache of raw transactions. The cache // only stores the hash of the raw transaction. type LRUTxCache struct { - mtx tmsync.Mutex + mtx cmtsync.Mutex size int cacheMap map[types.TxKey]*list.Element list *list.List diff --git a/mempool/v0/clist_mempool.go b/mempool/v0/clist_mempool.go index 516a57f224a..85ba96e4889 100644 --- a/mempool/v0/clist_mempool.go +++ b/mempool/v0/clist_mempool.go @@ -10,8 +10,8 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/proxy" @@ -36,7 +36,7 @@ type CListMempool struct { // Exclusive mutex for Update method to prevent concurrent execution of // CheckTx or ReapMaxBytesMaxGas(ReapMaxTxs) methods. - updateMtx tmsync.RWMutex + updateMtx cmtsync.RWMutex preCheck mempool.PreCheckFunc postCheck mempool.PostCheckFunc @@ -529,7 +529,7 @@ func (mem *CListMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs { // TODO: we will get a performance boost if we have a good estimate of avg // size per tx, and set the initial capacity based off of that. - // txs := make([]types.Tx, 0, tmmath.MinInt(mem.txs.Len(), max/mem.avgTxSize)) + // txs := make([]types.Tx, 0, cmtmath.MinInt(mem.txs.Len(), max/mem.avgTxSize)) txs := make([]types.Tx, 0, mem.txs.Len()) for e := mem.txs.Front(); e != nil; e = e.Next() { memTx := e.Value.(*mempoolTx) @@ -567,7 +567,7 @@ func (mem *CListMempool) ReapMaxTxs(max int) types.Txs { max = mem.txs.Len() } - txs := make([]types.Tx, 0, tmmath.MinInt(mem.txs.Len(), max)) + txs := make([]types.Tx, 0, cmtmath.MinInt(mem.txs.Len(), max)) for e := mem.txs.Front(); e != nil && len(txs) <= max; e = e.Next() { memTx := e.Value.(*mempoolTx) txs = append(txs, memTx.tx) diff --git a/mempool/v0/clist_mempool_test.go b/mempool/v0/clist_mempool_test.go index 8cb2aa7ad9e..776e85a31eb 100644 --- a/mempool/v0/clist_mempool_test.go +++ b/mempool/v0/clist_mempool_test.go @@ -23,7 +23,7 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/proxy" @@ -528,7 +528,7 @@ func TestMempool_CheckTxChecksTxSize(t *testing.T) { for i, testCase := range testCases { caseString := fmt.Sprintf("case %d, len %d", i, testCase.len) - tx := tmrand.Bytes(testCase.len) + tx := cmtrand.Bytes(testCase.len) err := mempl.CheckTx(tx, nil, mempool.TxInfo{}) bv := gogotypes.BytesValue{Value: tx} @@ -644,7 +644,7 @@ func TestMempoolTxsBytes(t *testing.T) { // TODO: all of the tests should probably also run using the remote proxy app // since otherwise we're not actually testing the concurrency of the mempool here! func TestMempoolRemoteAppConcurrency(t *testing.T) { - sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6)) + sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", cmtrand.Str(6)) app := kvstore.NewApplication() _, server := newRemoteApp(t, sockPath, app) t.Cleanup(func() { @@ -663,7 +663,7 @@ func TestMempoolRemoteAppConcurrency(t *testing.T) { txLen := 200 txs := make([]types.Tx, nTxs) for i := 0; i < nTxs; i++ { - txs[i] = tmrand.Bytes(txLen) + txs[i] = cmtrand.Bytes(txLen) } // simulate a group of peers sending them over and over diff --git a/mempool/v0/reactor.go b/mempool/v0/reactor.go index 30f1bc50d0a..f71b909c32b 100644 --- a/mempool/v0/reactor.go +++ b/mempool/v0/reactor.go @@ -8,7 +8,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" protomem "github.com/tendermint/tendermint/proto/tendermint/mempool" @@ -26,7 +26,7 @@ type Reactor struct { } type mempoolIDs struct { - mtx tmsync.RWMutex + mtx cmtsync.RWMutex peerMap map[p2p.ID]uint16 nextID uint16 // assumes that a node will never have over 65536 active peers activeIDs map[uint16]struct{} // used to check if a given peerID key is used, the value doesn't matter diff --git a/mempool/v0/reactor_test.go b/mempool/v0/reactor_test.go index ca4f7abad94..f41a1225fd7 100644 --- a/mempool/v0/reactor_test.go +++ b/mempool/v0/reactor_test.go @@ -17,7 +17,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p/mock" @@ -170,7 +170,7 @@ func TestReactor_MaxTxBytes(t *testing.T) { // Broadcast a tx, which has the max size // => ensure it's received by the second reactor. - tx1 := tmrand.Bytes(config.Mempool.MaxTxBytes) + tx1 := cmtrand.Bytes(config.Mempool.MaxTxBytes) err := reactors[0].mempool.CheckTx(tx1, nil, mempool.TxInfo{SenderID: mempool.UnknownPeerID}) require.NoError(t, err) waitForTxsOnReactors(t, []types.Tx{tx1}, reactors) @@ -180,7 +180,7 @@ func TestReactor_MaxTxBytes(t *testing.T) { // Broadcast a tx, which is beyond the max size // => ensure it's not sent - tx2 := tmrand.Bytes(config.Mempool.MaxTxBytes + 1) + tx2 := cmtrand.Bytes(config.Mempool.MaxTxBytes + 1) err = reactors[0].mempool.CheckTx(tx2, nil, mempool.TxInfo{SenderID: mempool.UnknownPeerID}) require.Error(t, err) } diff --git a/mempool/v1/reactor.go b/mempool/v1/reactor.go index 58218bf719f..de54a985d4a 100644 --- a/mempool/v1/reactor.go +++ b/mempool/v1/reactor.go @@ -8,7 +8,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" protomem "github.com/tendermint/tendermint/proto/tendermint/mempool" @@ -26,7 +26,7 @@ type Reactor struct { } type mempoolIDs struct { - mtx tmsync.RWMutex + mtx cmtsync.RWMutex peerMap map[p2p.ID]uint16 nextID uint16 // assumes that a node will never have over 65536 active peers activeIDs map[uint16]struct{} // used to check if a given peerID key is used, the value doesn't matter diff --git a/node/node.go b/node/node.go index 0829db7af89..5b35fab5379 100644 --- a/node/node.go +++ b/node/node.go @@ -17,7 +17,7 @@ import ( "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" mempl "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" @@ -33,7 +33,7 @@ import ( "github.com/tendermint/tendermint/statesync" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" _ "net/http/pprof" //nolint: gosec @@ -374,7 +374,7 @@ func NewNode(config *cfg.Config, // OnStart starts the Node. It implements service.Service. func (n *Node) OnStart() error { - now := tmtime.Now() + now := cmttime.Now() genTime := n.genesisDoc.GenesisTime if genTime.After(now) { n.Logger.Info("Genesis time is in the future. Sleeping until then...", "genTime", genTime) @@ -570,7 +570,7 @@ func (n *Node) startRPC() ([]net.Listener, error) { wm := rpcserver.NewWebsocketManager(routes, rpcserver.OnDisconnect(func(remoteAddr string) { err := n.eventBus.UnsubscribeAll(context.Background(), remoteAddr) - if err != nil && err != tmpubsub.ErrSubscriptionNotFound { + if err != nil && err != cmtpubsub.ErrSubscriptionNotFound { wmLogger.Error("Failed to unsubscribe addr from events", "addr", remoteAddr, "err", err) } }), diff --git a/node/node_test.go b/node/node_test.go index 01a8e01ab95..9fa68b561e1 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -21,7 +21,7 @@ import ( "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" mempl "github.com/tendermint/tendermint/mempool" mempoolv0 "github.com/tendermint/tendermint/mempool/v0" mempoolv1 "github.com/tendermint/tendermint/mempool/v1" @@ -33,7 +33,7 @@ import ( sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) func TestNodeStartStop(t *testing.T) { @@ -101,7 +101,7 @@ func TestSplitAndTrimEmpty(t *testing.T) { func TestNodeDelayedStart(t *testing.T) { config := test.ResetTestRoot("node_delayed_start_test") defer os.RemoveAll(config.RootDir) - now := tmtime.Now() + now := cmttime.Now() // create & start node n, err := DefaultNewNode(config, log.TestingLogger()) @@ -112,7 +112,7 @@ func TestNodeDelayedStart(t *testing.T) { require.NoError(t, err) defer n.Stop() //nolint:errcheck // ignore for tests - startTime := tmtime.Now() + startTime := cmttime.Now() assert.Equal(t, true, startTime.After(n.GenesisDoc().GenesisTime)) } @@ -205,7 +205,7 @@ func TestPrivValidatorListenAddrNoProtocol(t *testing.T) { } func TestNodeSetPrivValIPC(t *testing.T) { - tmpfile := "/tmp/kms." + tmrand.Str(6) + ".sock" + tmpfile := "/tmp/kms." + cmtrand.Str(6) + ".sock" defer os.Remove(tmpfile) // clean up config := test.ResetTestRoot("node_priv_val_tcp_test") @@ -319,7 +319,7 @@ func TestCreateProposalBlock(t *testing.T) { // than can fit in a block txLength := 100 for i := 0; i <= maxBytes/txLength; i++ { - tx := tmrand.Bytes(txLength) + tx := cmtrand.Bytes(txLength) err := mempool.CheckTx(tx, nil, mempl.TxInfo{}) assert.NoError(t, err) } @@ -406,7 +406,7 @@ func TestMaxProposalBlockSize(t *testing.T) { // fill the mempool with one txs just below the maximum size txLength := int(types.MaxDataBytesNoEvidence(maxBytes, 1)) - tx := tmrand.Bytes(txLength - 4) // to account for the varint + tx := cmtrand.Bytes(txLength - 4) // to account for the varint err = mempool.CheckTx(tx, nil, mempl.TxInfo{}) assert.NoError(t, err) diff --git a/node/setup.go b/node/setup.go index a70894469e4..cfc1808ec1e 100644 --- a/node/setup.go +++ b/node/setup.go @@ -21,7 +21,7 @@ import ( "github.com/tendermint/tendermint/evidence" "github.com/tendermint/tendermint/statesync" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/light" mempl "github.com/tendermint/tendermint/mempool" @@ -602,7 +602,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { return nil, errors.New("genesis doc not found") } var genDoc *types.GenesisDoc - err = tmjson.Unmarshal(b, &genDoc) + err = cmtjson.Unmarshal(b, &genDoc) if err != nil { panic(fmt.Sprintf("Failed to load genesis doc due to unmarshaling error: %v (bytes: %X)", err, b)) } @@ -611,7 +611,7 @@ func loadGenesisDoc(db dbm.DB) (*types.GenesisDoc, error) { // panics if failed to marshal the given genesis document func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) error { - b, err := tmjson.Marshal(genDoc) + b, err := cmtjson.Marshal(genDoc) if err != nil { return fmt.Errorf("failed to save genesis doc due to marshaling error: %w", err) } diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index 3fd09059c56..7da48698c3e 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -16,10 +16,10 @@ import ( flow "github.com/tendermint/tendermint/libs/flowrate" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" "github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/libs/timer" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" ) @@ -102,7 +102,7 @@ type MConnection struct { // used to ensure FlushStop and OnStop // are safe to call concurrently. - stopMtx tmsync.Mutex + stopMtx cmtsync.Mutex flushTimer *timer.ThrottleTimer // flush writes as necessary but throttled. pingTimer *time.Ticker // send pings periodically @@ -570,7 +570,7 @@ FOR_LOOP: // Peek into bufConnReader for debugging /* if numBytes := c.bufConnReader.Buffered(); numBytes > 0 { - bz, err := c.bufConnReader.Peek(tmmath.MinInt(numBytes, 100)) + bz, err := c.bufConnReader.Peek(cmtmath.MinInt(numBytes, 100)) if err == nil { // return } else { @@ -830,14 +830,14 @@ func (ch *Channel) isSendPending() bool { func (ch *Channel) nextPacketMsg() tmp2p.PacketMsg { packet := tmp2p.PacketMsg{ChannelID: int32(ch.desc.ID)} maxSize := ch.maxPacketMsgPayloadSize - packet.Data = ch.sending[:tmmath.MinInt(maxSize, len(ch.sending))] + packet.Data = ch.sending[:cmtmath.MinInt(maxSize, len(ch.sending))] if len(ch.sending) <= maxSize { packet.EOF = true ch.sending = nil atomic.AddInt32(&ch.sendQueueSize, -1) // decrement sendQueueSize } else { packet.EOF = false - ch.sending = ch.sending[tmmath.MinInt(maxSize, len(ch.sending)):] + ch.sending = ch.sending[cmtmath.MinInt(maxSize, len(ch.sending)):] } return packet } diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index 1f95df37f8b..9d706b538a9 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -26,7 +26,7 @@ import ( cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/libs/async" "github.com/tendermint/tendermint/libs/protoio" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" ) @@ -76,11 +76,11 @@ type SecretConnection struct { // are independent, so we can use two mtxs. // All .Read are covered by recvMtx, // all .Write are covered by sendMtx. - recvMtx tmsync.Mutex + recvMtx cmtsync.Mutex recvBuffer []byte recvNonce *[aeadNonceSize]byte - sendMtx tmsync.Mutex + sendMtx cmtsync.Mutex sendNonce *[aeadNonceSize]byte } diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index 7fa5abda009..7f06155aa65 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -21,8 +21,8 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/sr25519" "github.com/tendermint/tendermint/libs/async" - tmos "github.com/tendermint/tendermint/libs/os" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) // Run go test -update from within this module @@ -65,7 +65,7 @@ func TestSecretConnectionHandshake(t *testing.T) { func TestConcurrentWrite(t *testing.T) { fooSecConn, barSecConn := makeSecretConnPair(t) - fooWriteText := tmrand.Str(dataMaxSize) + fooWriteText := cmtrand.Str(dataMaxSize) // write from two routines. // should be safe from race according to net.Conn: @@ -87,7 +87,7 @@ func TestConcurrentWrite(t *testing.T) { func TestConcurrentRead(t *testing.T) { fooSecConn, barSecConn := makeSecretConnPair(t) - fooWriteText := tmrand.Str(dataMaxSize) + fooWriteText := cmtrand.Str(dataMaxSize) n := 100 // read from two routines. @@ -114,8 +114,8 @@ func TestSecretConnectionReadWrite(t *testing.T) { // Pre-generate the things to write (for foo & bar) for i := 0; i < 100; i++ { - fooWrites = append(fooWrites, tmrand.Str((tmrand.Int()%(dataMaxSize*5))+1)) - barWrites = append(barWrites, tmrand.Str((tmrand.Int()%(dataMaxSize*5))+1)) + fooWrites = append(fooWrites, cmtrand.Str((cmtrand.Int()%(dataMaxSize*5))+1)) + barWrites = append(barWrites, cmtrand.Str((cmtrand.Int()%(dataMaxSize*5))+1)) } // A helper that will run with (fooConn, fooWrites, fooReads) and vice versa @@ -229,7 +229,7 @@ func TestDeriveSecretsAndChallengeGolden(t *testing.T) { if *update { t.Logf("Updating golden test vector file %s", goldenFilepath) data := createGoldenTestVectors(t) - err := tmos.WriteFile(goldenFilepath, []byte(data), 0644) + err := cmtos.WriteFile(goldenFilepath, []byte(data), 0644) require.NoError(t, err) } f, err := os.Open(goldenFilepath) @@ -312,11 +312,11 @@ func readLots(t *testing.T, wg *sync.WaitGroup, conn io.Reader, n int) { func createGoldenTestVectors(t *testing.T) string { data := "" for i := 0; i < 32; i++ { - randSecretVector := tmrand.Bytes(32) + randSecretVector := cmtrand.Bytes(32) randSecret := new([32]byte) copy((*randSecret)[:], randSecretVector) data += hex.EncodeToString((*randSecret)[:]) + "," - locIsLeast := tmrand.Bool() + locIsLeast := cmtrand.Bool() data += strconv.FormatBool(locIsLeast) + "," recvSecret, sendSecret := deriveSecrets(randSecret, locIsLeast) data += hex.EncodeToString((*recvSecret)[:]) + "," @@ -398,7 +398,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) { } fooWriteBytes := make([][]byte, 0, len(randomMsgSizes)) for _, size := range randomMsgSizes { - fooWriteBytes = append(fooWriteBytes, tmrand.Bytes(size)) + fooWriteBytes = append(fooWriteBytes, cmtrand.Bytes(size)) } // Consume reads from bar's reader go func() { @@ -416,7 +416,7 @@ func BenchmarkWriteSecretConnection(b *testing.B) { b.StartTimer() for i := 0; i < b.N; i++ { - idx := tmrand.Intn(len(fooWriteBytes)) + idx := cmtrand.Intn(len(fooWriteBytes)) _, err := fooSecConn.Write(fooWriteBytes[idx]) if err != nil { b.Errorf("failed to write to fooSecConn: %v", err) @@ -446,11 +446,11 @@ func BenchmarkReadSecretConnection(b *testing.B) { } fooWriteBytes := make([][]byte, 0, len(randomMsgSizes)) for _, size := range randomMsgSizes { - fooWriteBytes = append(fooWriteBytes, tmrand.Bytes(size)) + fooWriteBytes = append(fooWriteBytes, cmtrand.Bytes(size)) } go func() { for i := 0; i < b.N; i++ { - idx := tmrand.Intn(len(fooWriteBytes)) + idx := cmtrand.Intn(len(fooWriteBytes)) _, err := fooSecConn.Write(fooWriteBytes[idx]) if err != nil { b.Errorf("failed to write to fooSecConn: %v, %v,%v", err, i, b.N) diff --git a/p2p/conn_set.go b/p2p/conn_set.go index 376510d7270..0a568c37f6e 100644 --- a/p2p/conn_set.go +++ b/p2p/conn_set.go @@ -3,7 +3,7 @@ package p2p import ( "net" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // ConnSet is a lookup table for connections and all their ips. @@ -21,7 +21,7 @@ type connSetItem struct { } type connSet struct { - tmsync.RWMutex + cmtsync.RWMutex conns map[string]connSetItem } diff --git a/p2p/fuzz.go b/p2p/fuzz.go index e41e989bb9f..5110a101a2c 100644 --- a/p2p/fuzz.go +++ b/p2p/fuzz.go @@ -5,8 +5,8 @@ import ( "time" "github.com/tendermint/tendermint/config" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // FuzzedConnection wraps any net.Conn and depending on the mode either delays @@ -14,7 +14,7 @@ import ( type FuzzedConnection struct { conn net.Conn - mtx tmsync.Mutex + mtx cmtsync.Mutex start <-chan time.Time active bool @@ -103,7 +103,7 @@ func (fc *FuzzedConnection) SetWriteDeadline(t time.Time) error { func (fc *FuzzedConnection) randomDuration() time.Duration { maxDelayMillis := int(fc.config.MaxDelay.Nanoseconds() / 1000) - return time.Millisecond * time.Duration(tmrand.Int()%maxDelayMillis) //nolint: gas + return time.Millisecond * time.Duration(cmtrand.Int()%maxDelayMillis) //nolint: gas } // implements the fuzz (delay, kill conn) @@ -116,7 +116,7 @@ func (fc *FuzzedConnection) fuzz() bool { switch fc.config.Mode { case config.FuzzModeDrop: // randomly drop the r/w, drop the conn, or sleep - r := tmrand.Float64() + r := cmtrand.Float64() switch { case r <= fc.config.ProbDropRW: return true diff --git a/p2p/key.go b/p2p/key.go index f98e88eee0e..a6fc7dd91ab 100644 --- a/p2p/key.go +++ b/p2p/key.go @@ -8,8 +8,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - tmjson "github.com/tendermint/tendermint/libs/json" - tmos "github.com/tendermint/tendermint/libs/os" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtos "github.com/tendermint/tendermint/libs/os" ) // ID is a hex-encoded crypto.Address @@ -48,7 +48,7 @@ func PubKeyToID(pubKey crypto.PubKey) ID { // LoadOrGenNodeKey attempts to load the NodeKey from the given filePath. If // the file does not exist, it generates and saves a new NodeKey. func LoadOrGenNodeKey(filePath string) (*NodeKey, error) { - if tmos.FileExists(filePath) { + if cmtos.FileExists(filePath) { nodeKey, err := LoadNodeKey(filePath) if err != nil { return nil, err @@ -75,7 +75,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) { return nil, err } nodeKey := new(NodeKey) - err = tmjson.Unmarshal(jsonBytes, nodeKey) + err = cmtjson.Unmarshal(jsonBytes, nodeKey) if err != nil { return nil, err } @@ -84,7 +84,7 @@ func LoadNodeKey(filePath string) (*NodeKey, error) { // SaveAs persists the NodeKey to filePath. func (nodeKey *NodeKey) SaveAs(filePath string) error { - jsonBytes, err := tmjson.Marshal(nodeKey) + jsonBytes, err := cmtjson.Marshal(nodeKey) if err != nil { return err } diff --git a/p2p/key_test.go b/p2p/key_test.go index 7593df239cc..4930900b870 100644 --- a/p2p/key_test.go +++ b/p2p/key_test.go @@ -10,11 +10,11 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestLoadOrGenNodeKey(t *testing.T) { - filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json") + filePath := filepath.Join(os.TempDir(), cmtrand.Str(12)+"_peer_id.json") nodeKey, err := LoadOrGenNodeKey(filePath) assert.Nil(t, err) @@ -26,7 +26,7 @@ func TestLoadOrGenNodeKey(t *testing.T) { } func TestLoadNodeKey(t *testing.T) { - filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json") + filePath := filepath.Join(os.TempDir(), cmtrand.Str(12)+"_peer_id.json") _, err := LoadNodeKey(filePath) assert.True(t, os.IsNotExist(err)) @@ -40,7 +40,7 @@ func TestLoadNodeKey(t *testing.T) { } func TestNodeKeySaveAs(t *testing.T) { - filePath := filepath.Join(os.TempDir(), tmrand.Str(12)+"_peer_id.json") + filePath := filepath.Join(os.TempDir(), cmtrand.Str(12)+"_peer_id.json") assert.NoFileExists(t, filePath) diff --git a/p2p/node_info.go b/p2p/node_info.go index 6b004680458..ced32374480 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -6,8 +6,8 @@ import ( "fmt" "reflect" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmstrings "github.com/tendermint/tendermint/libs/strings" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtstrings "github.com/tendermint/tendermint/libs/strings" tmp2p "github.com/tendermint/tendermint/proto/tendermint/p2p" "github.com/tendermint/tendermint/version" ) @@ -86,9 +86,9 @@ type DefaultNodeInfo struct { // Check compatibility. // Channels are HexBytes so easier to read as JSON - Network string `json:"network"` // network/chain ID - Version string `json:"version"` // major.minor.revision - Channels tmbytes.HexBytes `json:"channels"` // channels this node knows about + Network string `json:"network"` // network/chain ID + Version string `json:"version"` // major.minor.revision + Channels cmtbytes.HexBytes `json:"channels"` // channels this node knows about // ASCIIText fields Moniker string `json:"moniker"` // arbitrary moniker @@ -133,7 +133,7 @@ func (info DefaultNodeInfo) Validate() error { // Validate Version if len(info.Version) > 0 && - (!tmstrings.IsASCIIText(info.Version) || tmstrings.ASCIITrim(info.Version) == "") { + (!cmtstrings.IsASCIIText(info.Version) || cmtstrings.ASCIITrim(info.Version) == "") { return fmt.Errorf("info.Version must be valid ASCII text without tabs, but got %v", info.Version) } @@ -152,7 +152,7 @@ func (info DefaultNodeInfo) Validate() error { } // Validate Moniker. - if !tmstrings.IsASCIIText(info.Moniker) || tmstrings.ASCIITrim(info.Moniker) == "" { + if !cmtstrings.IsASCIIText(info.Moniker) || cmtstrings.ASCIITrim(info.Moniker) == "" { return fmt.Errorf("info.Moniker must be valid non-empty ASCII text without tabs, but got %v", info.Moniker) } @@ -166,7 +166,7 @@ func (info DefaultNodeInfo) Validate() error { } // XXX: Should we be more strict about address formats? rpcAddr := other.RPCAddress - if len(rpcAddr) > 0 && (!tmstrings.IsASCIIText(rpcAddr) || tmstrings.ASCIITrim(rpcAddr) == "") { + if len(rpcAddr) > 0 && (!cmtstrings.IsASCIIText(rpcAddr) || cmtstrings.ASCIITrim(rpcAddr) == "") { return fmt.Errorf("info.Other.RPCAddress=%v must be valid ASCII text without tabs", rpcAddr) } diff --git a/p2p/peer.go b/p2p/peer.go index 9a61cc896c9..d364e9e8fa4 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -12,7 +12,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" - tmconn "github.com/tendermint/tendermint/p2p/conn" + cmtconn "github.com/tendermint/tendermint/p2p/conn" ) //go:generate ../scripts/mockery_generate.sh Peer @@ -34,7 +34,7 @@ type Peer interface { CloseConn() error // close original connection NodeInfo() NodeInfo // peer's info - Status() tmconn.ConnectionStatus + Status() cmtconn.ConnectionStatus SocketAddr() *NetAddress // actual address of the socket Send(Envelope) bool @@ -78,7 +78,7 @@ func newPeerConn( // ID only exists for SecretConnection. // NOTE: Will panic if conn is not *SecretConnection. func (pc peerConn) ID() ID { - return PubKeyToID(pc.conn.(*tmconn.SecretConnection).RemotePubKey()) + return PubKeyToID(pc.conn.(*cmtconn.SecretConnection).RemotePubKey()) } // Return the IP from the connection RemoteAddr @@ -110,7 +110,7 @@ type peer struct { // raw peerConn and the multiplex connection peerConn - mconn *tmconn.MConnection + mconn *cmtconn.MConnection // peer's node info and the channel it knows about // channels = nodeInfo.Channels @@ -133,11 +133,11 @@ type PeerOption func(*peer) func newPeer( pc peerConn, - mConfig tmconn.MConnConfig, + mConfig cmtconn.MConnConfig, nodeInfo NodeInfo, reactorsByCh map[byte]Reactor, msgTypeByChID map[byte]proto.Message, - chDescs []*tmconn.ChannelDescriptor, + chDescs []*cmtconn.ChannelDescriptor, onPeerError func(Peer, interface{}), mlc *metricsLabelCache, options ...PeerOption, @@ -251,7 +251,7 @@ func (p *peer) SocketAddr() *NetAddress { } // Status returns the peer's ConnectionStatus. -func (p *peer) Status() tmconn.ConnectionStatus { +func (p *peer) Status() cmtconn.ConnectionStatus { return p.mconn.Status() } @@ -392,10 +392,10 @@ func createMConnection( p *peer, reactorsByCh map[byte]Reactor, msgTypeByChID map[byte]proto.Message, - chDescs []*tmconn.ChannelDescriptor, + chDescs []*cmtconn.ChannelDescriptor, onPeerError func(Peer, interface{}), - config tmconn.MConnConfig, -) *tmconn.MConnection { + config cmtconn.MConnConfig, +) *cmtconn.MConnection { onReceive := func(chID byte, msgBytes []byte) { reactor := reactorsByCh[chID] @@ -433,7 +433,7 @@ func createMConnection( onPeerError(p, r) } - return tmconn.NewMConnectionWithConfig( + return cmtconn.NewMConnectionWithConfig( conn, chDescs, onReceive, diff --git a/p2p/peer_set.go b/p2p/peer_set.go index 30bcc4d32f5..c27d579801c 100644 --- a/p2p/peer_set.go +++ b/p2p/peer_set.go @@ -3,7 +3,7 @@ package p2p import ( "net" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" ) // IPeerSet has a (immutable) subset of the methods of PeerSet. @@ -20,7 +20,7 @@ type IPeerSet interface { // PeerSet is a special structure for keeping a table of peers. // Iteration over the peers is super fast and thread-safe. type PeerSet struct { - mtx tmsync.Mutex + mtx cmtsync.Mutex lookup map[ID]*peerSetItem list []Peer } diff --git a/p2p/peer_test.go b/p2p/peer_test.go index ddfeb423415..2309a3d4823 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -18,7 +18,7 @@ import ( "github.com/tendermint/tendermint/proto/tendermint/p2p" "github.com/tendermint/tendermint/config" - tmconn "github.com/tendermint/tendermint/p2p/conn" + cmtconn "github.com/tendermint/tendermint/p2p/conn" ) func TestPeerBasic(t *testing.T) { @@ -29,7 +29,7 @@ func TestPeerBasic(t *testing.T) { rp.Start() t.Cleanup(rp.Stop) - p, err := createOutboundPeerAndPerformHandshake(rp.Addr(), cfg, tmconn.DefaultMConnConfig()) + p, err := createOutboundPeerAndPerformHandshake(rp.Addr(), cfg, cmtconn.DefaultMConnConfig()) require.Nil(err) err = p.Start() @@ -59,7 +59,7 @@ func TestPeerSend(t *testing.T) { rp.Start() t.Cleanup(rp.Stop) - p, err := createOutboundPeerAndPerformHandshake(rp.Addr(), config, tmconn.DefaultMConnConfig()) + p, err := createOutboundPeerAndPerformHandshake(rp.Addr(), config, cmtconn.DefaultMConnConfig()) require.Nil(err) err = p.Start() @@ -78,9 +78,9 @@ func TestPeerSend(t *testing.T) { func createOutboundPeerAndPerformHandshake( addr *NetAddress, config *config.P2PConfig, - mConfig tmconn.MConnConfig, + mConfig cmtconn.MConnConfig, ) (*peer, error) { - chDescs := []*tmconn.ChannelDescriptor{ + chDescs := []*cmtconn.ChannelDescriptor{ {ID: testCh, Priority: 1}, } reactorsByCh := map[byte]Reactor{testCh: NewTestReactor(chDescs, true)} diff --git a/p2p/pex/addrbook.go b/p2p/pex/addrbook.go index 2b8071041f1..5b696c1a838 100644 --- a/p2p/pex/addrbook.go +++ b/p2p/pex/addrbook.go @@ -18,10 +18,10 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" ) @@ -89,8 +89,8 @@ type addrBook struct { service.BaseService // accessed concurrently - mtx tmsync.Mutex - rand *tmrand.Rand + mtx cmtsync.Mutex + rand *cmtrand.Rand ourAddrs map[string]struct{} privateIDs map[p2p.ID]struct{} addrLookup map[p2p.ID]*knownAddress // new & old @@ -122,7 +122,7 @@ func mustNewHasher() hash.Hash64 { // Use Start to begin processing asynchronous address updates. func NewAddrBook(filePath string, routabilityStrict bool) AddrBook { am := &addrBook{ - rand: tmrand.NewRand(), + rand: cmtrand.NewRand(), ourAddrs: make(map[string]struct{}), privateIDs: make(map[p2p.ID]struct{}), addrLookup: make(map[p2p.ID]*knownAddress), @@ -403,10 +403,10 @@ func (a *addrBook) GetSelection() []*p2p.NetAddress { return nil } - numAddresses := tmmath.MaxInt( - tmmath.MinInt(minGetSelection, bookSize), + numAddresses := cmtmath.MaxInt( + cmtmath.MinInt(minGetSelection, bookSize), bookSize*getSelectionPercent/100) - numAddresses = tmmath.MinInt(maxGetSelection, numAddresses) + numAddresses = cmtmath.MinInt(maxGetSelection, numAddresses) // XXX: instead of making a list of all addresses, shuffling, and slicing a random chunk, // could we just select a random numAddresses of indexes? @@ -421,7 +421,7 @@ func (a *addrBook) GetSelection() []*p2p.NetAddress { // `numAddresses' since we are throwing the rest. for i := 0; i < numAddresses; i++ { // pick a number between current index and the end - j := tmrand.Intn(len(allAddr)-i) + i + j := cmtrand.Intn(len(allAddr)-i) + i allAddr[i], allAddr[j] = allAddr[j], allAddr[i] } @@ -460,14 +460,14 @@ func (a *addrBook) GetSelectionWithBias(biasTowardsNewAddrs int) []*p2p.NetAddre biasTowardsNewAddrs = 0 } - numAddresses := tmmath.MaxInt( - tmmath.MinInt(minGetSelection, bookSize), + numAddresses := cmtmath.MaxInt( + cmtmath.MinInt(minGetSelection, bookSize), bookSize*getSelectionPercent/100) - numAddresses = tmmath.MinInt(maxGetSelection, numAddresses) + numAddresses = cmtmath.MinInt(maxGetSelection, numAddresses) // number of new addresses that, if possible, should be in the beginning of the selection // if there are no enough old addrs, will choose new addr instead. - numRequiredNewAdd := tmmath.MaxInt(percentageOfNum(biasTowardsNewAddrs, numAddresses), numAddresses-a.nOld) + numRequiredNewAdd := cmtmath.MaxInt(percentageOfNum(biasTowardsNewAddrs, numAddresses), numAddresses-a.nOld) selection := a.randomPickAddresses(bucketTypeNew, numRequiredNewAdd) selection = append(selection, a.randomPickAddresses(bucketTypeOld, numAddresses-len(selection))...) return selection diff --git a/p2p/pex/addrbook_test.go b/p2p/pex/addrbook_test.go index e7888662a2e..588c2bdb376 100644 --- a/p2p/pex/addrbook_test.go +++ b/p2p/pex/addrbook_test.go @@ -13,8 +13,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" ) @@ -193,13 +193,13 @@ func randNetAddressPairs(t *testing.T, n int) []netAddressPair { func randIPv4Address(t *testing.T) *p2p.NetAddress { for { ip := fmt.Sprintf("%v.%v.%v.%v", - tmrand.Intn(254)+1, - tmrand.Intn(255), - tmrand.Intn(255), - tmrand.Intn(255), + cmtrand.Intn(254)+1, + cmtrand.Intn(255), + cmtrand.Intn(255), + cmtrand.Intn(255), ) - port := tmrand.Intn(65535-1) + 1 - id := p2p.ID(hex.EncodeToString(tmrand.Bytes(p2p.IDByteLength))) + port := cmtrand.Intn(65535-1) + 1 + id := p2p.ID(hex.EncodeToString(cmtrand.Bytes(p2p.IDByteLength))) idAddr := p2p.IDAddressString(id, fmt.Sprintf("%v:%v", ip, port)) addr, err := p2p.NewNetAddressString(idAddr) assert.Nil(t, err, "error generating rand network address") @@ -525,8 +525,8 @@ func testAddrBookAddressSelection(t *testing.T, bookSize int) { // There is at least one partition and at most three. var ( k = percentageOfNum(biasToSelectNewPeers, nAddrs) - expNew = tmmath.MinInt(nNew, tmmath.MaxInt(k, nAddrs-nBookOld)) - expOld = tmmath.MinInt(nOld, nAddrs-expNew) + expNew = cmtmath.MinInt(nNew, cmtmath.MaxInt(k, nAddrs-nBookOld)) + expOld = cmtmath.MinInt(nOld, nAddrs-expNew) ) // Verify that the number of old and new addresses are as expected @@ -580,7 +580,7 @@ func TestMultipleAddrBookAddressSelection(t *testing.T) { ranges := [...][]int{{33, 100}, {100, 175}} bookSizes := make([]int, 0, len(ranges)) for _, r := range ranges { - bookSizes = append(bookSizes, tmrand.Intn(r[1]-r[0])+r[0]) + bookSizes = append(bookSizes, cmtrand.Intn(r[1]-r[0])+r[0]) } t.Logf("Testing address selection for the following book sizes %v\n", bookSizes) for _, bookSize := range bookSizes { diff --git a/p2p/pex/pex_reactor.go b/p2p/pex/pex_reactor.go index 3296648d0e7..16d6af3833b 100644 --- a/p2p/pex/pex_reactor.go +++ b/p2p/pex/pex_reactor.go @@ -7,8 +7,8 @@ import ( "time" "github.com/tendermint/tendermint/libs/cmap" - tmmath "github.com/tendermint/tendermint/libs/math" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/p2p/conn" @@ -417,7 +417,7 @@ func (r *Reactor) SetEnsurePeersPeriod(d time.Duration) { // Ensures that sufficient peers are connected. (continuous) func (r *Reactor) ensurePeersRoutine() { var ( - seed = tmrand.NewRand() + seed = cmtrand.NewRand() jitter = seed.Int63n(r.ensurePeersPeriod.Nanoseconds()) ) @@ -470,7 +470,7 @@ func (r *Reactor) ensurePeers() { // bias to prefer more vetted peers when we have fewer connections. // not perfect, but somewhate ensures that we prioritize connecting to more-vetted // NOTE: range here is [10, 90]. Too high ? - newBias := tmmath.MinInt(out, 8)*10 + 10 + newBias := cmtmath.MinInt(out, 8)*10 + 10 toDial := make(map[p2p.ID]*p2p.NetAddress) // Try maxAttempts times to pick numToDial addresses to dial @@ -519,7 +519,7 @@ func (r *Reactor) ensurePeers() { peers := r.Switch.Peers().List() peersCount := len(peers) if peersCount > 0 { - peer := peers[tmrand.Int()%peersCount] + peer := peers[cmtrand.Int()%peersCount] r.Logger.Info("We need more addresses. Sending pexRequest to random peer", "peer", peer) r.RequestAddrs(peer) } @@ -552,7 +552,7 @@ func (r *Reactor) dialPeer(addr *p2p.NetAddress) error { // exponential backoff if it's not our first attempt to dial given address if attempts > 0 { - jitter := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) + jitter := time.Duration(cmtrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) backoffDuration := jitter + ((1 << uint(attempts)) * time.Second) backoffDuration = r.maxBackoffDurationForPeer(addr, backoffDuration) sinceLastDialed := time.Since(lastDialed) @@ -618,7 +618,7 @@ func (r *Reactor) checkSeeds() (numOnline int, netAddrs []*p2p.NetAddress, err e // randomly dial seeds until we connect to one or exhaust them func (r *Reactor) dialSeeds() { - perm := tmrand.Perm(len(r.seedAddrs)) + perm := cmtrand.Perm(len(r.seedAddrs)) // perm := r.Switch.rng.Perm(lSeeds) for _, i := range perm { // dial a random seed diff --git a/p2p/switch_test.go b/p2p/switch_test.go index 4a75033f1cc..1e735226a33 100644 --- a/p2p/switch_test.go +++ b/p2p/switch_test.go @@ -22,7 +22,7 @@ import ( "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p/conn" p2pproto "github.com/tendermint/tendermint/proto/tendermint/p2p" ) @@ -45,7 +45,7 @@ type PeerMessage struct { type TestReactor struct { BaseReactor - mtx tmsync.Mutex + mtx cmtsync.Mutex channels []*conn.ChannelDescriptor logMessages bool msgsCounter int diff --git a/p2p/test_util.go b/p2p/test_util.go index 1d9a4883cb2..ccc692c4e0d 100644 --- a/p2p/test_util.go +++ b/p2p/test_util.go @@ -8,8 +8,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtnet "github.com/tendermint/tendermint/libs/net" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/p2p/conn" @@ -51,11 +51,11 @@ func CreateRoutableAddr() (addr string, netAddr *NetAddress) { for { var err error addr = fmt.Sprintf("%X@%v.%v.%v.%v:26656", - tmrand.Bytes(20), - tmrand.Int()%256, - tmrand.Int()%256, - tmrand.Int()%256, - tmrand.Int()%256) + cmtrand.Bytes(20), + cmtrand.Int()%256, + cmtrand.Int()%256, + cmtrand.Int()%256, + cmtrand.Int()%256) netAddr, err = NewNetAddressString(addr) if err != nil { panic(err) @@ -276,7 +276,7 @@ func testNodeInfoWithNetwork(id ID, name, network string) NodeInfo { } func getFreePort() int { - port, err := tmnet.GetFreePort() + port, err := cmtnet.GetFreePort() if err != nil { panic(err) } diff --git a/privval/file.go b/privval/file.go index ad56239159e..d4cd27a6d16 100644 --- a/privval/file.go +++ b/privval/file.go @@ -11,14 +11,14 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmjson "github.com/tendermint/tendermint/libs/json" - tmos "github.com/tendermint/tendermint/libs/os" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/tempfile" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) // TODO: type ? @@ -30,11 +30,11 @@ const ( ) // A vote is either stepPrevote or stepPrecommit. -func voteToStep(vote *tmproto.Vote) int8 { +func voteToStep(vote *cmtproto.Vote) int8 { switch vote.Type { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: return stepPrevote - case tmproto.PrecommitType: + case cmtproto.PrecommitType: return stepPrecommit default: panic(fmt.Sprintf("Unknown vote type: %v", vote.Type)) @@ -59,7 +59,7 @@ func (pvKey FilePVKey) Save() { panic("cannot save PrivValidator key: filePath not set") } - jsonBytes, err := tmjson.MarshalIndent(pvKey, "", " ") + jsonBytes, err := cmtjson.MarshalIndent(pvKey, "", " ") if err != nil { panic(err) } @@ -73,11 +73,11 @@ func (pvKey FilePVKey) Save() { // FilePVLastSignState stores the mutable part of PrivValidator. type FilePVLastSignState struct { - Height int64 `json:"height"` - Round int32 `json:"round"` - Step int8 `json:"step"` - Signature []byte `json:"signature,omitempty"` - SignBytes tmbytes.HexBytes `json:"signbytes,omitempty"` + Height int64 `json:"height"` + Round int32 `json:"round"` + Step int8 `json:"step"` + Signature []byte `json:"signature,omitempty"` + SignBytes cmtbytes.HexBytes `json:"signbytes,omitempty"` filePath string } @@ -129,7 +129,7 @@ func (lss *FilePVLastSignState) Save() { if outFile == "" { panic("cannot save FilePVLastSignState: filePath not set") } - jsonBytes, err := tmjson.MarshalIndent(lss, "", " ") + jsonBytes, err := cmtjson.MarshalIndent(lss, "", " ") if err != nil { panic(err) } @@ -190,12 +190,12 @@ func LoadFilePVEmptyState(keyFilePath, stateFilePath string) *FilePV { func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV { keyJSONBytes, err := os.ReadFile(keyFilePath) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } pvKey := FilePVKey{} - err = tmjson.Unmarshal(keyJSONBytes, &pvKey) + err = cmtjson.Unmarshal(keyJSONBytes, &pvKey) if err != nil { - tmos.Exit(fmt.Sprintf("Error reading PrivValidator key from %v: %v\n", keyFilePath, err)) + cmtos.Exit(fmt.Sprintf("Error reading PrivValidator key from %v: %v\n", keyFilePath, err)) } // overwrite pubkey and address for convenience @@ -208,11 +208,11 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV { if loadState { stateJSONBytes, err := os.ReadFile(stateFilePath) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } - err = tmjson.Unmarshal(stateJSONBytes, &pvState) + err = cmtjson.Unmarshal(stateJSONBytes, &pvState) if err != nil { - tmos.Exit(fmt.Sprintf("Error reading PrivValidator state from %v: %v\n", stateFilePath, err)) + cmtos.Exit(fmt.Sprintf("Error reading PrivValidator state from %v: %v\n", stateFilePath, err)) } } @@ -228,7 +228,7 @@ func loadFilePV(keyFilePath, stateFilePath string, loadState bool) *FilePV { // or else generates a new one and saves it to the filePaths. func LoadOrGenFilePV(keyFilePath, stateFilePath string) *FilePV { var pv *FilePV - if tmos.FileExists(keyFilePath) { + if cmtos.FileExists(keyFilePath) { pv = LoadFilePV(keyFilePath, stateFilePath) } else { pv = GenFilePV(keyFilePath, stateFilePath) @@ -251,7 +251,7 @@ func (pv *FilePV) GetPubKey() (crypto.PubKey, error) { // SignVote signs a canonical representation of the vote, along with the // chainID. Implements PrivValidator. -func (pv *FilePV) SignVote(chainID string, vote *tmproto.Vote) error { +func (pv *FilePV) SignVote(chainID string, vote *cmtproto.Vote) error { if err := pv.signVote(chainID, vote); err != nil { return fmt.Errorf("error signing vote: %v", err) } @@ -260,7 +260,7 @@ func (pv *FilePV) SignVote(chainID string, vote *tmproto.Vote) error { // SignProposal signs a canonical representation of the proposal, along with // the chainID. Implements PrivValidator. -func (pv *FilePV) SignProposal(chainID string, proposal *tmproto.Proposal) error { +func (pv *FilePV) SignProposal(chainID string, proposal *cmtproto.Proposal) error { if err := pv.signProposal(chainID, proposal); err != nil { return fmt.Errorf("error signing proposal: %v", err) } @@ -301,7 +301,7 @@ func (pv *FilePV) String() string { // signVote checks if the vote is good to sign and sets the vote signature. // It may need to set the timestamp as well if the vote is otherwise the same as // a previously signed vote (ie. we crashed after signing but before the vote hit the WAL). -func (pv *FilePV) signVote(chainID string, vote *tmproto.Vote) error { +func (pv *FilePV) signVote(chainID string, vote *cmtproto.Vote) error { height, round, step := vote.Height, vote.Round, voteToStep(vote) lss := pv.LastSignState @@ -343,7 +343,7 @@ func (pv *FilePV) signVote(chainID string, vote *tmproto.Vote) error { // signProposal checks if the proposal is good to sign and sets the proposal signature. // It may need to set the timestamp as well if the proposal is otherwise the same as // a previously signed proposal ie. we crashed after signing but before the proposal hit the WAL). -func (pv *FilePV) signProposal(chainID string, proposal *tmproto.Proposal) error { +func (pv *FilePV) signProposal(chainID string, proposal *cmtproto.Proposal) error { height, round, step := proposal.Height, proposal.Round, stepPropose lss := pv.LastSignState @@ -399,7 +399,7 @@ func (pv *FilePV) saveSigned(height int64, round int32, step int8, // returns the timestamp from the lastSignBytes. // returns true if the only difference in the votes is their timestamp. func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) { - var lastVote, newVote tmproto.CanonicalVote + var lastVote, newVote cmtproto.CanonicalVote if err := protoio.UnmarshalDelimited(lastSignBytes, &lastVote); err != nil { panic(fmt.Sprintf("LastSignBytes cannot be unmarshalled into vote: %v", err)) } @@ -409,7 +409,7 @@ func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.T lastTime := lastVote.Timestamp // set the times to the same value and check equality - now := tmtime.Now() + now := cmttime.Now() lastVote.Timestamp = now newVote.Timestamp = now @@ -419,7 +419,7 @@ func checkVotesOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.T // returns the timestamp from the lastSignBytes. // returns true if the only difference in the proposals is their timestamp func checkProposalsOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (time.Time, bool) { - var lastProposal, newProposal tmproto.CanonicalProposal + var lastProposal, newProposal cmtproto.CanonicalProposal if err := protoio.UnmarshalDelimited(lastSignBytes, &lastProposal); err != nil { panic(fmt.Sprintf("LastSignBytes cannot be unmarshalled into proposal: %v", err)) } @@ -429,7 +429,7 @@ func checkProposalsOnlyDifferByTimestamp(lastSignBytes, newSignBytes []byte) (ti lastTime := lastProposal.Timestamp // set the times to the same value and check equality - now := tmtime.Now() + now := cmttime.Now() lastProposal.Timestamp = now newProposal.Timestamp = now diff --git a/privval/file_test.go b/privval/file_test.go index c847af2fdf0..3f2f7f3ed4f 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -12,11 +12,11 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/tmhash" - tmjson "github.com/tendermint/tendermint/libs/json" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) func TestGenLoadValidator(t *testing.T) { @@ -53,8 +53,8 @@ func TestResetValidator(t *testing.T) { // test vote height, round := int64(10), int32(1) - voteType := tmproto.PrevoteType - randBytes := tmrand.Bytes(tmhash.Size) + voteType := cmtproto.PrevoteType + randBytes := cmtrand.Bytes(tmhash.Size) blockID := types.BlockID{Hash: randBytes, PartSetHeader: types.PartSetHeader{}} vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID) err = privVal.SignVote("mychainid", vote.ToProto()) @@ -102,7 +102,7 @@ func TestUnmarshalValidatorState(t *testing.T) { }` val := FilePVLastSignState{} - err := tmjson.Unmarshal([]byte(serialized), &val) + err := cmtjson.Unmarshal([]byte(serialized), &val) require.Nil(err, "%+v", err) // make sure the values match @@ -111,7 +111,7 @@ func TestUnmarshalValidatorState(t *testing.T) { assert.EqualValues(val.Step, 1) // export it and make sure it is the same - out, err := tmjson.Marshal(val) + out, err := cmtjson.Marshal(val) require.Nil(err, "%+v", err) assert.JSONEq(serialized, string(out)) } @@ -141,7 +141,7 @@ func TestUnmarshalValidatorKey(t *testing.T) { }`, addr, pubB64, privB64) val := FilePVKey{} - err := tmjson.Unmarshal([]byte(serialized), &val) + err := cmtjson.Unmarshal([]byte(serialized), &val) require.Nil(err, "%+v", err) // make sure the values match @@ -150,7 +150,7 @@ func TestUnmarshalValidatorKey(t *testing.T) { assert.EqualValues(privKey, val.PrivKey) // export it and make sure it is the same - out, err := tmjson.Marshal(val) + out, err := cmtjson.Marshal(val) require.Nil(err, "%+v", err) assert.JSONEq(serialized, string(out)) } @@ -165,8 +165,8 @@ func TestSignVote(t *testing.T) { privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name()) - randbytes := tmrand.Bytes(tmhash.Size) - randbytes2 := tmrand.Bytes(tmhash.Size) + randbytes := cmtrand.Bytes(tmhash.Size) + randbytes2 := cmtrand.Bytes(tmhash.Size) block1 := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{Total: 5, Hash: randbytes}} @@ -174,7 +174,7 @@ func TestSignVote(t *testing.T) { PartSetHeader: types.PartSetHeader{Total: 10, Hash: randbytes2}} height, round := int64(10), int32(1) - voteType := tmproto.PrevoteType + voteType := cmtproto.PrevoteType // sign a vote for first time vote := newVote(privVal.Key.Address, 0, height, round, voteType, block1) @@ -218,8 +218,8 @@ func TestSignProposal(t *testing.T) { privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name()) - randbytes := tmrand.Bytes(tmhash.Size) - randbytes2 := tmrand.Bytes(tmhash.Size) + randbytes := cmtrand.Bytes(tmhash.Size) + randbytes2 := cmtrand.Bytes(tmhash.Size) block1 := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{Total: 5, Hash: randbytes}} @@ -265,7 +265,7 @@ func TestDifferByTimestamp(t *testing.T) { require.Nil(t, err) privVal := GenFilePV(tempKeyFile.Name(), tempStateFile.Name()) - randbytes := tmrand.Bytes(tmhash.Size) + randbytes := cmtrand.Bytes(tmhash.Size) block1 := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{Total: 5, Hash: randbytes}} height, round := int64(10), int32(1) chainID := "mychainid" @@ -295,7 +295,7 @@ func TestDifferByTimestamp(t *testing.T) { // test vote { - voteType := tmproto.PrevoteType + voteType := cmtproto.PrevoteType blockID := types.BlockID{Hash: randbytes, PartSetHeader: types.PartSetHeader{}} vote := newVote(privVal.Key.Address, 0, height, round, voteType, blockID) v := vote.ToProto() @@ -320,14 +320,14 @@ func TestDifferByTimestamp(t *testing.T) { } func newVote(addr types.Address, idx int32, height int64, round int32, - typ tmproto.SignedMsgType, blockID types.BlockID) *types.Vote { + typ cmtproto.SignedMsgType, blockID types.BlockID) *types.Vote { return &types.Vote{ ValidatorAddress: addr, ValidatorIndex: idx, Height: height, Round: round, Type: typ, - Timestamp: tmtime.Now(), + Timestamp: cmttime.Now(), BlockID: blockID, } } @@ -337,6 +337,6 @@ func newProposal(height int64, round int32, blockID types.BlockID) *types.Propos Height: height, Round: round, BlockID: blockID, - Timestamp: tmtime.Now(), + Timestamp: cmttime.Now(), } } diff --git a/privval/msgs_test.go b/privval/msgs_test.go index 9a2cebf1c75..01cee9ac460 100644 --- a/privval/msgs_test.go +++ b/privval/msgs_test.go @@ -14,7 +14,7 @@ import ( "github.com/tendermint/tendermint/crypto/tmhash" cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto" privproto "github.com/tendermint/tendermint/proto/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -22,7 +22,7 @@ var stamp = time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC) func exampleVote() *types.Vote { return &types.Vote{ - Type: tmproto.SignedMsgType(1), + Type: cmtproto.SignedMsgType(1), Height: 3, Round: 2, Timestamp: stamp, @@ -41,7 +41,7 @@ func exampleVote() *types.Vote { func exampleProposal() *types.Proposal { return &types.Proposal{ - Type: tmproto.SignedMsgType(1), + Type: cmtproto.SignedMsgType(1), Height: 3, Round: 2, Timestamp: stamp, @@ -86,10 +86,10 @@ func TestPrivvalVectors(t *testing.T) { {"pubKey response with error", &privproto.PubKeyResponse{PubKey: cryptoproto.PublicKey{}, Error: remoteError}, "12140a0012100801120c697427732061206572726f72"}, {"Vote Request", &privproto.SignVoteRequest{Vote: votepb}, "1a760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"}, {"Vote Response", &privproto.SignedVoteResponse{Vote: *votepb, Error: nil}, "22760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"}, - {"Vote Response with error", &privproto.SignedVoteResponse{Vote: tmproto.Vote{}, Error: remoteError}, "22250a11220212002a0b088092b8c398feffffff0112100801120c697427732061206572726f72"}, + {"Vote Response with error", &privproto.SignedVoteResponse{Vote: cmtproto.Vote{}, Error: remoteError}, "22250a11220212002a0b088092b8c398feffffff0112100801120c697427732061206572726f72"}, {"Proposal Request", &privproto.SignProposalRequest{Proposal: proposalpb}, "2a700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"}, {"Proposal Response", &privproto.SignedProposalResponse{Proposal: *proposalpb, Error: nil}, "32700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"}, - {"Proposal Response with error", &privproto.SignedProposalResponse{Proposal: tmproto.Proposal{}, Error: remoteError}, "32250a112a021200320b088092b8c398feffffff0112100801120c697427732061206572726f72"}, + {"Proposal Response with error", &privproto.SignedProposalResponse{Proposal: cmtproto.Proposal{}, Error: remoteError}, "32250a112a021200320b088092b8c398feffffff0112100801120c697427732061206572726f72"}, } for _, tc := range testCases { diff --git a/privval/retry_signer_client.go b/privval/retry_signer_client.go index 92a7d06551a..27eef644305 100644 --- a/privval/retry_signer_client.go +++ b/privval/retry_signer_client.go @@ -5,7 +5,7 @@ import ( "time" "github.com/tendermint/tendermint/crypto" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -63,7 +63,7 @@ func (sc *RetrySignerClient) GetPubKey() (crypto.PubKey, error) { return nil, fmt.Errorf("exhausted all attempts to get pubkey: %w", err) } -func (sc *RetrySignerClient) SignVote(chainID string, vote *tmproto.Vote) error { +func (sc *RetrySignerClient) SignVote(chainID string, vote *cmtproto.Vote) error { var err error for i := 0; i < sc.retries || sc.retries == 0; i++ { err = sc.next.SignVote(chainID, vote) @@ -79,7 +79,7 @@ func (sc *RetrySignerClient) SignVote(chainID string, vote *tmproto.Vote) error return fmt.Errorf("exhausted all attempts to sign vote: %w", err) } -func (sc *RetrySignerClient) SignProposal(chainID string, proposal *tmproto.Proposal) error { +func (sc *RetrySignerClient) SignProposal(chainID string, proposal *cmtproto.Proposal) error { var err error for i := 0; i < sc.retries || sc.retries == 0; i++ { err = sc.next.SignProposal(chainID, proposal) diff --git a/privval/signer_client.go b/privval/signer_client.go index aecb0381ef2..68ce47a4b0d 100644 --- a/privval/signer_client.go +++ b/privval/signer_client.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" cryptoenc "github.com/tendermint/tendermint/crypto/encoding" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -91,7 +91,7 @@ func (sc *SignerClient) GetPubKey() (crypto.PubKey, error) { } // SignVote requests a remote signer to sign a vote -func (sc *SignerClient) SignVote(chainID string, vote *tmproto.Vote) error { +func (sc *SignerClient) SignVote(chainID string, vote *cmtproto.Vote) error { response, err := sc.endpoint.SendRequest(mustWrapMsg(&privvalproto.SignVoteRequest{Vote: vote, ChainId: chainID})) if err != nil { return err @@ -111,7 +111,7 @@ func (sc *SignerClient) SignVote(chainID string, vote *tmproto.Vote) error { } // SignProposal requests a remote signer to sign a proposal -func (sc *SignerClient) SignProposal(chainID string, proposal *tmproto.Proposal) error { +func (sc *SignerClient) SignProposal(chainID string, proposal *cmtproto.Proposal) error { response, err := sc.endpoint.SendRequest(mustWrapMsg( &privvalproto.SignProposalRequest{Proposal: proposal, ChainId: chainID}, )) diff --git a/privval/signer_client_test.go b/privval/signer_client_test.go index 019fd2c96a4..b94f78d6324 100644 --- a/privval/signer_client_test.go +++ b/privval/signer_client_test.go @@ -10,10 +10,10 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -29,7 +29,7 @@ func getSignerTestCases(t *testing.T) []signerTestCase { // Get test cases for each possible dialer (DialTCP / DialUnix / etc) for _, dtc := range getDialerTestCases(t) { - chainID := tmrand.Str(12) + chainID := cmtrand.Str(12) mockPV := types.NewMockPV() // get a pair of signer listener, signer dialer endpoints @@ -117,9 +117,9 @@ func TestSignerGetPubKey(t *testing.T) { func TestSignerProposal(t *testing.T) { for _, tc := range getSignerTestCases(t) { ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) + hash := cmtrand.Bytes(tmhash.Size) have := &types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 1, Round: 2, POLRound: 2, @@ -127,7 +127,7 @@ func TestSignerProposal(t *testing.T) { Timestamp: ts, } want := &types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 1, Round: 2, POLRound: 2, @@ -157,10 +157,10 @@ func TestSignerProposal(t *testing.T) { func TestSignerVote(t *testing.T) { for _, tc := range getSignerTestCases(t) { ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) - valAddr := tmrand.Bytes(crypto.AddressSize) + hash := cmtrand.Bytes(tmhash.Size) + valAddr := cmtrand.Bytes(crypto.AddressSize) want := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -170,7 +170,7 @@ func TestSignerVote(t *testing.T) { } have := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -201,10 +201,10 @@ func TestSignerVote(t *testing.T) { func TestSignerVoteResetDeadline(t *testing.T) { for _, tc := range getSignerTestCases(t) { ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) - valAddr := tmrand.Bytes(crypto.AddressSize) + hash := cmtrand.Bytes(tmhash.Size) + valAddr := cmtrand.Bytes(crypto.AddressSize) want := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -214,7 +214,7 @@ func TestSignerVoteResetDeadline(t *testing.T) { } have := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -255,10 +255,10 @@ func TestSignerVoteResetDeadline(t *testing.T) { func TestSignerVoteKeepAlive(t *testing.T) { for _, tc := range getSignerTestCases(t) { ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) - valAddr := tmrand.Bytes(crypto.AddressSize) + hash := cmtrand.Bytes(tmhash.Size) + valAddr := cmtrand.Bytes(crypto.AddressSize) want := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -268,7 +268,7 @@ func TestSignerVoteKeepAlive(t *testing.T) { } have := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -324,9 +324,9 @@ func TestSignerSignProposalErrors(t *testing.T) { }) ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) + hash := cmtrand.Bytes(tmhash.Size) proposal := &types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 1, Round: 2, POLRound: 2, @@ -349,10 +349,10 @@ func TestSignerSignProposalErrors(t *testing.T) { func TestSignerSignVoteErrors(t *testing.T) { for _, tc := range getSignerTestCases(t) { ts := time.Now() - hash := tmrand.Bytes(tmhash.Size) - valAddr := tmrand.Bytes(crypto.AddressSize) + hash := cmtrand.Bytes(tmhash.Size) + valAddr := cmtrand.Bytes(crypto.AddressSize) vote := &types.Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: 1, Round: 2, BlockID: types.BlockID{Hash: hash, PartSetHeader: types.PartSetHeader{Hash: hash, Total: 2}}, @@ -431,7 +431,7 @@ func TestSignerUnexpectedResponse(t *testing.T) { }) ts := time.Now() - want := &types.Vote{Timestamp: ts, Type: tmproto.PrecommitType} + want := &types.Vote{Timestamp: ts, Type: cmtproto.PrecommitType} e := tc.signerClient.SignVote(tc.chainID, want.ToProto()) assert.EqualError(t, e, "empty response") diff --git a/privval/signer_endpoint.go b/privval/signer_endpoint.go index e1594438cca..c17e83ec2c1 100644 --- a/privval/signer_endpoint.go +++ b/privval/signer_endpoint.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/libs/protoio" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" ) @@ -18,7 +18,7 @@ const ( type signerEndpoint struct { service.BaseService - connMtx tmsync.Mutex + connMtx cmtsync.Mutex conn net.Conn timeoutReadWrite time.Duration diff --git a/privval/signer_listener_endpoint.go b/privval/signer_listener_endpoint.go index fefa683172c..959d3ea0720 100644 --- a/privval/signer_listener_endpoint.go +++ b/privval/signer_listener_endpoint.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" ) @@ -38,7 +38,7 @@ type SignerListenerEndpoint struct { pingTimer *time.Ticker pingInterval time.Duration - instanceMtx tmsync.Mutex // Ensures instance public methods access, i.e. SendRequest + instanceMtx cmtsync.Mutex // Ensures instance public methods access, i.e. SendRequest } // NewSignerListenerEndpoint returns an instance of SignerListenerEndpoint. diff --git a/privval/signer_listener_endpoint_test.go b/privval/signer_listener_endpoint_test.go index cbd45e6ceed..afb889d5f9b 100644 --- a/privval/signer_listener_endpoint_test.go +++ b/privval/signer_listener_endpoint_test.go @@ -10,8 +10,8 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtnet "github.com/tendermint/tendermint/libs/net" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/types" ) @@ -67,7 +67,7 @@ func TestSignerRemoteRetryTCPOnly(t *testing.T) { SignerDialerEndpointTimeoutReadWrite(time.Millisecond)(dialerEndpoint) SignerDialerEndpointConnRetries(retries)(dialerEndpoint) - chainID := tmrand.Str(12) + chainID := cmtrand.Str(12) mockPV := types.NewMockPV() signerServer := NewSignerServer(dialerEndpoint, chainID, mockPV) @@ -91,7 +91,7 @@ func TestRetryConnToRemoteSigner(t *testing.T) { for _, tc := range getDialerTestCases(t) { var ( logger = log.TestingLogger() - chainID = tmrand.Str(12) + chainID = cmtrand.Str(12) mockPV = types.NewMockPV() endpointIsOpenCh = make(chan struct{}) thisConnTimeout = testTimeoutReadWrite @@ -146,7 +146,7 @@ func TestRetryConnToRemoteSigner(t *testing.T) { } func newSignerListenerEndpoint(logger log.Logger, addr string, timeoutReadWrite time.Duration) *SignerListenerEndpoint { - proto, address := tmnet.ProtocolAndAddress(addr) + proto, address := cmtnet.ProtocolAndAddress(addr) ln, err := net.Listen(proto, address) logger.Info("SignerListener: Listening", "proto", proto, "address", address) diff --git a/privval/signer_requestHandler.go b/privval/signer_requestHandler.go index 682863b19fa..56c0fcca17d 100644 --- a/privval/signer_requestHandler.go +++ b/privval/signer_requestHandler.go @@ -7,7 +7,7 @@ import ( cryptoenc "github.com/tendermint/tendermint/crypto/encoding" cryptoproto "github.com/tendermint/tendermint/proto/tendermint/crypto" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -50,7 +50,7 @@ func DefaultValidationRequestHandler( case *privvalproto.Message_SignVoteRequest: if r.SignVoteRequest.ChainId != chainID { res = mustWrapMsg(&privvalproto.SignedVoteResponse{ - Vote: tmproto.Vote{}, Error: &privvalproto.RemoteSignerError{ + Vote: cmtproto.Vote{}, Error: &privvalproto.RemoteSignerError{ Code: 0, Description: "unable to sign vote"}}) return res, fmt.Errorf("want chainID: %s, got chainID: %s", r.SignVoteRequest.GetChainId(), chainID) } @@ -60,7 +60,7 @@ func DefaultValidationRequestHandler( err = privVal.SignVote(chainID, vote) if err != nil { res = mustWrapMsg(&privvalproto.SignedVoteResponse{ - Vote: tmproto.Vote{}, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}}) + Vote: cmtproto.Vote{}, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}}) } else { res = mustWrapMsg(&privvalproto.SignedVoteResponse{Vote: *vote, Error: nil}) } @@ -68,7 +68,7 @@ func DefaultValidationRequestHandler( case *privvalproto.Message_SignProposalRequest: if r.SignProposalRequest.GetChainId() != chainID { res = mustWrapMsg(&privvalproto.SignedProposalResponse{ - Proposal: tmproto.Proposal{}, Error: &privvalproto.RemoteSignerError{ + Proposal: cmtproto.Proposal{}, Error: &privvalproto.RemoteSignerError{ Code: 0, Description: "unable to sign proposal"}}) return res, fmt.Errorf("want chainID: %s, got chainID: %s", r.SignProposalRequest.GetChainId(), chainID) @@ -79,7 +79,7 @@ func DefaultValidationRequestHandler( err = privVal.SignProposal(chainID, proposal) if err != nil { res = mustWrapMsg(&privvalproto.SignedProposalResponse{ - Proposal: tmproto.Proposal{}, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}}) + Proposal: cmtproto.Proposal{}, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}}) } else { res = mustWrapMsg(&privvalproto.SignedProposalResponse{Proposal: *proposal, Error: nil}) } diff --git a/privval/signer_server.go b/privval/signer_server.go index c14524e3652..ac242d44e4c 100644 --- a/privval/signer_server.go +++ b/privval/signer_server.go @@ -4,7 +4,7 @@ import ( "io" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval" "github.com/tendermint/tendermint/types" ) @@ -22,7 +22,7 @@ type SignerServer struct { chainID string privVal types.PrivValidator - handlerMtx tmsync.Mutex + handlerMtx cmtsync.Mutex validationRequestHandler ValidationRequestHandlerFunc } diff --git a/privval/socket_dialers.go b/privval/socket_dialers.go index b91b0a45a1a..1c6ce5d76c7 100644 --- a/privval/socket_dialers.go +++ b/privval/socket_dialers.go @@ -6,7 +6,7 @@ import ( "time" "github.com/tendermint/tendermint/crypto" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" p2pconn "github.com/tendermint/tendermint/p2p/conn" ) @@ -22,7 +22,7 @@ type SocketDialer func() (net.Conn, error) // privKey for the authenticated encryption handshake. func DialTCPFn(addr string, timeoutReadWrite time.Duration, privKey crypto.PrivKey) SocketDialer { return func() (net.Conn, error) { - conn, err := tmnet.Connect(addr) + conn, err := cmtnet.Connect(addr) if err == nil { deadline := time.Now().Add(timeoutReadWrite) err = conn.SetDeadline(deadline) diff --git a/privval/utils.go b/privval/utils.go index 0b8cced342e..b435ddc3966 100644 --- a/privval/utils.go +++ b/privval/utils.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" ) // IsConnTimeout returns a boolean indicating whether the error is known to @@ -29,7 +29,7 @@ func IsConnTimeout(err error) bool { func NewSignerListener(listenAddr string, logger log.Logger) (*SignerListenerEndpoint, error) { var listener net.Listener - protocol, address := tmnet.ProtocolAndAddress(listenAddr) + protocol, address := cmtnet.ProtocolAndAddress(listenAddr) ln, err := net.Listen(protocol, address) if err != nil { return nil, err @@ -54,7 +54,7 @@ func NewSignerListener(listenAddr string, logger log.Logger) (*SignerListenerEnd // GetFreeLocalhostAddrPort returns a free localhost:port address func GetFreeLocalhostAddrPort() string { - port, err := tmnet.GetFreePort() + port, err := cmtnet.GetFreePort() if err != nil { panic(err) } diff --git a/proxy/app_conn_test.go b/proxy/app_conn_test.go index 683fe47e0dd..2b566404706 100644 --- a/proxy/app_conn_test.go +++ b/proxy/app_conn_test.go @@ -10,7 +10,7 @@ import ( "github.com/tendermint/tendermint/abci/server" "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) //---------------------------------------- @@ -46,7 +46,7 @@ func (app *appConnTest) InfoSync(req types.RequestInfo) (*types.ResponseInfo, er var SOCKET = "socket" func TestEcho(t *testing.T) { - sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6)) + sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", cmtrand.Str(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server @@ -84,7 +84,7 @@ func TestEcho(t *testing.T) { func BenchmarkEcho(b *testing.B) { b.StopTimer() // Initialize - sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6)) + sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", cmtrand.Str(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server @@ -127,7 +127,7 @@ func BenchmarkEcho(b *testing.B) { } func TestInfo(t *testing.T) { - sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", tmrand.Str(6)) + sockPath := fmt.Sprintf("unix:///tmp/echo_%v.sock", cmtrand.Str(6)) clientCreator := NewRemoteClientCreator(sockPath, SOCKET, true) // Start server diff --git a/proxy/client.go b/proxy/client.go index e4455bead6a..d0900f690df 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -6,7 +6,7 @@ import ( abcicli "github.com/tendermint/tendermint/abci/client" "github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/abci/types" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" e2e "github.com/tendermint/tendermint/test/e2e/app" ) @@ -22,7 +22,7 @@ type ClientCreator interface { // local proxy uses a mutex on an in-proc app type localClientCreator struct { - mtx *tmsync.Mutex + mtx *cmtsync.Mutex app types.Application } @@ -34,7 +34,7 @@ type localClientCreator struct { // use [NewUnsyncLocalClientCreator]. func NewLocalClientCreator(app types.Application) ClientCreator { return &localClientCreator{ - mtx: new(tmsync.Mutex), + mtx: new(cmtsync.Mutex), app: app, } } diff --git a/proxy/multi_app_conn.go b/proxy/multi_app_conn.go index 37a5c166eb6..e1c3660df4c 100644 --- a/proxy/multi_app_conn.go +++ b/proxy/multi_app_conn.go @@ -4,8 +4,8 @@ import ( "fmt" abcicli "github.com/tendermint/tendermint/abci/client" - tmlog "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtlog "github.com/tendermint/tendermint/libs/log" + cmtos "github.com/tendermint/tendermint/libs/os" "github.com/tendermint/tendermint/libs/service" ) @@ -127,11 +127,11 @@ func (app *multiAppConn) OnStop() { } func (app *multiAppConn) killTMOnClientError() { - killFn := func(conn string, err error, logger tmlog.Logger) { + killFn := func(conn string, err error, logger cmtlog.Logger) { logger.Error( fmt.Sprintf("%s connection terminated. Did the application crash? Please restart tendermint", conn), "err", err) - killErr := tmos.Kill() + killErr := cmtos.Kill() if killErr != nil { logger.Error("Failed to kill this process - please do so manually", "err", killErr) } diff --git a/proxy/multi_app_conn_test.go b/proxy/multi_app_conn_test.go index 4fd62ad771d..44a77f140cf 100644 --- a/proxy/multi_app_conn_test.go +++ b/proxy/multi_app_conn_test.go @@ -41,7 +41,7 @@ func TestAppConns_Start_Stop(t *testing.T) { clientMock.AssertExpectations(t) } -// Upon failure, we call tmos.Kill +// Upon failure, we call cmtos.Kill func TestAppConns_Failure(t *testing.T) { ok := make(chan struct{}) c := make(chan os.Signal, 1) diff --git a/rpc/client/event_test.go b/rpc/client/event_test.go index 5734d6c1bd4..d1d0b7a7de7 100644 --- a/rpc/client/event_test.go +++ b/rpc/client/event_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" @@ -21,8 +21,8 @@ var waitForEventTimeout = 8 * time.Second // MakeTxKV returns a text transaction, allong with expected key, value pair func MakeTxKV() ([]byte, []byte, []byte) { - k := []byte(tmrand.Str(8)) - v := []byte(tmrand.Str(8)) + k := []byte(cmtrand.Str(8)) + v := []byte(cmtrand.Str(8)) return k, v, append(k, append([]byte("="), v...)...) } diff --git a/rpc/client/evidence_test.go b/rpc/client/evidence_test.go index ca4e0567ee0..46ecbce9132 100644 --- a/rpc/client/evidence_test.go +++ b/rpc/client/evidence_test.go @@ -14,9 +14,9 @@ import ( cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/internal/test" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/rpc/client" rpctest "github.com/tendermint/tendermint/rpc/test" "github.com/tendermint/tendermint/types" @@ -61,10 +61,10 @@ func makeEvidences( ValidatorIndex: 0, Height: 1, Round: 0, - Type: tmproto.PrevoteType, + Type: cmtproto.PrevoteType, Timestamp: defaultTestTime, BlockID: types.BlockID{ - Hash: tmhash.Sum(tmrand.Bytes(tmhash.Size)), + Hash: tmhash.Sum(cmtrand.Bytes(tmhash.Size)), PartSetHeader: types.PartSetHeader{ Total: 1000, Hash: tmhash.Sum([]byte("partset")), @@ -102,7 +102,7 @@ func makeEvidences( // different type { v := vote2 - v.Type = tmproto.PrecommitType + v.Type = cmtproto.PrecommitType fakes = append(fakes, newEvidence(t, val, &vote, &v, chainID)) } diff --git a/rpc/client/http/http.go b/rpc/client/http/http.go index 8af6b3ee74b..a75a8b601bc 100644 --- a/rpc/client/http/http.go +++ b/rpc/client/http/http.go @@ -8,11 +8,11 @@ import ( "time" "github.com/tendermint/tendermint/libs/bytes" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" rpcclient "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" jsonrpcclient "github.com/tendermint/tendermint/rpc/jsonrpc/client" @@ -604,7 +604,7 @@ type WSEvents struct { endpoint string ws *jsonrpcclient.WSClient - mtx tmsync.RWMutex + mtx cmtsync.RWMutex subscriptions map[string]chan ctypes.ResultEvent // query -> chan } @@ -739,7 +739,7 @@ func (w *WSEvents) redoSubscriptionsAfter(d time.Duration) { } func isErrAlreadySubscribed(err error) bool { - return strings.Contains(err.Error(), tmpubsub.ErrAlreadySubscribed.Error()) + return strings.Contains(err.Error(), cmtpubsub.ErrAlreadySubscribed.Error()) } func (w *WSEvents) eventListener() { @@ -765,7 +765,7 @@ func (w *WSEvents) eventListener() { } result := new(ctypes.ResultEvent) - err := tmjson.Unmarshal(resp.Result, result) + err := cmtjson.Unmarshal(resp.Result, result) if err != nil { w.Logger.Error("failed to unmarshal response", "err", err) continue diff --git a/rpc/client/local/local.go b/rpc/client/local/local.go index 31f78f6b5a7..884fe8e29e3 100644 --- a/rpc/client/local/local.go +++ b/rpc/client/local/local.go @@ -7,8 +7,8 @@ import ( "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" nm "github.com/tendermint/tendermint/node" rpcclient "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/core" @@ -216,7 +216,7 @@ func (c *Local) Subscribe( subscriber, query string, outCapacity ...int) (out <-chan ctypes.ResultEvent, err error) { - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return nil, fmt.Errorf("failed to parse query: %w", err) } @@ -245,7 +245,7 @@ func (c *Local) Subscribe( func (c *Local) eventsRoutine( sub types.Subscription, subscriber string, - q tmpubsub.Query, + q cmtpubsub.Query, outc chan<- ctypes.ResultEvent) { for { select { @@ -261,7 +261,7 @@ func (c *Local) eventsRoutine( } } case <-sub.Canceled(): - if sub.Err() == tmpubsub.ErrUnsubscribed { + if sub.Err() == cmtpubsub.ErrUnsubscribed { return } @@ -277,7 +277,7 @@ func (c *Local) eventsRoutine( } // Try to resubscribe with exponential backoff. -func (c *Local) resubscribe(subscriber string, q tmpubsub.Query) types.Subscription { +func (c *Local) resubscribe(subscriber string, q cmtpubsub.Query) types.Subscription { attempts := 0 for { if !c.IsRunning() { @@ -295,7 +295,7 @@ func (c *Local) resubscribe(subscriber string, q tmpubsub.Query) types.Subscript } func (c *Local) Unsubscribe(ctx context.Context, subscriber, query string) error { - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return fmt.Errorf("failed to parse query: %w", err) } diff --git a/rpc/client/rpc_test.go b/rpc/client/rpc_test.go index 4b8b11f9894..76471cb8bb4 100644 --- a/rpc/client/rpc_test.go +++ b/rpc/client/rpc_test.go @@ -15,9 +15,9 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" mempl "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/rpc/client" rpchttp "github.com/tendermint/tendermint/rpc/client/http" @@ -208,7 +208,7 @@ func TestGenesisChunked(t *testing.T) { doc := []byte(strings.Join(decoded, "")) var out types.GenesisDoc - require.NoError(t, tmjson.Unmarshal(doc, &out), + require.NoError(t, cmtjson.Unmarshal(doc, &out), "first: %+v, doc: %s", first, string(doc)) } } @@ -665,7 +665,7 @@ func testBatchedJSONRPCCalls(t *testing.T, c *rpchttp.HTTP) { bresult2, ok := bresults[1].(*ctypes.ResultBroadcastTxCommit) require.True(t, ok) require.Equal(t, *bresult2, *r2) - apph := tmmath.MaxInt64(bresult1.Height, bresult2.Height) + 1 + apph := cmtmath.MaxInt64(bresult1.Height, bresult2.Height) + 1 err = client.WaitForHeight(c, apph, nil) require.NoError(t, err) diff --git a/rpc/core/blocks.go b/rpc/core/blocks.go index 360e59e1222..06544981f41 100644 --- a/rpc/core/blocks.go +++ b/rpc/core/blocks.go @@ -6,8 +6,8 @@ import ( "sort" "github.com/tendermint/tendermint/libs/bytes" - tmmath "github.com/tendermint/tendermint/libs/math" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" blockidxnull "github.com/tendermint/tendermint/state/indexer/block/null" @@ -70,14 +70,14 @@ func filterMinMax(base, height, min, max, limit int64) (int64, int64, error) { } // limit max to the height - max = tmmath.MinInt64(height, max) + max = cmtmath.MinInt64(height, max) // limit min to the base - min = tmmath.MaxInt64(base, min) + min = cmtmath.MaxInt64(base, min) // limit min to within `limit` of max // so the total number of blocks returned will be `limit` - min = tmmath.MaxInt64(min, max-limit+1) + min = cmtmath.MaxInt64(min, max-limit+1) if min > max { return min, max, fmt.Errorf("min height %d can't be greater than max height %d", min, max) @@ -215,7 +215,7 @@ func (env *Environment) BlockSearch( return nil, errors.New("block indexing is disabled") } - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return nil, err } @@ -247,7 +247,7 @@ func (env *Environment) BlockSearch( } skipCount := validateSkipCount(page, perPage) - pageSize := tmmath.MinInt(perPage, totalCount-skipCount) + pageSize := cmtmath.MinInt(perPage, totalCount-skipCount) apiResults := make([]*ctypes.ResultBlock, 0, pageSize) for i := skipCount; i < skipCount+pageSize; i++ { diff --git a/rpc/core/blocks_test.go b/rpc/core/blocks_test.go index 5ea778fbda3..029d3763b8d 100644 --- a/rpc/core/blocks_test.go +++ b/rpc/core/blocks_test.go @@ -10,7 +10,7 @@ import ( dbm "github.com/tendermint/tm-db" abci "github.com/tendermint/tendermint/abci/types" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" sm "github.com/tendermint/tendermint/state" @@ -70,7 +70,7 @@ func TestBlockchainInfo(t *testing.T) { } func TestBlockResults(t *testing.T) { - results := &tmstate.ABCIResponses{ + results := &cmtstate.ABCIResponses{ DeliverTxs: []*abci.ResponseDeliverTx{ {Code: 0, Data: []byte{0x01}, Log: "ok"}, {Code: 0, Data: []byte{0x02}, Log: "ok"}, diff --git a/rpc/core/consensus.go b/rpc/core/consensus.go index f51b44f22aa..53a6f0e470e 100644 --- a/rpc/core/consensus.go +++ b/rpc/core/consensus.go @@ -2,7 +2,7 @@ package core import ( cm "github.com/tendermint/tendermint/consensus" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" "github.com/tendermint/tendermint/types" @@ -40,7 +40,7 @@ func (env *Environment) Validators( skipCount := validateSkipCount(page, perPage) - v := validators.Validators[skipCount : skipCount+tmmath.MinInt(perPage, totalCount-skipCount)] + v := validators.Validators[skipCount : skipCount+cmtmath.MinInt(perPage, totalCount-skipCount)] return &ctypes.ResultValidators{ BlockHeight: height, diff --git a/rpc/core/env.go b/rpc/core/env.go index 17cf45ff285..cdd36f559a9 100644 --- a/rpc/core/env.go +++ b/rpc/core/env.go @@ -7,7 +7,7 @@ import ( cfg "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" mempl "github.com/tendermint/tendermint/mempool" "github.com/tendermint/tendermint/p2p" @@ -142,7 +142,7 @@ func (env *Environment) InitGenesisChunks() error { return nil } - data, err := tmjson.Marshal(env.GenDoc) + data, err := cmtjson.Marshal(env.GenDoc) if err != nil { return err } diff --git a/rpc/core/events.go b/rpc/core/events.go index 63ed90fa772..e780b8bdd81 100644 --- a/rpc/core/events.go +++ b/rpc/core/events.go @@ -6,8 +6,8 @@ import ( "fmt" "time" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -33,7 +33,7 @@ func (env *Environment) Subscribe(ctx *rpctypes.Context, query string) (*ctypes. env.Logger.Info("Subscribe to query", "remote", addr, "query", query) - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return nil, fmt.Errorf("failed to parse query: %w", err) } @@ -77,7 +77,7 @@ func (env *Environment) Subscribe(ctx *rpctypes.Context, query string) (*ctypes. } } case <-sub.Canceled(): - if sub.Err() != tmpubsub.ErrUnsubscribed { + if sub.Err() != cmtpubsub.ErrUnsubscribed { var reason string if sub.Err() == nil { reason = "Tendermint exited" @@ -106,7 +106,7 @@ func (env *Environment) Subscribe(ctx *rpctypes.Context, query string) (*ctypes. func (env *Environment) Unsubscribe(ctx *rpctypes.Context, query string) (*ctypes.ResultUnsubscribe, error) { addr := ctx.RemoteAddr() env.Logger.Info("Unsubscribe from query", "remote", addr, "query", query) - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return nil, fmt.Errorf("failed to parse query: %w", err) } diff --git a/rpc/core/status.go b/rpc/core/status.go index 2fd9bfe49bf..20974f95f9b 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -3,7 +3,7 @@ package core import ( "time" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/p2p" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" @@ -16,8 +16,8 @@ import ( func (env *Environment) Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { var ( earliestBlockHeight int64 - earliestBlockHash tmbytes.HexBytes - earliestAppHash tmbytes.HexBytes + earliestBlockHash cmtbytes.HexBytes + earliestAppHash cmtbytes.HexBytes earliestBlockTimeNano int64 ) @@ -29,8 +29,8 @@ func (env *Environment) Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, err } var ( - latestBlockHash tmbytes.HexBytes - latestAppHash tmbytes.HexBytes + latestBlockHash cmtbytes.HexBytes + latestAppHash cmtbytes.HexBytes latestBlockTimeNano int64 latestHeight = env.BlockStore.Height() diff --git a/rpc/core/tx.go b/rpc/core/tx.go index d7518752fad..fe465a3f633 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -5,8 +5,8 @@ import ( "fmt" "sort" - tmmath "github.com/tendermint/tendermint/libs/math" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" "github.com/tendermint/tendermint/state/txindex/null" @@ -66,7 +66,7 @@ func (env *Environment) TxSearch( return nil, errors.New("maximum query length exceeded") } - q, err := tmquery.New(query) + q, err := cmtquery.New(query) if err != nil { return nil, err } @@ -106,7 +106,7 @@ func (env *Environment) TxSearch( } skipCount := validateSkipCount(page, perPage) - pageSize := tmmath.MinInt(perPage, totalCount-skipCount) + pageSize := cmtmath.MinInt(perPage, totalCount-skipCount) apiResults := make([]*ctypes.ResultTx, 0, pageSize) for i := skipCount; i < skipCount+pageSize; i++ { diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 6da818890f3..b4736621975 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/p2p" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -57,7 +57,7 @@ type ResultBlockResults struct { BeginBlockEvents []abci.Event `json:"begin_block_events"` EndBlockEvents []abci.Event `json:"end_block_events"` ValidatorUpdates []abci.ValidatorUpdate `json:"validator_updates"` - ConsensusParamUpdates *tmproto.ConsensusParams `json:"consensus_param_updates"` + ConsensusParamUpdates *cmtproto.ConsensusParams `json:"consensus_param_updates"` } // NewResultCommit is a helper to initialize the ResultCommit with diff --git a/rpc/grpc/client_server.go b/rpc/grpc/client_server.go index 57380c2c5b4..d07ef05103d 100644 --- a/rpc/grpc/client_server.go +++ b/rpc/grpc/client_server.go @@ -6,7 +6,7 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/rpc/core" ) @@ -36,5 +36,5 @@ func StartGRPCClient(protoAddr string) BroadcastAPIClient { } func dialerFunc(ctx context.Context, addr string) (net.Conn, error) { - return tmnet.Connect(addr) + return cmtnet.Connect(addr) } diff --git a/rpc/jsonrpc/client/decode.go b/rpc/jsonrpc/client/decode.go index d0f46207646..d351791d1b2 100644 --- a/rpc/jsonrpc/client/decode.go +++ b/rpc/jsonrpc/client/decode.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -31,7 +31,7 @@ func unmarshalResponseBytes( } // Unmarshal the RawMessage into the result. - if err := tmjson.Unmarshal(response.Result, result); err != nil { + if err := cmtjson.Unmarshal(response.Result, result); err != nil { return nil, fmt.Errorf("error unmarshalling result: %w", err) } @@ -77,7 +77,7 @@ func unmarshalResponseBytesArray( } for i := 0; i < len(responses); i++ { - if err := tmjson.Unmarshal(responses[i].Result, results[i]); err != nil { + if err := cmtjson.Unmarshal(responses[i].Result, results[i]); err != nil { return nil, fmt.Errorf("error unmarshalling #%d result: %w", i, err) } } diff --git a/rpc/jsonrpc/client/encode.go b/rpc/jsonrpc/client/encode.go index e085f51a244..c8ea4952ea4 100644 --- a/rpc/jsonrpc/client/encode.go +++ b/rpc/jsonrpc/client/encode.go @@ -5,7 +5,7 @@ import ( "net/url" "reflect" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" ) func argsToURLValues(args map[string]interface{}) (url.Values, error) { @@ -36,7 +36,7 @@ func argsToJSON(args map[string]interface{}) error { continue } - data, err := tmjson.Marshal(v) + data, err := cmtjson.Marshal(v) if err != nil { return err } diff --git a/rpc/jsonrpc/client/http_json_client.go b/rpc/jsonrpc/client/http_json_client.go index 8fbf9fa4ff0..bd43776ed68 100644 --- a/rpc/jsonrpc/client/http_json_client.go +++ b/rpc/jsonrpc/client/http_json_client.go @@ -11,7 +11,7 @@ import ( "net/url" "strings" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -128,7 +128,7 @@ type Client struct { client *http.Client - mtx tmsync.Mutex + mtx cmtsync.Mutex nextReqID int } @@ -302,7 +302,7 @@ type jsonRPCBufferedRequest struct { type RequestBatch struct { client *Client - mtx tmsync.Mutex + mtx cmtsync.Mutex requests []*jsonRPCBufferedRequest } diff --git a/rpc/jsonrpc/client/ws_client.go b/rpc/jsonrpc/client/ws_client.go index 5a4839b045b..69a1489e058 100644 --- a/rpc/jsonrpc/client/ws_client.go +++ b/rpc/jsonrpc/client/ws_client.go @@ -13,9 +13,9 @@ import ( metrics "github.com/rcrowley/go-metrics" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/libs/service" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -58,7 +58,7 @@ type WSClient struct { //nolint: maligned wg sync.WaitGroup - mtx tmsync.RWMutex + mtx cmtsync.RWMutex sentLastPingAt time.Time reconnecting bool nextReqID int @@ -290,7 +290,7 @@ func (c *WSClient) reconnect() error { }() for { - jitter := time.Duration(tmrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) + jitter := time.Duration(cmtrand.Float64() * float64(time.Second)) // 1s == (1e9 ns) backoffDuration := jitter + ((1 << uint(attempt)) * time.Second) c.Logger.Info("reconnecting", "attempt", attempt+1, "backoff_duration", backoffDuration) diff --git a/rpc/jsonrpc/client/ws_client_test.go b/rpc/jsonrpc/client/ws_client_test.go index b4ac8f83b94..c32228b8f77 100644 --- a/rpc/jsonrpc/client/ws_client_test.go +++ b/rpc/jsonrpc/client/ws_client_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -21,7 +21,7 @@ var wsCallTimeout = 5 * time.Second type myHandler struct { closeConnAfterRead bool - mtx tmsync.RWMutex + mtx cmtsync.RWMutex } var upgrader = websocket.Upgrader{ diff --git a/rpc/jsonrpc/jsonrpc_test.go b/rpc/jsonrpc/jsonrpc_test.go index d6d98e5fc0c..ab17ed4c649 100644 --- a/rpc/jsonrpc/jsonrpc_test.go +++ b/rpc/jsonrpc/jsonrpc_test.go @@ -18,9 +18,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" client "github.com/tendermint/tendermint/rpc/jsonrpc/client" server "github.com/tendermint/tendermint/rpc/jsonrpc/server" @@ -54,7 +54,7 @@ type ResultEchoBytes struct { } type ResultEchoDataBytes struct { - Value tmbytes.HexBytes `json:"value"` + Value cmtbytes.HexBytes `json:"value"` } type ResultEchoWithDefault struct { @@ -87,7 +87,7 @@ func EchoBytesResult(ctx *types.Context, v []byte) (*ResultEchoBytes, error) { return &ResultEchoBytes{v}, nil } -func EchoDataBytesResult(ctx *types.Context, v tmbytes.HexBytes) (*ResultEchoDataBytes, error) { +func EchoDataBytesResult(ctx *types.Context, v cmtbytes.HexBytes) (*ResultEchoDataBytes, error) { return &ResultEchoDataBytes{v}, nil } @@ -201,7 +201,7 @@ func echoBytesViaHTTP(cl client.Caller, bytes []byte) ([]byte, error) { return result.Value, nil } -func echoDataBytesViaHTTP(cl client.Caller, bytes tmbytes.HexBytes) (tmbytes.HexBytes, error) { +func echoDataBytesViaHTTP(cl client.Caller, bytes cmtbytes.HexBytes) (cmtbytes.HexBytes, error) { params := map[string]interface{}{ "arg": bytes, } @@ -235,12 +235,12 @@ func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { require.NoError(t, err) assert.Equal(t, got2, val2) - val3 := tmbytes.HexBytes(randBytes(t)) + val3 := cmtbytes.HexBytes(randBytes(t)) got3, err := echoDataBytesViaHTTP(cl, val3) require.NoError(t, err) assert.Equal(t, got3, val3) - val4 := tmrand.Intn(10000) + val4 := cmtrand.Intn(10000) got4, err := echoIntViaHTTP(cl, val4) require.NoError(t, err) assert.Equal(t, got4, val4) @@ -249,7 +249,7 @@ func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { require.NoError(t, err) assert.Equal(t, got5, -1) - val6 := tmrand.Intn(10000) + val6 := cmtrand.Intn(10000) got6, err := echoWithDefaultViaHTTP(cl, &val6) require.NoError(t, err) assert.Equal(t, got6, val6) @@ -447,7 +447,7 @@ func TestJSONRPCCaching(t *testing.T) { assert.Equal(t, "", res1.Header.Get("Cache-control")) // Supplying the arg should result in caching - params["arg"] = tmrand.Intn(10000) + params["arg"] = cmtrand.Intn(10000) req, err = types.MapToRequest(types.JSONRPCIntID(1001), "echo_default", params) require.NoError(t, err) @@ -483,7 +483,7 @@ func TestURICaching(t *testing.T) { assert.Equal(t, "", res1.Header.Get("Cache-control")) // Supplying the arg should result in caching - args.Set("arg", fmt.Sprintf("%d", tmrand.Intn(10000))) + args.Set("arg", fmt.Sprintf("%d", cmtrand.Intn(10000))) res2, err := rawURIRequest(t, cl, httpAddr+"/echo_default", args) defer func() { _ = res2.Body.Close() }() require.NoError(t, err) @@ -500,7 +500,7 @@ func rawURIRequest(t *testing.T, cl *http.Client, url string, args url.Values) ( } func randBytes(t *testing.T) []byte { - n := tmrand.Intn(10) + 2 + n := cmtrand.Intn(10) + 2 buf := make([]byte, n) _, err := crand.Read(buf) require.Nil(t, err) diff --git a/rpc/jsonrpc/server/http_json_handler.go b/rpc/jsonrpc/server/http_json_handler.go index db162f17abc..00b88e85f2b 100644 --- a/rpc/jsonrpc/server/http_json_handler.go +++ b/rpc/jsonrpc/server/http_json_handler.go @@ -9,7 +9,7 @@ import ( "reflect" "sort" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -152,7 +152,7 @@ func mapParamsToArgs( if p, ok := params[argName]; ok && p != nil && len(p) > 0 { val := reflect.New(argType) - err := tmjson.Unmarshal(p, val.Interface()) + err := cmtjson.Unmarshal(p, val.Interface()) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func arrayParamsToArgs( for i, p := range params { argType := rpcFunc.args[i+argsOffset] val := reflect.New(argType) - err := tmjson.Unmarshal(p, val.Interface()) + err := cmtjson.Unmarshal(p, val.Interface()) if err != nil { return nil, err } diff --git a/rpc/jsonrpc/server/http_uri_handler.go b/rpc/jsonrpc/server/http_uri_handler.go index e99a1b0ac7b..b0433a3daad 100644 --- a/rpc/jsonrpc/server/http_uri_handler.go +++ b/rpc/jsonrpc/server/http_uri_handler.go @@ -8,7 +8,7 @@ import ( "regexp" "strings" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/libs/log" types "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -117,7 +117,7 @@ func httpParamsToArgs(rpcFunc *RPCFunc, r *http.Request) ([]reflect.Value, error func jsonStringToArg(rt reflect.Type, arg string) (reflect.Value, error) { rv := reflect.New(rt) - err := tmjson.Unmarshal([]byte(arg), rv.Interface()) + err := cmtjson.Unmarshal([]byte(arg), rv.Interface()) if err != nil { return rv, err } @@ -198,7 +198,7 @@ func _nonJSONStringToArg(rt reflect.Type, arg string) (reflect.Value, bool, erro if isQuotedString && expectingByteSlice { v := reflect.New(reflect.TypeOf("")) - err := tmjson.Unmarshal([]byte(arg), v.Interface()) + err := cmtjson.Unmarshal([]byte(arg), v.Interface()) if err != nil { return reflect.ValueOf(nil), false, err } diff --git a/rpc/jsonrpc/test/main.go b/rpc/jsonrpc/test/main.go index 72583a43eb4..7b5506d55be 100644 --- a/rpc/jsonrpc/test/main.go +++ b/rpc/jsonrpc/test/main.go @@ -6,7 +6,7 @@ import ( "os" "github.com/tendermint/tendermint/libs/log" - tmos "github.com/tendermint/tendermint/libs/os" + cmtos "github.com/tendermint/tendermint/libs/os" rpcserver "github.com/tendermint/tendermint/rpc/jsonrpc/server" rpctypes "github.com/tendermint/tendermint/rpc/jsonrpc/types" ) @@ -30,16 +30,16 @@ func main() { ) // Stop upon receiving SIGTERM or CTRL-C. - tmos.TrapSignal(logger, func() {}) + cmtos.TrapSignal(logger, func() {}) rpcserver.RegisterRPCFuncs(mux, routes, logger) config := rpcserver.DefaultConfig() listener, err := rpcserver.Listen("tcp://127.0.0.1:8008", config.MaxOpenConnections) if err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } if err = rpcserver.Serve(listener, mux, logger, config); err != nil { - tmos.Exit(err.Error()) + cmtos.Exit(err.Error()) } } diff --git a/rpc/jsonrpc/types/types.go b/rpc/jsonrpc/types/types.go index 33eb0a6c9dd..45fa0b380c0 100644 --- a/rpc/jsonrpc/types/types.go +++ b/rpc/jsonrpc/types/types.go @@ -8,7 +8,7 @@ import ( "reflect" "strings" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" ) // a wrapper to emulate a sum type: jsonrpcid = string | int @@ -101,7 +101,7 @@ func (req RPCRequest) String() string { func MapToRequest(id jsonrpcid, method string, params map[string]interface{}) (RPCRequest, error) { var paramsMap = make(map[string]json.RawMessage, len(params)) for name, value := range params { - valueJSON, err := tmjson.Marshal(value) + valueJSON, err := cmtjson.Marshal(value) if err != nil { return RPCRequest{}, err } @@ -119,7 +119,7 @@ func MapToRequest(id jsonrpcid, method string, params map[string]interface{}) (R func ArrayToRequest(id jsonrpcid, method string, params []interface{}) (RPCRequest, error) { var paramsMap = make([]json.RawMessage, len(params)) for i, value := range params { - valueJSON, err := tmjson.Marshal(value) + valueJSON, err := cmtjson.Marshal(value) if err != nil { return RPCRequest{}, err } @@ -189,7 +189,7 @@ func NewRPCSuccessResponse(id jsonrpcid, res interface{}) RPCResponse { if res != nil { var js []byte - js, err := tmjson.Marshal(res) + js, err := cmtjson.Marshal(res) if err != nil { return RPCInternalError(id, fmt.Errorf("error marshaling response: %w", err)) } diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index 14be9e22ff1..0e2c59d0c8b 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -13,7 +13,7 @@ import ( "github.com/tendermint/tendermint/libs/log" cfg "github.com/tendermint/tendermint/config" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" nm "github.com/tendermint/tendermint/node" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" @@ -77,7 +77,7 @@ func makePathname() string { } func randPort() int { - port, err := tmnet.GetFreePort() + port, err := cmtnet.GetFreePort() if err != nil { panic(err) } diff --git a/scripts/json2wal/main.go b/scripts/json2wal/main.go index ef98977d9d3..3b7101b0a9f 100644 --- a/scripts/json2wal/main.go +++ b/scripts/json2wal/main.go @@ -15,7 +15,7 @@ import ( "strings" cs "github.com/tendermint/tendermint/consensus" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/types" ) @@ -56,7 +56,7 @@ func main() { } var msg cs.TimedWALMessage - err = tmjson.Unmarshal(msgJSON, &msg) + err = cmtjson.Unmarshal(msgJSON, &msg) if err != nil { panic(fmt.Errorf("failed to unmarshal json: %v", err)) } diff --git a/scripts/wal2json/main.go b/scripts/wal2json/main.go index 6fa890522f4..f82b4f71653 100644 --- a/scripts/wal2json/main.go +++ b/scripts/wal2json/main.go @@ -13,7 +13,7 @@ import ( "os" cs "github.com/tendermint/tendermint/consensus" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" ) func main() { @@ -37,7 +37,7 @@ func main() { panic(fmt.Errorf("failed to decode msg: %v", err)) } - json, err := tmjson.Marshal(msg) + json, err := cmtjson.Marshal(msg) if err != nil { panic(fmt.Errorf("failed to marshal msg: %v", err)) } diff --git a/state/execution.go b/state/execution.go index 4ba630db741..15d2c005050 100644 --- a/state/execution.go +++ b/state/execution.go @@ -10,7 +10,7 @@ import ( "github.com/tendermint/tendermint/libs/fail" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/mempool" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/types" ) @@ -339,11 +339,11 @@ func execBlockOnProxyApp( block *types.Block, store Store, initialHeight int64, -) (*tmstate.ABCIResponses, error) { +) (*cmtstate.ABCIResponses, error) { var validTxs, invalidTxs = 0, 0 txIndex := 0 - abciResponses := new(tmstate.ABCIResponses) + abciResponses := new(cmtstate.ABCIResponses) dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs)) abciResponses.DeliverTxs = dtxs @@ -495,7 +495,7 @@ func updateState( state State, blockID types.BlockID, header *types.Header, - abciResponses *tmstate.ABCIResponses, + abciResponses *cmtstate.ABCIResponses, validatorUpdates []*types.Validator, ) (State, error) { @@ -563,7 +563,7 @@ func fireEvents( logger log.Logger, eventBus types.BlockEventPublisher, block *types.Block, - abciResponses *tmstate.ABCIResponses, + abciResponses *cmtstate.ABCIResponses, validatorUpdates []*types.Validator, ) { if err := eventBus.PublishEventNewBlock(types.EventDataNewBlock{ diff --git a/state/execution_test.go b/state/execution_test.go index 53a7c3f3171..242dbf1d9de 100644 --- a/state/execution_test.go +++ b/state/execution_test.go @@ -22,14 +22,14 @@ import ( "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" mpmocks "github.com/tendermint/tendermint/mempool/mocks" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/proxy" pmocks "github.com/tendermint/tendermint/proxy/mocks" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" ) @@ -97,7 +97,7 @@ func TestBeginBlockValidators(t *testing.T) { prevBlockID := types.BlockID{Hash: prevHash, PartSetHeader: prevParts} var ( - now = tmtime.Now() + now = cmttime.Now() commitSig0 = types.NewCommitSigForBlock( []byte("Signature1"), state.Validators.Validators[0].Address, @@ -161,7 +161,7 @@ func TestBeginBlockByzantineValidators(t *testing.T) { privVal := privVals[state.Validators.Validators[0].Address.String()] blockID := makeBlockID([]byte("headerhash"), 1000, []byte("partshash")) header := &types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: state.ChainID, Height: 10, Time: defaultEvidenceTime, diff --git a/state/export_test.go b/state/export_test.go index 7ab180916b8..5418d7fc882 100644 --- a/state/export_test.go +++ b/state/export_test.go @@ -4,7 +4,7 @@ import ( dbm "github.com/tendermint/tm-db" abci "github.com/tendermint/tendermint/abci/types" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -27,7 +27,7 @@ func UpdateState( state State, blockID types.BlockID, header *types.Header, - abciResponses *tmstate.ABCIResponses, + abciResponses *cmtstate.ABCIResponses, validatorUpdates []*types.Validator, ) (State, error) { return updateState(state, blockID, header, abciResponses, validatorUpdates) diff --git a/state/helpers_test.go b/state/helpers_test.go index a965a666155..9250a6934ec 100644 --- a/state/helpers_test.go +++ b/state/helpers_test.go @@ -12,12 +12,12 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/internal/test" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/proxy" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) type paramsChangeTestCase struct { @@ -153,10 +153,10 @@ func makeHeaderPartsResponsesValPubKeyChange( t *testing.T, state sm.State, pubkey crypto.PubKey, -) (types.Header, types.BlockID, *tmstate.ABCIResponses) { +) (types.Header, types.BlockID, *cmtstate.ABCIResponses) { block := makeBlock(state, state.LastBlockHeight+1, new(types.Commit)) - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -178,10 +178,10 @@ func makeHeaderPartsResponsesValPowerChange( t *testing.T, state sm.State, power int64, -) (types.Header, types.BlockID, *tmstate.ABCIResponses) { +) (types.Header, types.BlockID, *cmtstate.ABCIResponses) { block := makeBlock(state, state.LastBlockHeight+1, new(types.Commit)) - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -202,11 +202,11 @@ func makeHeaderPartsResponsesValPowerChange( func makeHeaderPartsResponsesParams( t *testing.T, state sm.State, - params tmproto.ConsensusParams, -) (types.Header, types.BlockID, *tmstate.ABCIResponses) { + params cmtproto.ConsensusParams, +) (types.Header, types.BlockID, *cmtstate.ABCIResponses) { block := makeBlock(state, state.LastBlockHeight+1, new(types.Commit)) - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ConsensusParamUpdates: ¶ms}, } @@ -216,7 +216,7 @@ func makeHeaderPartsResponsesParams( func randomGenesisDoc() *types.GenesisDoc { pubkey := ed25519.GenPrivKey().PubKey() return &types.GenesisDoc{ - GenesisTime: tmtime.Now(), + GenesisTime: cmttime.Now(), ChainID: "abc", Validators: []types.GenesisValidator{ { @@ -255,8 +255,8 @@ func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlo func (app *testApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock { return abci.ResponseEndBlock{ ValidatorUpdates: app.ValidatorUpdates, - ConsensusParamUpdates: &tmproto.ConsensusParams{ - Version: &tmproto.VersionParams{ + ConsensusParamUpdates: &cmtproto.ConsensusParams{ + Version: &cmtproto.VersionParams{ App: 1}}} } diff --git a/state/rollback.go b/state/rollback.go index 57bb276b8df..b47545853bf 100644 --- a/state/rollback.go +++ b/state/rollback.go @@ -4,8 +4,8 @@ import ( "errors" "fmt" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/version" ) @@ -79,8 +79,8 @@ func Rollback(bs BlockStore, ss Store, removeBlock bool) (int64, []byte, error) // build the new state from the old state and the prior block rolledBackState := State{ - Version: tmstate.Version{ - Consensus: tmversion.Consensus{ + Version: cmtstate.Version{ + Consensus: cmtversion.Consensus{ Block: version.BlockProtocol, App: previousParams.Version.App, }, diff --git a/state/rollback_test.go b/state/rollback_test.go index 9e2d03efc9e..5d7c7dc653b 100644 --- a/state/rollback_test.go +++ b/state/rollback_test.go @@ -10,8 +10,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/store" @@ -98,7 +98,7 @@ func TestRollbackHard(t *testing.T) { block := &types.Block{ Header: types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: "test-chain", Time: now, Height: height, @@ -121,7 +121,7 @@ func TestRollbackHard(t *testing.T) { blockStore.SaveBlock(block, partSet, &types.Commit{Height: block.Height}) currState := state.State{ - Version: tmstate.Version{ + Version: cmtstate.Version{ Consensus: block.Header.Version, Software: version.TMCoreSemVer, }, @@ -140,7 +140,7 @@ func TestRollbackHard(t *testing.T) { nextBlock := &types.Block{ Header: types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: block.ChainID, Time: block.Time, Height: currState.LastBlockHeight + 1, @@ -178,7 +178,7 @@ func TestRollbackHard(t *testing.T) { params.Version.App = 11 nextState := state.State{ - Version: tmstate.Version{ + Version: cmtstate.Version{ Consensus: block.Header.Version, Software: version.TMCoreSemVer, }, @@ -245,8 +245,8 @@ func setupStateStore(t *testing.T, height int64) state.Store { params.Version.App = 10 initialState := state.State{ - Version: tmstate.Version{ - Consensus: tmversion.Consensus{ + Version: cmtstate.Version{ + Consensus: cmtversion.Consensus{ Block: version.BlockProtocol, App: 10, }, diff --git a/state/state.go b/state/state.go index 51ce5a3f810..6f846c3f301 100644 --- a/state/state.go +++ b/state/state.go @@ -9,10 +9,10 @@ import ( "github.com/cosmos/gogoproto/proto" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" ) @@ -27,8 +27,8 @@ var ( // but leaves the Consensus.App version blank. // The Consensus.App version will be set during the Handshake, once // we hear from the app what protocol version it is running. -var InitStateVersion = tmstate.Version{ - Consensus: tmversion.Consensus{ +var InitStateVersion = cmtstate.Version{ + Consensus: cmtversion.Consensus{ Block: version.BlockProtocol, App: 0, }, @@ -45,7 +45,7 @@ var InitStateVersion = tmstate.Version{ // Instead, use state.Copy() or state.NextState(...). // NOTE: not goroutine-safe. type State struct { - Version tmstate.Version + Version cmtstate.Version // immutable ChainID string @@ -131,12 +131,12 @@ func (state State) IsEmpty() bool { } // ToProto takes the local state type and returns the equivalent proto type -func (state *State) ToProto() (*tmstate.State, error) { +func (state *State) ToProto() (*cmtstate.State, error) { if state == nil { return nil, errors.New("state is nil") } - sm := new(tmstate.State) + sm := new(cmtstate.State) sm.Version = state.Version sm.ChainID = state.ChainID @@ -175,7 +175,7 @@ func (state *State) ToProto() (*tmstate.State, error) { } // FromProto takes a state proto message & returns the local state type -func FromProto(pb *tmstate.State) (*State, error) { //nolint:golint +func FromProto(pb *cmtstate.State) (*State, error) { //nolint:golint if pb == nil { return nil, errors.New("nil State") } @@ -267,7 +267,7 @@ func (state State) MakeBlock( // the votes sent by honest processes, i.e., a faulty processes can not arbitrarily increase or decrease the // computed value. func MedianTime(commit *types.Commit, validators *types.ValidatorSet) time.Time { - weightedTimes := make([]*tmtime.WeightedTime, len(commit.Signatures)) + weightedTimes := make([]*cmttime.WeightedTime, len(commit.Signatures)) totalVotingPower := int64(0) for i, commitSig := range commit.Signatures { @@ -278,11 +278,11 @@ func MedianTime(commit *types.Commit, validators *types.ValidatorSet) time.Time // If there's no condition, TestValidateBlockCommit panics; not needed normally. if validator != nil { totalVotingPower += validator.VotingPower - weightedTimes[i] = tmtime.NewWeightedTime(commitSig.Timestamp, validator.VotingPower) + weightedTimes[i] = cmttime.NewWeightedTime(commitSig.Timestamp, validator.VotingPower) } } - return tmtime.WeightedMedian(weightedTimes, totalVotingPower) + return cmttime.WeightedMedian(weightedTimes, totalVotingPower) } //------------------------------------------------------------------------ diff --git a/state/state_test.go b/state/state_test.go index f88affa5618..e91c4804dc7 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -17,8 +17,8 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/internal/test" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -108,7 +108,7 @@ func TestABCIResponsesSaveLoad1(t *testing.T) { // Build mock responses. block := makeBlock(state, 2, new(types.Commit)) - abciResponses := new(tmstate.ABCIResponses) + abciResponses := new(cmtstate.ABCIResponses) dtxs := make([]*abci.ResponseDeliverTx, 2) abciResponses.DeliverTxs = dtxs @@ -192,7 +192,7 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { // Add all cases. for i, tc := range cases { h := int64(i + 1) // last block height, one below what we save - responses := &tmstate.ABCIResponses{ + responses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, DeliverTxs: tc.added, EndBlock: &abci.ResponseEndBlock{}, @@ -207,7 +207,7 @@ func TestABCIResponsesSaveLoad2(t *testing.T) { res, err := stateStore.LoadABCIResponses(h) if assert.NoError(err, "%d", i) { t.Log(res) - responses := &tmstate.ABCIResponses{ + responses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, DeliverTxs: tc.expected, EndBlock: &abci.ResponseEndBlock{}, @@ -367,18 +367,18 @@ func TestProposerFrequency(t *testing.T) { maxPower := 1000 nTestCases := 5 for i := 0; i < nTestCases; i++ { - N := tmrand.Int()%maxVals + 1 + N := cmtrand.Int()%maxVals + 1 vals := make([]*types.Validator, N) totalVotePower := int64(0) for j := 0; j < N; j++ { // make sure votePower > 0 - votePower := int64(tmrand.Int()%maxPower) + 1 + votePower := int64(cmtrand.Int()%maxPower) + 1 totalVotePower += votePower privVal := types.NewMockPV() pubKey, err := privVal.GetPubKey() require.NoError(t, err) val := types.NewValidator(pubKey, votePower) - val.ProposerPriority = tmrand.Int64() + val.ProposerPriority = cmtrand.Int64() vals[j] = val } valSet := types.NewValidatorSet(vals) @@ -395,7 +395,7 @@ func genValSetWithPowers(powers []int64) *types.ValidatorSet { for i := 0; i < size; i++ { totalVotePower += powers[i] val := types.NewValidator(ed25519.GenPrivKey().PubKey(), powers[i]) - val.ProposerPriority = tmrand.Int64() + val.ProposerPriority = cmtrand.Int64() vals[i] = val } valSet := types.NewValidatorSet(vals) @@ -458,7 +458,7 @@ func TestProposerPriorityDoesNotGetResetToZero(t *testing.T) { bps, err := block.MakePartSet(testPartSize) require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -575,7 +575,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { require.NoError(t, err) blockID := types.BlockID{Hash: block.Hash(), PartSetHeader: bps.Header()} // no updates: - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -678,7 +678,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { // no changes in voting power and both validators have same voting power // -> proposers should alternate: oldState := updatedState3 - abciResponses = &tmstate.ABCIResponses{ + abciResponses = &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -694,7 +694,7 @@ func TestProposerPriorityProposerAlternates(t *testing.T) { for i := 0; i < 1000; i++ { // no validator updates: - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -752,7 +752,7 @@ func TestLargeGenesisValidator(t *testing.T) { oldState := state for i := 0; i < 10; i++ { // no updates: - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -786,7 +786,7 @@ func TestLargeGenesisValidator(t *testing.T) { firstAddedVal := abci.ValidatorUpdate{PubKey: fvp, Power: firstAddedValVotingPower} validatorUpdates, err := types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{firstAddedVal}) assert.NoError(t, err) - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{firstAddedVal}}, } @@ -802,7 +802,7 @@ func TestLargeGenesisValidator(t *testing.T) { lastState := updatedState for i := 0; i < 200; i++ { // no updates: - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -842,7 +842,7 @@ func TestLargeGenesisValidator(t *testing.T) { validatorUpdates, err := types.PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{addedVal}) assert.NoError(t, err) - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{addedVal}}, } @@ -860,7 +860,7 @@ func TestLargeGenesisValidator(t *testing.T) { gp, err := cryptoenc.PubKeyToProto(genesisPubKey) require.NoError(t, err) removeGenesisVal := abci.ValidatorUpdate{PubKey: gp, Power: 0} - abciResponses = &tmstate.ABCIResponses{ + abciResponses = &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.ValidatorUpdate{removeGenesisVal}}, } @@ -885,7 +885,7 @@ func TestLargeGenesisValidator(t *testing.T) { count := 0 isProposerUnchanged := true for isProposerUnchanged { - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } @@ -913,7 +913,7 @@ func TestLargeGenesisValidator(t *testing.T) { proposers := make([]*types.Validator, numVals) for i := 0; i < 100; i++ { // no updates: - abciResponses := &tmstate.ABCIResponses{ + abciResponses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: nil}, } diff --git a/state/store.go b/state/store.go index 8503ce68720..1e62f23c478 100644 --- a/state/store.go +++ b/state/store.go @@ -8,10 +8,10 @@ import ( dbm "github.com/tendermint/tm-db" abci "github.com/tendermint/tendermint/abci/types" - tmmath "github.com/tendermint/tendermint/libs/math" - tmos "github.com/tendermint/tendermint/libs/os" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -59,15 +59,15 @@ type Store interface { // LoadValidators loads the validator set at a given height LoadValidators(int64) (*types.ValidatorSet, error) // LoadABCIResponses loads the abciResponse for a given height - LoadABCIResponses(int64) (*tmstate.ABCIResponses, error) + LoadABCIResponses(int64) (*cmtstate.ABCIResponses, error) // LoadLastABCIResponse loads the last abciResponse for a given height - LoadLastABCIResponse(int64) (*tmstate.ABCIResponses, error) + LoadLastABCIResponse(int64) (*cmtstate.ABCIResponses, error) // LoadConsensusParams loads the consensus params for a given height LoadConsensusParams(int64) (types.ConsensusParams, error) // Save overwrites the previous state with the updated one Save(State) error // SaveABCIResponses saves ABCIResponses for a given height - SaveABCIResponses(int64, *tmstate.ABCIResponses) error + SaveABCIResponses(int64, *cmtstate.ABCIResponses) error // Bootstrap is used for bootstrapping state when not starting from a initial height Bootstrap(State) error // PruneStates takes the height from which to start pruning and which height stop at @@ -149,12 +149,12 @@ func (store dbStore) loadState(key []byte) (state State, err error) { return state, nil } - sp := new(tmstate.State) + sp := new(cmtstate.State) err = proto.Unmarshal(buf, sp) if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - tmos.Exit(fmt.Sprintf(`LoadState: Data has been corrupted or its spec has changed: + cmtos.Exit(fmt.Sprintf(`LoadState: Data has been corrupted or its spec has changed: %v\n`, err)) } @@ -260,7 +260,7 @@ func (store dbStore) PruneStates(from int64, to int64, evidenceThresholdHeight i keepVals[lastStoredHeightFor(to, valInfo.LastHeightChanged)] = true // keep last checkpoint too } keepParams := make(map[int64]bool) - if paramsInfo.ConsensusParams.Equal(&tmproto.ConsensusParams{}) { + if paramsInfo.ConsensusParams.Equal(&cmtproto.ConsensusParams{}) { keepParams[paramsInfo.LastHeightChanged] = true } @@ -314,7 +314,7 @@ func (store dbStore) PruneStates(from int64, to int64, evidenceThresholdHeight i return err } - if p.ConsensusParams.Equal(&tmproto.ConsensusParams{}) { + if p.ConsensusParams.Equal(&cmtproto.ConsensusParams{}) { params, err := store.LoadConsensusParams(h) if err != nil { return err @@ -371,14 +371,14 @@ func (store dbStore) PruneStates(from int64, to int64, evidenceThresholdHeight i // ResponseDeliverTx responses (see ABCIResults.Hash) // // See merkle.SimpleHashFromByteSlices -func ABCIResponsesResultsHash(ar *tmstate.ABCIResponses) []byte { +func ABCIResponsesResultsHash(ar *cmtstate.ABCIResponses) []byte { return types.NewResults(ar.DeliverTxs).Hash() } // LoadABCIResponses loads the ABCIResponses for the given height from the // database. If the node has DiscardABCIResponses set to true, ErrABCIResponsesNotPersisted // is persisted. If not found, ErrNoABCIResponsesForHeight is returned. -func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, error) { +func (store dbStore) LoadABCIResponses(height int64) (*cmtstate.ABCIResponses, error) { if store.DiscardABCIResponses { return nil, ErrABCIResponsesNotPersisted } @@ -392,11 +392,11 @@ func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, er return nil, ErrNoABCIResponsesForHeight{height} } - abciResponses := new(tmstate.ABCIResponses) + abciResponses := new(cmtstate.ABCIResponses) err = abciResponses.Unmarshal(buf) if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - tmos.Exit(fmt.Sprintf(`LoadABCIResponses: Data has been corrupted or its spec has + cmtos.Exit(fmt.Sprintf(`LoadABCIResponses: Data has been corrupted or its spec has changed: %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -410,7 +410,7 @@ func (store dbStore) LoadABCIResponses(height int64) (*tmstate.ABCIResponses, er // // This method is used for recovering in the case that we called the Commit ABCI // method on the application but crashed before persisting the results. -func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponses, error) { +func (store dbStore) LoadLastABCIResponse(height int64) (*cmtstate.ABCIResponses, error) { bz, err := store.db.Get(lastABCIResponseKey) if err != nil { return nil, err @@ -420,10 +420,10 @@ func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponses, return nil, errors.New("no last ABCI response has been persisted") } - abciResponse := new(tmstate.ABCIResponsesInfo) + abciResponse := new(cmtstate.ABCIResponsesInfo) err = abciResponse.Unmarshal(bz) if err != nil { - tmos.Exit(fmt.Sprintf(`LoadLastABCIResponses: Data has been corrupted or its spec has + cmtos.Exit(fmt.Sprintf(`LoadLastABCIResponses: Data has been corrupted or its spec has changed: %v\n`, err)) } @@ -441,7 +441,7 @@ func (store dbStore) LoadLastABCIResponse(height int64) (*tmstate.ABCIResponses, // Merkle proofs. // // CONTRACT: height must be monotonically increasing every time this is called. -func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCIResponses) error { +func (store dbStore) SaveABCIResponses(height int64, abciResponses *cmtstate.ABCIResponses) error { var dtxs []*abci.ResponseDeliverTx // strip nil values, for _, tx := range abciResponses.DeliverTxs { @@ -465,7 +465,7 @@ func (store dbStore) SaveABCIResponses(height int64, abciResponses *tmstate.ABCI // We always save the last ABCI response for crash recovery. // This overwrites the previous saved ABCI Response. - response := &tmstate.ABCIResponsesInfo{ + response := &cmtstate.ABCIResponsesInfo{ AbciResponses: abciResponses, Height: height, } @@ -503,7 +503,7 @@ func (store dbStore) LoadValidators(height int64) (*types.ValidatorSet, error) { return nil, err } - vs.IncrementProposerPriority(tmmath.SafeConvertInt32(height - lastStoredHeight)) // mutate + vs.IncrementProposerPriority(cmtmath.SafeConvertInt32(height - lastStoredHeight)) // mutate vi2, err := vs.ToProto() if err != nil { return nil, err @@ -523,11 +523,11 @@ func (store dbStore) LoadValidators(height int64) (*types.ValidatorSet, error) { func lastStoredHeightFor(height, lastHeightChanged int64) int64 { checkpointHeight := height - height%valSetCheckpointInterval - return tmmath.MaxInt64(checkpointHeight, lastHeightChanged) + return cmtmath.MaxInt64(checkpointHeight, lastHeightChanged) } // CONTRACT: Returned ValidatorsInfo can be mutated. -func loadValidatorsInfo(db dbm.DB, height int64) (*tmstate.ValidatorsInfo, error) { +func loadValidatorsInfo(db dbm.DB, height int64) (*cmtstate.ValidatorsInfo, error) { buf, err := db.Get(calcValidatorsKey(height)) if err != nil { return nil, err @@ -537,11 +537,11 @@ func loadValidatorsInfo(db dbm.DB, height int64) (*tmstate.ValidatorsInfo, error return nil, errors.New("value retrieved from db is empty") } - v := new(tmstate.ValidatorsInfo) + v := new(cmtstate.ValidatorsInfo) err = v.Unmarshal(buf) if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - tmos.Exit(fmt.Sprintf(`LoadValidators: Data has been corrupted or its spec has changed: + cmtos.Exit(fmt.Sprintf(`LoadValidators: Data has been corrupted or its spec has changed: %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -558,7 +558,7 @@ func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet if lastHeightChanged > height { return errors.New("lastHeightChanged cannot be greater than ValidatorsInfo height") } - valInfo := &tmstate.ValidatorsInfo{ + valInfo := &cmtstate.ValidatorsInfo{ LastHeightChanged: lastHeightChanged, } // Only persist validator set if it was updated or checkpoint height (see @@ -592,7 +592,7 @@ func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet func (store dbStore) LoadConsensusParams(height int64) (types.ConsensusParams, error) { var ( empty = types.ConsensusParams{} - emptypb = tmproto.ConsensusParams{} + emptypb = cmtproto.ConsensusParams{} ) paramsInfo, err := store.loadConsensusParamsInfo(height) if err != nil { @@ -616,7 +616,7 @@ func (store dbStore) LoadConsensusParams(height int64) (types.ConsensusParams, e return types.ConsensusParamsFromProto(paramsInfo.ConsensusParams), nil } -func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusParamsInfo, error) { +func (store dbStore) loadConsensusParamsInfo(height int64) (*cmtstate.ConsensusParamsInfo, error) { buf, err := store.db.Get(calcConsensusParamsKey(height)) if err != nil { return nil, err @@ -625,10 +625,10 @@ func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusPa return nil, errors.New("value retrieved from db is empty") } - paramsInfo := new(tmstate.ConsensusParamsInfo) + paramsInfo := new(cmtstate.ConsensusParamsInfo) if err = paramsInfo.Unmarshal(buf); err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED - tmos.Exit(fmt.Sprintf(`LoadConsensusParams: Data has been corrupted or its spec has changed: + cmtos.Exit(fmt.Sprintf(`LoadConsensusParams: Data has been corrupted or its spec has changed: %v\n`, err)) } // TODO: ensure that buf is completely read. @@ -641,7 +641,7 @@ func (store dbStore) loadConsensusParamsInfo(height int64) (*tmstate.ConsensusPa // If the consensus params did not change after processing the latest block, // only the last height for which they changed is persisted. func (store dbStore) saveConsensusParamsInfo(nextHeight, changeHeight int64, params types.ConsensusParams) error { - paramsInfo := &tmstate.ConsensusParamsInfo{ + paramsInfo := &cmtstate.ConsensusParamsInfo{ LastHeightChanged: changeHeight, } diff --git a/state/store_test.go b/state/store_test.go index 4d467c559aa..48d36d16ece 100644 --- a/state/store_test.go +++ b/state/store_test.go @@ -14,8 +14,8 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/internal/test" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -119,7 +119,7 @@ func TestPruneStates(t *testing.T) { // Generate a bunch of state data. Validators change for heights ending with 3, and // parameters when ending with 5. - validator := &types.Validator{Address: tmrand.Bytes(crypto.AddressSize), VotingPower: 100, PubKey: pk} + validator := &types.Validator{Address: cmtrand.Bytes(crypto.AddressSize), VotingPower: 100, PubKey: pk} validatorSet := &types.ValidatorSet{ Validators: []*types.Validator{validator}, Proposer: validator, @@ -154,7 +154,7 @@ func TestPruneStates(t *testing.T) { err := stateStore.Save(state) require.NoError(t, err) - err = stateStore.SaveABCIResponses(h, &tmstate.ABCIResponses{ + err = stateStore.SaveABCIResponses(h, &cmtstate.ABCIResponses{ DeliverTxs: []*abci.ResponseDeliverTx{ {Data: []byte{1}}, {Data: []byte{2}}, @@ -209,7 +209,7 @@ func TestPruneStates(t *testing.T) { } func TestABCIResponsesResultsHash(t *testing.T) { - responses := &tmstate.ABCIResponses{ + responses := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, DeliverTxs: []*abci.ResponseDeliverTx{ {Code: 32, Data: []byte("Hello"), Log: "Huh?"}, @@ -249,7 +249,7 @@ func TestLastABCIResponses(t *testing.T) { require.Error(t, err) require.Nil(t, responses) // stub the abciresponses. - response1 := &tmstate.ABCIResponses{ + response1 := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, DeliverTxs: []*abci.ResponseDeliverTx{ {Code: 32, Data: []byte("Hello"), Log: "Huh?"}, @@ -281,7 +281,7 @@ func TestLastABCIResponses(t *testing.T) { stateDB := dbm.NewMemDB() height := int64(10) // stub the second abciresponse. - response2 := &tmstate.ABCIResponses{ + response2 := &cmtstate.ABCIResponses{ BeginBlock: &abci.ResponseBeginBlock{}, DeliverTxs: []*abci.ResponseDeliverTx{ {Code: 44, Data: []byte("Hello again"), Log: "????"}, diff --git a/state/tx_filter_test.go b/state/tx_filter_test.go index d5ab761ac61..fd8e71e7335 100644 --- a/state/tx_filter_test.go +++ b/state/tx_filter_test.go @@ -9,7 +9,7 @@ import ( dbm "github.com/tendermint/tm-db" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -25,9 +25,9 @@ func TestTxFilter(t *testing.T) { tx types.Tx isErr bool }{ - {types.Tx(tmrand.Bytes(2155)), false}, - {types.Tx(tmrand.Bytes(2156)), true}, - {types.Tx(tmrand.Bytes(3000)), true}, + {types.Tx(cmtrand.Bytes(2155)), false}, + {types.Tx(cmtrand.Bytes(2156)), true}, + {types.Tx(cmtrand.Bytes(3000)), true}, } for i, tc := range testCases { diff --git a/state/txindex/kv/kv_test.go b/state/txindex/kv/kv_test.go index b5f2d65cdc0..8dd19442ac4 100644 --- a/state/txindex/kv/kv_test.go +++ b/state/txindex/kv/kv_test.go @@ -14,7 +14,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/pubsub/query" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/types" ) @@ -436,7 +436,7 @@ func benchmarkTxIndex(txsCount int64, b *testing.B) { batch := txindex.NewBatch(txsCount) txIndex := uint32(0) for i := int64(0); i < txsCount; i++ { - tx := tmrand.Bytes(250) + tx := cmtrand.Bytes(250) txResult := &abci.TxResult{ Height: 1, Index: txIndex, diff --git a/state/validation_test.go b/state/validation_test.go index 152eb1d7476..865c8ebf2b1 100644 --- a/state/validation_test.go +++ b/state/validation_test.go @@ -16,12 +16,12 @@ import ( "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" mpmocks "github.com/tendermint/tendermint/mempool/mocks" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/state/mocks" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" ) const validationTestsStopHeight int64 = 10 @@ -228,8 +228,8 @@ func TestValidateBlockCommit(t *testing.T) { ValidatorIndex: 0, Height: height, Round: 0, - Timestamp: tmtime.Now(), - Type: tmproto.PrecommitType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrecommitType, BlockID: blockID, } diff --git a/statesync/chunks.go b/statesync/chunks.go index d3f8d33c6bf..07e29b7f58b 100644 --- a/statesync/chunks.go +++ b/statesync/chunks.go @@ -8,7 +8,7 @@ import ( "strconv" "time" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" ) @@ -28,7 +28,7 @@ type chunk struct { // iterator over all chunks, but callers can request chunks to be retried, optionally after // refetching. type chunkQueue struct { - tmsync.Mutex + cmtsync.Mutex snapshot *snapshot // if this is nil, the queue has been closed dir string // temp dir for on-disk chunk storage chunkFiles map[uint32]string // path to temporary chunk file diff --git a/statesync/messages_test.go b/statesync/messages_test.go index 962e1cab189..71f028eb8e9 100644 --- a/statesync/messages_test.go +++ b/statesync/messages_test.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tendermint/p2p" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func TestValidateMsg(t *testing.T) { @@ -18,7 +18,7 @@ func TestValidateMsg(t *testing.T) { valid bool }{ "nil": {nil, false}, - "unrelated": {&tmproto.Block{}, false}, + "unrelated": {&cmtproto.Block{}, false}, "ChunkRequest valid": {&ssproto.ChunkRequest{Height: 1, Format: 1, Index: 1}, true}, "ChunkRequest 0 height": {&ssproto.ChunkRequest{Height: 0, Format: 1, Index: 1}, false}, diff --git a/statesync/reactor.go b/statesync/reactor.go index d650a6a55db..e9a115e640e 100644 --- a/statesync/reactor.go +++ b/statesync/reactor.go @@ -7,7 +7,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" "github.com/tendermint/tendermint/proxy" @@ -37,7 +37,7 @@ type Reactor struct { // This will only be set when a state sync is in progress. It is used to feed received // snapshots and chunks into the sync. - mtx tmsync.RWMutex + mtx cmtsync.RWMutex syncer *syncer } diff --git a/statesync/snapshots.go b/statesync/snapshots.go index 917c0494754..efe705cc24e 100644 --- a/statesync/snapshots.go +++ b/statesync/snapshots.go @@ -6,7 +6,7 @@ import ( "math/rand" "sort" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" ) @@ -40,7 +40,7 @@ func (s *snapshot) Key() snapshotKey { // snapshotPool discovers and aggregates snapshots across peers. type snapshotPool struct { - tmsync.Mutex + cmtsync.Mutex snapshots map[snapshotKey]*snapshot snapshotPeers map[snapshotKey]map[p2p.ID]p2p.Peer diff --git a/statesync/stateprovider.go b/statesync/stateprovider.go index 2ed7b93a203..b1300a82da0 100644 --- a/statesync/stateprovider.go +++ b/statesync/stateprovider.go @@ -9,13 +9,13 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/light" lightprovider "github.com/tendermint/tendermint/light/provider" lighthttp "github.com/tendermint/tendermint/light/provider/http" lightrpc "github.com/tendermint/tendermint/light/rpc" lightdb "github.com/tendermint/tendermint/light/store/db" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" rpchttp "github.com/tendermint/tendermint/rpc/client/http" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" @@ -37,9 +37,9 @@ type StateProvider interface { // lightClientStateProvider is a state provider using the light client. type lightClientStateProvider struct { - tmsync.Mutex // light.Client is not concurrency-safe + cmtsync.Mutex // light.Client is not concurrency-safe lc *light.Client - version tmstate.Version + version cmtstate.Version initialHeight int64 providers map[lightprovider.Provider]string } @@ -48,7 +48,7 @@ type lightClientStateProvider struct { func NewLightClientStateProvider( ctx context.Context, chainID string, - version tmstate.Version, + version cmtstate.Version, initialHeight int64, servers []string, trustOptions light.TrustOptions, @@ -156,7 +156,7 @@ func (s *lightClientStateProvider) State(ctx context.Context, height uint64) (sm return sm.State{}, err } - state.Version = tmstate.Version{ + state.Version = cmtstate.Version{ Consensus: currentLightBlock.Version, Software: version.TMCoreSemVer, } diff --git a/statesync/syncer.go b/statesync/syncer.go index cfa7db51cee..8d2af3c84f9 100644 --- a/statesync/syncer.go +++ b/statesync/syncer.go @@ -10,7 +10,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/light" "github.com/tendermint/tendermint/p2p" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" @@ -60,7 +60,7 @@ type syncer struct { chunkFetchers int32 retryTimeout time.Duration - mtx tmsync.RWMutex + mtx cmtsync.RWMutex chunks *chunkQueue } diff --git a/statesync/syncer_test.go b/statesync/syncer_test.go index 100349eb381..5133279894b 100644 --- a/statesync/syncer_test.go +++ b/statesync/syncer_test.go @@ -12,12 +12,12 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" "github.com/tendermint/tendermint/p2p" p2pmocks "github.com/tendermint/tendermint/p2p/mocks" - tmstate "github.com/tendermint/tendermint/proto/tendermint/state" + cmtstate "github.com/tendermint/tendermint/proto/tendermint/state" ssproto "github.com/tendermint/tendermint/proto/tendermint/statesync" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/proxy" proxymocks "github.com/tendermint/tendermint/proxy/mocks" sm "github.com/tendermint/tendermint/state" @@ -50,8 +50,8 @@ func simplePeer(id string) *p2pmocks.Peer { func TestSyncer_SyncAny(t *testing.T) { state := sm.State{ ChainID: "chain", - Version: tmstate.Version{ - Consensus: tmversion.Consensus{ + Version: cmtstate.Version{ + Consensus: cmtversion.Consensus{ Block: version.BlockProtocol, App: testAppVersion, }, @@ -159,7 +159,7 @@ func TestSyncer_SyncAny(t *testing.T) { }).Times(2).Return(&abci.ResponseOfferSnapshot{Result: abci.ResponseOfferSnapshot_ACCEPT}, nil) chunkRequests := make(map[uint32]int) - chunkRequestsMtx := tmsync.Mutex{} + chunkRequestsMtx := cmtsync.Mutex{} onChunkRequest := func(args mock.Arguments) { e, ok := args[0].(p2p.Envelope) require.True(t, ok) diff --git a/store/store.go b/store/store.go index c56622e47d6..0b3160e73c8 100644 --- a/store/store.go +++ b/store/store.go @@ -8,9 +8,9 @@ import ( dbm "github.com/tendermint/tm-db" "github.com/tendermint/tendermint/evidence" - tmsync "github.com/tendermint/tendermint/libs/sync" - tmstore "github.com/tendermint/tendermint/proto/tendermint/store" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtsync "github.com/tendermint/tendermint/libs/sync" + cmtstore "github.com/tendermint/tendermint/proto/tendermint/store" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" ) @@ -40,7 +40,7 @@ type BlockStore struct { // database contents. The only reason for keeping these fields in the struct is that the data // can't efficiently be queried from the database since the key encoding we use is not // lexicographically ordered (see https://github.com/tendermint/tendermint/issues/4567). - mtx tmsync.RWMutex + mtx cmtsync.RWMutex base int64 height int64 } @@ -98,7 +98,7 @@ func (bs *BlockStore) LoadBlock(height int64) *types.Block { return nil } - pbb := new(tmproto.Block) + pbb := new(cmtproto.Block) buf := []byte{} for i := 0; i < int(blockMeta.BlockID.PartSetHeader.Total); i++ { part := bs.LoadBlockPart(height, i) @@ -149,7 +149,7 @@ func (bs *BlockStore) LoadBlockByHash(hash []byte) *types.Block { // from the block at the given height. // If no part is found for the given height and index, it returns nil. func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part { - var pbpart = new(tmproto.Part) + var pbpart = new(cmtproto.Part) bz, err := bs.db.Get(calcBlockPartKey(height, index)) if err != nil { @@ -161,7 +161,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part { err = proto.Unmarshal(bz, pbpart) if err != nil { - panic(fmt.Errorf("unmarshal to tmproto.Part failed: %w", err)) + panic(fmt.Errorf("unmarshal to cmtproto.Part failed: %w", err)) } part, err := types.PartFromProto(pbpart) if err != nil { @@ -174,7 +174,7 @@ func (bs *BlockStore) LoadBlockPart(height int64, index int) *types.Part { // LoadBlockMeta returns the BlockMeta for the given height. // If no block is found for the given height, it returns nil. func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta { - var pbbm = new(tmproto.BlockMeta) + var pbbm = new(cmtproto.BlockMeta) bz, err := bs.db.Get(calcBlockMetaKey(height)) if err != nil { @@ -187,7 +187,7 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta { err = proto.Unmarshal(bz, pbbm) if err != nil { - panic(fmt.Errorf("unmarshal to tmproto.BlockMeta: %w", err)) + panic(fmt.Errorf("unmarshal to cmtproto.BlockMeta: %w", err)) } blockMeta, err := types.BlockMetaFromProto(pbbm) @@ -223,7 +223,7 @@ func (bs *BlockStore) LoadBlockMetaByHash(hash []byte) *types.BlockMeta { // and it comes from the block.LastCommit for `height+1`. // If no commit is found for the given height, it returns nil. func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit { - var pbc = new(tmproto.Commit) + var pbc = new(cmtproto.Commit) bz, err := bs.db.Get(calcBlockCommitKey(height)) if err != nil { panic(err) @@ -246,7 +246,7 @@ func (bs *BlockStore) LoadBlockCommit(height int64) *types.Commit { // This is useful when we've seen a commit, but there has not yet been // a new block at `height + 1` that includes this commit in its block.LastCommit. func (bs *BlockStore) LoadSeenCommit(height int64) *types.Commit { - var pbc = new(tmproto.Commit) + var pbc = new(cmtproto.Commit) bz, err := bs.db.Get(calcSeenCommitKey(height)) if err != nil { panic(err) @@ -445,7 +445,7 @@ func (bs *BlockStore) saveBlockPart(height int64, index int, part *types.Part) { func (bs *BlockStore) saveState() { bs.mtx.RLock() - bss := tmstore.BlockStoreState{ + bss := cmtstore.BlockStoreState{ Base: bs.base, Height: bs.height, } @@ -494,7 +494,7 @@ func calcBlockHashKey(hash []byte) []byte { var blockStoreKey = []byte("blockStore") // SaveBlockStoreState persists the blockStore state to the database. -func SaveBlockStoreState(bsj *tmstore.BlockStoreState, db dbm.DB) { +func SaveBlockStoreState(bsj *cmtstore.BlockStoreState, db dbm.DB) { bytes, err := proto.Marshal(bsj) if err != nil { panic(fmt.Sprintf("Could not marshal state bytes: %v", err)) @@ -506,20 +506,20 @@ func SaveBlockStoreState(bsj *tmstore.BlockStoreState, db dbm.DB) { // LoadBlockStoreState returns the BlockStoreState as loaded from disk. // If no BlockStoreState was previously persisted, it returns the zero value. -func LoadBlockStoreState(db dbm.DB) tmstore.BlockStoreState { +func LoadBlockStoreState(db dbm.DB) cmtstore.BlockStoreState { bytes, err := db.Get(blockStoreKey) if err != nil { panic(err) } if len(bytes) == 0 { - return tmstore.BlockStoreState{ + return cmtstore.BlockStoreState{ Base: 0, Height: 0, } } - var bsj tmstore.BlockStoreState + var bsj cmtstore.BlockStoreState if err := proto.Unmarshal(bytes, &bsj); err != nil { panic(fmt.Sprintf("Could not unmarshal bytes: %X", bytes)) } diff --git a/store/store_test.go b/store/store_test.go index 93c9227d64d..4395a23fa70 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -18,12 +18,12 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/internal/test" "github.com/tendermint/tendermint/libs/log" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmstore "github.com/tendermint/tendermint/proto/tendermint/store" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtstore "github.com/tendermint/tendermint/proto/tendermint/store" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" ) @@ -35,7 +35,7 @@ type cleanupFunc func() func makeTestCommit(height int64, timestamp time.Time) *types.Commit { commitSigs := []types.CommitSig{{ BlockIDFlag: types.BlockIDFlagCommit, - ValidatorAddress: tmrand.Bytes(crypto.AddressSize), + ValidatorAddress: cmtrand.Bytes(crypto.AddressSize), Timestamp: timestamp, Signature: []byte("Signature"), }} @@ -63,15 +63,15 @@ func TestLoadBlockStoreState(t *testing.T) { type blockStoreTest struct { testName string - bss *tmstore.BlockStoreState - want tmstore.BlockStoreState + bss *cmtstore.BlockStoreState + want cmtstore.BlockStoreState } testCases := []blockStoreTest{ - {"success", &tmstore.BlockStoreState{Base: 100, Height: 1000}, - tmstore.BlockStoreState{Base: 100, Height: 1000}}, - {"empty", &tmstore.BlockStoreState{}, tmstore.BlockStoreState{}}, - {"no base", &tmstore.BlockStoreState{Height: 1000}, tmstore.BlockStoreState{Base: 1, Height: 1000}}, + {"success", &cmtstore.BlockStoreState{Base: 100, Height: 1000}, + cmtstore.BlockStoreState{Base: 100, Height: 1000}}, + {"empty", &cmtstore.BlockStoreState{}, cmtstore.BlockStoreState{}}, + {"no base", &cmtstore.BlockStoreState{Height: 1000}, cmtstore.BlockStoreState{Base: 1, Height: 1000}}, } for _, tc := range testCases { @@ -84,7 +84,7 @@ func TestLoadBlockStoreState(t *testing.T) { func TestNewBlockStore(t *testing.T) { db := dbm.NewMemDB() - bss := tmstore.BlockStoreState{Base: 100, Height: 10000} + bss := cmtstore.BlockStoreState{Base: 100, Height: 10000} bz, _ := proto.Marshal(&bss) err := db.Set(blockStoreKey, bz) require.NoError(t, err) @@ -145,7 +145,7 @@ func TestMain(m *testing.M) { } part1 = partSet.GetPart(0) part2 = partSet.GetPart(1) - seenCommit1 = makeTestCommit(10, tmtime.Now()) + seenCommit1 = makeTestCommit(10, cmttime.Now()) code := m.Run() cleanup() os.Exit(code) @@ -171,7 +171,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { block := state.MakeBlock(bs.Height()+1, nil, new(types.Commit), nil, state.Validators.GetProposer().Address) validPartSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(10, tmtime.Now()) + seenCommit := makeTestCommit(10, cmttime.Now()) bs.SaveBlock(block, partSet, seenCommit) require.EqualValues(t, 1, bs.Base(), "expecting the new height to be changed") require.EqualValues(t, block.Header.Height, bs.Height(), "expecting the new height to be changed") @@ -182,16 +182,16 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { require.Error(t, err) header1 := types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol}, + Version: cmtversion.Consensus{Block: version.BlockProtocol}, Height: 1, ChainID: "block_test", - Time: tmtime.Now(), - ProposerAddress: tmrand.Bytes(crypto.AddressSize), + Time: cmttime.Now(), + ProposerAddress: cmtrand.Bytes(crypto.AddressSize), } // End of setup, test data - commitAtH10 := makeTestCommit(10, tmtime.Now()) + commitAtH10 := makeTestCommit(10, cmttime.Now()) tuples := []struct { block *types.Block parts *types.PartSet @@ -219,15 +219,15 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { { block: newBlock( // New block at height 5 in empty block store is fine types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol}, + Version: cmtversion.Consensus{Block: version.BlockProtocol}, Height: 5, ChainID: "block_test", - Time: tmtime.Now(), - ProposerAddress: tmrand.Bytes(crypto.AddressSize)}, - makeTestCommit(5, tmtime.Now()), + Time: cmttime.Now(), + ProposerAddress: cmtrand.Bytes(crypto.AddressSize)}, + makeTestCommit(5, cmttime.Now()), ), parts: validPartSet, - seenCommit: makeTestCommit(5, tmtime.Now()), + seenCommit: makeTestCommit(5, cmttime.Now()), }, { @@ -248,7 +248,7 @@ func TestBlockStoreSaveLoadBlock(t *testing.T) { block: newBlock(header1, commitAtH10), parts: validPartSet, seenCommit: seenCommit1, - wantPanic: "unmarshal to tmproto.BlockMeta", + wantPanic: "unmarshal to cmtproto.BlockMeta", corruptBlockInDB: true, // Corrupt the DB's block entry }, @@ -377,7 +377,7 @@ func TestLoadBaseMeta(t *testing.T) { block := state.MakeBlock(h, test.MakeNTxs(h, 10), new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(h, tmtime.Now()) + seenCommit := makeTestCommit(h, cmttime.Now()) bs.SaveBlock(block, partSet, seenCommit) } @@ -411,7 +411,7 @@ func TestLoadBlockPart(t *testing.T) { require.NoError(t, err) res, _, panicErr = doFn(loadPart) require.NotNil(t, panicErr, "expecting a non-nil panic") - require.Contains(t, panicErr.Error(), "unmarshal to tmproto.Part failed") + require.Contains(t, panicErr.Error(), "unmarshal to cmtproto.Part failed") // 3. A good block serialized and saved to the DB should be retrievable pb1, err := part1.ToProto() @@ -451,7 +451,7 @@ func TestPruneBlocks(t *testing.T) { block := state.MakeBlock(h, test.MakeNTxs(h, 10), new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(h, tmtime.Now()) + seenCommit := makeTestCommit(h, cmttime.Now()) bs.SaveBlock(block, partSet, seenCommit) } @@ -545,12 +545,12 @@ func TestLoadBlockMeta(t *testing.T) { require.NoError(t, err) res, _, panicErr = doFn(loadMeta) require.NotNil(t, panicErr, "expecting a non-nil panic") - require.Contains(t, panicErr.Error(), "unmarshal to tmproto.BlockMeta") + require.Contains(t, panicErr.Error(), "unmarshal to cmtproto.BlockMeta") // 3. A good blockMeta serialized and saved to the DB should be retrievable meta := &types.BlockMeta{Header: types.Header{ - Version: tmversion.Consensus{ - Block: version.BlockProtocol, App: 0}, Height: 1, ProposerAddress: tmrand.Bytes(crypto.AddressSize)}} + Version: cmtversion.Consensus{ + Block: version.BlockProtocol, App: 0}, Height: 1, ProposerAddress: cmtrand.Bytes(crypto.AddressSize)}} pbm := meta.ToProto() err = db.Set(calcBlockMetaKey(height), mustEncode(pbm)) require.NoError(t, err) @@ -578,7 +578,7 @@ func TestLoadBlockMetaByHash(t *testing.T) { b1 := state.MakeBlock(state.LastBlockHeight+1, test.MakeNTxs(state.LastBlockHeight+1, 10), new(types.Commit), nil, state.Validators.GetProposer().Address) partSet, err := b1.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(1, tmtime.Now()) + seenCommit := makeTestCommit(1, cmttime.Now()) bs.SaveBlock(b1, partSet, seenCommit) baseBlock := bs.LoadBlockMetaByHash(b1.Hash()) @@ -595,7 +595,7 @@ func TestBlockFetchAtHeight(t *testing.T) { partSet, err := block.MakePartSet(2) require.NoError(t, err) - seenCommit := makeTestCommit(10, tmtime.Now()) + seenCommit := makeTestCommit(10, cmttime.Now()) bs.SaveBlock(block, partSet, seenCommit) require.Equal(t, bs.Height(), block.Header.Height, "expecting the new height to be changed") diff --git a/test/app/grpc_client.go b/test/app/grpc_client.go index 73022aaf832..d171784b240 100644 --- a/test/app/grpc_client.go +++ b/test/app/grpc_client.go @@ -7,7 +7,7 @@ import ( "context" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" coregrpc "github.com/tendermint/tendermint/rpc/grpc" ) @@ -33,7 +33,7 @@ func main() { os.Exit(1) } - bz, err := tmjson.Marshal(res) + bz, err := cmtjson.Marshal(res) if err != nil { fmt.Println(err) os.Exit(1) diff --git a/test/e2e/node/main.go b/test/e2e/node/main.go index 232be0cabc0..9304f0ba496 100644 --- a/test/e2e/node/main.go +++ b/test/e2e/node/main.go @@ -15,9 +15,9 @@ import ( "github.com/tendermint/tendermint/abci/server" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/crypto/ed25519" - tmflags "github.com/tendermint/tendermint/libs/cli/flags" + cmtflags "github.com/tendermint/tendermint/libs/cli/flags" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" + cmtnet "github.com/tendermint/tendermint/libs/net" "github.com/tendermint/tendermint/light" lproxy "github.com/tendermint/tendermint/light/proxy" lrpc "github.com/tendermint/tendermint/light/rpc" @@ -118,7 +118,7 @@ func startNode(cfg *Config) error { return err } - tmcfg, nodeLogger, nodeKey, err := setupNode() + cmtcfg, nodeLogger, nodeKey, err := setupNode() if err != nil { return fmt.Errorf("failed to setup config: %w", err) } @@ -132,13 +132,13 @@ func startNode(cfg *Config) error { nodeLogger.Info("Using default (synchronized) local client creator") } - n, err := node.NewNode(tmcfg, - privval.LoadOrGenFilePV(tmcfg.PrivValidatorKeyFile(), tmcfg.PrivValidatorStateFile()), + n, err := node.NewNode(cmtcfg, + privval.LoadOrGenFilePV(cmtcfg.PrivValidatorKeyFile(), cmtcfg.PrivValidatorStateFile()), nodeKey, clientCreator, - node.DefaultGenesisDocProviderFunc(tmcfg), + node.DefaultGenesisDocProviderFunc(cmtcfg), config.DefaultDBProvider, - node.DefaultMetricsProvider(tmcfg.Instrumentation), + node.DefaultMetricsProvider(cmtcfg.Instrumentation), nodeLogger, ) if err != nil { @@ -148,26 +148,26 @@ func startNode(cfg *Config) error { } func startLightClient(cfg *Config) error { - tmcfg, nodeLogger, _, err := setupNode() + cmtcfg, nodeLogger, _, err := setupNode() if err != nil { return err } - dbContext := &config.DBContext{ID: "light", Config: tmcfg} + dbContext := &config.DBContext{ID: "light", Config: cmtcfg} lightDB, err := config.DefaultDBProvider(dbContext) if err != nil { return err } - providers := rpcEndpoints(tmcfg.P2P.PersistentPeers) + providers := rpcEndpoints(cmtcfg.P2P.PersistentPeers) c, err := light.NewHTTPClient( context.Background(), cfg.ChainID, light.TrustOptions{ - Period: tmcfg.StateSync.TrustPeriod, - Height: tmcfg.StateSync.TrustHeight, - Hash: tmcfg.StateSync.TrustHashBytes(), + Period: cmtcfg.StateSync.TrustPeriod, + Height: cmtcfg.StateSync.TrustHeight, + Hash: cmtcfg.StateSync.TrustHashBytes(), }, providers[0], providers[1:], @@ -179,23 +179,23 @@ func startLightClient(cfg *Config) error { } rpccfg := rpcserver.DefaultConfig() - rpccfg.MaxBodyBytes = tmcfg.RPC.MaxBodyBytes - rpccfg.MaxHeaderBytes = tmcfg.RPC.MaxHeaderBytes - rpccfg.MaxOpenConnections = tmcfg.RPC.MaxOpenConnections + rpccfg.MaxBodyBytes = cmtcfg.RPC.MaxBodyBytes + rpccfg.MaxHeaderBytes = cmtcfg.RPC.MaxHeaderBytes + rpccfg.MaxOpenConnections = cmtcfg.RPC.MaxOpenConnections // If necessary adjust global WriteTimeout to ensure it's greater than // TimeoutBroadcastTxCommit. // See https://github.com/tendermint/tendermint/issues/3435 - if rpccfg.WriteTimeout <= tmcfg.RPC.TimeoutBroadcastTxCommit { - rpccfg.WriteTimeout = tmcfg.RPC.TimeoutBroadcastTxCommit + 1*time.Second + if rpccfg.WriteTimeout <= cmtcfg.RPC.TimeoutBroadcastTxCommit { + rpccfg.WriteTimeout = cmtcfg.RPC.TimeoutBroadcastTxCommit + 1*time.Second } - p, err := lproxy.NewProxy(c, tmcfg.RPC.ListenAddress, providers[0], rpccfg, nodeLogger, + p, err := lproxy.NewProxy(c, cmtcfg.RPC.ListenAddress, providers[0], rpccfg, nodeLogger, lrpc.KeyPathFn(lrpc.DefaultMerkleKeyPathFn())) if err != nil { return err } - logger.Info("Starting proxy...", "laddr", tmcfg.RPC.ListenAddress) + logger.Info("Starting proxy...", "laddr", cmtcfg.RPC.ListenAddress) if err := p.ListenAndServe(); err != http.ErrServerClosed { // Error starting or closing listener: logger.Error("proxy ListenAndServe", "err", err) @@ -208,7 +208,7 @@ func startLightClient(cfg *Config) error { func startSigner(cfg *Config) error { filePV := privval.LoadFilePV(cfg.PrivValKey, cfg.PrivValState) - protocol, address := tmnet.ProtocolAndAddress(cfg.PrivValServer) + protocol, address := cmtnet.ProtocolAndAddress(cfg.PrivValServer) var dialFn privval.SocketDialer switch protocol { case "tcp": @@ -231,7 +231,7 @@ func startSigner(cfg *Config) error { } func setupNode() (*config.Config, log.Logger, *p2p.NodeKey, error) { - var tmcfg *config.Config + var cmtcfg *config.Config home := os.Getenv("TMHOME") if home == "" { @@ -245,35 +245,35 @@ func setupNode() (*config.Config, log.Logger, *p2p.NodeKey, error) { return nil, nil, nil, err } - tmcfg = config.DefaultConfig() + cmtcfg = config.DefaultConfig() - if err := viper.Unmarshal(tmcfg); err != nil { + if err := viper.Unmarshal(cmtcfg); err != nil { return nil, nil, nil, err } - tmcfg.SetRoot(home) + cmtcfg.SetRoot(home) - if err := tmcfg.ValidateBasic(); err != nil { + if err := cmtcfg.ValidateBasic(); err != nil { return nil, nil, nil, fmt.Errorf("error in config file: %w", err) } - if tmcfg.LogFormat == config.LogFormatJSON { + if cmtcfg.LogFormat == config.LogFormatJSON { logger = log.NewTMJSONLogger(log.NewSyncWriter(os.Stdout)) } - nodeLogger, err := tmflags.ParseLogLevel(tmcfg.LogLevel, logger, config.DefaultLogLevel) + nodeLogger, err := cmtflags.ParseLogLevel(cmtcfg.LogLevel, logger, config.DefaultLogLevel) if err != nil { return nil, nil, nil, err } nodeLogger = nodeLogger.With("module", "main") - nodeKey, err := p2p.LoadOrGenNodeKey(tmcfg.NodeKeyFile()) + nodeKey, err := p2p.LoadOrGenNodeKey(cmtcfg.NodeKeyFile()) if err != nil { - return nil, nil, nil, fmt.Errorf("failed to load or gen node key %s: %w", tmcfg.NodeKeyFile(), err) + return nil, nil, nil, fmt.Errorf("failed to load or gen node key %s: %w", cmtcfg.NodeKeyFile(), err) } - return tmcfg, nodeLogger, nodeKey, nil + return cmtcfg, nodeLogger, nodeKey, nil } // rpcEndpoints takes a list of persistent peers and splits them into a list of rpc endpoints diff --git a/test/e2e/runner/evidence.go b/test/e2e/runner/evidence.go index 8edfaa4ba5b..3c92ed76171 100644 --- a/test/e2e/runner/evidence.go +++ b/test/e2e/runner/evidence.go @@ -13,10 +13,10 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/internal/test" - tmjson "github.com/tendermint/tendermint/libs/json" + cmtjson "github.com/tendermint/tendermint/libs/json" "github.com/tendermint/tendermint/privval" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" e2e "github.com/tendermint/tendermint/test/e2e/pkg" "github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/version" @@ -166,7 +166,7 @@ func generateLightClientAttackEvidence( // create a commit for the forged header blockID := makeBlockID(header.Hash(), 1000, []byte("partshash")) - voteSet := types.NewVoteSet(chainID, forgedHeight, 0, tmproto.SignedMsgType(2), conflictingVals) + voteSet := types.NewVoteSet(chainID, forgedHeight, 0, cmtproto.SignedMsgType(2), conflictingVals) commit, err := test.MakeCommitFromVoteSet(blockID, voteSet, pv, forgedTime) if err != nil { return nil, err @@ -239,7 +239,7 @@ func readPrivKey(keyFilePath string) (crypto.PrivKey, error) { return nil, err } pvKey := privval.FilePVKey{} - err = tmjson.Unmarshal(keyJSONBytes, &pvKey) + err = cmtjson.Unmarshal(keyJSONBytes, &pvKey) if err != nil { return nil, fmt.Errorf("error reading PrivValidator key from %v: %w", keyFilePath, err) } @@ -249,7 +249,7 @@ func readPrivKey(keyFilePath string) (crypto.PrivKey, error) { func makeHeaderRandom(chainID string, height int64) *types.Header { return &types.Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: chainID, Height: height, Time: time.Now(), diff --git a/test/fuzz/tests/mempool_test.go b/test/fuzz/tests/mempool_test.go index 7b09e7c6ad4..cdd3108ba22 100644 --- a/test/fuzz/tests/mempool_test.go +++ b/test/fuzz/tests/mempool_test.go @@ -9,7 +9,7 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" "github.com/tendermint/tendermint/config" "github.com/tendermint/tendermint/libs/log" - tmsync "github.com/tendermint/tendermint/libs/sync" + cmtsync "github.com/tendermint/tendermint/libs/sync" mempool "github.com/tendermint/tendermint/mempool" mempoolv1 "github.com/tendermint/tendermint/mempool/v1" ) @@ -17,7 +17,7 @@ import ( func FuzzMempool(f *testing.F) { app := kvstore.NewApplication() logger := log.NewNopLogger() - mtx := new(tmsync.Mutex) + mtx := new(cmtsync.Mutex) conn := abciclient.NewLocalClient(mtx, app) err := conn.Start() if err != nil { diff --git a/tools/tm-signer-harness/internal/test_harness.go b/tools/tm-signer-harness/internal/test_harness.go index 33ae537fe01..8dcb9601353 100644 --- a/tools/tm-signer-harness/internal/test_harness.go +++ b/tools/tm-signer-harness/internal/test_harness.go @@ -15,9 +15,9 @@ import ( "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/libs/log" - tmnet "github.com/tendermint/tendermint/libs/net" - tmos "github.com/tendermint/tendermint/libs/os" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtnet "github.com/tendermint/tendermint/libs/net" + cmtos "github.com/tendermint/tendermint/libs/os" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" "github.com/tendermint/tendermint/types" ) @@ -36,7 +36,7 @@ const ( ErrTestSignVoteFailed // 10 ) -var voteTypes = []tmproto.SignedMsgType{tmproto.PrevoteType, tmproto.PrecommitType} +var voteTypes = []cmtproto.SignedMsgType{cmtproto.PrevoteType, cmtproto.PrecommitType} // TestHarnessError allows us to keep track of which exit code should be used // when exiting the main program. @@ -216,7 +216,7 @@ func (th *TestHarness) TestSignProposal() error { // sha256 hash of "hash" hash := tmhash.Sum([]byte("hash")) prop := &types.Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: 100, Round: 0, POLRound: -1, @@ -345,10 +345,10 @@ func (th *TestHarness) Shutdown(err error) { // newTestHarnessListener creates our client instance which we will use for testing. func newTestHarnessListener(logger log.Logger, cfg TestHarnessConfig) (*privval.SignerListenerEndpoint, error) { - proto, addr := tmnet.ProtocolAndAddress(cfg.BindAddr) + proto, addr := cmtnet.ProtocolAndAddress(cfg.BindAddr) if proto == "unix" { // make sure the socket doesn't exist - if so, try to delete it - if tmos.FileExists(addr) { + if cmtos.FileExists(addr) { if err := os.Remove(addr); err != nil { logger.Error("Failed to remove existing Unix domain socket", "addr", addr) return nil, err diff --git a/tools/tm-signer-harness/main.go b/tools/tm-signer-harness/main.go index 03f35bc6cd3..3c36d49c2b7 100644 --- a/tools/tm-signer-harness/main.go +++ b/tools/tm-signer-harness/main.go @@ -106,13 +106,13 @@ Usage: } } -func runTestHarness(acceptRetries int, bindAddr, tmhome string) { - tmhome = internal.ExpandPath(tmhome) +func runTestHarness(acceptRetries int, bindAddr, cmthome string) { + cmthome = internal.ExpandPath(cmthome) cfg := internal.TestHarnessConfig{ BindAddr: bindAddr, - KeyFile: filepath.Join(tmhome, "config", "priv_validator_key.json"), - StateFile: filepath.Join(tmhome, "data", "priv_validator_state.json"), - GenesisFile: filepath.Join(tmhome, "config", "genesis.json"), + KeyFile: filepath.Join(cmthome, "config", "priv_validator_key.json"), + StateFile: filepath.Join(cmthome, "data", "priv_validator_state.json"), + GenesisFile: filepath.Join(cmthome, "config", "genesis.json"), AcceptDeadline: time.Duration(defaultAcceptDeadline) * time.Second, AcceptRetries: acceptRetries, ConnDeadline: time.Duration(defaultConnDeadline) * time.Second, @@ -130,9 +130,9 @@ func runTestHarness(acceptRetries int, bindAddr, tmhome string) { harness.Run() } -func extractKey(tmhome, outputPath string) { - keyFile := filepath.Join(internal.ExpandPath(tmhome), "config", "priv_validator_key.json") - stateFile := filepath.Join(internal.ExpandPath(tmhome), "data", "priv_validator_state.json") +func extractKey(cmthome, outputPath string) { + keyFile := filepath.Join(internal.ExpandPath(cmthome), "config", "priv_validator_key.json") + stateFile := filepath.Join(internal.ExpandPath(cmthome), "data", "priv_validator_state.json") fpv := privval.LoadFilePV(keyFile, stateFile) pkb := []byte(fpv.Key.PrivKey.(ed25519.PrivKey)) if err := os.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0600); err != nil { diff --git a/types/block.go b/types/block.go index 5bf1cbfdb2a..6bed51a7350 100644 --- a/types/block.go +++ b/types/block.go @@ -14,11 +14,11 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/bits" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmmath "github.com/tendermint/tendermint/libs/math" - tmsync "github.com/tendermint/tendermint/libs/sync" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtsync "github.com/tendermint/tendermint/libs/sync" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/version" ) @@ -41,7 +41,7 @@ const ( // Block defines the atomic unit of a Tendermint blockchain. type Block struct { - mtx tmsync.Mutex + mtx cmtsync.Mutex Header `json:"header"` Data `json:"data"` @@ -120,7 +120,7 @@ func (b *Block) fillHeader() { // Hash computes and returns the block hash. // If the block is incomplete, block hash is nil for safety. -func (b *Block) Hash() tmbytes.HexBytes { +func (b *Block) Hash() cmtbytes.HexBytes { if b == nil { return nil } @@ -217,12 +217,12 @@ func (b *Block) StringShort() string { } // ToProto converts Block to protobuf -func (b *Block) ToProto() (*tmproto.Block, error) { +func (b *Block) ToProto() (*cmtproto.Block, error) { if b == nil { return nil, errors.New("nil Block") } - pb := new(tmproto.Block) + pb := new(cmtproto.Block) pb.Header = *b.Header.ToProto() pb.LastCommit = b.LastCommit.ToProto() @@ -239,7 +239,7 @@ func (b *Block) ToProto() (*tmproto.Block, error) { // FromProto sets a protobuf Block to the given pointer. // It returns an error if the block is invalid. -func BlockFromProto(bp *tmproto.Block) (*Block, error) { +func BlockFromProto(bp *cmtproto.Block) (*Block, error) { if bp == nil { return nil, errors.New("nil block") } @@ -324,36 +324,36 @@ func MaxDataBytesNoEvidence(maxBytes int64, valsCount int) int64 { // - https://github.com/tendermint/tendermint/blob/main/spec/blockchain/blockchain.md type Header struct { // basic block info - Version tmversion.Consensus `json:"version"` - ChainID string `json:"chain_id"` - Height int64 `json:"height"` - Time time.Time `json:"time"` + Version cmtversion.Consensus `json:"version"` + ChainID string `json:"chain_id"` + Height int64 `json:"height"` + Time time.Time `json:"time"` // prev block info LastBlockID BlockID `json:"last_block_id"` // hashes of block data - LastCommitHash tmbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block - DataHash tmbytes.HexBytes `json:"data_hash"` // transactions + LastCommitHash cmtbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block + DataHash cmtbytes.HexBytes `json:"data_hash"` // transactions // hashes from the app output from the prev block - ValidatorsHash tmbytes.HexBytes `json:"validators_hash"` // validators for the current block - NextValidatorsHash tmbytes.HexBytes `json:"next_validators_hash"` // validators for the next block - ConsensusHash tmbytes.HexBytes `json:"consensus_hash"` // consensus params for current block - AppHash tmbytes.HexBytes `json:"app_hash"` // state after txs from the previous block + ValidatorsHash cmtbytes.HexBytes `json:"validators_hash"` // validators for the current block + NextValidatorsHash cmtbytes.HexBytes `json:"next_validators_hash"` // validators for the next block + ConsensusHash cmtbytes.HexBytes `json:"consensus_hash"` // consensus params for current block + AppHash cmtbytes.HexBytes `json:"app_hash"` // state after txs from the previous block // root hash of all results from the txs from the previous block // see `deterministicResponseDeliverTx` to understand which parts of a tx is hashed into here - LastResultsHash tmbytes.HexBytes `json:"last_results_hash"` + LastResultsHash cmtbytes.HexBytes `json:"last_results_hash"` // consensus info - EvidenceHash tmbytes.HexBytes `json:"evidence_hash"` // evidence included in the block - ProposerAddress Address `json:"proposer_address"` // original proposer of the block + EvidenceHash cmtbytes.HexBytes `json:"evidence_hash"` // evidence included in the block + ProposerAddress Address `json:"proposer_address"` // original proposer of the block } // Populate the Header with state-derived data. // Call this after MakeBlock to complete the Header. func (h *Header) Populate( - version tmversion.Consensus, chainID string, + version cmtversion.Consensus, chainID string, timestamp time.Time, lastBlockID BlockID, valHash, nextValHash []byte, consensusHash, appHash, lastResultsHash []byte, @@ -437,7 +437,7 @@ func (h Header) ValidateBasic() error { // Returns nil if ValidatorHash is missing, // since a Header is not valid unless there is // a ValidatorsHash (corresponding to the validator set). -func (h *Header) Hash() tmbytes.HexBytes { +func (h *Header) Hash() cmtbytes.HexBytes { if h == nil || len(h.ValidatorsHash) == 0 { return nil } @@ -514,12 +514,12 @@ func (h *Header) StringIndented(indent string) string { } // ToProto converts Header to protobuf -func (h *Header) ToProto() *tmproto.Header { +func (h *Header) ToProto() *cmtproto.Header { if h == nil { return nil } - return &tmproto.Header{ + return &cmtproto.Header{ Version: h.Version, ChainID: h.ChainID, Height: h.Height, @@ -539,7 +539,7 @@ func (h *Header) ToProto() *tmproto.Header { // FromProto sets a protobuf Header to the given pointer. // It returns an error if the header is invalid. -func HeaderFromProto(ph *tmproto.Header) (Header, error) { +func HeaderFromProto(ph *cmtproto.Header) (Header, error) { if ph == nil { return Header{}, errors.New("nil Header") } @@ -642,8 +642,8 @@ func (cs CommitSig) Absent() bool { // 4. timestamp func (cs CommitSig) String() string { return fmt.Sprintf("CommitSig{%X by %X on %v @ %s}", - tmbytes.Fingerprint(cs.Signature), - tmbytes.Fingerprint(cs.ValidatorAddress), + cmtbytes.Fingerprint(cs.Signature), + cmtbytes.Fingerprint(cs.ValidatorAddress), cs.BlockIDFlag, CanonicalTime(cs.Timestamp)) } @@ -706,13 +706,13 @@ func (cs CommitSig) ValidateBasic() error { } // ToProto converts CommitSig to protobuf -func (cs *CommitSig) ToProto() *tmproto.CommitSig { +func (cs *CommitSig) ToProto() *cmtproto.CommitSig { if cs == nil { return nil } - return &tmproto.CommitSig{ - BlockIdFlag: tmproto.BlockIDFlag(cs.BlockIDFlag), + return &cmtproto.CommitSig{ + BlockIdFlag: cmtproto.BlockIDFlag(cs.BlockIDFlag), ValidatorAddress: cs.ValidatorAddress, Timestamp: cs.Timestamp, Signature: cs.Signature, @@ -721,7 +721,7 @@ func (cs *CommitSig) ToProto() *tmproto.CommitSig { // FromProto sets a protobuf CommitSig to the given pointer. // It returns an error if the CommitSig is invalid. -func (cs *CommitSig) FromProto(csp tmproto.CommitSig) error { +func (cs *CommitSig) FromProto(csp cmtproto.CommitSig) error { cs.BlockIDFlag = BlockIDFlag(csp.BlockIdFlag) cs.ValidatorAddress = csp.ValidatorAddress @@ -748,7 +748,7 @@ type Commit struct { // Memoized in first call to corresponding method. // NOTE: can't memoize in constructor because constructor isn't used for // unmarshaling. - hash tmbytes.HexBytes + hash cmtbytes.HexBytes bitArray *bits.BitArray } @@ -766,7 +766,7 @@ func NewCommit(height int64, round int32, blockID BlockID, commitSigs []CommitSi // Panics if signatures from the commit can't be added to the voteset. // Inverse of VoteSet.MakeCommit(). func CommitToVoteSet(chainID string, commit *Commit, vals *ValidatorSet) *VoteSet { - voteSet := NewVoteSet(chainID, commit.Height, commit.Round, tmproto.PrecommitType, vals) + voteSet := NewVoteSet(chainID, commit.Height, commit.Round, cmtproto.PrecommitType, vals) for idx, commitSig := range commit.Signatures { if commitSig.Absent() { continue // OK, some precommits can be missing. @@ -785,7 +785,7 @@ func CommitToVoteSet(chainID string, commit *Commit, vals *ValidatorSet) *VoteSe func (commit *Commit) GetVote(valIdx int32) *Vote { commitSig := commit.Signatures[valIdx] return &Vote{ - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, Height: commit.Height, Round: commit.Round, BlockID: commitSig.BlockID(commit.BlockID), @@ -813,7 +813,7 @@ func (commit *Commit) VoteSignBytes(chainID string, valIdx int32) []byte { // Type returns the vote type of the commit, which is always VoteTypePrecommit // Implements VoteSetReader. func (commit *Commit) Type() byte { - return byte(tmproto.PrecommitType) + return byte(cmtproto.PrecommitType) } // GetHeight returns height of the commit. @@ -892,7 +892,7 @@ func (commit *Commit) ValidateBasic() error { } // Hash returns the hash of the commit -func (commit *Commit) Hash() tmbytes.HexBytes { +func (commit *Commit) Hash() cmtbytes.HexBytes { if commit == nil { return nil } @@ -937,13 +937,13 @@ func (commit *Commit) StringIndented(indent string) string { } // ToProto converts Commit to protobuf -func (commit *Commit) ToProto() *tmproto.Commit { +func (commit *Commit) ToProto() *cmtproto.Commit { if commit == nil { return nil } - c := new(tmproto.Commit) - sigs := make([]tmproto.CommitSig, len(commit.Signatures)) + c := new(cmtproto.Commit) + sigs := make([]cmtproto.CommitSig, len(commit.Signatures)) for i := range commit.Signatures { sigs[i] = *commit.Signatures[i].ToProto() } @@ -958,7 +958,7 @@ func (commit *Commit) ToProto() *tmproto.Commit { // FromProto sets a protobuf Commit to the given pointer. // It returns an error if the commit is invalid. -func CommitFromProto(cp *tmproto.Commit) (*Commit, error) { +func CommitFromProto(cp *cmtproto.Commit) (*Commit, error) { if cp == nil { return nil, errors.New("nil Commit") } @@ -998,11 +998,11 @@ type Data struct { Txs Txs `json:"txs"` // Volatile - hash tmbytes.HexBytes + hash cmtbytes.HexBytes } // Hash returns the hash of the data -func (data *Data) Hash() tmbytes.HexBytes { +func (data *Data) Hash() cmtbytes.HexBytes { if data == nil { return (Txs{}).Hash() } @@ -1017,7 +1017,7 @@ func (data *Data) StringIndented(indent string) string { if data == nil { return "nil-Data" } - txStrings := make([]string, tmmath.MinInt(len(data.Txs), 21)) + txStrings := make([]string, cmtmath.MinInt(len(data.Txs), 21)) for i, tx := range data.Txs { if i == 20 { txStrings[i] = fmt.Sprintf("... (%v total)", len(data.Txs)) @@ -1033,8 +1033,8 @@ func (data *Data) StringIndented(indent string) string { } // ToProto converts Data to protobuf -func (data *Data) ToProto() tmproto.Data { - tp := new(tmproto.Data) +func (data *Data) ToProto() cmtproto.Data { + tp := new(cmtproto.Data) if len(data.Txs) > 0 { txBzs := make([][]byte, len(data.Txs)) @@ -1049,7 +1049,7 @@ func (data *Data) ToProto() tmproto.Data { // DataFromProto takes a protobuf representation of Data & // returns the native type. -func DataFromProto(dp *tmproto.Data) (Data, error) { +func DataFromProto(dp *cmtproto.Data) (Data, error) { if dp == nil { return Data{}, errors.New("nil data") } @@ -1075,12 +1075,12 @@ type EvidenceData struct { Evidence EvidenceList `json:"evidence"` // Volatile. Used as cache - hash tmbytes.HexBytes + hash cmtbytes.HexBytes byteSize int64 } // Hash returns the hash of the data. -func (data *EvidenceData) Hash() tmbytes.HexBytes { +func (data *EvidenceData) Hash() cmtbytes.HexBytes { if data.hash == nil { data.hash = data.Evidence.Hash() } @@ -1104,7 +1104,7 @@ func (data *EvidenceData) StringIndented(indent string) string { if data == nil { return "nil-Evidence" } - evStrings := make([]string, tmmath.MinInt(len(data.Evidence), 21)) + evStrings := make([]string, cmtmath.MinInt(len(data.Evidence), 21)) for i, ev := range data.Evidence { if i == 20 { evStrings[i] = fmt.Sprintf("... (%v total)", len(data.Evidence)) @@ -1120,13 +1120,13 @@ func (data *EvidenceData) StringIndented(indent string) string { } // ToProto converts EvidenceData to protobuf -func (data *EvidenceData) ToProto() (*tmproto.EvidenceList, error) { +func (data *EvidenceData) ToProto() (*cmtproto.EvidenceList, error) { if data == nil { return nil, errors.New("nil evidence data") } - evi := new(tmproto.EvidenceList) - eviBzs := make([]tmproto.Evidence, len(data.Evidence)) + evi := new(cmtproto.EvidenceList) + eviBzs := make([]cmtproto.Evidence, len(data.Evidence)) for i := range data.Evidence { protoEvi, err := EvidenceToProto(data.Evidence[i]) if err != nil { @@ -1140,7 +1140,7 @@ func (data *EvidenceData) ToProto() (*tmproto.EvidenceList, error) { } // FromProto sets a protobuf EvidenceData to the given pointer. -func (data *EvidenceData) FromProto(eviData *tmproto.EvidenceList) error { +func (data *EvidenceData) FromProto(eviData *cmtproto.EvidenceList) error { if eviData == nil { return errors.New("nil evidenceData") } @@ -1163,8 +1163,8 @@ func (data *EvidenceData) FromProto(eviData *tmproto.EvidenceList) error { // BlockID type BlockID struct { - Hash tmbytes.HexBytes `json:"hash"` - PartSetHeader PartSetHeader `json:"parts"` + Hash cmtbytes.HexBytes `json:"hash"` + PartSetHeader PartSetHeader `json:"parts"` } // Equals returns true if the BlockID matches the given BlockID @@ -1220,12 +1220,12 @@ func (blockID BlockID) String() string { } // ToProto converts BlockID to protobuf -func (blockID *BlockID) ToProto() tmproto.BlockID { +func (blockID *BlockID) ToProto() cmtproto.BlockID { if blockID == nil { - return tmproto.BlockID{} + return cmtproto.BlockID{} } - return tmproto.BlockID{ + return cmtproto.BlockID{ Hash: blockID.Hash, PartSetHeader: blockID.PartSetHeader.ToProto(), } @@ -1233,7 +1233,7 @@ func (blockID *BlockID) ToProto() tmproto.BlockID { // FromProto sets a protobuf BlockID to the given pointer. // It returns an error if the block id is invalid. -func BlockIDFromProto(bID *tmproto.BlockID) (*BlockID, error) { +func BlockIDFromProto(bID *cmtproto.BlockID) (*BlockID, error) { if bID == nil { return nil, errors.New("nil BlockID") } diff --git a/types/block_meta.go b/types/block_meta.go index 1ce262d9a9e..9684e7becfb 100644 --- a/types/block_meta.go +++ b/types/block_meta.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // BlockMeta contains meta information. @@ -26,12 +26,12 @@ func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta { } } -func (bm *BlockMeta) ToProto() *tmproto.BlockMeta { +func (bm *BlockMeta) ToProto() *cmtproto.BlockMeta { if bm == nil { return nil } - pb := &tmproto.BlockMeta{ + pb := &cmtproto.BlockMeta{ BlockID: bm.BlockID.ToProto(), BlockSize: int64(bm.BlockSize), Header: *bm.Header.ToProto(), @@ -40,7 +40,7 @@ func (bm *BlockMeta) ToProto() *tmproto.BlockMeta { return pb } -func BlockMetaFromProto(pb *tmproto.BlockMeta) (*BlockMeta, error) { +func BlockMetaFromProto(pb *cmtproto.BlockMeta) (*BlockMeta, error) { if pb == nil { return nil, errors.New("blockmeta is empty") } diff --git a/types/block_meta_test.go b/types/block_meta_test.go index 1e29a132aa2..08c50b53fe3 100644 --- a/types/block_meta_test.go +++ b/types/block_meta_test.go @@ -6,12 +6,12 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/tmhash" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestBlockMeta_ToProto(t *testing.T) { h := makeRandHeader() - bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}} + bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: cmtrand.Bytes(tmhash.Size)}} bm := &BlockMeta{ BlockID: bi, @@ -48,9 +48,9 @@ func TestBlockMeta_ToProto(t *testing.T) { func TestBlockMeta_ValidateBasic(t *testing.T) { h := makeRandHeader() - bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}} - bi2 := BlockID{Hash: tmrand.Bytes(tmhash.Size), - PartSetHeader: PartSetHeader{Total: 123, Hash: tmrand.Bytes(tmhash.Size)}} + bi := BlockID{Hash: h.Hash(), PartSetHeader: PartSetHeader{Total: 123, Hash: cmtrand.Bytes(tmhash.Size)}} + bi2 := BlockID{Hash: cmtrand.Bytes(tmhash.Size), + PartSetHeader: PartSetHeader{Total: 123, Hash: cmtrand.Bytes(tmhash.Size)}} bi3 := BlockID{Hash: []byte("incorrect hash"), PartSetHeader: PartSetHeader{Total: 123, Hash: []byte("incorrect hash")}} diff --git a/types/block_test.go b/types/block_test.go index cbc4cf65ad1..8b65d6f9211 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -20,10 +20,10 @@ import ( "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/bits" "github.com/tendermint/tendermint/libs/bytes" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" - tmtime "github.com/tendermint/tendermint/types/time" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmttime "github.com/tendermint/tendermint/types/time" "github.com/tendermint/tendermint/version" ) @@ -37,7 +37,7 @@ func TestBlockAddEvidence(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, _, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) @@ -58,7 +58,7 @@ func TestBlockValidateBasic(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, valSet, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) @@ -84,7 +84,7 @@ func TestBlockValidateBasic(t *testing.T) { blk.Data.hash = nil // clear hash or change wont be noticed }, true}, {"Tampered DataHash", func(blk *Block) { - blk.DataHash = tmrand.Bytes(len(blk.DataHash)) + blk.DataHash = cmtrand.Bytes(len(blk.DataHash)) }, true}, {"Tampered EvidenceHash", func(blk *Block) { blk.EvidenceHash = []byte("something else") @@ -130,7 +130,7 @@ func TestBlockMakePartSetWithEvidence(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, _, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) @@ -150,7 +150,7 @@ func TestBlockHashesTo(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, valSet, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) @@ -229,13 +229,13 @@ func TestNilDataHashDoesntCrash(t *testing.T) { func TestCommit(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, _, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) require.NoError(t, err) assert.Equal(t, h-1, commit.Height) assert.EqualValues(t, 1, commit.Round) - assert.Equal(t, tmproto.PrecommitType, tmproto.SignedMsgType(commit.Type())) + assert.Equal(t, cmtproto.PrecommitType, cmtproto.SignedMsgType(commit.Type())) if commit.Size() <= 0 { t.Fatalf("commit %v has a zero or negative size: %d", commit, commit.Size()) } @@ -320,7 +320,7 @@ func TestHeaderHash(t *testing.T) { expectHash bytes.HexBytes }{ {"Generates expected hash", &Header{ - Version: tmversion.Consensus{Block: 1, App: 2}, + Version: cmtversion.Consensus{Block: 1, App: 2}, ChainID: "chainId", Height: 3, Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC), @@ -337,7 +337,7 @@ func TestHeaderHash(t *testing.T) { }, hexBytesFromString("F740121F553B5418C3EFBD343C2DBFE9E007BB67B0D020A0741374BAB65242A4")}, {"nil header yields nil", nil, nil}, {"nil ValidatorsHash yields nil", &Header{ - Version: tmversion.Consensus{Block: 1, App: 2}, + Version: cmtversion.Consensus{Block: 1, App: 2}, ChainID: "chainId", Height: 3, Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC), @@ -377,7 +377,7 @@ func TestHeaderHash(t *testing.T) { bz, err := gogotypes.StdTimeMarshal(f) require.NoError(t, err) byteSlices = append(byteSlices, bz) - case tmversion.Consensus: + case cmtversion.Consensus: bz, err := f.Marshal() require.NoError(t, err) byteSlices = append(byteSlices, bz) @@ -412,7 +412,7 @@ func TestMaxHeaderBytes(t *testing.T) { timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC) h := Header{ - Version: tmversion.Consensus{Block: math.MaxInt64, App: math.MaxInt64}, + Version: cmtversion.Consensus{Block: math.MaxInt64, App: math.MaxInt64}, ChainID: maxChainID, Height: math.MaxInt64, Time: timestamp, @@ -437,7 +437,7 @@ func TestMaxHeaderBytes(t *testing.T) { func randCommit(now time.Time) *Commit { lastID := makeBlockIDRandom() h := int64(3) - voteSet, _, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, _, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, now) if err != nil { panic(err) @@ -518,7 +518,7 @@ func TestCommitToVoteSet(t *testing.T) { lastID := makeBlockIDRandom() h := int64(3) - voteSet, valSet, vals := randVoteSet(h-1, 1, tmproto.PrecommitType, 10, 1) + voteSet, valSet, vals := randVoteSet(h-1, 1, cmtproto.PrecommitType, 10, 1) commit, err := MakeCommit(lastID, h-1, 1, voteSet, vals, time.Now()) assert.NoError(t, err) @@ -561,7 +561,7 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) { } for _, tc := range testCases { - voteSet, valSet, vals := randVoteSet(height-1, round, tmproto.PrecommitType, tc.numValidators, 1) + voteSet, valSet, vals := randVoteSet(height-1, round, cmtproto.PrecommitType, tc.numValidators, 1) vi := int32(0) for n := range tc.blockIDs { @@ -573,9 +573,9 @@ func TestCommitToVoteSetWithVotesForNilBlock(t *testing.T) { ValidatorIndex: vi, Height: height - 1, Round: round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: tc.blockIDs[n], - Timestamp: tmtime.Now(), + Timestamp: cmttime.Now(), } added, err := signAddVote(vals[vi], vote, voteSet) @@ -638,13 +638,13 @@ func TestBlockIDValidateBasic(t *testing.T) { } func TestBlockProtoBuf(t *testing.T) { - h := tmrand.Int63() + h := cmtrand.Int63() c1 := randCommit(time.Now()) b1 := MakeBlock(h, []Tx{Tx([]byte{1})}, &Commit{Signatures: []CommitSig{}}, []Evidence{}) - b1.ProposerAddress = tmrand.Bytes(crypto.AddressSize) + b1.ProposerAddress = cmtrand.Bytes(crypto.AddressSize) b2 := MakeBlock(h, []Tx{Tx([]byte{1})}, c1, []Evidence{}) - b2.ProposerAddress = tmrand.Bytes(crypto.AddressSize) + b2.ProposerAddress = cmtrand.Bytes(crypto.AddressSize) evidenceTime := time.Date(2019, 1, 1, 0, 0, 0, 0, time.UTC) evi, err := NewMockDuplicateVoteEvidence(h, evidenceTime, "block-test-chain") require.NoError(t, err) @@ -652,7 +652,7 @@ func TestBlockProtoBuf(t *testing.T) { b2.EvidenceHash = b2.Evidence.Hash() b3 := MakeBlock(h, []Tx{}, c1, []Evidence{}) - b3.ProposerAddress = tmrand.Bytes(crypto.AddressSize) + b3.ProposerAddress = cmtrand.Bytes(crypto.AddressSize) testCases := []struct { msg string b1 *Block @@ -748,11 +748,11 @@ func TestEvidenceDataProtoBuf(t *testing.T) { func makeRandHeader() Header { chainID := "test" t := time.Now() - height := tmrand.Int63() - randBytes := tmrand.Bytes(tmhash.Size) - randAddress := tmrand.Bytes(crypto.AddressSize) + height := cmtrand.Int63() + randBytes := cmtrand.Bytes(tmhash.Size) + randAddress := cmtrand.Bytes(crypto.AddressSize) h := Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, ChainID: chainID, Height: height, Time: t, diff --git a/types/canonical.go b/types/canonical.go index 49d98405dc1..199b4d4414d 100644 --- a/types/canonical.go +++ b/types/canonical.go @@ -3,8 +3,8 @@ package types import ( "time" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmttime "github.com/tendermint/tendermint/types/time" ) // Canonical* wraps the structs in types for amino encoding them for use in SignBytes / the Signable interface. @@ -15,16 +15,16 @@ const TimeFormat = time.RFC3339Nano //----------------------------------- // Canonicalize the structs -func CanonicalizeBlockID(bid tmproto.BlockID) *tmproto.CanonicalBlockID { +func CanonicalizeBlockID(bid cmtproto.BlockID) *cmtproto.CanonicalBlockID { rbid, err := BlockIDFromProto(&bid) if err != nil { panic(err) } - var cbid *tmproto.CanonicalBlockID + var cbid *cmtproto.CanonicalBlockID if rbid == nil || rbid.IsZero() { cbid = nil } else { - cbid = &tmproto.CanonicalBlockID{ + cbid = &cmtproto.CanonicalBlockID{ Hash: bid.Hash, PartSetHeader: CanonicalizePartSetHeader(bid.PartSetHeader), } @@ -34,14 +34,14 @@ func CanonicalizeBlockID(bid tmproto.BlockID) *tmproto.CanonicalBlockID { } // CanonicalizeVote transforms the given PartSetHeader to a CanonicalPartSetHeader. -func CanonicalizePartSetHeader(psh tmproto.PartSetHeader) tmproto.CanonicalPartSetHeader { - return tmproto.CanonicalPartSetHeader(psh) +func CanonicalizePartSetHeader(psh cmtproto.PartSetHeader) cmtproto.CanonicalPartSetHeader { + return cmtproto.CanonicalPartSetHeader(psh) } // CanonicalizeVote transforms the given Proposal to a CanonicalProposal. -func CanonicalizeProposal(chainID string, proposal *tmproto.Proposal) tmproto.CanonicalProposal { - return tmproto.CanonicalProposal{ - Type: tmproto.ProposalType, +func CanonicalizeProposal(chainID string, proposal *cmtproto.Proposal) cmtproto.CanonicalProposal { + return cmtproto.CanonicalProposal{ + Type: cmtproto.ProposalType, Height: proposal.Height, // encoded as sfixed64 Round: int64(proposal.Round), // encoded as sfixed64 POLRound: int64(proposal.PolRound), @@ -53,8 +53,8 @@ func CanonicalizeProposal(chainID string, proposal *tmproto.Proposal) tmproto.Ca // CanonicalizeVote transforms the given Vote to a CanonicalVote, which does // not contain ValidatorIndex and ValidatorAddress fields. -func CanonicalizeVote(chainID string, vote *tmproto.Vote) tmproto.CanonicalVote { - return tmproto.CanonicalVote{ +func CanonicalizeVote(chainID string, vote *cmtproto.Vote) cmtproto.CanonicalVote { + return cmtproto.CanonicalVote{ Type: vote.Type, Height: vote.Height, // encoded as sfixed64 Round: int64(vote.Round), // encoded as sfixed64 @@ -69,5 +69,5 @@ func CanonicalTime(t time.Time) string { // Note that sending time over amino resets it to // local time, we need to force UTC here, so the // signatures match - return tmtime.Canonical(t).Format(TimeFormat) + return cmttime.Canonical(t).Format(TimeFormat) } diff --git a/types/canonical_test.go b/types/canonical_test.go index 53a8ea52fc1..e6cb8c7fd82 100644 --- a/types/canonical_test.go +++ b/types/canonical_test.go @@ -5,25 +5,25 @@ import ( "testing" "github.com/tendermint/tendermint/crypto/tmhash" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func TestCanonicalizeBlockID(t *testing.T) { - randhash := tmrand.Bytes(tmhash.Size) - block1 := tmproto.BlockID{Hash: randhash, - PartSetHeader: tmproto.PartSetHeader{Total: 5, Hash: randhash}} - block2 := tmproto.BlockID{Hash: randhash, - PartSetHeader: tmproto.PartSetHeader{Total: 10, Hash: randhash}} - cblock1 := tmproto.CanonicalBlockID{Hash: randhash, - PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}} - cblock2 := tmproto.CanonicalBlockID{Hash: randhash, - PartSetHeader: tmproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}} + randhash := cmtrand.Bytes(tmhash.Size) + block1 := cmtproto.BlockID{Hash: randhash, + PartSetHeader: cmtproto.PartSetHeader{Total: 5, Hash: randhash}} + block2 := cmtproto.BlockID{Hash: randhash, + PartSetHeader: cmtproto.PartSetHeader{Total: 10, Hash: randhash}} + cblock1 := cmtproto.CanonicalBlockID{Hash: randhash, + PartSetHeader: cmtproto.CanonicalPartSetHeader{Total: 5, Hash: randhash}} + cblock2 := cmtproto.CanonicalBlockID{Hash: randhash, + PartSetHeader: cmtproto.CanonicalPartSetHeader{Total: 10, Hash: randhash}} tests := []struct { name string - args tmproto.BlockID - want *tmproto.CanonicalBlockID + args cmtproto.BlockID + want *cmtproto.CanonicalBlockID }{ {"first", block1, &cblock1}, {"second", block2, &cblock2}, diff --git a/types/event_bus.go b/types/event_bus.go index 3efa008e2cd..bc3f86f7087 100644 --- a/types/event_bus.go +++ b/types/event_bus.go @@ -6,15 +6,15 @@ import ( "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" ) const defaultCapacity = 0 type EventBusSubscriber interface { - Subscribe(ctx context.Context, subscriber string, query tmpubsub.Query, outCapacity ...int) (Subscription, error) - Unsubscribe(ctx context.Context, subscriber string, query tmpubsub.Query) error + Subscribe(ctx context.Context, subscriber string, query cmtpubsub.Query, outCapacity ...int) (Subscription, error) + Unsubscribe(ctx context.Context, subscriber string, query cmtpubsub.Query) error UnsubscribeAll(ctx context.Context, subscriber string) error NumClients() int @@ -22,7 +22,7 @@ type EventBusSubscriber interface { } type Subscription interface { - Out() <-chan tmpubsub.Message + Out() <-chan cmtpubsub.Message Canceled() <-chan struct{} Err() error } @@ -32,7 +32,7 @@ type Subscription interface { // EventBus to ensure correct data types. type EventBus struct { service.BaseService - pubsub *tmpubsub.Server + pubsub *cmtpubsub.Server } // NewEventBus returns a new event bus. @@ -43,7 +43,7 @@ func NewEventBus() *EventBus { // NewEventBusWithBufferCapacity returns a new event bus with the given buffer capacity. func NewEventBusWithBufferCapacity(cap int) *EventBus { // capacity could be exposed later if needed - pubsub := tmpubsub.NewServer(tmpubsub.BufferCapacity(cap)) + pubsub := cmtpubsub.NewServer(cmtpubsub.BufferCapacity(cap)) b := &EventBus{pubsub: pubsub} b.BaseService = *service.NewBaseService(nil, "EventBus", b) return b @@ -75,7 +75,7 @@ func (b *EventBus) NumClientSubscriptions(clientID string) int { func (b *EventBus) Subscribe( ctx context.Context, subscriber string, - query tmpubsub.Query, + query cmtpubsub.Query, outCapacity ...int, ) (Subscription, error) { return b.pubsub.Subscribe(ctx, subscriber, query, outCapacity...) @@ -86,12 +86,12 @@ func (b *EventBus) Subscribe( func (b *EventBus) SubscribeUnbuffered( ctx context.Context, subscriber string, - query tmpubsub.Query, + query cmtpubsub.Query, ) (Subscription, error) { return b.pubsub.SubscribeUnbuffered(ctx, subscriber, query) } -func (b *EventBus) Unsubscribe(ctx context.Context, subscriber string, query tmpubsub.Query) error { +func (b *EventBus) Unsubscribe(ctx context.Context, subscriber string, query cmtpubsub.Query) error { return b.pubsub.Unsubscribe(ctx, subscriber, query) } @@ -233,13 +233,13 @@ type NopEventBus struct{} func (NopEventBus) Subscribe( ctx context.Context, subscriber string, - query tmpubsub.Query, + query cmtpubsub.Query, out chan<- interface{}, ) error { return nil } -func (NopEventBus) Unsubscribe(ctx context.Context, subscriber string, query tmpubsub.Query) error { +func (NopEventBus) Unsubscribe(ctx context.Context, subscriber string, query cmtpubsub.Query) error { return nil } diff --git a/types/event_bus_test.go b/types/event_bus_test.go index 09461d085ee..d77ac3b1f1f 100644 --- a/types/event_bus_test.go +++ b/types/event_bus_test.go @@ -11,9 +11,9 @@ import ( "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) func TestEventBusPublishEventTx(t *testing.T) { @@ -36,7 +36,7 @@ func TestEventBusPublishEventTx(t *testing.T) { // PublishEventTx adds 3 composite keys, so the query below should work query := fmt.Sprintf("tm.event='Tx' AND tx.height=1 AND tx.hash='%X' AND testType.baz=1", tx.Hash()) - txsSub, err := eventBus.Subscribe(context.Background(), "test", tmquery.MustCompile(query)) + txsSub, err := eventBus.Subscribe(context.Background(), "test", cmtquery.MustCompile(query)) require.NoError(t, err) done := make(chan struct{}) @@ -89,7 +89,7 @@ func TestEventBusPublishEventNewBlock(t *testing.T) { // PublishEventNewBlock adds the tm.event compositeKey, so the query below should work query := "tm.event='NewBlock' AND testType.baz=1 AND testType.foz=2" - blocksSub, err := eventBus.Subscribe(context.Background(), "test", tmquery.MustCompile(query)) + blocksSub, err := eventBus.Subscribe(context.Background(), "test", cmtquery.MustCompile(query)) require.NoError(t, err) done := make(chan struct{}) @@ -184,7 +184,7 @@ func TestEventBusPublishEventTxDuplicateKeys(t *testing.T) { } for i, tc := range testCases { - sub, err := eventBus.Subscribe(context.Background(), fmt.Sprintf("client-%d", i), tmquery.MustCompile(tc.query)) + sub, err := eventBus.Subscribe(context.Background(), fmt.Sprintf("client-%d", i), cmtquery.MustCompile(tc.query)) require.NoError(t, err) done := make(chan struct{}) @@ -248,7 +248,7 @@ func TestEventBusPublishEventNewBlockHeader(t *testing.T) { // PublishEventNewBlockHeader adds the tm.event compositeKey, so the query below should work query := "tm.event='NewBlockHeader' AND testType.baz=1 AND testType.foz=2" - headersSub, err := eventBus.Subscribe(context.Background(), "test", tmquery.MustCompile(query)) + headersSub, err := eventBus.Subscribe(context.Background(), "test", cmtquery.MustCompile(query)) require.NoError(t, err) done := make(chan struct{}) @@ -289,7 +289,7 @@ func TestEventBusPublishEventNewEvidence(t *testing.T) { require.NoError(t, err) query := "tm.event='NewEvidence'" - evSub, err := eventBus.Subscribe(context.Background(), "test", tmquery.MustCompile(query)) + evSub, err := eventBus.Subscribe(context.Background(), "test", cmtquery.MustCompile(query)) require.NoError(t, err) done := make(chan struct{}) @@ -326,7 +326,7 @@ func TestEventBusPublish(t *testing.T) { const numEventsExpected = 14 - sub, err := eventBus.Subscribe(context.Background(), "test", tmquery.All, numEventsExpected) + sub, err := eventBus.Subscribe(context.Background(), "test", cmtquery.All, numEventsExpected) require.NoError(t, err) done := make(chan struct{}) @@ -477,10 +477,10 @@ var events = []string{ EventVote} func randEvent() string { - return events[tmrand.Intn(len(events))] + return events[cmtrand.Intn(len(events))] } -var queries = []tmpubsub.Query{ +var queries = []cmtpubsub.Query{ EventQueryNewBlock, EventQueryNewBlockHeader, EventQueryNewRound, @@ -494,6 +494,6 @@ var queries = []tmpubsub.Query{ EventQueryTimeoutWait, EventQueryVote} -func randQuery() tmpubsub.Query { - return queries[tmrand.Intn(len(queries))] +func randQuery() cmtpubsub.Query { + return queries[cmtrand.Intn(len(queries))] } diff --git a/types/events.go b/types/events.go index ae6c8637bc3..f0e47cbf8fd 100644 --- a/types/events.go +++ b/types/events.go @@ -4,9 +4,9 @@ import ( "fmt" abci "github.com/tendermint/tendermint/abci/types" - tmjson "github.com/tendermint/tendermint/libs/json" - tmpubsub "github.com/tendermint/tendermint/libs/pubsub" - tmquery "github.com/tendermint/tendermint/libs/pubsub/query" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtpubsub "github.com/tendermint/tendermint/libs/pubsub" + cmtquery "github.com/tendermint/tendermint/libs/pubsub/query" ) // Reserved event types (alphabetically sorted). @@ -46,16 +46,16 @@ type TMEventData interface { } func init() { - tmjson.RegisterType(EventDataNewBlock{}, "tendermint/event/NewBlock") - tmjson.RegisterType(EventDataNewBlockHeader{}, "tendermint/event/NewBlockHeader") - tmjson.RegisterType(EventDataNewEvidence{}, "tendermint/event/NewEvidence") - tmjson.RegisterType(EventDataTx{}, "tendermint/event/Tx") - tmjson.RegisterType(EventDataRoundState{}, "tendermint/event/RoundState") - tmjson.RegisterType(EventDataNewRound{}, "tendermint/event/NewRound") - tmjson.RegisterType(EventDataCompleteProposal{}, "tendermint/event/CompleteProposal") - tmjson.RegisterType(EventDataVote{}, "tendermint/event/Vote") - tmjson.RegisterType(EventDataValidatorSetUpdates{}, "tendermint/event/ValidatorSetUpdates") - tmjson.RegisterType(EventDataString(""), "tendermint/event/ProposalString") + cmtjson.RegisterType(EventDataNewBlock{}, "tendermint/event/NewBlock") + cmtjson.RegisterType(EventDataNewBlockHeader{}, "tendermint/event/NewBlockHeader") + cmtjson.RegisterType(EventDataNewEvidence{}, "tendermint/event/NewEvidence") + cmtjson.RegisterType(EventDataTx{}, "tendermint/event/Tx") + cmtjson.RegisterType(EventDataRoundState{}, "tendermint/event/RoundState") + cmtjson.RegisterType(EventDataNewRound{}, "tendermint/event/NewRound") + cmtjson.RegisterType(EventDataCompleteProposal{}, "tendermint/event/CompleteProposal") + cmtjson.RegisterType(EventDataVote{}, "tendermint/event/Vote") + cmtjson.RegisterType(EventDataValidatorSetUpdates{}, "tendermint/event/ValidatorSetUpdates") + cmtjson.RegisterType(EventDataString(""), "tendermint/event/ProposalString") } // Most event messages are basic types (a block, a transaction) @@ -161,12 +161,12 @@ var ( EventQueryVote = QueryForEvent(EventVote) ) -func EventQueryTxFor(tx Tx) tmpubsub.Query { - return tmquery.MustCompile(fmt.Sprintf("%s='%s' AND %s='%X'", EventTypeKey, EventTx, TxHashKey, tx.Hash())) +func EventQueryTxFor(tx Tx) cmtpubsub.Query { + return cmtquery.MustCompile(fmt.Sprintf("%s='%s' AND %s='%X'", EventTypeKey, EventTx, TxHashKey, tx.Hash())) } -func QueryForEvent(eventType string) tmpubsub.Query { - return tmquery.MustCompile(fmt.Sprintf("%s='%s'", EventTypeKey, eventType)) +func QueryForEvent(eventType string) cmtpubsub.Query { + return cmtquery.MustCompile(fmt.Sprintf("%s='%s'", EventTypeKey, eventType)) } // BlockEventPublisher publishes all block related events diff --git a/types/evidence.go b/types/evidence.go index df158de338c..a2216b582cb 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -12,9 +12,9 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" - tmjson "github.com/tendermint/tendermint/libs/json" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // Evidence represents any provable malicious activity by a validator. @@ -145,10 +145,10 @@ func (dve *DuplicateVoteEvidence) ValidateBasic() error { } // ToProto encodes DuplicateVoteEvidence to protobuf -func (dve *DuplicateVoteEvidence) ToProto() *tmproto.DuplicateVoteEvidence { +func (dve *DuplicateVoteEvidence) ToProto() *cmtproto.DuplicateVoteEvidence { voteB := dve.VoteB.ToProto() voteA := dve.VoteA.ToProto() - tp := tmproto.DuplicateVoteEvidence{ + tp := cmtproto.DuplicateVoteEvidence{ VoteA: voteA, VoteB: voteB, TotalVotingPower: dve.TotalVotingPower, @@ -159,7 +159,7 @@ func (dve *DuplicateVoteEvidence) ToProto() *tmproto.DuplicateVoteEvidence { } // DuplicateVoteEvidenceFromProto decodes protobuf into DuplicateVoteEvidence -func DuplicateVoteEvidenceFromProto(pb *tmproto.DuplicateVoteEvidence) (*DuplicateVoteEvidence, error) { +func DuplicateVoteEvidenceFromProto(pb *cmtproto.DuplicateVoteEvidence) (*DuplicateVoteEvidence, error) { if pb == nil { return nil, errors.New("nil duplicate vote evidence") } @@ -372,13 +372,13 @@ func (l *LightClientAttackEvidence) ValidateBasic() error { } // ToProto encodes LightClientAttackEvidence to protobuf -func (l *LightClientAttackEvidence) ToProto() (*tmproto.LightClientAttackEvidence, error) { +func (l *LightClientAttackEvidence) ToProto() (*cmtproto.LightClientAttackEvidence, error) { conflictingBlock, err := l.ConflictingBlock.ToProto() if err != nil { return nil, err } - byzVals := make([]*tmproto.Validator, len(l.ByzantineValidators)) + byzVals := make([]*cmtproto.Validator, len(l.ByzantineValidators)) for idx, val := range l.ByzantineValidators { valpb, err := val.ToProto() if err != nil { @@ -387,7 +387,7 @@ func (l *LightClientAttackEvidence) ToProto() (*tmproto.LightClientAttackEvidenc byzVals[idx] = valpb } - return &tmproto.LightClientAttackEvidence{ + return &cmtproto.LightClientAttackEvidence{ ConflictingBlock: conflictingBlock, CommonHeight: l.CommonHeight, ByzantineValidators: byzVals, @@ -397,7 +397,7 @@ func (l *LightClientAttackEvidence) ToProto() (*tmproto.LightClientAttackEvidenc } // LightClientAttackEvidenceFromProto decodes protobuf -func LightClientAttackEvidenceFromProto(lpb *tmproto.LightClientAttackEvidence) (*LightClientAttackEvidence, error) { +func LightClientAttackEvidenceFromProto(lpb *cmtproto.LightClientAttackEvidence) (*LightClientAttackEvidence, error) { if lpb == nil { return nil, errors.New("empty light client attack evidence") } @@ -478,7 +478,7 @@ func (evl EvidenceList) ToABCI() []abci.Misbehavior { // EvidenceToProto is a generalized function for encoding evidence that conforms to the // evidence interface to protobuf -func EvidenceToProto(evidence Evidence) (*tmproto.Evidence, error) { +func EvidenceToProto(evidence Evidence) (*cmtproto.Evidence, error) { if evidence == nil { return nil, errors.New("nil evidence") } @@ -486,8 +486,8 @@ func EvidenceToProto(evidence Evidence) (*tmproto.Evidence, error) { switch evi := evidence.(type) { case *DuplicateVoteEvidence: pbev := evi.ToProto() - return &tmproto.Evidence{ - Sum: &tmproto.Evidence_DuplicateVoteEvidence{ + return &cmtproto.Evidence{ + Sum: &cmtproto.Evidence_DuplicateVoteEvidence{ DuplicateVoteEvidence: pbev, }, }, nil @@ -497,8 +497,8 @@ func EvidenceToProto(evidence Evidence) (*tmproto.Evidence, error) { if err != nil { return nil, err } - return &tmproto.Evidence{ - Sum: &tmproto.Evidence_LightClientAttackEvidence{ + return &cmtproto.Evidence{ + Sum: &cmtproto.Evidence_LightClientAttackEvidence{ LightClientAttackEvidence: pbev, }, }, nil @@ -510,15 +510,15 @@ func EvidenceToProto(evidence Evidence) (*tmproto.Evidence, error) { // EvidenceFromProto is a generalized function for decoding protobuf into the // evidence interface -func EvidenceFromProto(evidence *tmproto.Evidence) (Evidence, error) { +func EvidenceFromProto(evidence *cmtproto.Evidence) (Evidence, error) { if evidence == nil { return nil, errors.New("nil evidence") } switch evi := evidence.Sum.(type) { - case *tmproto.Evidence_DuplicateVoteEvidence: + case *cmtproto.Evidence_DuplicateVoteEvidence: return DuplicateVoteEvidenceFromProto(evi.DuplicateVoteEvidence) - case *tmproto.Evidence_LightClientAttackEvidence: + case *cmtproto.Evidence_LightClientAttackEvidence: return LightClientAttackEvidenceFromProto(evi.LightClientAttackEvidence) default: return nil, errors.New("evidence is not recognized") @@ -526,8 +526,8 @@ func EvidenceFromProto(evidence *tmproto.Evidence) (Evidence, error) { } func init() { - tmjson.RegisterType(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence") - tmjson.RegisterType(&LightClientAttackEvidence{}, "tendermint/LightClientAttackEvidence") + cmtjson.RegisterType(&DuplicateVoteEvidence{}, "tendermint/DuplicateVoteEvidence") + cmtjson.RegisterType(&LightClientAttackEvidence{}, "tendermint/LightClientAttackEvidence") } //-------------------------------------------- ERRORS -------------------------------------- @@ -602,7 +602,7 @@ func NewMockDuplicateVoteEvidenceWithValidator(height int64, time time.Time, func makeMockVote(height int64, round, index int32, addr Address, blockID BlockID, time time.Time) *Vote { return &Vote{ - Type: tmproto.SignedMsgType(2), + Type: cmtproto.SignedMsgType(2), Height: height, Round: round, BlockID: blockID, @@ -614,10 +614,10 @@ func makeMockVote(height int64, round, index int32, addr Address, func randBlockID() BlockID { return BlockID{ - Hash: tmrand.Bytes(tmhash.Size), + Hash: cmtrand.Bytes(tmhash.Size), PartSetHeader: PartSetHeader{ Total: 1, - Hash: tmrand.Bytes(tmhash.Size), + Hash: cmtrand.Bytes(tmhash.Size), }, } } diff --git a/types/evidence_test.go b/types/evidence_test.go index feb0b019524..8852e5450d5 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -10,9 +10,9 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/tmhash" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/version" ) @@ -95,7 +95,7 @@ func TestLightClientAttackEvidenceBasic(t *testing.T) { height := int64(5) commonHeight := height - 1 nValidators := 10 - voteSet, valSet, privVals := randVoteSet(height, 1, tmproto.PrecommitType, nValidators, 1) + voteSet, valSet, privVals := randVoteSet(height, 1, cmtproto.PrecommitType, nValidators, 1) header := makeHeaderRandom() header.Height = height blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash"))) @@ -154,7 +154,7 @@ func TestLightClientAttackEvidenceValidation(t *testing.T) { height := int64(5) commonHeight := height - 1 nValidators := 10 - voteSet, valSet, privVals := randVoteSet(height, 1, tmproto.PrecommitType, nValidators, 1) + voteSet, valSet, privVals := randVoteSet(height, 1, cmtproto.PrecommitType, nValidators, 1) header := makeHeaderRandom() header.Height = height header.ValidatorsHash = valSet.Hash() @@ -241,7 +241,7 @@ func makeVote( ValidatorIndex: valIndex, Height: height, Round: round, - Type: tmproto.SignedMsgType(step), + Type: cmtproto.SignedMsgType(step), BlockID: blockID, Timestamp: time, } @@ -256,9 +256,9 @@ func makeVote( func makeHeaderRandom() *Header { return &Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1}, - ChainID: tmrand.Str(12), - Height: int64(tmrand.Uint16()) + 1, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 1}, + ChainID: cmtrand.Str(12), + Height: int64(cmtrand.Uint16()) + 1, Time: time.Now(), LastBlockID: makeBlockIDRandom(), LastCommitHash: crypto.CRandBytes(tmhash.Size), diff --git a/types/genesis.go b/types/genesis.go index b75bce13e5e..97ba875f036 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -9,10 +9,10 @@ import ( "time" "github.com/tendermint/tendermint/crypto" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmjson "github.com/tendermint/tendermint/libs/json" - tmos "github.com/tendermint/tendermint/libs/os" - tmtime "github.com/tendermint/tendermint/types/time" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtos "github.com/tendermint/tendermint/libs/os" + cmttime "github.com/tendermint/tendermint/types/time" ) const ( @@ -41,17 +41,17 @@ type GenesisDoc struct { InitialHeight int64 `json:"initial_height"` ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"` Validators []GenesisValidator `json:"validators,omitempty"` - AppHash tmbytes.HexBytes `json:"app_hash"` + AppHash cmtbytes.HexBytes `json:"app_hash"` AppState json.RawMessage `json:"app_state,omitempty"` } // SaveAs is a utility method for saving GenensisDoc as a JSON file. func (genDoc *GenesisDoc) SaveAs(file string) error { - genDocBytes, err := tmjson.MarshalIndent(genDoc, "", " ") + genDocBytes, err := cmtjson.MarshalIndent(genDoc, "", " ") if err != nil { return err } - return tmos.WriteFile(file, genDocBytes, 0644) + return cmtos.WriteFile(file, genDocBytes, 0644) } // ValidatorHash returns the hash of the validator set contained in the GenesisDoc @@ -99,7 +99,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error { } if genDoc.GenesisTime.IsZero() { - genDoc.GenesisTime = tmtime.Now() + genDoc.GenesisTime = cmttime.Now() } return nil @@ -111,7 +111,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error { // GenesisDocFromJSON unmarshalls JSON data into a GenesisDoc. func GenesisDocFromJSON(jsonBlob []byte) (*GenesisDoc, error) { genDoc := GenesisDoc{} - err := tmjson.Unmarshal(jsonBlob, &genDoc) + err := cmtjson.Unmarshal(jsonBlob, &genDoc) if err != nil { return nil, err } diff --git a/types/genesis_test.go b/types/genesis_test.go index 213b1330f22..4a8c88d0648 100644 --- a/types/genesis_test.go +++ b/types/genesis_test.go @@ -8,8 +8,8 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/ed25519" - tmjson "github.com/tendermint/tendermint/libs/json" - tmtime "github.com/tendermint/tendermint/types/time" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmttime "github.com/tendermint/tendermint/types/time" ) func TestGenesisBad(t *testing.T) { @@ -82,7 +82,7 @@ func TestGenesisGood(t *testing.T) { ChainID: "abc", Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}}, } - genDocBytes, err = tmjson.Marshal(baseGenDoc) + genDocBytes, err = cmtjson.Marshal(baseGenDoc) assert.NoError(t, err, "error marshaling genDoc") // test base gendoc and check consensus params were filled @@ -94,14 +94,14 @@ func TestGenesisGood(t *testing.T) { assert.NotNil(t, genDoc.Validators[0].Address, "expected validator's address to be filled in") // create json with consensus params filled - genDocBytes, err = tmjson.Marshal(genDoc) + genDocBytes, err = cmtjson.Marshal(genDoc) assert.NoError(t, err, "error marshaling genDoc") genDoc, err = GenesisDocFromJSON(genDocBytes) assert.NoError(t, err, "expected no error for valid genDoc json") // test with invalid consensus params genDoc.ConsensusParams.Block.MaxBytes = 0 - genDocBytes, err = tmjson.Marshal(genDoc) + genDocBytes, err = cmtjson.Marshal(genDoc) assert.NoError(t, err, "error marshaling genDoc") _, err = GenesisDocFromJSON(genDocBytes) assert.Error(t, err, "expected error for genDoc json with block size of 0") @@ -154,7 +154,7 @@ func TestGenesisValidatorHash(t *testing.T) { func randomGenesisDoc() *GenesisDoc { pubkey := ed25519.GenPrivKey().PubKey() return &GenesisDoc{ - GenesisTime: tmtime.Now(), + GenesisTime: cmttime.Now(), ChainID: "abc", InitialHeight: 1000, Validators: []GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}}, diff --git a/types/light.go b/types/light.go index 5a650a15967..60605353a87 100644 --- a/types/light.go +++ b/types/light.go @@ -5,7 +5,7 @@ import ( "errors" "fmt" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // LightBlock is a SignedHeader and a ValidatorSet. @@ -63,12 +63,12 @@ func (lb LightBlock) StringIndented(indent string) string { } // ToProto converts the LightBlock to protobuf -func (lb *LightBlock) ToProto() (*tmproto.LightBlock, error) { +func (lb *LightBlock) ToProto() (*cmtproto.LightBlock, error) { if lb == nil { return nil, nil } - lbp := new(tmproto.LightBlock) + lbp := new(cmtproto.LightBlock) var err error if lb.SignedHeader != nil { lbp.SignedHeader = lb.SignedHeader.ToProto() @@ -85,7 +85,7 @@ func (lb *LightBlock) ToProto() (*tmproto.LightBlock, error) { // LightBlockFromProto converts from protobuf back into the Lightblock. // An error is returned if either the validator set or signed header are invalid -func LightBlockFromProto(pb *tmproto.LightBlock) (*LightBlock, error) { +func LightBlockFromProto(pb *cmtproto.LightBlock) (*LightBlock, error) { if pb == nil { return nil, errors.New("nil light block") } @@ -176,12 +176,12 @@ func (sh SignedHeader) StringIndented(indent string) string { } // ToProto converts SignedHeader to protobuf -func (sh *SignedHeader) ToProto() *tmproto.SignedHeader { +func (sh *SignedHeader) ToProto() *cmtproto.SignedHeader { if sh == nil { return nil } - psh := new(tmproto.SignedHeader) + psh := new(cmtproto.SignedHeader) if sh.Header != nil { psh.Header = sh.Header.ToProto() } @@ -194,7 +194,7 @@ func (sh *SignedHeader) ToProto() *tmproto.SignedHeader { // FromProto sets a protobuf SignedHeader to the given pointer. // It returns an error if the header or the commit is invalid. -func SignedHeaderFromProto(shp *tmproto.SignedHeader) (*SignedHeader, error) { +func SignedHeaderFromProto(shp *cmtproto.SignedHeader) (*SignedHeader, error) { if shp == nil { return nil, errors.New("nil SignedHeader") } diff --git a/types/light_test.go b/types/light_test.go index 68c065cde92..af5f60de5c9 100644 --- a/types/light_test.go +++ b/types/light_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/crypto" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/version" ) @@ -115,7 +115,7 @@ func TestSignedHeaderValidateBasic(t *testing.T) { chainID := "𠜎" timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC) h := Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: math.MaxInt64}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: math.MaxInt64}, ChainID: chainID, Height: commit.Height, Time: timestamp, diff --git a/types/params.go b/types/params.go index 246037d8537..fc7ce312eb1 100644 --- a/types/params.go +++ b/types/params.go @@ -8,7 +8,7 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/secp256k1" "github.com/tendermint/tendermint/crypto/tmhash" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) const ( @@ -173,7 +173,7 @@ func (params ConsensusParams) ValidateBasic() error { func (params ConsensusParams) Hash() []byte { hasher := tmhash.New() - hp := tmproto.HashedParams{ + hp := cmtproto.HashedParams{ BlockMaxBytes: params.Block.MaxBytes, BlockMaxGas: params.Block.MaxGas, } @@ -192,7 +192,7 @@ func (params ConsensusParams) Hash() []byte { // Update returns a copy of the params with updates from the non-zero fields of p2. // NOTE: note: must not modify the original -func (params ConsensusParams) Update(params2 *tmproto.ConsensusParams) ConsensusParams { +func (params ConsensusParams) Update(params2 *cmtproto.ConsensusParams) ConsensusParams { res := params // explicit copy if params2 == nil { @@ -220,27 +220,27 @@ func (params ConsensusParams) Update(params2 *tmproto.ConsensusParams) Consensus return res } -func (params *ConsensusParams) ToProto() tmproto.ConsensusParams { - return tmproto.ConsensusParams{ - Block: &tmproto.BlockParams{ +func (params *ConsensusParams) ToProto() cmtproto.ConsensusParams { + return cmtproto.ConsensusParams{ + Block: &cmtproto.BlockParams{ MaxBytes: params.Block.MaxBytes, MaxGas: params.Block.MaxGas, }, - Evidence: &tmproto.EvidenceParams{ + Evidence: &cmtproto.EvidenceParams{ MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks, MaxAgeDuration: params.Evidence.MaxAgeDuration, MaxBytes: params.Evidence.MaxBytes, }, - Validator: &tmproto.ValidatorParams{ + Validator: &cmtproto.ValidatorParams{ PubKeyTypes: params.Validator.PubKeyTypes, }, - Version: &tmproto.VersionParams{ + Version: &cmtproto.VersionParams{ App: params.Version.App, }, } } -func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams { +func ConsensusParamsFromProto(pbParams cmtproto.ConsensusParams) ConsensusParams { return ConsensusParams{ Block: BlockParams{ MaxBytes: pbParams.Block.MaxBytes, diff --git a/types/params_test.go b/types/params_test.go index c3ef682b448..8a33f91c22e 100644 --- a/types/params_test.go +++ b/types/params_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/assert" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) var ( @@ -100,29 +100,29 @@ func TestConsensusParamsHash(t *testing.T) { func TestConsensusParamsUpdate(t *testing.T) { testCases := []struct { params ConsensusParams - updates *tmproto.ConsensusParams + updates *cmtproto.ConsensusParams updatedParams ConsensusParams }{ // empty updates { makeParams(1, 2, 3, 0, valEd25519), - &tmproto.ConsensusParams{}, + &cmtproto.ConsensusParams{}, makeParams(1, 2, 3, 0, valEd25519), }, // fine updates { makeParams(1, 2, 3, 0, valEd25519), - &tmproto.ConsensusParams{ - Block: &tmproto.BlockParams{ + &cmtproto.ConsensusParams{ + Block: &cmtproto.BlockParams{ MaxBytes: 100, MaxGas: 200, }, - Evidence: &tmproto.EvidenceParams{ + Evidence: &cmtproto.EvidenceParams{ MaxAgeNumBlocks: 300, MaxAgeDuration: time.Duration(300), MaxBytes: 50, }, - Validator: &tmproto.ValidatorParams{ + Validator: &cmtproto.ValidatorParams{ PubKeyTypes: valSecp256k1, }, }, @@ -141,7 +141,7 @@ func TestConsensusParamsUpdate_AppVersion(t *testing.T) { assert.EqualValues(t, 0, params.Version.App) updated := params.Update( - &tmproto.ConsensusParams{Version: &tmproto.VersionParams{App: 1}}) + &cmtproto.ConsensusParams{Version: &cmtproto.VersionParams{App: 1}}) assert.EqualValues(t, 1, updated.Version.App) } diff --git a/types/part_set.go b/types/part_set.go index 5e76b57faa5..01fcec06aeb 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -8,11 +8,11 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/libs/bits" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmjson "github.com/tendermint/tendermint/libs/json" - tmmath "github.com/tendermint/tendermint/libs/math" - tmsync "github.com/tendermint/tendermint/libs/sync" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtsync "github.com/tendermint/tendermint/libs/sync" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) var ( @@ -21,9 +21,9 @@ var ( ) type Part struct { - Index uint32 `json:"index"` - Bytes tmbytes.HexBytes `json:"bytes"` - Proof merkle.Proof `json:"proof"` + Index uint32 `json:"index"` + Bytes cmtbytes.HexBytes `json:"bytes"` + Proof merkle.Proof `json:"proof"` } // ValidateBasic performs basic validation. @@ -53,16 +53,16 @@ func (part *Part) StringIndented(indent string) string { %s Proof: %v %s}`, part.Index, - indent, tmbytes.Fingerprint(part.Bytes), + indent, cmtbytes.Fingerprint(part.Bytes), indent, part.Proof.StringIndented(indent+" "), indent) } -func (part *Part) ToProto() (*tmproto.Part, error) { +func (part *Part) ToProto() (*cmtproto.Part, error) { if part == nil { return nil, errors.New("nil part") } - pb := new(tmproto.Part) + pb := new(cmtproto.Part) proof := part.Proof.ToProto() pb.Index = part.Index @@ -72,7 +72,7 @@ func (part *Part) ToProto() (*tmproto.Part, error) { return pb, nil } -func PartFromProto(pb *tmproto.Part) (*Part, error) { +func PartFromProto(pb *cmtproto.Part) (*Part, error) { if pb == nil { return nil, errors.New("nil part") } @@ -92,8 +92,8 @@ func PartFromProto(pb *tmproto.Part) (*Part, error) { //------------------------------------- type PartSetHeader struct { - Total uint32 `json:"total"` - Hash tmbytes.HexBytes `json:"hash"` + Total uint32 `json:"total"` + Hash cmtbytes.HexBytes `json:"hash"` } // String returns a string representation of PartSetHeader. @@ -101,7 +101,7 @@ type PartSetHeader struct { // 1. total number of parts // 2. first 6 bytes of the hash func (psh PartSetHeader) String() string { - return fmt.Sprintf("%v:%X", psh.Total, tmbytes.Fingerprint(psh.Hash)) + return fmt.Sprintf("%v:%X", psh.Total, cmtbytes.Fingerprint(psh.Hash)) } func (psh PartSetHeader) IsZero() bool { @@ -122,19 +122,19 @@ func (psh PartSetHeader) ValidateBasic() error { } // ToProto converts PartSetHeader to protobuf -func (psh *PartSetHeader) ToProto() tmproto.PartSetHeader { +func (psh *PartSetHeader) ToProto() cmtproto.PartSetHeader { if psh == nil { - return tmproto.PartSetHeader{} + return cmtproto.PartSetHeader{} } - return tmproto.PartSetHeader{ + return cmtproto.PartSetHeader{ Total: psh.Total, Hash: psh.Hash, } } // FromProto sets a protobuf PartSetHeader to the given pointer -func PartSetHeaderFromProto(ppsh *tmproto.PartSetHeader) (*PartSetHeader, error) { +func PartSetHeaderFromProto(ppsh *cmtproto.PartSetHeader) (*PartSetHeader, error) { if ppsh == nil { return nil, errors.New("nil PartSetHeader") } @@ -151,7 +151,7 @@ type PartSet struct { total uint32 hash []byte - mtx tmsync.Mutex + mtx cmtsync.Mutex parts []*Part partsBitArray *bits.BitArray count uint32 @@ -172,7 +172,7 @@ func NewPartSetFromData(data []byte, partSize uint32) *PartSet { for i := uint32(0); i < total; i++ { part := &Part{ Index: i, - Bytes: data[i*partSize : tmmath.MinInt(len(data), int((i+1)*partSize))], + Bytes: data[i*partSize : cmtmath.MinInt(len(data), int((i+1)*partSize))], } parts[i] = part partsBytes[i] = part.Bytes @@ -365,7 +365,7 @@ func (ps *PartSet) MarshalJSON() ([]byte, error) { ps.mtx.Lock() defer ps.mtx.Unlock() - return tmjson.Marshal(struct { + return cmtjson.Marshal(struct { CountTotal string `json:"count/total"` PartsBitArray *bits.BitArray `json:"parts_bit_array"` }{ diff --git a/types/part_set_test.go b/types/part_set_test.go index 2dfe12263a8..eaa5d6fbcb6 100644 --- a/types/part_set_test.go +++ b/types/part_set_test.go @@ -8,7 +8,7 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto/merkle" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ) const ( @@ -18,7 +18,7 @@ const ( func TestBasicPartSet(t *testing.T) { // Construct random data of size partSize * 100 nParts := 100 - data := tmrand.Bytes(testPartSize * nParts) + data := cmtrand.Bytes(testPartSize * nParts) partSet := NewPartSetFromData(data, testPartSize) assert.NotEmpty(t, partSet.Hash()) @@ -65,7 +65,7 @@ func TestBasicPartSet(t *testing.T) { func TestWrongProof(t *testing.T) { // Construct random data of size partSize * 100 - data := tmrand.Bytes(testPartSize * 100) + data := cmtrand.Bytes(testPartSize * 100) partSet := NewPartSetFromData(data, testPartSize) // Test adding a part with wrong data. @@ -100,7 +100,7 @@ func TestPartSetHeaderValidateBasic(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.testName, func(t *testing.T) { - data := tmrand.Bytes(testPartSize * 100) + data := cmtrand.Bytes(testPartSize * 100) ps := NewPartSetFromData(data, testPartSize) psHeader := ps.Header() tc.malleatePartSetHeader(&psHeader) @@ -129,7 +129,7 @@ func TestPartValidateBasic(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.testName, func(t *testing.T) { - data := tmrand.Bytes(testPartSize * 100) + data := cmtrand.Bytes(testPartSize * 100) ps := NewPartSetFromData(data, testPartSize) part := ps.GetPart(0) tc.malleatePart(part) @@ -166,7 +166,7 @@ func TestPartProtoBuf(t *testing.T) { proof := merkle.Proof{ Total: 1, Index: 1, - LeafHash: tmrand.Bytes(32), + LeafHash: cmtrand.Bytes(32), } testCases := []struct { msg string @@ -176,7 +176,7 @@ func TestPartProtoBuf(t *testing.T) { {"failure empty", &Part{}, false}, {"failure nil", nil, false}, {"success", - &Part{Index: 1, Bytes: tmrand.Bytes(32), Proof: proof}, true}, + &Part{Index: 1, Bytes: cmtrand.Bytes(32), Proof: proof}, true}, } for _, tc := range testCases { diff --git a/types/priv_validator.go b/types/priv_validator.go index 49211773a08..cb63b24b600 100644 --- a/types/priv_validator.go +++ b/types/priv_validator.go @@ -7,7 +7,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // PrivValidator defines the functionality of a local Tendermint validator @@ -15,8 +15,8 @@ import ( type PrivValidator interface { GetPubKey() (crypto.PubKey, error) - SignVote(chainID string, vote *tmproto.Vote) error - SignProposal(chainID string, proposal *tmproto.Proposal) error + SignVote(chainID string, vote *cmtproto.Vote) error + SignProposal(chainID string, proposal *cmtproto.Proposal) error } type PrivValidatorsByAddress []PrivValidator @@ -70,7 +70,7 @@ func (pv MockPV) GetPubKey() (crypto.PubKey, error) { } // Implements PrivValidator. -func (pv MockPV) SignVote(chainID string, vote *tmproto.Vote) error { +func (pv MockPV) SignVote(chainID string, vote *cmtproto.Vote) error { useChainID := chainID if pv.breakVoteSigning { useChainID = "incorrect-chain-id" @@ -86,7 +86,7 @@ func (pv MockPV) SignVote(chainID string, vote *tmproto.Vote) error { } // Implements PrivValidator. -func (pv MockPV) SignProposal(chainID string, proposal *tmproto.Proposal) error { +func (pv MockPV) SignProposal(chainID string, proposal *cmtproto.Proposal) error { useChainID := chainID if pv.breakProposalSigning { useChainID = "incorrect-chain-id" @@ -129,12 +129,12 @@ type ErroringMockPV struct { var ErroringMockPVErr = errors.New("erroringMockPV always returns an error") // Implements PrivValidator. -func (pv *ErroringMockPV) SignVote(chainID string, vote *tmproto.Vote) error { +func (pv *ErroringMockPV) SignVote(chainID string, vote *cmtproto.Vote) error { return ErroringMockPVErr } // Implements PrivValidator. -func (pv *ErroringMockPV) SignProposal(chainID string, proposal *tmproto.Proposal) error { +func (pv *ErroringMockPV) SignProposal(chainID string, proposal *cmtproto.Proposal) error { return ErroringMockPVErr } diff --git a/types/proposal.go b/types/proposal.go index 20f9e5fbe37..3401f6f055a 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -5,10 +5,10 @@ import ( "fmt" "time" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/protoio" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmttime "github.com/tendermint/tendermint/types/time" ) var ( @@ -23,7 +23,7 @@ var ( // a so-called Proof-of-Lock (POL) round, as noted in the POLRound. // If POLRound >= 0, then BlockID corresponds to the block that is locked in POLRound. type Proposal struct { - Type tmproto.SignedMsgType + Type cmtproto.SignedMsgType Height int64 `json:"height"` Round int32 `json:"round"` // there can not be greater than 2_147_483_647 rounds POLRound int32 `json:"pol_round"` // -1 if null. @@ -36,18 +36,18 @@ type Proposal struct { // If there is no POLRound, polRound should be -1. func NewProposal(height int64, round int32, polRound int32, blockID BlockID) *Proposal { return &Proposal{ - Type: tmproto.ProposalType, + Type: cmtproto.ProposalType, Height: height, Round: round, BlockID: blockID, POLRound: polRound, - Timestamp: tmtime.Now(), + Timestamp: cmttime.Now(), } } // ValidateBasic performs basic validation. func (p *Proposal) ValidateBasic() error { - if p.Type != tmproto.ProposalType { + if p.Type != cmtproto.ProposalType { return errors.New("invalid Type") } if p.Height < 0 { @@ -95,7 +95,7 @@ func (p *Proposal) String() string { p.Round, p.BlockID, p.POLRound, - tmbytes.Fingerprint(p.Signature), + cmtbytes.Fingerprint(p.Signature), CanonicalTime(p.Timestamp)) } @@ -107,7 +107,7 @@ func (p *Proposal) String() string { // devices that rely on this encoding. // // See CanonicalizeProposal -func ProposalSignBytes(chainID string, p *tmproto.Proposal) []byte { +func ProposalSignBytes(chainID string, p *cmtproto.Proposal) []byte { pb := CanonicalizeProposal(chainID, p) bz, err := protoio.MarshalDelimited(&pb) if err != nil { @@ -118,11 +118,11 @@ func ProposalSignBytes(chainID string, p *tmproto.Proposal) []byte { } // ToProto converts Proposal to protobuf -func (p *Proposal) ToProto() *tmproto.Proposal { +func (p *Proposal) ToProto() *cmtproto.Proposal { if p == nil { - return &tmproto.Proposal{} + return &cmtproto.Proposal{} } - pb := new(tmproto.Proposal) + pb := new(cmtproto.Proposal) pb.BlockID = p.BlockID.ToProto() pb.Type = p.Type @@ -137,7 +137,7 @@ func (p *Proposal) ToProto() *tmproto.Proposal { // FromProto sets a protobuf Proposal to the given pointer. // It returns an error if the proposal is invalid. -func ProposalFromProto(pp *tmproto.Proposal) (*Proposal, error) { +func ProposalFromProto(pp *cmtproto.Proposal) (*Proposal, error) { if pp == nil { return nil, errors.New("nil proposal") } diff --git a/types/proposal_test.go b/types/proposal_test.go index e8d998cf7f3..659cbc242d2 100644 --- a/types/proposal_test.go +++ b/types/proposal_test.go @@ -11,13 +11,13 @@ import ( "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/protoio" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) var ( testProposal *Proposal - pbp *tmproto.Proposal + pbp *cmtproto.Proposal ) func init() { @@ -61,7 +61,7 @@ func TestProposalVerifySignature(t *testing.T) { prop := NewProposal( 4, 2, 2, - BlockID{tmrand.Bytes(tmhash.Size), PartSetHeader{777, tmrand.Bytes(tmhash.Size)}}) + BlockID{cmtrand.Bytes(tmhash.Size), PartSetHeader{777, cmtrand.Bytes(tmhash.Size)}}) p := prop.ToProto() signBytes := ProposalSignBytes("test_chain_id", p) @@ -75,7 +75,7 @@ func TestProposalVerifySignature(t *testing.T) { require.True(t, valid) // serialize, deserialize and verify again.... - newProp := new(tmproto.Proposal) + newProp := new(cmtproto.Proposal) pb := prop.ToProto() bs, err := proto.Marshal(pb) @@ -131,7 +131,7 @@ func TestProposalValidateBasic(t *testing.T) { expectErr bool }{ {"Good Proposal", func(p *Proposal) {}, false}, - {"Invalid Type", func(p *Proposal) { p.Type = tmproto.PrecommitType }, true}, + {"Invalid Type", func(p *Proposal) { p.Type = cmtproto.PrecommitType }, true}, {"Invalid Height", func(p *Proposal) { p.Height = -1 }, true}, {"Invalid Round", func(p *Proposal) { p.Round = -1 }, true}, {"Invalid POLRound", func(p *Proposal) { p.POLRound = -2 }, true}, diff --git a/types/protobuf.go b/types/protobuf.go index 70b48da18ab..0ac2d7ea706 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -4,7 +4,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" cryptoenc "github.com/tendermint/tendermint/crypto/encoding" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) //------------------------------------------------------- @@ -15,8 +15,8 @@ var TM2PB = tm2pb{} type tm2pb struct{} -func (tm2pb) Header(header *Header) tmproto.Header { - return tmproto.Header{ +func (tm2pb) Header(header *Header) cmtproto.Header { + return cmtproto.Header{ Version: header.Version, ChainID: header.ChainID, Height: header.Height, @@ -45,15 +45,15 @@ func (tm2pb) Validator(val *Validator) abci.Validator { } } -func (tm2pb) BlockID(blockID BlockID) tmproto.BlockID { - return tmproto.BlockID{ +func (tm2pb) BlockID(blockID BlockID) cmtproto.BlockID { + return cmtproto.BlockID{ Hash: blockID.Hash, PartSetHeader: TM2PB.PartSetHeader(blockID.PartSetHeader), } } -func (tm2pb) PartSetHeader(header PartSetHeader) tmproto.PartSetHeader { - return tmproto.PartSetHeader{ +func (tm2pb) PartSetHeader(header PartSetHeader) cmtproto.PartSetHeader { + return cmtproto.PartSetHeader{ Total: header.Total, Hash: header.Hash, } @@ -101,13 +101,13 @@ var PB2TM = pb2tm{} type pb2tm struct{} func (pb2tm) ValidatorUpdates(vals []abci.ValidatorUpdate) ([]*Validator, error) { - tmVals := make([]*Validator, len(vals)) + cmtVals := make([]*Validator, len(vals)) for i, v := range vals { pub, err := cryptoenc.PubKeyFromProto(v.PubKey) if err != nil { return nil, err } - tmVals[i] = NewValidator(pub, v.Power) + cmtVals[i] = NewValidator(pub, v.Power) } - return tmVals, nil + return cmtVals, nil } diff --git a/types/protobuf_test.go b/types/protobuf_test.go index bfe7084bd23..e1eedb2a476 100644 --- a/types/protobuf_test.go +++ b/types/protobuf_test.go @@ -31,25 +31,25 @@ func TestABCIValidators(t *testing.T) { pkEd := ed25519.GenPrivKey().PubKey() // correct validator - tmValExpected := NewValidator(pkEd, 10) + cmtValExpected := NewValidator(pkEd, 10) - tmVal := NewValidator(pkEd, 10) + cmtVal := NewValidator(pkEd, 10) - abciVal := TM2PB.ValidatorUpdate(tmVal) - tmVals, err := PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal}) + abciVal := TM2PB.ValidatorUpdate(cmtVal) + cmtVals, err := PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal}) assert.Nil(t, err) - assert.Equal(t, tmValExpected, tmVals[0]) + assert.Equal(t, cmtValExpected, cmtVals[0]) - abciVals := TM2PB.ValidatorUpdates(NewValidatorSet(tmVals)) + abciVals := TM2PB.ValidatorUpdates(NewValidatorSet(cmtVals)) assert.Equal(t, []abci.ValidatorUpdate{abciVal}, abciVals) // val with address - tmVal.Address = pkEd.Address() + cmtVal.Address = pkEd.Address() - abciVal = TM2PB.ValidatorUpdate(tmVal) - tmVals, err = PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal}) + abciVal = TM2PB.ValidatorUpdate(cmtVal) + cmtVals, err = PB2TM.ValidatorUpdates([]abci.ValidatorUpdate{abciVal}) assert.Nil(t, err) - assert.Equal(t, tmValExpected, tmVals[0]) + assert.Equal(t, cmtValExpected, cmtVals[0]) } type pubKeyEddie struct{} @@ -77,10 +77,10 @@ func TestABCIValidatorWithoutPubKey(t *testing.T) { abciVal := TM2PB.Validator(NewValidator(pkEd, 10)) // pubkey must be nil - tmValExpected := abci.Validator{ + cmtValExpected := abci.Validator{ Address: pkEd.Address(), Power: 10, } - assert.Equal(t, tmValExpected, abciVal) + assert.Equal(t, cmtValExpected, abciVal) } diff --git a/types/signable.go b/types/signable.go index 25e30731686..1de5352baf5 100644 --- a/types/signable.go +++ b/types/signable.go @@ -2,14 +2,14 @@ package types import ( "github.com/tendermint/tendermint/crypto/ed25519" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" ) var ( // MaxSignatureSize is a maximum allowed signature size for the Proposal // and Vote. // XXX: secp256k1 does not have Size nor MaxSize defined. - MaxSignatureSize = tmmath.MaxInt(ed25519.SignatureSize, 64) + MaxSignatureSize = cmtmath.MaxInt(ed25519.SignatureSize, 64) ) // Signable is an interface for all signable things. diff --git a/types/signed_msg_type.go b/types/signed_msg_type.go index 4ab5685a765..de9f6fc3387 100644 --- a/types/signed_msg_type.go +++ b/types/signed_msg_type.go @@ -1,11 +1,11 @@ package types -import tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +import cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" // IsVoteTypeValid returns true if t is a valid vote type. -func IsVoteTypeValid(t tmproto.SignedMsgType) bool { +func IsVoteTypeValid(t cmtproto.SignedMsgType) bool { switch t { - case tmproto.PrevoteType, tmproto.PrecommitType: + case cmtproto.PrevoteType, cmtproto.PrecommitType: return true default: return false diff --git a/types/test_util.go b/types/test_util.go index 0481c138834..51e321cdb2e 100644 --- a/types/test_util.go +++ b/types/test_util.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmversion "github.com/tendermint/tendermint/proto/tendermint/version" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtversion "github.com/tendermint/tendermint/proto/tendermint/version" "github.com/tendermint/tendermint/version" ) @@ -23,7 +23,7 @@ func MakeCommit(blockID BlockID, height int64, round int32, ValidatorIndex: int32(i), Height: height, Round: round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: blockID, Timestamp: now, } @@ -67,7 +67,7 @@ func MakeVote( Height: height, Round: 0, Timestamp: now, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: blockID, } v := vote.ToProto() @@ -87,7 +87,7 @@ func MakeVote( func MakeBlock(height int64, txs []Tx, lastCommit *Commit, evidence []Evidence) *Block { block := &Block{ Header: Header{ - Version: tmversion.Consensus{Block: version.BlockProtocol, App: 0}, + Version: cmtversion.Consensus{Block: version.BlockProtocol, App: 0}, Height: height, }, Data: Data{ diff --git a/types/tx.go b/types/tx.go index 8ed067ff753..92987bfa645 100644 --- a/types/tx.go +++ b/types/tx.go @@ -8,8 +8,8 @@ import ( "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" - tmbytes "github.com/tendermint/tendermint/libs/bytes" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // TxKeySize is the size of the transaction key index @@ -126,9 +126,9 @@ func (txs Txs) ToSliceOfBytes() [][]byte { // TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree. type TxProof struct { - RootHash tmbytes.HexBytes `json:"root_hash"` - Data Tx `json:"data"` - Proof merkle.Proof `json:"proof"` + RootHash cmtbytes.HexBytes `json:"root_hash"` + Data Tx `json:"data"` + Proof merkle.Proof `json:"proof"` } // Leaf returns the hash(tx), which is the leaf in the merkle tree which this proof refers to. @@ -155,11 +155,11 @@ func (tp TxProof) Validate(dataHash []byte) error { return nil } -func (tp TxProof) ToProto() tmproto.TxProof { +func (tp TxProof) ToProto() cmtproto.TxProof { pbProof := tp.Proof.ToProto() - pbtp := tmproto.TxProof{ + pbtp := cmtproto.TxProof{ RootHash: tp.RootHash, Data: tp.Data, Proof: pbProof, @@ -167,7 +167,7 @@ func (tp TxProof) ToProto() tmproto.TxProof { return pbtp } -func TxProofFromProto(pb tmproto.TxProof) (TxProof, error) { +func TxProofFromProto(pb cmtproto.TxProof) (TxProof, error) { pbProof, err := merkle.ProofFromProto(pb.Proof) if err != nil { @@ -183,7 +183,7 @@ func TxProofFromProto(pb tmproto.TxProof) (TxProof, error) { return pbtp, nil } -// ComputeProtoSizeForTxs wraps the transactions in tmproto.Data{} and calculates the size. +// ComputeProtoSizeForTxs wraps the transactions in cmtproto.Data{} and calculates the size. // https://developers.google.com/protocol-buffers/docs/encoding func ComputeProtoSizeForTxs(txs []Tx) int64 { data := Data{Txs: txs} diff --git a/types/tx_test.go b/types/tx_test.go index bb53e0ea5eb..e562e5e3a7a 100644 --- a/types/tx_test.go +++ b/types/tx_test.go @@ -8,15 +8,15 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmrand "github.com/tendermint/tendermint/libs/rand" + cmtrand "github.com/tendermint/tendermint/libs/rand" ctest "github.com/tendermint/tendermint/libs/test" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func makeTxs(cnt, size int) Txs { txs := make(Txs, cnt) for i := 0; i < cnt; i++ { - txs[i] = tmrand.Bytes(size) + txs[i] = cmtrand.Bytes(size) } return txs } @@ -77,7 +77,7 @@ func TestValidTxProof(t *testing.T) { // read-write must also work var ( p2 TxProof - pb2 tmproto.TxProof + pb2 cmtproto.TxProof ) pbProof := proof.ToProto() bin, err := pbProof.Marshal() @@ -128,7 +128,7 @@ func assertBadProof(t *testing.T, root []byte, bad []byte, good TxProof) { var ( proof TxProof - pbProof tmproto.TxProof + pbProof cmtproto.TxProof ) err := pbProof.Unmarshal(bad) if err == nil { diff --git a/types/validation.go b/types/validation.go index 3b33e90db02..cfe3ff6a3d1 100644 --- a/types/validation.go +++ b/types/validation.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto/batch" "github.com/tendermint/tendermint/crypto/tmhash" - tmmath "github.com/tendermint/tendermint/libs/math" + cmtmath "github.com/tendermint/tendermint/libs/math" ) const batchVerifyThreshold = 2 @@ -91,7 +91,7 @@ func VerifyCommitLight(chainID string, vals *ValidatorSet, blockID BlockID, // // This method is primarily used by the light client and does not check all the // signatures. -func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *Commit, trustLevel tmmath.Fraction) error { +func VerifyCommitLightTrusting(chainID string, vals *ValidatorSet, commit *Commit, trustLevel cmtmath.Fraction) error { // sanity checks if vals == nil { return errors.New("nil validator set") diff --git a/types/validation_test.go b/types/validation_test.go index d194d680e62..4d396c3db12 100644 --- a/types/validation_test.go +++ b/types/validation_test.go @@ -7,8 +7,8 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - tmmath "github.com/tendermint/tendermint/libs/math" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // Check VerifyCommit, VerifyCommitLight and VerifyCommitLightTrusting basic @@ -20,7 +20,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) { blockID = makeBlockID([]byte("blockhash"), 1000, []byte("partshash")) chainID = "Lalande21185" - trustLevel = tmmath.Fraction{Numerator: 2, Denominator: 3} + trustLevel = cmtmath.Fraction{Numerator: 2, Denominator: 3} ) testCases := []struct { @@ -59,7 +59,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) { for _, tc := range testCases { tc := tc t.Run(tc.description, func(t *testing.T) { - _, valSet, vals := randVoteSet(tc.height, round, tmproto.PrecommitType, tc.valSize, 10) + _, valSet, vals := randVoteSet(tc.height, round, cmtproto.PrecommitType, tc.valSize, 10) totalVotes := tc.blockVotes + tc.absentVotes + tc.nilVotes sigs := make([]CommitSig, totalVotes) vi := 0 @@ -77,7 +77,7 @@ func TestValidatorSet_VerifyCommit_All(t *testing.T) { ValidatorIndex: int32(vi), Height: tc.height, Round: round, - Type: tmproto.PrecommitType, + Type: cmtproto.PrecommitType, BlockID: tc.blockID, Timestamp: time.Now(), } @@ -137,7 +137,7 @@ func TestValidatorSet_VerifyCommit_CheckAllSignatures(t *testing.T) { blockID = makeBlockIDRandom() ) - voteSet, valSet, vals := randVoteSet(h, 0, tmproto.PrecommitType, 4, 10) + voteSet, valSet, vals := randVoteSet(h, 0, cmtproto.PrecommitType, 4, 10) commit, err := MakeCommit(blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) @@ -163,7 +163,7 @@ func TestValidatorSet_VerifyCommitLight_ReturnsAsSoonAsMajorityOfVotingPowerSign blockID = makeBlockIDRandom() ) - voteSet, valSet, vals := randVoteSet(h, 0, tmproto.PrecommitType, 4, 10) + voteSet, valSet, vals := randVoteSet(h, 0, cmtproto.PrecommitType, 4, 10) commit, err := MakeCommit(blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) @@ -187,7 +187,7 @@ func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotin blockID = makeBlockIDRandom() ) - voteSet, valSet, vals := randVoteSet(h, 0, tmproto.PrecommitType, 4, 10) + voteSet, valSet, vals := randVoteSet(h, 0, cmtproto.PrecommitType, 4, 10) commit, err := MakeCommit(blockID, h, 0, voteSet, vals, time.Now()) require.NoError(t, err) require.NoError(t, valSet.VerifyCommit(chainID, blockID, h, commit)) @@ -200,14 +200,14 @@ func TestValidatorSet_VerifyCommitLightTrusting_ReturnsAsSoonAsTrustLevelOfVotin vote.Signature = v.Signature commit.Signatures[2] = vote.CommitSig() - err = valSet.VerifyCommitLightTrusting(chainID, commit, tmmath.Fraction{Numerator: 1, Denominator: 3}) + err = valSet.VerifyCommitLightTrusting(chainID, commit, cmtmath.Fraction{Numerator: 1, Denominator: 3}) assert.NoError(t, err) } func TestValidatorSet_VerifyCommitLightTrusting(t *testing.T) { var ( blockID = makeBlockIDRandom() - voteSet, originalValset, vals = randVoteSet(1, 1, tmproto.PrecommitType, 6, 1) + voteSet, originalValset, vals = randVoteSet(1, 1, cmtproto.PrecommitType, 6, 1) commit, err = MakeCommit(blockID, 1, 1, voteSet, vals, time.Now()) newValSet, _ = RandValidatorSet(2, 1) ) @@ -236,7 +236,7 @@ func TestValidatorSet_VerifyCommitLightTrusting(t *testing.T) { for _, tc := range testCases { err = tc.valSet.VerifyCommitLightTrusting("test_chain_id", commit, - tmmath.Fraction{Numerator: 1, Denominator: 3}) + cmtmath.Fraction{Numerator: 1, Denominator: 3}) if tc.err { assert.Error(t, err) } else { @@ -248,13 +248,13 @@ func TestValidatorSet_VerifyCommitLightTrusting(t *testing.T) { func TestValidatorSet_VerifyCommitLightTrustingErrorsOnOverflow(t *testing.T) { var ( blockID = makeBlockIDRandom() - voteSet, valSet, vals = randVoteSet(1, 1, tmproto.PrecommitType, 1, MaxTotalVotingPower) + voteSet, valSet, vals = randVoteSet(1, 1, cmtproto.PrecommitType, 1, MaxTotalVotingPower) commit, err = MakeCommit(blockID, 1, 1, voteSet, vals, time.Now()) ) require.NoError(t, err) err = valSet.VerifyCommitLightTrusting("test_chain_id", commit, - tmmath.Fraction{Numerator: 25, Denominator: 55}) + cmtmath.Fraction{Numerator: 25, Denominator: 55}) if assert.Error(t, err) { assert.Contains(t, err.Error(), "int64 overflow") } diff --git a/types/validator.go b/types/validator.go index 961b833e41f..321d1cf08ce 100644 --- a/types/validator.go +++ b/types/validator.go @@ -8,8 +8,8 @@ import ( "github.com/tendermint/tendermint/crypto" ce "github.com/tendermint/tendermint/crypto/encoding" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) // Volatile state for each Validator @@ -120,7 +120,7 @@ func (v *Validator) Bytes() []byte { panic(err) } - pbv := tmproto.SimpleValidator{ + pbv := cmtproto.SimpleValidator{ PubKey: &pk, VotingPower: v.VotingPower, } @@ -133,7 +133,7 @@ func (v *Validator) Bytes() []byte { } // ToProto converts Valiator to protobuf -func (v *Validator) ToProto() (*tmproto.Validator, error) { +func (v *Validator) ToProto() (*cmtproto.Validator, error) { if v == nil { return nil, errors.New("nil validator") } @@ -143,7 +143,7 @@ func (v *Validator) ToProto() (*tmproto.Validator, error) { return nil, err } - vp := tmproto.Validator{ + vp := cmtproto.Validator{ Address: v.Address, PubKey: pk, VotingPower: v.VotingPower, @@ -155,7 +155,7 @@ func (v *Validator) ToProto() (*tmproto.Validator, error) { // FromProto sets a protobuf Validator to the given pointer. // It returns an error if the public key is invalid. -func ValidatorFromProto(vp *tmproto.Validator) (*Validator, error) { +func ValidatorFromProto(vp *cmtproto.Validator) (*Validator, error) { if vp == nil { return nil, errors.New("nil validator") } @@ -182,7 +182,7 @@ func RandValidator(randPower bool, minPower int64) (*Validator, PrivValidator) { privVal := NewMockPV() votePower := minPower if randPower { - votePower += int64(tmrand.Uint32()) + votePower += int64(cmtrand.Uint32()) } pubKey, err := privVal.GetPubKey() if err != nil { diff --git a/types/validator_set.go b/types/validator_set.go index 04232973b2a..6a5c8b48a9a 100644 --- a/types/validator_set.go +++ b/types/validator_set.go @@ -10,8 +10,8 @@ import ( "strings" "github.com/tendermint/tendermint/crypto/merkle" - tmmath "github.com/tendermint/tendermint/libs/math" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) const ( @@ -674,7 +674,7 @@ func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID BlockID, // VerifyCommitLightTrusting verifies that trustLevel of the validator set signed // this commit. -func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Commit, trustLevel tmmath.Fraction) error { +func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Commit, trustLevel cmtmath.Fraction) error { return VerifyCommitLightTrusting(chainID, vals, commit, trustLevel) } @@ -782,13 +782,13 @@ func (valz ValidatorsByAddress) Swap(i, j int) { } // ToProto converts ValidatorSet to protobuf -func (vals *ValidatorSet) ToProto() (*tmproto.ValidatorSet, error) { +func (vals *ValidatorSet) ToProto() (*cmtproto.ValidatorSet, error) { if vals.IsNilOrEmpty() { - return &tmproto.ValidatorSet{}, nil // validator set should never be nil + return &cmtproto.ValidatorSet{}, nil // validator set should never be nil } - vp := new(tmproto.ValidatorSet) - valsProto := make([]*tmproto.Validator, len(vals.Validators)) + vp := new(cmtproto.ValidatorSet) + valsProto := make([]*cmtproto.Validator, len(vals.Validators)) for i := 0; i < len(vals.Validators); i++ { valp, err := vals.Validators[i].ToProto() if err != nil { @@ -814,7 +814,7 @@ func (vals *ValidatorSet) ToProto() (*tmproto.ValidatorSet, error) { // ValidatorSetFromProto sets a protobuf ValidatorSet to the given pointer. // It returns an error if any of the validators from the set or the proposer // is invalid -func ValidatorSetFromProto(vp *tmproto.ValidatorSet) (*ValidatorSet, error) { +func ValidatorSetFromProto(vp *cmtproto.ValidatorSet) (*ValidatorSet, error) { if vp == nil { return nil, errors.New("nil validator set") // validator set should never be nil, bigger issues are at play if empty } diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 6973fc80bfd..0f31314a1cc 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -14,9 +14,9 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - tmmath "github.com/tendermint/tendermint/libs/math" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtmath "github.com/tendermint/tendermint/libs/math" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func TestValidatorSetBasic(t *testing.T) { @@ -350,10 +350,10 @@ func TestProposerSelection3(t *testing.T) { // times is usually 1 times := int32(1) - mod := (tmrand.Int() % 5) + 1 - if tmrand.Int()%mod > 0 { + mod := (cmtrand.Int() % 5) + 1 + if cmtrand.Int()%mod > 0 { // sometimes its up to 5 - times = (tmrand.Int31() % 4) + 1 + times = (cmtrand.Int31() % 4) + 1 } vset.IncrementProposerPriority(times) @@ -367,15 +367,15 @@ func newValidator(address []byte, power int64) *Validator { func randPubKey() crypto.PubKey { pubKey := make(ed25519.PubKey, ed25519.PubKeySize) - copy(pubKey, tmrand.Bytes(32)) - return ed25519.PubKey(tmrand.Bytes(32)) + copy(pubKey, cmtrand.Bytes(32)) + return ed25519.PubKey(cmtrand.Bytes(32)) } func randValidator(totalVotingPower int64) *Validator { // this modulo limits the ProposerPriority/VotingPower to stay in the // bounds of MaxTotalVotingPower minus the already existing voting power: - val := NewValidator(randPubKey(), int64(tmrand.Uint64()%uint64(MaxTotalVotingPower-totalVotingPower))) - val.ProposerPriority = tmrand.Int64() % (MaxTotalVotingPower - totalVotingPower) + val := NewValidator(randPubKey(), int64(cmtrand.Uint64()%uint64(MaxTotalVotingPower-totalVotingPower))) + val.ProposerPriority = cmtrand.Int64() % (MaxTotalVotingPower - totalVotingPower) return val } @@ -404,7 +404,7 @@ func (vals *ValidatorSet) toBytes() []byte { } func (vals *ValidatorSet) fromBytes(b []byte) *ValidatorSet { - pbvs := new(tmproto.ValidatorSet) + pbvs := new(cmtproto.ValidatorSet) err := pbvs.Unmarshal(b) if err != nil { // DATA HAS BEEN CORRUPTED OR THE SPEC HAS CHANGED @@ -733,7 +733,7 @@ func permutation(valList []testVal) []testVal { return nil } permList := make([]testVal, len(valList)) - perm := tmrand.Perm(len(valList)) + perm := cmtrand.Perm(len(valList)) for i, v := range perm { permList[v] = valList[i] } @@ -1037,7 +1037,7 @@ func TestValSetUpdatesOrderIndependenceTestsExecute(t *testing.T) { // perform at most 20 permutations on the updates and call UpdateWithChangeSet() n := len(tt.updateVals) - maxNumPerms := tmmath.MinInt(20, n*n) + maxNumPerms := cmtmath.MinInt(20, n*n) for j := 0; j < maxNumPerms; j++ { // create a copy of original set and apply a random permutation of updates valSetCopy := valSet.Copy() @@ -1135,14 +1135,14 @@ func randTestVSetCfg(t *testing.T, nBase, nAddMax int) testVSetCfg { const maxPower = 1000 var nOld, nDel, nChanged, nAdd int - nOld = int(tmrand.Uint()%uint(nBase)) + 1 + nOld = int(cmtrand.Uint()%uint(nBase)) + 1 if nBase-nOld > 0 { - nDel = int(tmrand.Uint() % uint(nBase-nOld)) + nDel = int(cmtrand.Uint() % uint(nBase-nOld)) } nChanged = nBase - nOld - nDel if nAddMax > 0 { - nAdd = tmrand.Int()%nAddMax + 1 + nAdd = cmtrand.Int()%nAddMax + 1 } cfg := testVSetCfg{} @@ -1154,12 +1154,12 @@ func randTestVSetCfg(t *testing.T, nBase, nAddMax int) testVSetCfg { cfg.expectedVals = make([]testVal, nBase-nDel+nAdd) for i := 0; i < nBase; i++ { - cfg.startVals[i] = testVal{fmt.Sprintf("v%d", i), int64(tmrand.Uint()%maxPower + 1)} + cfg.startVals[i] = testVal{fmt.Sprintf("v%d", i), int64(cmtrand.Uint()%maxPower + 1)} if i < nOld { cfg.expectedVals[i] = cfg.startVals[i] } if i >= nOld && i < nOld+nChanged { - cfg.updatedVals[i-nOld] = testVal{fmt.Sprintf("v%d", i), int64(tmrand.Uint()%maxPower + 1)} + cfg.updatedVals[i-nOld] = testVal{fmt.Sprintf("v%d", i), int64(cmtrand.Uint()%maxPower + 1)} cfg.expectedVals[i] = cfg.updatedVals[i-nOld] } if i >= nOld+nChanged { @@ -1168,7 +1168,7 @@ func randTestVSetCfg(t *testing.T, nBase, nAddMax int) testVSetCfg { } for i := nBase; i < nBase+nAdd; i++ { - cfg.addedVals[i-nBase] = testVal{fmt.Sprintf("v%d", i), int64(tmrand.Uint()%maxPower + 1)} + cfg.addedVals[i-nBase] = testVal{fmt.Sprintf("v%d", i), int64(cmtrand.Uint()%maxPower + 1)} cfg.expectedVals[i-nDel] = cfg.addedVals[i-nBase] } @@ -1249,7 +1249,7 @@ func TestValSetUpdatePriorityOrderTests(t *testing.T) { func verifyValSetUpdatePriorityOrder(t *testing.T, valSet *ValidatorSet, cfg testVSetCfg, nMaxElections int32) { // Run election up to nMaxElections times, sort validators by priorities - valSet.IncrementProposerPriority(tmrand.Int31()%nMaxElections + 1) + valSet.IncrementProposerPriority(cmtrand.Int31()%nMaxElections + 1) // apply the changes, get the updated validators, sort by priorities applyChangesToValSet(t, nil, valSet, cfg.addedVals, cfg.updatedVals, cfg.deletedVals) diff --git a/types/vote.go b/types/vote.go index 02b3cad3dad..af4e338a2a9 100644 --- a/types/vote.go +++ b/types/vote.go @@ -7,9 +7,9 @@ import ( "time" "github.com/tendermint/tendermint/crypto" - tmbytes "github.com/tendermint/tendermint/libs/bytes" + cmtbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/protoio" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) const ( @@ -48,14 +48,14 @@ type Address = crypto.Address // Vote represents a prevote, precommit, or commit vote from validators for // consensus. type Vote struct { - Type tmproto.SignedMsgType `json:"type"` - Height int64 `json:"height"` - Round int32 `json:"round"` // assume there will not be greater than 2_147_483_647 rounds - BlockID BlockID `json:"block_id"` // zero if vote is nil. - Timestamp time.Time `json:"timestamp"` - ValidatorAddress Address `json:"validator_address"` - ValidatorIndex int32 `json:"validator_index"` - Signature []byte `json:"signature"` + Type cmtproto.SignedMsgType `json:"type"` + Height int64 `json:"height"` + Round int32 `json:"round"` // assume there will not be greater than 2_147_483_647 rounds + BlockID BlockID `json:"block_id"` // zero if vote is nil. + Timestamp time.Time `json:"timestamp"` + ValidatorAddress Address `json:"validator_address"` + ValidatorIndex int32 `json:"validator_index"` + Signature []byte `json:"signature"` } // CommitSig converts the Vote to a CommitSig. @@ -90,7 +90,7 @@ func (vote *Vote) CommitSig() CommitSig { // devices that rely on this encoding. // // See CanonicalizeVote -func VoteSignBytes(chainID string, vote *tmproto.Vote) []byte { +func VoteSignBytes(chainID string, vote *cmtproto.Vote) []byte { pb := CanonicalizeVote(chainID, vote) bz, err := protoio.MarshalDelimited(&pb) if err != nil { @@ -123,9 +123,9 @@ func (vote *Vote) String() string { var typeString string switch vote.Type { - case tmproto.PrevoteType: + case cmtproto.PrevoteType: typeString = "Prevote" - case tmproto.PrecommitType: + case cmtproto.PrecommitType: typeString = "Precommit" default: panic("Unknown vote type") @@ -133,13 +133,13 @@ func (vote *Vote) String() string { return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}", vote.ValidatorIndex, - tmbytes.Fingerprint(vote.ValidatorAddress), + cmtbytes.Fingerprint(vote.ValidatorAddress), vote.Height, vote.Round, vote.Type, typeString, - tmbytes.Fingerprint(vote.BlockID.Hash), - tmbytes.Fingerprint(vote.Signature), + cmtbytes.Fingerprint(vote.BlockID.Hash), + cmtbytes.Fingerprint(vote.Signature), CanonicalTime(vote.Timestamp), ) } @@ -203,12 +203,12 @@ func (vote *Vote) ValidateBasic() error { // ToProto converts the handwritten type to proto generated type // return type, nil if everything converts safely, otherwise nil, error -func (vote *Vote) ToProto() *tmproto.Vote { +func (vote *Vote) ToProto() *cmtproto.Vote { if vote == nil { return nil } - return &tmproto.Vote{ + return &cmtproto.Vote{ Type: vote.Type, Height: vote.Height, Round: vote.Round, @@ -220,12 +220,12 @@ func (vote *Vote) ToProto() *tmproto.Vote { } } -func VotesToProto(votes []*Vote) []*tmproto.Vote { +func VotesToProto(votes []*Vote) []*cmtproto.Vote { if votes == nil { return nil } - res := make([]*tmproto.Vote, 0, len(votes)) + res := make([]*cmtproto.Vote, 0, len(votes)) for _, vote := range votes { v := vote.ToProto() // protobuf crashes when serializing "repeated" fields with nil elements @@ -238,7 +238,7 @@ func VotesToProto(votes []*Vote) []*tmproto.Vote { // FromProto converts a proto generetad type to a handwritten type // return type, nil if everything converts safely, otherwise nil, error -func VoteFromProto(pv *tmproto.Vote) (*Vote, error) { +func VoteFromProto(pv *cmtproto.Vote) (*Vote, error) { if pv == nil { return nil, errors.New("nil vote") } diff --git a/types/vote_set.go b/types/vote_set.go index 2fec823488b..e48facaa96f 100644 --- a/types/vote_set.go +++ b/types/vote_set.go @@ -6,9 +6,9 @@ import ( "strings" "github.com/tendermint/tendermint/libs/bits" - tmjson "github.com/tendermint/tendermint/libs/json" - tmsync "github.com/tendermint/tendermint/libs/sync" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtjson "github.com/tendermint/tendermint/libs/json" + cmtsync "github.com/tendermint/tendermint/libs/sync" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) const ( @@ -62,10 +62,10 @@ type VoteSet struct { chainID string height int64 round int32 - signedMsgType tmproto.SignedMsgType + signedMsgType cmtproto.SignedMsgType valSet *ValidatorSet - mtx tmsync.Mutex + mtx cmtsync.Mutex votesBitArray *bits.BitArray votes []*Vote // Primary votes to share sum int64 // Sum of voting power for seen votes, discounting conflicts @@ -76,7 +76,7 @@ type VoteSet struct { // Constructs a new VoteSet struct used to accumulate votes for given height/round. func NewVoteSet(chainID string, height int64, round int32, - signedMsgType tmproto.SignedMsgType, valSet *ValidatorSet) *VoteSet { + signedMsgType cmtproto.SignedMsgType, valSet *ValidatorSet) *VoteSet { if height == 0 { panic("Cannot make VoteSet for height == 0, doesn't make sense.") } @@ -425,7 +425,7 @@ func (voteSet *VoteSet) IsCommit() bool { if voteSet == nil { return false } - if voteSet.signedMsgType != tmproto.PrecommitType { + if voteSet.signedMsgType != cmtproto.PrecommitType { return false } voteSet.mtx.Lock() @@ -518,7 +518,7 @@ func (voteSet *VoteSet) StringIndented(indent string) string { func (voteSet *VoteSet) MarshalJSON() ([]byte, error) { voteSet.mtx.Lock() defer voteSet.mtx.Unlock() - return tmjson.Marshal(VoteSetJSON{ + return cmtjson.Marshal(VoteSetJSON{ voteSet.voteStrings(), voteSet.bitArrayString(), voteSet.peerMaj23s, @@ -617,7 +617,7 @@ func (voteSet *VoteSet) sumTotalFrac() (int64, int64, float64) { // Panics if the vote type is not PrecommitType or if there's no +2/3 votes for // a single block. func (voteSet *VoteSet) MakeCommit() *Commit { - if voteSet.signedMsgType != tmproto.PrecommitType { + if voteSet.signedMsgType != cmtproto.PrecommitType { panic("Cannot MakeCommit() unless VoteSet.Type is PrecommitType") } voteSet.mtx.Lock() diff --git a/types/vote_set_test.go b/types/vote_set_test.go index 4899b04b263..d2a115903c5 100644 --- a/types/vote_set_test.go +++ b/types/vote_set_test.go @@ -8,14 +8,14 @@ import ( "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/crypto" - tmrand "github.com/tendermint/tendermint/libs/rand" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - tmtime "github.com/tendermint/tendermint/types/time" + cmtrand "github.com/tendermint/tendermint/libs/rand" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmttime "github.com/tendermint/tendermint/types/time" ) func TestVoteSet_AddVote_Good(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrevoteType, 10, 1) val0 := privValidators[0] val0p, err := val0.GetPubKey() @@ -32,8 +32,8 @@ func TestVoteSet_AddVote_Good(t *testing.T) { ValidatorIndex: 0, // since privValidators are in order Height: height, Round: round, - Type: tmproto.PrevoteType, - Timestamp: tmtime.Now(), + Type: cmtproto.PrevoteType, + Timestamp: cmttime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, } _, err = signAddVote(val0, vote, voteSet) @@ -47,15 +47,15 @@ func TestVoteSet_AddVote_Good(t *testing.T) { func TestVoteSet_AddVote_Bad(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrevoteType, 10, 1) voteProto := &Vote{ ValidatorAddress: nil, ValidatorIndex: -1, Height: height, Round: round, - Timestamp: tmtime.Now(), - Type: tmproto.PrevoteType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, } @@ -77,7 +77,7 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { require.NoError(t, err) addr := pubKey.Address() vote := withValidator(voteProto, addr, 0) - added, err := signAddVote(privValidators[0], withBlockHash(vote, tmrand.Bytes(32)), voteSet) + added, err := signAddVote(privValidators[0], withBlockHash(vote, cmtrand.Bytes(32)), voteSet) if added || err == nil { t.Errorf("expected VoteSet.Add to fail, conflicting vote.") } @@ -113,7 +113,7 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { require.NoError(t, err) addr := pubKey.Address() vote := withValidator(voteProto, addr, 3) - added, err := signAddVote(privValidators[3], withType(vote, byte(tmproto.PrecommitType)), voteSet) + added, err := signAddVote(privValidators[3], withType(vote, byte(cmtproto.PrecommitType)), voteSet) if added || err == nil { t.Errorf("expected VoteSet.Add to fail, wrong type") } @@ -122,15 +122,15 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { func TestVoteSet_2_3Majority(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrevoteType, 10, 1) voteProto := &Vote{ ValidatorAddress: nil, // NOTE: must fill in ValidatorIndex: -1, // NOTE: must fill in Height: height, Round: round, - Type: tmproto.PrevoteType, - Timestamp: tmtime.Now(), + Type: cmtproto.PrevoteType, + Timestamp: cmttime.Now(), BlockID: BlockID{nil, PartSetHeader{}}, } // 6 out of 10 voted for nil. @@ -151,7 +151,7 @@ func TestVoteSet_2_3Majority(t *testing.T) { require.NoError(t, err) addr := pubKey.Address() vote := withValidator(voteProto, addr, 6) - _, err = signAddVote(privValidators[6], withBlockHash(vote, tmrand.Bytes(32)), voteSet) + _, err = signAddVote(privValidators[6], withBlockHash(vote, cmtrand.Bytes(32)), voteSet) require.NoError(t, err) blockID, ok = voteSet.TwoThirdsMajority() assert.False(t, ok || !blockID.IsZero(), "there should be no 2/3 majority") @@ -172,7 +172,7 @@ func TestVoteSet_2_3Majority(t *testing.T) { func TestVoteSet_2_3MajorityRedux(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 100, 1) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrevoteType, 100, 1) blockHash := crypto.CRandBytes(32) blockPartsTotal := uint32(123) @@ -183,8 +183,8 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { ValidatorIndex: -1, // NOTE: must fill in Height: height, Round: round, - Timestamp: tmtime.Now(), - Type: tmproto.PrevoteType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrevoteType, BlockID: BlockID{blockHash, blockPartSetHeader}, } @@ -248,7 +248,7 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { require.NoError(t, err) addr := pubKey.Address() vote := withValidator(voteProto, addr, 69) - _, err = signAddVote(privValidators[69], withBlockHash(vote, tmrand.Bytes(32)), voteSet) + _, err = signAddVote(privValidators[69], withBlockHash(vote, cmtrand.Bytes(32)), voteSet) require.NoError(t, err) blockID, ok = voteSet.TwoThirdsMajority() assert.False(t, ok || !blockID.IsZero(), @@ -271,17 +271,17 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { func TestVoteSet_Conflicts(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 4, 1) - blockHash1 := tmrand.Bytes(32) - blockHash2 := tmrand.Bytes(32) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrevoteType, 4, 1) + blockHash1 := cmtrand.Bytes(32) + blockHash2 := cmtrand.Bytes(32) voteProto := &Vote{ ValidatorAddress: nil, ValidatorIndex: -1, Height: height, Round: round, - Timestamp: tmtime.Now(), - Type: tmproto.PrevoteType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrevoteType, BlockID: BlockID{nil, PartSetHeader{}}, } @@ -400,7 +400,7 @@ func TestVoteSet_Conflicts(t *testing.T) { func TestVoteSet_MakeCommit(t *testing.T) { height, round := int64(1), int32(0) - voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrecommitType, 10, 1) + voteSet, _, privValidators := randVoteSet(height, round, cmtproto.PrecommitType, 10, 1) blockHash, blockPartSetHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)} voteProto := &Vote{ @@ -408,8 +408,8 @@ func TestVoteSet_MakeCommit(t *testing.T) { ValidatorIndex: -1, Height: height, Round: round, - Timestamp: tmtime.Now(), - Type: tmproto.PrecommitType, + Timestamp: cmttime.Now(), + Type: cmtproto.PrecommitType, BlockID: BlockID{blockHash, blockPartSetHeader}, } @@ -434,8 +434,8 @@ func TestVoteSet_MakeCommit(t *testing.T) { assert.NoError(t, err) addr := pv.Address() vote := withValidator(voteProto, addr, 6) - vote = withBlockHash(vote, tmrand.Bytes(32)) - vote = withBlockPartSetHeader(vote, PartSetHeader{123, tmrand.Bytes(32)}) + vote = withBlockHash(vote, cmtrand.Bytes(32)) + vote = withBlockPartSetHeader(vote, PartSetHeader{123, cmtrand.Bytes(32)}) _, err = signAddVote(privValidators[6], vote, voteSet) require.NoError(t, err) @@ -478,7 +478,7 @@ func TestVoteSet_MakeCommit(t *testing.T) { func randVoteSet( height int64, round int32, - signedMsgType tmproto.SignedMsgType, + signedMsgType cmtproto.SignedMsgType, numValidators int, votingPower int64, ) (*VoteSet, *ValidatorSet, []PrivValidator) { @@ -511,7 +511,7 @@ func withRound(vote *Vote, round int32) *Vote { // Convenience: Return new vote with different type func withType(vote *Vote, signedMsgType byte) *Vote { vote = vote.Copy() - vote.Type = tmproto.SignedMsgType(signedMsgType) + vote.Type = cmtproto.SignedMsgType(signedMsgType) return vote } diff --git a/types/vote_test.go b/types/vote_test.go index 927b9abc57a..46dfa0f26c4 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -12,15 +12,15 @@ import ( "github.com/tendermint/tendermint/crypto/ed25519" "github.com/tendermint/tendermint/crypto/tmhash" "github.com/tendermint/tendermint/libs/protoio" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + cmtproto "github.com/tendermint/tendermint/proto/tendermint/types" ) func examplePrevote() *Vote { - return exampleVote(byte(tmproto.PrevoteType)) + return exampleVote(byte(cmtproto.PrevoteType)) } func examplePrecommit() *Vote { - return exampleVote(byte(tmproto.PrecommitType)) + return exampleVote(byte(cmtproto.PrecommitType)) } func exampleVote(t byte) *Vote { @@ -30,7 +30,7 @@ func exampleVote(t byte) *Vote { } return &Vote{ - Type: tmproto.SignedMsgType(t), + Type: cmtproto.SignedMsgType(t), Height: 12345, Round: 2, Timestamp: stamp, @@ -71,7 +71,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // with proper (fixed size) height and round (PreCommit): 1: { - "", &Vote{Height: 1, Round: 1, Type: tmproto.PrecommitType}, + "", &Vote{Height: 1, Round: 1, Type: cmtproto.PrecommitType}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -86,7 +86,7 @@ func TestVoteSignBytesTestVectors(t *testing.T) { }, // with proper (fixed size) height and round (PreVote): 2: { - "", &Vote{Height: 1, Round: 1, Type: tmproto.PrevoteType}, + "", &Vote{Height: 1, Round: 1, Type: cmtproto.PrevoteType}, []byte{ 0x21, // length 0x8, // (field_number << 3) | wire_type @@ -137,8 +137,8 @@ func TestVoteSignBytesTestVectors(t *testing.T) { } func TestVoteProposalNotEq(t *testing.T) { - cv := CanonicalizeVote("", &tmproto.Vote{Height: 1, Round: 1}) - p := CanonicalizeProposal("", &tmproto.Proposal{Height: 1, Round: 1}) + cv := CanonicalizeVote("", &cmtproto.Vote{Height: 1, Round: 1}) + p := CanonicalizeProposal("", &cmtproto.Proposal{Height: 1, Round: 1}) vb, err := proto.Marshal(&cv) require.NoError(t, err) pb, err := proto.Marshal(&p) @@ -164,7 +164,7 @@ func TestVoteVerifySignature(t *testing.T) { require.True(t, valid) // serialize, deserialize and verify again.... - precommit := new(tmproto.Vote) + precommit := new(cmtproto.Vote) bs, err := proto.Marshal(v) require.NoError(t, err) err = proto.Unmarshal(bs, precommit) @@ -180,12 +180,12 @@ func TestVoteVerifySignature(t *testing.T) { func TestIsVoteTypeValid(t *testing.T) { tc := []struct { name string - in tmproto.SignedMsgType + in cmtproto.SignedMsgType out bool }{ - {"Prevote", tmproto.PrevoteType, true}, - {"Precommit", tmproto.PrecommitType, true}, - {"InvalidType", tmproto.SignedMsgType(0x3), false}, + {"Prevote", cmtproto.PrevoteType, true}, + {"Precommit", cmtproto.PrecommitType, true}, + {"InvalidType", cmtproto.SignedMsgType(0x3), false}, } for _, tt := range tc {