From 89f0bbbd76622bda14fc475bef0f83128119f014 Mon Sep 17 00:00:00 2001 From: Marko Date: Wed, 11 Dec 2019 23:16:35 +0100 Subject: [PATCH] libs/common: Refactor libs/common 4 (#4237) * libs/common: Refactor libs/common 4 - move byte function out of cmn to its own pkg - move tempfile out of cmn to its own pkg - move throttletimer to its own pkg ref #4147 Signed-off-by: Marko Baricevic * add changelog entry * fix linting issues --- CHANGELOG_PENDING.md | 3 ++ abci/client/socket_client.go | 5 ++- cmd/tendermint/commands/testnet.go | 4 +- consensus/common_test.go | 3 +- consensus/reactor_test.go | 9 ++-- consensus/types/round_state.go | 8 ++-- crypto/crypto.go | 4 +- libs/.editorconfig | 19 -------- libs/.gitignore | 5 --- libs/README.md | 44 ------------------- libs/{common => bytes}/bytes.go | 2 +- libs/{common => bytes}/bytes_test.go | 2 +- libs/{common => bytes}/byteslice.go | 2 +- libs/{common => tempfile}/tempfile.go | 2 +- libs/{common => tempfile}/tempfile_test.go | 2 +- libs/test.sh | 15 ------- libs/{common => timer}/throttle_timer.go | 2 +- libs/{common => timer}/throttle_timer_test.go | 2 +- lite/proxy/proxy.go | 6 +-- lite/proxy/query.go | 4 +- lite/proxy/wrapper.go | 7 ++- lite2/proxy/routes.go | 6 +-- lite2/rpc/client.go | 6 +-- p2p/conn/connection.go | 7 +-- p2p/node_info.go | 7 +-- p2p/peer_test.go | 4 +- p2p/pex/file.go | 4 +- privval/file.go | 16 ++++--- privval/file_deprecated.go | 4 +- rpc/client/httpclient.go | 6 +-- rpc/client/interface.go | 6 +-- rpc/client/localclient.go | 6 +-- rpc/client/mock/abci.go | 16 +++---- rpc/client/mock/abci_test.go | 10 ++--- rpc/client/mock/client.go | 6 +-- rpc/client/mock/status_test.go | 6 +-- rpc/core/abci.go | 4 +- rpc/core/status.go | 6 +-- rpc/core/types/responses.go | 30 ++++++------- rpc/lib/rpc_test.go | 10 ++--- rpc/lib/server/parse_test.go | 20 ++++----- types/block.go | 43 +++++++++--------- types/block_test.go | 17 +++---- types/canonical.go | 6 +-- types/genesis.go | 3 +- types/part_set.go | 11 ++--- types/proposal.go | 4 +- types/results.go | 6 +-- types/tx.go | 4 +- types/vote.go | 8 ++-- 50 files changed, 181 insertions(+), 251 deletions(-) delete mode 100644 libs/.editorconfig delete mode 100644 libs/.gitignore delete mode 100644 libs/README.md rename libs/{common => bytes}/bytes.go (98%) rename libs/{common => bytes}/bytes_test.go (98%) rename libs/{common => bytes}/byteslice.go (94%) rename libs/{common => tempfile}/tempfile.go (99%) rename libs/{common => tempfile}/tempfile_test.go (99%) delete mode 100755 libs/test.sh rename libs/{common => timer}/throttle_timer.go (98%) rename libs/{common => timer}/throttle_timer_test.go (98%) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 5be7db7f7..84254d818 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -74,6 +74,9 @@ program](https://hackerone.com/tendermint). - [libs/common] \#4232 Move `Service` & `BaseService` from `libs/common` to `libs/service` - [libs/common] \#4232 Move `common/nil.go` to `types/utils.go` & make the functions private - [libs/common] \#4231 Move random functions from `libs/common` into pkg `rand` + - [libs/common] \#4237 Move byte functions from `libs/common` into pkg `bytes` + - [libs/common] \#4237 Move throttletimer functions from `libs/common` into pkg `timer` + - [libs/common] \#4237 Move tempfile functions from `libs/common` into pkg `tempfile` - Blockchain Protocol diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go index 98ddbb610..a3d07ff0a 100644 --- a/abci/client/socket_client.go +++ b/abci/client/socket_client.go @@ -14,6 +14,7 @@ import ( "github.com/tendermint/tendermint/abci/types" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/service" + "github.com/tendermint/tendermint/libs/timer" ) const reqQueueSize = 256 // TODO make configurable @@ -33,7 +34,7 @@ type socketClient struct { conn net.Conn reqQueue chan *ReqRes - flushTimer *cmn.ThrottleTimer + flushTimer *timer.ThrottleTimer mtx sync.Mutex err error @@ -45,7 +46,7 @@ type socketClient struct { func NewSocketClient(addr string, mustConnect bool) *socketClient { cli := &socketClient{ reqQueue: make(chan *ReqRes, reqQueueSize), - flushTimer: cmn.NewThrottleTimer("socketClient", flushThrottleMS), + flushTimer: timer.NewThrottleTimer("socketClient", flushThrottleMS), mustConnect: mustConnect, addr: addr, diff --git a/cmd/tendermint/commands/testnet.go b/cmd/tendermint/commands/testnet.go index c85d635fd..7782dbf1c 100644 --- a/cmd/tendermint/commands/testnet.go +++ b/cmd/tendermint/commands/testnet.go @@ -11,7 +11,7 @@ import ( "github.com/spf13/viper" cfg "github.com/tendermint/tendermint/config" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/rand" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/privval" @@ -262,5 +262,5 @@ func moniker(i int) string { } func randomMoniker() string { - return cmn.HexBytes(rand.RandBytes(8)).String() + return bytes.HexBytes(rand.RandBytes(8)).String() } diff --git a/consensus/common_test.go b/consensus/common_test.go index f73f7023a..9f5cac40b 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -22,6 +22,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" + tmbytes "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" @@ -518,7 +519,7 @@ func ensureNewBlock(blockCh <-chan tmpubsub.Message, height int64) { } } -func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash cmn.HexBytes) { +func ensureNewBlockHeader(blockCh <-chan tmpubsub.Message, height int64, blockHash tmbytes.HexBytes) { select { case <-time.After(ensureTimeout): panic("Timeout expired while waiting for NewBlockHeader event") diff --git a/consensus/reactor_test.go b/consensus/reactor_test.go index fe0db1402..c0e05ee5f 100644 --- a/consensus/reactor_test.go +++ b/consensus/reactor_test.go @@ -20,6 +20,7 @@ import ( cfg "github.com/tendermint/tendermint/config" cstypes "github.com/tendermint/tendermint/consensus/types" "github.com/tendermint/tendermint/crypto/tmhash" + "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/libs/log" mempl "github.com/tendermint/tendermint/mempool" @@ -850,10 +851,10 @@ func TestVoteSetMaj23MessageValidateBasic(t *testing.T) { validBlockID := types.BlockID{} invalidBlockID := types.BlockID{ - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, PartsHeader: types.PartSetHeader{ Total: -1, - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, }, } @@ -898,10 +899,10 @@ func TestVoteSetBitsMessageValidateBasic(t *testing.T) { {func(msg *VoteSetBitsMessage) { msg.Type = 0x03 }, "invalid Type"}, {func(msg *VoteSetBitsMessage) { msg.BlockID = types.BlockID{ - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, PartsHeader: types.PartSetHeader{ Total: -1, - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, }, } }, "wrong BlockID: wrong PartsHeader: negative Total"}, diff --git a/consensus/types/round_state.go b/consensus/types/round_state.go index abb085669..490110357 100644 --- a/consensus/types/round_state.go +++ b/consensus/types/round_state.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/types" ) @@ -97,9 +97,9 @@ type RoundState struct { type RoundStateSimple struct { HeightRoundStep string `json:"height/round/step"` StartTime time.Time `json:"start_time"` - ProposalBlockHash cmn.HexBytes `json:"proposal_block_hash"` - LockedBlockHash cmn.HexBytes `json:"locked_block_hash"` - ValidBlockHash cmn.HexBytes `json:"valid_block_hash"` + ProposalBlockHash bytes.HexBytes `json:"proposal_block_hash"` + LockedBlockHash bytes.HexBytes `json:"locked_block_hash"` + ValidBlockHash bytes.HexBytes `json:"valid_block_hash"` Votes json.RawMessage `json:"height_vote_set"` } diff --git a/crypto/crypto.go b/crypto/crypto.go index b3526f881..045a35e86 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -2,7 +2,7 @@ package crypto import ( "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" ) const ( @@ -13,7 +13,7 @@ const ( // An address is a []byte, but hex-encoded even in JSON. // []byte leaves us the option to change the address length. // Use an alias so Unmarshal methods (with ptr receivers) are available too. -type Address = cmn.HexBytes +type Address = bytes.HexBytes func AddressHash(bz []byte) Address { return Address(tmhash.SumTruncated(bz)) diff --git a/libs/.editorconfig b/libs/.editorconfig deleted file mode 100644 index 82f774362..000000000 --- a/libs/.editorconfig +++ /dev/null @@ -1,19 +0,0 @@ -# top-most EditorConfig file -root = true - -# Unix-style newlines with a newline ending every file -[*] -charset = utf-8 -end_of_line = lf -insert_final_newline = true -trim_trailing_whitespace = true - -[Makefile] -indent_style = tab - -[*.sh] -indent_style = tab - -[*.proto] -indent_style = space -indent_size = 2 diff --git a/libs/.gitignore b/libs/.gitignore deleted file mode 100644 index a2ebfde29..000000000 --- a/libs/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -*.sw[opqr] -vendor -.glide - -pubsub/query/fuzz_test/output diff --git a/libs/README.md b/libs/README.md deleted file mode 100644 index 595568120..000000000 --- a/libs/README.md +++ /dev/null @@ -1,44 +0,0 @@ -# TMLIBS - -This repo is a home for various small packages. - -## autofile - -Autofile is file access with automatic log rotation. A group of files is maintained and rotation happens -when the leading file gets too big. Provides a reader for reading from the file group. - -## cli - -CLI wraps the `cobra` and `viper` packages and handles some common elements of building a CLI like flags and env vars for the home directory and the logger. - -## clist - -Clist provides a linked list that is safe for concurrent access by many readers. - -## common - -Common provides a hodgepodge of useful functions. - -## events - -Events is a synchronous PubSub package. - -## flowrate - -Flowrate is a fork of https://github.com/mxk/go-flowrate that added a `SetREMA` method. - -## log - -Log is a log package structured around key-value pairs that allows logging level to be set differently for different keys. - -## merkle - -Merkle provides a simple static merkle tree and corresponding proofs. - -## process - -Process is a simple utility for spawning OS processes. - -## pubsub - -PubSub is an asynchronous PubSub package. diff --git a/libs/common/bytes.go b/libs/bytes/bytes.go similarity index 98% rename from libs/common/bytes.go rename to libs/bytes/bytes.go index 3c1c77589..d7682437b 100644 --- a/libs/common/bytes.go +++ b/libs/bytes/bytes.go @@ -1,4 +1,4 @@ -package common +package bytes import ( "encoding/hex" diff --git a/libs/common/bytes_test.go b/libs/bytes/bytes_test.go similarity index 98% rename from libs/common/bytes_test.go rename to libs/bytes/bytes_test.go index 49c8cacb9..6205beec2 100644 --- a/libs/common/bytes_test.go +++ b/libs/bytes/bytes_test.go @@ -1,4 +1,4 @@ -package common +package bytes import ( "encoding/json" diff --git a/libs/common/byteslice.go b/libs/bytes/byteslice.go similarity index 94% rename from libs/common/byteslice.go rename to libs/bytes/byteslice.go index af2d7949d..1d535eb4a 100644 --- a/libs/common/byteslice.go +++ b/libs/bytes/byteslice.go @@ -1,4 +1,4 @@ -package common +package bytes // Fingerprint returns the first 6 bytes of a byte slice. // If the slice is less than 6 bytes, the fingerprint diff --git a/libs/common/tempfile.go b/libs/tempfile/tempfile.go similarity index 99% rename from libs/common/tempfile.go rename to libs/tempfile/tempfile.go index c0bcfe3a3..38d987698 100644 --- a/libs/common/tempfile.go +++ b/libs/tempfile/tempfile.go @@ -1,4 +1,4 @@ -package common +package tempfile import ( fmt "fmt" diff --git a/libs/common/tempfile_test.go b/libs/tempfile/tempfile_test.go similarity index 99% rename from libs/common/tempfile_test.go rename to libs/tempfile/tempfile_test.go index 1a799c422..d3d762674 100644 --- a/libs/common/tempfile_test.go +++ b/libs/tempfile/tempfile_test.go @@ -1,4 +1,4 @@ -package common +package tempfile // Need access to internal variables, so can't use _test package diff --git a/libs/test.sh b/libs/test.sh deleted file mode 100755 index d0618768b..000000000 --- a/libs/test.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env bash -set -e - -# run the linter -# make lint - -# run the unit tests with coverage -echo "" > coverage.txt -for d in $(go list ./... | grep -v vendor); do - go test -race -coverprofile=profile.out -covermode=atomic "$d" - if [ -f profile.out ]; then - cat profile.out >> coverage.txt - rm profile.out - fi -done diff --git a/libs/common/throttle_timer.go b/libs/timer/throttle_timer.go similarity index 98% rename from libs/common/throttle_timer.go rename to libs/timer/throttle_timer.go index 38ef4e9a3..76db87ee8 100644 --- a/libs/common/throttle_timer.go +++ b/libs/timer/throttle_timer.go @@ -1,4 +1,4 @@ -package common +package timer import ( "sync" diff --git a/libs/common/throttle_timer_test.go b/libs/timer/throttle_timer_test.go similarity index 98% rename from libs/common/throttle_timer_test.go rename to libs/timer/throttle_timer_test.go index f5c9dfeff..894447974 100644 --- a/libs/common/throttle_timer_test.go +++ b/libs/timer/throttle_timer_test.go @@ -1,4 +1,4 @@ -package common +package timer import ( "sync" diff --git a/lite/proxy/proxy.go b/lite/proxy/proxy.go index dbe897464..5fb51f0b3 100644 --- a/lite/proxy/proxy.go +++ b/lite/proxy/proxy.go @@ -6,7 +6,7 @@ import ( amino "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/rpc/client" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -168,9 +168,9 @@ func makeBroadcastTxAsyncFunc(c rpcclient.Client) func( func makeABCIQueryFunc(c rpcclient.Client) func( ctx *rpctypes.Context, path string, - data cmn.HexBytes, + data bytes.HexBytes, ) (*ctypes.ResultABCIQuery, error) { - return func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { + return func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQuery(path, data) } } diff --git a/lite/proxy/query.go b/lite/proxy/query.go index 054ae014c..f95b4708b 100644 --- a/lite/proxy/query.go +++ b/lite/proxy/query.go @@ -7,7 +7,7 @@ import ( "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto/merkle" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/lite" lerr "github.com/tendermint/tendermint/lite/errors" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -21,7 +21,7 @@ import ( // If there is any error in checking, returns an error. func GetWithProof(prt *merkle.ProofRuntime, key []byte, reqHeight int64, node rpcclient.Client, cert lite.Verifier) ( - val cmn.HexBytes, height int64, proof *merkle.Proof, err error) { + val bytes.HexBytes, height int64, proof *merkle.Proof, err error) { if reqHeight < 0 { err = errors.New("height cannot be negative") diff --git a/lite/proxy/wrapper.go b/lite/proxy/wrapper.go index d3a69cc3f..e823cc5f0 100644 --- a/lite/proxy/wrapper.go +++ b/lite/proxy/wrapper.go @@ -3,9 +3,8 @@ package proxy import ( "context" - cmn "github.com/tendermint/tendermint/libs/common" - "github.com/tendermint/tendermint/crypto/merkle" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/lite" rpcclient "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -39,7 +38,7 @@ func SecureClient(c rpcclient.Client, cert *lite.DynamicVerifier) Wrapper { } // ABCIQueryWithOptions exposes all options for the ABCI query and verifies the returned proof -func (w Wrapper) ABCIQueryWithOptions(path string, data cmn.HexBytes, +func (w Wrapper) ABCIQueryWithOptions(path string, data bytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { res, err := GetWithProofOptions(w.prt, path, data, opts, w.Client, w.cert) @@ -47,7 +46,7 @@ func (w Wrapper) ABCIQueryWithOptions(path string, data cmn.HexBytes, } // ABCIQuery uses default options for the ABCI query and verifies the returned proof -func (w Wrapper) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (w Wrapper) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return w.ABCIQueryWithOptions(path, data, rpcclient.DefaultABCIQueryOptions) } diff --git a/lite2/proxy/routes.go b/lite2/proxy/routes.go index e0d04de0b..110cfe88f 100644 --- a/lite2/proxy/routes.go +++ b/lite2/proxy/routes.go @@ -1,7 +1,7 @@ package proxy import ( - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" lrpc "github.com/tendermint/tendermint/lite2/rpc" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpcserver "github.com/tendermint/tendermint/rpc/lib/server" @@ -203,10 +203,10 @@ func makeBroadcastTxAsyncFunc(c *lrpc.Client) rpcBroadcastTxAsyncFunc { } } -type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) +type rpcABCIQueryFunc func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) func makeABCIQueryFunc(c *lrpc.Client) rpcABCIQueryFunc { - return func(ctx *rpctypes.Context, path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { + return func(ctx *rpctypes.Context, path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQuery(path, data) } } diff --git a/lite2/rpc/client.go b/lite2/rpc/client.go index 06aa57eea..fe940ea74 100644 --- a/lite2/rpc/client.go +++ b/lite2/rpc/client.go @@ -10,7 +10,7 @@ import ( "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto/merkle" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" service "github.com/tendermint/tendermint/libs/service" lite "github.com/tendermint/tendermint/lite2" rpcclient "github.com/tendermint/tendermint/rpc/client" @@ -63,13 +63,13 @@ func (c *Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return c.next.ABCIInfo() } -func (c *Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (c *Client) ABCIQuery(path string, data tmbytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQueryWithOptions(path, data, rpcclient.DefaultABCIQueryOptions) } // GetWithProofOptions is useful if you want full access to the ABCIQueryOptions. // XXX Usage of path? It's not used, and sometimes it's /, sometimes /key, sometimes /store. -func (c *Client) ABCIQueryWithOptions(path string, data cmn.HexBytes, +func (c *Client) ABCIQueryWithOptions(path string, data tmbytes.HexBytes, opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { res, err := c.next.ABCIQueryWithOptions(path, data, opts) diff --git a/p2p/conn/connection.go b/p2p/conn/connection.go index 6a5e9d110..f9c4ee1d6 100644 --- a/p2p/conn/connection.go +++ b/p2p/conn/connection.go @@ -20,6 +20,7 @@ import ( flow "github.com/tendermint/tendermint/libs/flowrate" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/service" + "github.com/tendermint/tendermint/libs/timer" ) const ( @@ -101,8 +102,8 @@ type MConnection struct { // are safe to call concurrently. stopMtx sync.Mutex - flushTimer *cmn.ThrottleTimer // flush writes as necessary but throttled. - pingTimer *time.Ticker // send pings periodically + flushTimer *timer.ThrottleTimer // flush writes as necessary but throttled. + pingTimer *time.Ticker // send pings periodically // close conn if pong is not received in pongTimeout pongTimer *time.Timer @@ -218,7 +219,7 @@ func (c *MConnection) OnStart() error { if err := c.BaseService.OnStart(); err != nil { return err } - c.flushTimer = cmn.NewThrottleTimer("flush", c.config.FlushThrottle) + c.flushTimer = timer.NewThrottleTimer("flush", c.config.FlushThrottle) c.pingTimer = time.NewTicker(c.config.PingInterval) c.pongTimeoutCh = make(chan bool, 1) c.chStatsTimer = time.NewTicker(updateStats) diff --git a/p2p/node_info.go b/p2p/node_info.go index c80344e4f..5b72446fd 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -4,6 +4,7 @@ import ( "fmt" "reflect" + "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/version" ) @@ -82,9 +83,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 cmn.HexBytes `json:"channels"` // channels this node knows about + Network string `json:"network"` // network/chain ID + Version string `json:"version"` // major.minor.revision + Channels bytes.HexBytes `json:"channels"` // channels this node knows about // ASCIIText fields Moniker string `json:"moniker"` // arbitrary moniker diff --git a/p2p/peer_test.go b/p2p/peer_test.go index 524470fab..508cef7fa 100644 --- a/p2p/peer_test.go +++ b/p2p/peer_test.go @@ -13,7 +13,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/config" @@ -140,7 +140,7 @@ type remotePeer struct { PrivKey crypto.PrivKey Config *config.P2PConfig addr *NetAddress - channels cmn.HexBytes + channels bytes.HexBytes listenAddr string listener net.Listener } diff --git a/p2p/pex/file.go b/p2p/pex/file.go index a42eddaf9..3579db893 100644 --- a/p2p/pex/file.go +++ b/p2p/pex/file.go @@ -5,7 +5,7 @@ import ( "fmt" "os" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/tempfile" ) /* Loading & Saving */ @@ -35,7 +35,7 @@ func (a *addrBook) saveToFile(filePath string) { a.Logger.Error("Failed to save AddrBook to file", "err", err) return } - err = cmn.WriteFileAtomic(filePath, jsonBytes, 0644) + err = tempfile.WriteFileAtomic(filePath, jsonBytes, 0644) if err != nil { a.Logger.Error("Failed to save AddrBook to file", "file", filePath, "err", err) } diff --git a/privval/file.go b/privval/file.go index 2fa9b81cd..d77ec269d 100644 --- a/privval/file.go +++ b/privval/file.go @@ -9,7 +9,9 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/ed25519" + tmbytes "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/tempfile" "github.com/tendermint/tendermint/types" tmtime "github.com/tendermint/tendermint/types/time" ) @@ -56,7 +58,7 @@ func (pvKey FilePVKey) Save() { if err != nil { panic(err) } - err = cmn.WriteFileAtomic(outFile, jsonBytes, 0600) + err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600) if err != nil { panic(err) } @@ -67,11 +69,11 @@ func (pvKey FilePVKey) Save() { // FilePVLastSignState stores the mutable part of PrivValidator. type FilePVLastSignState struct { - Height int64 `json:"height"` - Round int `json:"round"` - Step int8 `json:"step"` - Signature []byte `json:"signature,omitempty"` - SignBytes cmn.HexBytes `json:"signbytes,omitempty"` + Height int64 `json:"height"` + Round int `json:"round"` + Step int8 `json:"step"` + Signature []byte `json:"signature,omitempty"` + SignBytes tmbytes.HexBytes `json:"signbytes,omitempty"` filePath string } @@ -127,7 +129,7 @@ func (lss *FilePVLastSignState) Save() { if err != nil { panic(err) } - err = cmn.WriteFileAtomic(outFile, jsonBytes, 0600) + err = tempfile.WriteFileAtomic(outFile, jsonBytes, 0600) if err != nil { panic(err) } diff --git a/privval/file_deprecated.go b/privval/file_deprecated.go index d010de763..c30c273d7 100644 --- a/privval/file_deprecated.go +++ b/privval/file_deprecated.go @@ -5,7 +5,7 @@ import ( "os" "github.com/tendermint/tendermint/crypto" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/types" ) @@ -18,7 +18,7 @@ type OldFilePV struct { LastRound int `json:"last_round"` LastStep int8 `json:"last_step"` LastSignature []byte `json:"last_signature,omitempty"` - LastSignBytes cmn.HexBytes `json:"last_signbytes,omitempty"` + LastSignBytes bytes.HexBytes `json:"last_signbytes,omitempty"` PrivKey crypto.PrivKey `json:"priv_key"` filePath string diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index 528c90446..5b0703529 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -11,7 +11,7 @@ import ( amino "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" tmpubsub "github.com/tendermint/tendermint/libs/pubsub" "github.com/tendermint/tendermint/libs/service" @@ -172,13 +172,13 @@ func (c *baseRPCClient) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return result, nil } -func (c *baseRPCClient) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (c *baseRPCClient) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions) } func (c *baseRPCClient) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { result := new(ctypes.ResultABCIQuery) _, err := c.caller.Call("abci_query", diff --git a/rpc/client/interface.go b/rpc/client/interface.go index 3d9cdc9f6..72e899551 100644 --- a/rpc/client/interface.go +++ b/rpc/client/interface.go @@ -23,7 +23,7 @@ implementation. import ( "context" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/service" ctypes "github.com/tendermint/tendermint/rpc/core/types" "github.com/tendermint/tendermint/types" @@ -51,8 +51,8 @@ type Client interface { type ABCIClient interface { // Reading from abci app ABCIInfo() (*ctypes.ResultABCIInfo, error) - ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) - ABCIQueryWithOptions(path string, data cmn.HexBytes, + ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) + ABCIQueryWithOptions(path string, data bytes.HexBytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) // Writing to abci app diff --git a/rpc/client/localclient.go b/rpc/client/localclient.go index 0b5f171e2..95cc879b8 100644 --- a/rpc/client/localclient.go +++ b/rpc/client/localclient.go @@ -6,7 +6,7 @@ import ( "github.com/pkg/errors" - cmn "github.com/tendermint/tendermint/libs/common" + "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" @@ -73,13 +73,13 @@ func (c *Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return core.ABCIInfo(c.ctx) } -func (c *Local) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (c *Local) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions) } func (c *Local) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { return core.ABCIQuery(c.ctx, path, data, opts.Height, opts.Prove) } diff --git a/rpc/client/mock/abci.go b/rpc/client/mock/abci.go index 0b4b1c87e..d1f84f2b1 100644 --- a/rpc/client/mock/abci.go +++ b/rpc/client/mock/abci.go @@ -2,7 +2,7 @@ package mock import ( abci "github.com/tendermint/tendermint/abci/types" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/rpc/client" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -26,13 +26,13 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return &ctypes.ResultABCIInfo{Response: a.App.Info(proxy.RequestInfo)}, nil } -func (a ABCIApp) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (a ABCIApp) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return a.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions) } func (a ABCIApp) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { q := a.App.Query(abci.RequestQuery{ Data: data, @@ -93,13 +93,13 @@ func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return &ctypes.ResultABCIInfo{Response: res.(abci.ResponseInfo)}, nil } -func (m ABCIMock) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (m ABCIMock) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return m.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions) } func (m ABCIMock) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Prove}) if err != nil { @@ -149,7 +149,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder { type QueryArgs struct { Path string - Data cmn.HexBytes + Data bytes.HexBytes Height int64 Prove bool } @@ -168,13 +168,13 @@ func (r *ABCIRecorder) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return res, err } -func (r *ABCIRecorder) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (r *ABCIRecorder) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return r.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions) } func (r *ABCIRecorder) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { res, err := r.Client.ABCIQueryWithOptions(path, data, opts) r.addCall(Call{ diff --git a/rpc/client/mock/abci_test.go b/rpc/client/mock/abci_test.go index 485db88b5..1d923f996 100644 --- a/rpc/client/mock/abci_test.go +++ b/rpc/client/mock/abci_test.go @@ -11,7 +11,7 @@ import ( "github.com/tendermint/tendermint/abci/example/kvstore" abci "github.com/tendermint/tendermint/abci/types" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/client/mock" ctypes "github.com/tendermint/tendermint/rpc/core/types" @@ -37,8 +37,8 @@ func TestABCIMock(t *testing.T) { BroadcastCommit: mock.Call{ Args: goodTx, Response: &ctypes.ResultBroadcastTxCommit{ - CheckTx: abci.ResponseCheckTx{Data: cmn.HexBytes("stand")}, - DeliverTx: abci.ResponseDeliverTx{Data: cmn.HexBytes("deliver")}, + CheckTx: abci.ResponseCheckTx{Data: bytes.HexBytes("stand")}, + DeliverTx: abci.ResponseDeliverTx{Data: bytes.HexBytes("deliver")}, }, Error: errors.New("bad tx"), }, @@ -98,7 +98,7 @@ func TestABCIRecorder(t *testing.T) { _, err := r.ABCIInfo() assert.Nil(err, "expected no err on info") - _, err = r.ABCIQueryWithOptions("path", cmn.HexBytes("data"), client.ABCIQueryOptions{Prove: false}) + _, err = r.ABCIQueryWithOptions("path", bytes.HexBytes("data"), client.ABCIQueryOptions{Prove: false}) assert.NotNil(err, "expected error on query") require.Equal(2, len(r.Calls)) @@ -180,7 +180,7 @@ func TestABCIApp(t *testing.T) { } // check the key - _qres, err := m.ABCIQueryWithOptions("/key", cmn.HexBytes(key), client.ABCIQueryOptions{Prove: true}) + _qres, err := m.ABCIQueryWithOptions("/key", bytes.HexBytes(key), client.ABCIQueryOptions{Prove: true}) qres := _qres.Response require.Nil(err) assert.EqualValues(value, qres.Value) diff --git a/rpc/client/mock/client.go b/rpc/client/mock/client.go index 05379061e..869d7b3e9 100644 --- a/rpc/client/mock/client.go +++ b/rpc/client/mock/client.go @@ -17,7 +17,7 @@ want to directly call a tendermint node in process, you can use the import ( "reflect" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/service" "github.com/tendermint/tendermint/rpc/client" "github.com/tendermint/tendermint/rpc/core" @@ -87,13 +87,13 @@ func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return core.ABCIInfo(&rpctypes.Context{}) } -func (c Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) { +func (c Client) ABCIQuery(path string, data bytes.HexBytes) (*ctypes.ResultABCIQuery, error) { return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions) } func (c Client) ABCIQueryWithOptions( path string, - data cmn.HexBytes, + data bytes.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) { return core.ABCIQuery(&rpctypes.Context{}, path, data, opts.Height, opts.Prove) } diff --git a/rpc/client/mock/status_test.go b/rpc/client/mock/status_test.go index fa64c6a83..d252a54eb 100644 --- a/rpc/client/mock/status_test.go +++ b/rpc/client/mock/status_test.go @@ -6,7 +6,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/rpc/client/mock" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) @@ -18,8 +18,8 @@ func TestStatus(t *testing.T) { Call: mock.Call{ Response: &ctypes.ResultStatus{ SyncInfo: ctypes.SyncInfo{ - LatestBlockHash: cmn.HexBytes("block"), - LatestAppHash: cmn.HexBytes("app"), + LatestBlockHash: bytes.HexBytes("block"), + LatestAppHash: bytes.HexBytes("app"), LatestBlockHeight: 10, }, }}, diff --git a/rpc/core/abci.go b/rpc/core/abci.go index 423fb3398..a9955d1a5 100644 --- a/rpc/core/abci.go +++ b/rpc/core/abci.go @@ -2,7 +2,7 @@ package core import ( abci "github.com/tendermint/tendermint/abci/types" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/proxy" ctypes "github.com/tendermint/tendermint/rpc/core/types" rpctypes "github.com/tendermint/tendermint/rpc/lib/types" @@ -13,7 +13,7 @@ import ( func ABCIQuery( ctx *rpctypes.Context, path string, - data cmn.HexBytes, + data bytes.HexBytes, height int64, prove bool, ) (*ctypes.ResultABCIQuery, error) { diff --git a/rpc/core/status.go b/rpc/core/status.go index 6cda9f655..36c521f30 100644 --- a/rpc/core/status.go +++ b/rpc/core/status.go @@ -4,7 +4,7 @@ import ( "bytes" "time" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "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/lib/types" @@ -24,8 +24,8 @@ func Status(ctx *rpctypes.Context) (*ctypes.ResultStatus, error) { } var ( latestBlockMeta *types.BlockMeta - latestBlockHash cmn.HexBytes - latestAppHash cmn.HexBytes + latestBlockHash tmbytes.HexBytes + latestAppHash tmbytes.HexBytes latestBlockTimeNano int64 ) if latestHeight != 0 { diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index b3a89b34f..9aee485e9 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -6,7 +6,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/p2p" "github.com/tendermint/tendermint/types" @@ -61,18 +61,18 @@ func NewResultCommit(header *types.Header, commit *types.Commit, // Info about the node's syncing state type SyncInfo struct { - LatestBlockHash cmn.HexBytes `json:"latest_block_hash"` - LatestAppHash cmn.HexBytes `json:"latest_app_hash"` - LatestBlockHeight int64 `json:"latest_block_height"` - LatestBlockTime time.Time `json:"latest_block_time"` - CatchingUp bool `json:"catching_up"` + LatestBlockHash bytes.HexBytes `json:"latest_block_hash"` + LatestAppHash bytes.HexBytes `json:"latest_app_hash"` + LatestBlockHeight int64 `json:"latest_block_height"` + LatestBlockTime time.Time `json:"latest_block_time"` + CatchingUp bool `json:"catching_up"` } // Info about the node's validator type ValidatorInfo struct { - Address cmn.HexBytes `json:"address"` - PubKey crypto.PubKey `json:"pub_key"` - VotingPower int64 `json:"voting_power"` + Address bytes.HexBytes `json:"address"` + PubKey crypto.PubKey `json:"pub_key"` + VotingPower int64 `json:"voting_power"` } // Node Status @@ -148,24 +148,24 @@ type ResultConsensusState struct { // CheckTx result type ResultBroadcastTx struct { - Code uint32 `json:"code"` - Data cmn.HexBytes `json:"data"` - Log string `json:"log"` + Code uint32 `json:"code"` + Data bytes.HexBytes `json:"data"` + Log string `json:"log"` - Hash cmn.HexBytes `json:"hash"` + Hash bytes.HexBytes `json:"hash"` } // CheckTx and DeliverTx results type ResultBroadcastTxCommit struct { CheckTx abci.ResponseCheckTx `json:"check_tx"` DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` - Hash cmn.HexBytes `json:"hash"` + Hash bytes.HexBytes `json:"hash"` Height int64 `json:"height"` } // Result of querying for a tx type ResultTx struct { - Hash cmn.HexBytes `json:"hash"` + Hash bytes.HexBytes `json:"hash"` Height int64 `json:"height"` Index uint32 `json:"index"` TxResult abci.ResponseDeliverTx `json:"tx_result"` diff --git a/rpc/lib/rpc_test.go b/rpc/lib/rpc_test.go index ae5768457..2403266b7 100644 --- a/rpc/lib/rpc_test.go +++ b/rpc/lib/rpc_test.go @@ -17,7 +17,7 @@ import ( "github.com/stretchr/testify/require" amino "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/libs/rand" @@ -51,7 +51,7 @@ type ResultEchoBytes struct { } type ResultEchoDataBytes struct { - Value cmn.HexBytes `json:"value"` + Value tmbytes.HexBytes `json:"value"` } // Define some routes @@ -82,7 +82,7 @@ func EchoBytesResult(ctx *types.Context, v []byte) (*ResultEchoBytes, error) { return &ResultEchoBytes{v}, nil } -func EchoDataBytesResult(ctx *types.Context, v cmn.HexBytes) (*ResultEchoDataBytes, error) { +func EchoDataBytesResult(ctx *types.Context, v tmbytes.HexBytes) (*ResultEchoDataBytes, error) { return &ResultEchoDataBytes{v}, nil } @@ -180,7 +180,7 @@ func echoBytesViaHTTP(cl client.JSONRPCCaller, bytes []byte) ([]byte, error) { return result.Value, nil } -func echoDataBytesViaHTTP(cl client.JSONRPCCaller, bytes cmn.HexBytes) (cmn.HexBytes, error) { +func echoDataBytesViaHTTP(cl client.JSONRPCCaller, bytes tmbytes.HexBytes) (tmbytes.HexBytes, error) { params := map[string]interface{}{ "arg": bytes, } @@ -202,7 +202,7 @@ func testWithHTTPClient(t *testing.T, cl client.HTTPClient) { require.Nil(t, err) assert.Equal(t, got2, val2) - val3 := cmn.HexBytes(randBytes(t)) + val3 := tmbytes.HexBytes(randBytes(t)) got3, err := echoDataBytesViaHTTP(cl, val3) require.Nil(t, err) assert.Equal(t, got3, val3) diff --git a/rpc/lib/server/parse_test.go b/rpc/lib/server/parse_test.go index 9196bb71b..3780861e4 100644 --- a/rpc/lib/server/parse_test.go +++ b/rpc/lib/server/parse_test.go @@ -9,7 +9,7 @@ import ( "github.com/stretchr/testify/assert" amino "github.com/tendermint/go-amino" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" types "github.com/tendermint/tendermint/rpc/lib/types" ) @@ -33,7 +33,7 @@ func TestParseJSONMap(t *testing.T) { // preloading map with values doesn't help tmp := 0 p2 := map[string]interface{}{ - "value": &cmn.HexBytes{}, + "value": &bytes.HexBytes{}, "height": &tmp, } err = json.Unmarshal(input, &p2) @@ -56,7 +56,7 @@ func TestParseJSONMap(t *testing.T) { Height interface{} `json:"height"` }{ Height: &tmp, - Value: &cmn.HexBytes{}, + Value: &bytes.HexBytes{}, } err = json.Unmarshal(input, &p3) if assert.Nil(t, err) { @@ -64,7 +64,7 @@ func TestParseJSONMap(t *testing.T) { if assert.True(t, ok, "%#v", p3.Height) { assert.Equal(t, 22, *h) } - v, ok := p3.Value.(*cmn.HexBytes) + v, ok := p3.Value.(*bytes.HexBytes) if assert.True(t, ok, "%#v", p3.Value) { assert.EqualValues(t, []byte{0x12, 0x34}, *v) } @@ -72,8 +72,8 @@ func TestParseJSONMap(t *testing.T) { // simplest solution, but hard-coded p4 := struct { - Value cmn.HexBytes `json:"value"` - Height int `json:"height"` + Value bytes.HexBytes `json:"value"` + Height int `json:"height"` }{} err = json.Unmarshal(input, &p4) if assert.Nil(t, err) { @@ -92,10 +92,10 @@ func TestParseJSONMap(t *testing.T) { assert.Equal(t, 22, h) } - var v cmn.HexBytes + var v bytes.HexBytes err = json.Unmarshal(*p5["value"], &v) if assert.Nil(t, err) { - assert.Equal(t, cmn.HexBytes{0x12, 0x34}, v) + assert.Equal(t, bytes.HexBytes{0x12, 0x34}, v) } } } @@ -119,10 +119,10 @@ func TestParseJSONArray(t *testing.T) { // preloading map with values helps here (unlike map - p2 above) tmp := 0 - p2 := []interface{}{&cmn.HexBytes{}, &tmp} + p2 := []interface{}{&bytes.HexBytes{}, &tmp} err = json.Unmarshal(input, &p2) if assert.Nil(t, err) { - v, ok := p2[0].(*cmn.HexBytes) + v, ok := p2[0].(*bytes.HexBytes) if assert.True(t, ok, "%#v", p2[0]) { assert.EqualValues(t, []byte{0x12, 0x34}, *v) } diff --git a/types/block.go b/types/block.go index b2fca5f09..c67b9ade9 100644 --- a/types/block.go +++ b/types/block.go @@ -12,6 +12,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" + tmbytes "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" "github.com/tendermint/tendermint/version" ) @@ -156,7 +157,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() cmn.HexBytes { +func (b *Block) Hash() tmbytes.HexBytes { if b == nil { return nil } @@ -329,20 +330,20 @@ type Header struct { LastBlockID BlockID `json:"last_block_id"` // hashes of block data - LastCommitHash cmn.HexBytes `json:"last_commit_hash"` // commit from validators from the last block - DataHash cmn.HexBytes `json:"data_hash"` // transactions + LastCommitHash tmbytes.HexBytes `json:"last_commit_hash"` // commit from validators from the last block + DataHash tmbytes.HexBytes `json:"data_hash"` // transactions // hashes from the app output from the prev block - ValidatorsHash cmn.HexBytes `json:"validators_hash"` // validators for the current block - NextValidatorsHash cmn.HexBytes `json:"next_validators_hash"` // validators for the next block - ConsensusHash cmn.HexBytes `json:"consensus_hash"` // consensus params for current block - AppHash cmn.HexBytes `json:"app_hash"` // state after txs from the previous 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 // root hash of all results from the txs from the previous block - LastResultsHash cmn.HexBytes `json:"last_results_hash"` + LastResultsHash tmbytes.HexBytes `json:"last_results_hash"` // consensus info - EvidenceHash cmn.HexBytes `json:"evidence_hash"` // evidence included in the block - ProposerAddress Address `json:"proposer_address"` // original proposer of the block + EvidenceHash tmbytes.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. @@ -372,7 +373,7 @@ func (h *Header) Populate( // 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() cmn.HexBytes { +func (h *Header) Hash() tmbytes.HexBytes { if h == nil || len(h.ValidatorsHash) == 0 { return nil } @@ -479,8 +480,8 @@ func (cs CommitSig) Absent() bool { func (cs CommitSig) String() string { return fmt.Sprintf("CommitSig{%X by %X on %v @ %s}", - cmn.Fingerprint(cs.Signature), - cmn.Fingerprint(cs.ValidatorAddress), + tmbytes.Fingerprint(cs.Signature), + tmbytes.Fingerprint(cs.ValidatorAddress), cs.BlockIDFlag, CanonicalTime(cs.Timestamp)) } @@ -559,7 +560,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 cmn.HexBytes + hash tmbytes.HexBytes bitArray *cmn.BitArray } @@ -696,7 +697,7 @@ func (commit *Commit) ValidateBasic() error { } // Hash returns the hash of the commit -func (commit *Commit) Hash() cmn.HexBytes { +func (commit *Commit) Hash() tmbytes.HexBytes { if commit == nil { return nil } @@ -809,11 +810,11 @@ type Data struct { Txs Txs `json:"txs"` // Volatile - hash cmn.HexBytes + hash tmbytes.HexBytes } // Hash returns the hash of the data -func (data *Data) Hash() cmn.HexBytes { +func (data *Data) Hash() tmbytes.HexBytes { if data == nil { return (Txs{}).Hash() } @@ -850,11 +851,11 @@ type EvidenceData struct { Evidence EvidenceList `json:"evidence"` // Volatile - hash cmn.HexBytes + hash tmbytes.HexBytes } // Hash returns the hash of the data. -func (data *EvidenceData) Hash() cmn.HexBytes { +func (data *EvidenceData) Hash() tmbytes.HexBytes { if data.hash == nil { data.hash = data.Evidence.Hash() } @@ -885,8 +886,8 @@ func (data *EvidenceData) StringIndented(indent string) string { // BlockID defines the unique ID of a block as its Hash and its PartSetHeader type BlockID struct { - Hash cmn.HexBytes `json:"hash"` - PartsHeader PartSetHeader `json:"parts"` + Hash tmbytes.HexBytes `json:"hash"` + PartsHeader PartSetHeader `json:"parts"` } // Equals returns true if the BlockID matches the given BlockID diff --git a/types/block_test.go b/types/block_test.go index 79a2605f5..d3454f54b 100644 --- a/types/block_test.go +++ b/types/block_test.go @@ -17,6 +17,7 @@ import ( "github.com/tendermint/tendermint/crypto" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" + "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" tmrand "github.com/tendermint/tendermint/libs/rand" tmtime "github.com/tendermint/tendermint/types/time" @@ -251,7 +252,7 @@ func TestHeaderHash(t *testing.T) { testCases := []struct { desc string header *Header - expectHash cmn.HexBytes + expectHash bytes.HexBytes }{ {"Generates expected hash", &Header{ Version: version.Consensus{Block: 1, App: 2}, @@ -304,7 +305,7 @@ func TestHeaderHash(t *testing.T) { byteSlices = append(byteSlices, cdcEncode(f.Interface())) } assert.Equal(t, - cmn.HexBytes(merkle.SimpleHashFromByteSlices(byteSlices)), tc.header.Hash()) + bytes.HexBytes(merkle.SimpleHashFromByteSlices(byteSlices)), tc.header.Hash()) } }) } @@ -358,12 +359,12 @@ func randCommit() *Commit { return commit } -func hexBytesFromString(s string) cmn.HexBytes { +func hexBytesFromString(s string) bytes.HexBytes { b, err := hex.DecodeString(s) if err != nil { panic(err) } - return cmn.HexBytes(b) + return bytes.HexBytes(b) } func TestBlockMaxDataBytes(t *testing.T) { @@ -559,10 +560,10 @@ func TestSignedHeaderValidateBasic(t *testing.T) { func TestBlockIDValidateBasic(t *testing.T) { validBlockID := BlockID{ - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, PartsHeader: PartSetHeader{ Total: 1, - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, }, } @@ -570,13 +571,13 @@ func TestBlockIDValidateBasic(t *testing.T) { Hash: []byte{0}, PartsHeader: PartSetHeader{ Total: -1, - Hash: cmn.HexBytes{}, + Hash: bytes.HexBytes{}, }, } testCases := []struct { testName string - blockIDHash cmn.HexBytes + blockIDHash bytes.HexBytes blockIDPartsHeader PartSetHeader expectErr bool }{ diff --git a/types/canonical.go b/types/canonical.go index 47a8c817f..59c52d741 100644 --- a/types/canonical.go +++ b/types/canonical.go @@ -3,7 +3,7 @@ package types import ( "time" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" tmtime "github.com/tendermint/tendermint/types/time" ) @@ -13,12 +13,12 @@ import ( const TimeFormat = time.RFC3339Nano type CanonicalBlockID struct { - Hash cmn.HexBytes + Hash bytes.HexBytes PartsHeader CanonicalPartSetHeader } type CanonicalPartSetHeader struct { - Hash cmn.HexBytes + Hash bytes.HexBytes Total int } diff --git a/types/genesis.go b/types/genesis.go index 4a1fb3e1b..a28bafdff 100644 --- a/types/genesis.go +++ b/types/genesis.go @@ -10,6 +10,7 @@ import ( "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto" + tmbytes "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" tmtime "github.com/tendermint/tendermint/types/time" ) @@ -39,7 +40,7 @@ type GenesisDoc struct { ChainID string `json:"chain_id"` ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"` Validators []GenesisValidator `json:"validators,omitempty"` - AppHash cmn.HexBytes `json:"app_hash"` + AppHash tmbytes.HexBytes `json:"app_hash"` AppState json.RawMessage `json:"app_state,omitempty"` } diff --git a/types/part_set.go b/types/part_set.go index 69ee3b006..cdacc0083 100644 --- a/types/part_set.go +++ b/types/part_set.go @@ -9,6 +9,7 @@ import ( "github.com/pkg/errors" "github.com/tendermint/tendermint/crypto/merkle" + tmbytes "github.com/tendermint/tendermint/libs/bytes" cmn "github.com/tendermint/tendermint/libs/common" ) @@ -19,7 +20,7 @@ var ( type Part struct { Index int `json:"index"` - Bytes cmn.HexBytes `json:"bytes"` + Bytes tmbytes.HexBytes `json:"bytes"` Proof merkle.SimpleProof `json:"proof"` } @@ -47,7 +48,7 @@ func (part *Part) StringIndented(indent string) string { %s Proof: %v %s}`, part.Index, - indent, cmn.Fingerprint(part.Bytes), + indent, tmbytes.Fingerprint(part.Bytes), indent, part.Proof.StringIndented(indent+" "), indent) } @@ -55,12 +56,12 @@ func (part *Part) StringIndented(indent string) string { //------------------------------------- type PartSetHeader struct { - Total int `json:"total"` - Hash cmn.HexBytes `json:"hash"` + Total int `json:"total"` + Hash tmbytes.HexBytes `json:"hash"` } func (psh PartSetHeader) String() string { - return fmt.Sprintf("%v:%X", psh.Total, cmn.Fingerprint(psh.Hash)) + return fmt.Sprintf("%v:%X", psh.Total, tmbytes.Fingerprint(psh.Hash)) } func (psh PartSetHeader) IsZero() bool { diff --git a/types/proposal.go b/types/proposal.go index 54ad3b2f7..8175c8a1f 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -5,7 +5,7 @@ import ( "fmt" "time" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" tmtime "github.com/tendermint/tendermint/types/time" ) @@ -83,7 +83,7 @@ func (p *Proposal) String() string { p.Round, p.BlockID, p.POLRound, - cmn.Fingerprint(p.Signature), + bytes.Fingerprint(p.Signature), CanonicalTime(p.Timestamp)) } diff --git a/types/results.go b/types/results.go index 6b0c37562..11ddbcea9 100644 --- a/types/results.go +++ b/types/results.go @@ -3,7 +3,7 @@ package types import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" - cmn "github.com/tendermint/tendermint/libs/common" + "github.com/tendermint/tendermint/libs/bytes" ) //----------------------------------------------------------------------------- @@ -12,8 +12,8 @@ import ( // TODO: add tags and other fields // https://github.com/tendermint/tendermint/issues/1007 type ABCIResult struct { - Code uint32 `json:"code"` - Data cmn.HexBytes `json:"data"` + Code uint32 `json:"code"` + Data bytes.HexBytes `json:"data"` } // Bytes returns the amino encoded ABCIResult diff --git a/types/tx.go b/types/tx.go index 73ff8d052..311730228 100644 --- a/types/tx.go +++ b/types/tx.go @@ -10,7 +10,7 @@ import ( abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" ) // Tx is an arbitrary byte array. @@ -83,7 +83,7 @@ func (txs Txs) Proof(i int) TxProof { // TxProof represents a Merkle proof of the presence of a transaction in the Merkle tree. type TxProof struct { - RootHash cmn.HexBytes `json:"root_hash"` + RootHash tmbytes.HexBytes `json:"root_hash"` Data Tx `json:"data"` Proof merkle.SimpleProof `json:"proof"` } diff --git a/types/vote.go b/types/vote.go index 98a5fbf19..da9134cd6 100644 --- a/types/vote.go +++ b/types/vote.go @@ -7,7 +7,7 @@ import ( "time" "github.com/tendermint/tendermint/crypto" - cmn "github.com/tendermint/tendermint/libs/common" + tmbytes "github.com/tendermint/tendermint/libs/bytes" ) const ( @@ -110,13 +110,13 @@ func (vote *Vote) String() string { return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}", vote.ValidatorIndex, - cmn.Fingerprint(vote.ValidatorAddress), + tmbytes.Fingerprint(vote.ValidatorAddress), vote.Height, vote.Round, vote.Type, typeString, - cmn.Fingerprint(vote.BlockID.Hash), - cmn.Fingerprint(vote.Signature), + tmbytes.Fingerprint(vote.BlockID.Hash), + tmbytes.Fingerprint(vote.Signature), CanonicalTime(vote.Timestamp), ) }