Browse Source

Merge pull request #1184 from tendermint/sdk2-tmlibs-abci

Updates for tmlibs and abci (sdk2)
pull/1191/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
bf84e82577
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
50 changed files with 355 additions and 367 deletions
  1. +1
    -1
      blockchain/store.go
  2. +1
    -2
      blockchain/store_test.go
  3. +1
    -2
      consensus/byzantine_test.go
  4. +3
    -3
      consensus/mempool_test.go
  5. +1
    -1
      consensus/replay.go
  6. +3
    -2
      consensus/replay_file.go
  7. +2
    -2
      evidence/store.go
  8. +24
    -37
      glide.lock
  9. +6
    -9
      glide.yaml
  10. +36
    -7
      lite/proxy/query.go
  11. +3
    -3
      lite/proxy/wrapper.go
  12. +1
    -1
      mempool/mempool_test.go
  13. +4
    -3
      node/node.go
  14. +3
    -6
      p2p/conn/connection.go
  15. +2
    -3
      rpc/client/httpclient.go
  16. +2
    -3
      rpc/client/interface.go
  17. +3
    -3
      rpc/client/localclient.go
  18. +8
    -8
      rpc/client/mock/abci.go
  19. +5
    -5
      rpc/client/mock/abci_test.go
  20. +2
    -3
      rpc/client/mock/client.go
  21. +3
    -3
      rpc/client/mock/status_test.go
  22. +2
    -11
      rpc/client/rpc_test.go
  23. +2
    -2
      rpc/core/abci.go
  24. +2
    -2
      rpc/core/mempool.go
  25. +3
    -3
      rpc/core/status.go
  26. +9
    -8
      rpc/core/types/responses.go
  27. +7
    -6
      rpc/lib/rpc_test.go
  28. +10
    -10
      rpc/lib/server/parse_test.go
  29. +8
    -19
      state/execution.go
  30. +7
    -6
      state/execution_test.go
  31. +32
    -31
      state/state_test.go
  32. +19
    -28
      state/txindex/kv/kv.go
  33. +15
    -14
      state/txindex/kv/kv_test.go
  34. +54
    -34
      types/block.go
  35. +9
    -9
      types/canonical_json.go
  36. +2
    -9
      types/event_bus.go
  37. +4
    -2
      types/evidence.go
  38. +1
    -2
      types/genesis.go
  39. +1
    -2
      types/heartbeat.go
  40. +7
    -7
      types/params.go
  41. +5
    -6
      types/part_set.go
  42. +4
    -5
      types/priv_validator.go
  43. +1
    -2
      types/priv_validator_test.go
  44. +10
    -10
      types/protobuf.go
  45. +9
    -9
      types/results.go
  46. +0
    -6
      types/signable.go
  47. +6
    -6
      types/tx.go
  48. +4
    -5
      types/validator.go
  49. +4
    -4
      types/validator_set.go
  50. +4
    -2
      types/vote.go

+ 1
- 1
blockchain/store.go View File

@ -254,7 +254,7 @@ func (bsj BlockStoreStateJSON) Save(db dbm.DB) {
// If no BlockStoreStateJSON was previously persisted, it returns the zero value.
func LoadBlockStoreStateJSON(db dbm.DB) BlockStoreStateJSON {
bytes := db.Get(blockStoreKey)
if bytes == nil {
if len(bytes) == 0 {
return BlockStoreStateJSON{
Height: 0,
}


+ 1
- 2
blockchain/store_test.go View File

@ -42,7 +42,6 @@ func TestNewBlockStore(t *testing.T) {
wantErr string
}{
{[]byte("artful-doger"), "not unmarshal bytes"},
{[]byte(""), "unmarshal bytes"},
{[]byte(" "), "unmarshal bytes"},
}
@ -76,7 +75,7 @@ func TestBlockStoreGetReader(t *testing.T) {
}{
0: {key: []byte("Foo"), want: []byte("Bar")},
1: {key: []byte("KnoxNonExistent"), want: nil},
2: {key: []byte("Foo1"), want: nil},
2: {key: []byte("Foo1"), want: []byte{}},
}
for i, tt := range tests {


+ 1
- 2
consensus/byzantine_test.go View File

@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
@ -281,7 +280,7 @@ func NewByzantinePrivValidator(pv types.PrivValidator) *ByzantinePrivValidator {
}
}
func (privVal *ByzantinePrivValidator) GetAddress() data.Bytes {
func (privVal *ByzantinePrivValidator) GetAddress() types.Address {
return privVal.pv.GetAddress()
}


+ 3
- 3
consensus/mempool_test.go View File

@ -129,7 +129,7 @@ func TestMempoolRmBadTx(t *testing.T) {
assert.False(t, resDeliver.IsErr(), cmn.Fmt("expected no error. got %v", resDeliver))
resCommit := app.Commit()
assert.False(t, resCommit.IsErr(), cmn.Fmt("expected no error. got %v", resCommit))
assert.True(t, len(resCommit.Data) > 0)
emptyMempoolCh := make(chan struct{})
checkTxRespCh := make(chan struct{})
@ -223,10 +223,10 @@ func txAsUint64(tx []byte) uint64 {
func (app *CounterApplication) Commit() abci.ResponseCommit {
app.mempoolTxCount = app.txCount
if app.txCount == 0 {
return abci.ResponseCommit{Code: code.CodeTypeOK}
return abci.ResponseCommit{}
} else {
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return abci.ResponseCommit{Code: code.CodeTypeOK, Data: hash}
return abci.ResponseCommit{Data: hash}
}
}

+ 1
- 1
consensus/replay.go View File

@ -423,5 +423,5 @@ func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlo
}
func (mock *mockProxyApp) Commit() abci.ResponseCommit {
return abci.ResponseCommit{Code: abci.CodeTypeOK, Data: mock.appHash}
return abci.ResponseCommit{Data: mock.appHash}
}

+ 3
- 2
consensus/replay_file.go View File

@ -280,12 +280,13 @@ func (pb *playback) replayConsoleLoop() int {
// convenience for replay mode
func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusConfig) *ConsensusState {
dbType := dbm.DBBackendType(config.DBBackend)
// Get BlockStore
blockStoreDB := dbm.NewDB("blockstore", config.DBBackend, config.DBDir())
blockStoreDB := dbm.NewDB("blockstore", dbType, config.DBDir())
blockStore := bc.NewBlockStore(blockStoreDB)
// Get State
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir())
stateDB := dbm.NewDB("state", dbType, config.DBDir())
state, err := sm.MakeGenesisStateFromFile(config.GenesisFile())
if err != nil {
cmn.Exit(err.Error())


+ 2
- 2
evidence/store.go View File

@ -99,8 +99,8 @@ func (store *EvidenceStore) PendingEvidence() (evidence []types.Evidence) {
// ListEvidence lists the evidence for the given prefix key.
// It is wrapped by PriorityEvidence and PendingEvidence for convenience.
func (store *EvidenceStore) ListEvidence(prefixKey string) (evidence []types.Evidence) {
iter := store.db.IteratorPrefix([]byte(prefixKey))
for iter.Next() {
iter := dbm.IteratePrefix(store.db, []byte(prefixKey))
for ; iter.Valid(); iter.Next() {
val := iter.Value()
var ei EvidenceInfo


+ 24
- 37
glide.lock View File

@ -1,32 +1,26 @@
hash: 9399a10e80d255104f8ec07b5d495c41d8a3f7a421f9da97ebd78c65189f381d
updated: 2018-01-18T23:11:10.703734578-05:00
hash: 78f23456c3ca7af06fc26e59107de92a7b208776643bda398b0a05348153da1b
updated: 2018-02-03T03:31:46.976175875-05:00
imports:
- name: github.com/btcsuite/btcd
version: 2e60448ffcc6bf78332d1fe590260095f554dd78
version: 50de9da05b50eb15658bb350f6ea24368a111ab7
subpackages:
- btcec
- name: github.com/ebuchman/fail-test
version: 95f809107225be108efcf10a3509e4ea6ceef3c4
- name: github.com/fsnotify/fsnotify
version: 4da3e2cfbabc9f751898f250b49f2439785783a1
version: c2828203cd70a50dcccfb2761f8b1f8ceef9a8e9
- name: github.com/go-kit/kit
version: 53f10af5d5c7375d4655a3d6852457ed17ab5cc7
version: 4dc7be5d2d12881735283bcab7352178e190fc71
subpackages:
- log
- log/level
- log/term
- name: github.com/go-logfmt/logfmt
version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5
- name: github.com/go-playground/locales
version: e4cbcb5d0652150d40ad0646651076b6bd2be4f6
subpackages:
- currency
- name: github.com/go-playground/universal-translator
version: 71201497bace774495daed26a3874fd339e0b538
- name: github.com/go-stack/stack
version: 259ab82a6cad3992b4e21ff5cac294ccb06474bc
- name: github.com/gogo/protobuf
version: 342cbe0a04158f6dcb03ca0079991a51a4248c02
version: 1adfc126b41513cc696b209667c8656ea7aac67c
subpackages:
- gogoproto
- jsonpb
@ -35,7 +29,7 @@ imports:
- sortkeys
- types
- name: github.com/golang/protobuf
version: 1e59b77b52bf8e4b449a57e6f79f21226d571845
version: bbd03ef6da3a115852eaf24c8a1c46aeb39aa175
subpackages:
- proto
- ptypes
@ -66,15 +60,15 @@ imports:
- name: github.com/magiconair/properties
version: 49d762b9817ba1c2e9d0c69183c2b4a8b8f1d934
- name: github.com/mitchellh/mapstructure
version: 06020f85339e21b2478f756a78e295255ffa4d6a
version: b4575eea38cca1123ec2dc90c26529b5c5acfcff
- name: github.com/pelletier/go-toml
version: 4e9e0ee19b60b13eb79915933f44d8ed5f268bdd
version: acdc4509485b587f5e675510c4f2c63e90ff68a8
- name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/rcrowley/go-metrics
version: e181e095bae94582363434144c61a9653aff6e50
version: 8732c616f52954686704c8645fe1a9d59e9df7c1
- name: github.com/spf13/afero
version: 8d919cbe7e2627e417f3e45c3c0e489a5b7e2536
version: bb8f1927f2a9d3ab41c9340aa034f6b803f4359c
subpackages:
- mem
- name: github.com/spf13/cast
@ -82,13 +76,13 @@ imports:
- name: github.com/spf13/cobra
version: 7b2c5ac9fc04fc5efafb60700713d4fa609b777b
- name: github.com/spf13/jwalterweatherman
version: 12bd96e66386c1960ab0f74ced1362f66f552f7b
version: 7c0cea34c8ece3fbeb2b27ab9b59511d360fb394
- name: github.com/spf13/pflag
version: 4c012f6dcd9546820e378d0bdda4d8fc772cdfea
- name: github.com/spf13/viper
version: 25b30aa063fc18e48662b86996252eabdcf2f0c7
- name: github.com/syndtr/goleveldb
version: adf24ef3f94bd13ec4163060b21a5678f22b429b
version: 211f780988068502fe874c44dae530528ebd840f
subpackages:
- leveldb
- leveldb/cache
@ -103,7 +97,7 @@ imports:
- leveldb/table
- leveldb/util
- name: github.com/tendermint/abci
version: 5d5ea6869b91cadb55dbc4211ad7b326f053a33e
version: 5a4f56056e23cdfd5f3733db056968e016468508
subpackages:
- client
- example/code
@ -122,14 +116,9 @@ imports:
version: b6fc872b42d41158a60307db4da051dd6f179415
subpackages:
- data
- data/base58
- nowriter/tmlegacy
- name: github.com/tendermint/iavl
version: 594cc0c062a7174475f0ab654384038d77067917
subpackages:
- iavl
- name: github.com/tendermint/tmlibs
version: 15e51fa76086a3c505f227679c2478043ae7261b
version: deaaf014d8b8d1095054380a38b1b00e293f725f
subpackages:
- autofile
- cli
@ -144,7 +133,7 @@ imports:
- pubsub/query
- test
- name: golang.org/x/crypto
version: 94eea52f7b742c7cbe0b03b22f0c4c8631ece122
version: 1875d0a70c90e57f11972aefd42276df65e895b9
subpackages:
- curve25519
- nacl/box
@ -155,7 +144,7 @@ imports:
- ripemd160
- salsa20/salsa
- name: golang.org/x/net
version: d866cfc389cec985d6fda2859936a575a55a3ab6
version: 2fb46b16b8dda405028c50f7c7f0f9dd1fa6bfb1
subpackages:
- context
- http2
@ -165,18 +154,18 @@ imports:
- lex/httplex
- trace
- name: golang.org/x/sys
version: 8b4580aae2a0dd0c231a45d3ccb8434ff533b840
version: 37707fdb30a5b38865cfb95e5aab41707daec7fd
subpackages:
- unix
- name: golang.org/x/text
version: 57961680700a5336d15015c8c50686ca5ba362a4
version: e19ae1496984b1c655b8044a65c0300a3c878dd3
subpackages:
- secure/bidirule
- transform
- unicode/bidi
- unicode/norm
- name: google.golang.org/genproto
version: a8101f21cf983e773d0c1133ebc5424792003214
version: 4eb30f4778eed4c258ba66527a0d4f9ec8a36c45
subpackages:
- googleapis/rpc/status
- name: google.golang.org/grpc
@ -198,21 +187,19 @@ imports:
- status
- tap
- transport
- name: gopkg.in/go-playground/validator.v9
version: 61caf9d3038e1af346dbf5c2e16f6678e1548364
- name: gopkg.in/yaml.v2
version: 287cf08546ab5e7e37d55a84f7ed3fd1db036de5
version: d670f9405373e636a5a2765eea47fac0c9bc91a4
testImports:
- name: github.com/davecgh/go-spew
version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9
version: 346938d642f2ec3594ed81d874461961cd0faa76
subpackages:
- spew
- name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
version: 792786c7400a136282c1664665ae0a8db921c6c2
subpackages:
- difflib
- name: github.com/stretchr/testify
version: 2aa2c176b9dab406a6970f6a55f513e8a8c8b18f
version: a726187e3128d0a0ec37f73ca7c4d3e508e6c2e5
subpackages:
- assert
- require

+ 6
- 9
glide.yaml View File

@ -2,7 +2,7 @@ package: github.com/tendermint/tendermint
import:
- package: github.com/ebuchman/fail-test
- package: github.com/gogo/protobuf
version: v0.5
version: ^1.0.0
subpackages:
- proto
- package: github.com/golang/protobuf
@ -18,23 +18,19 @@ import:
- package: github.com/spf13/viper
version: v1.0.0
- package: github.com/tendermint/abci
version: v0.9.0
version: develop
subpackages:
- client
- example/dummy
- types
- package: github.com/tendermint/go-crypto
version: ~0.4.1
version: master
- package: github.com/tendermint/go-wire
version: ~0.7.2
version: master
subpackages:
- data
- package: github.com/tendermint/iavl
version: ~0.2.0
subpackages:
- iavl
- package: github.com/tendermint/tmlibs
version: v0.6.1
version: develop
subpackages:
- autofile
- cli
@ -58,6 +54,7 @@ import:
version: v1.7.3
testImport:
- package: github.com/go-kit/kit
version: ^0.6.0
subpackages:
- log/term
- package: github.com/stretchr/testify


+ 36
- 7
lite/proxy/query.go View File

@ -3,8 +3,7 @@ package proxy
import (
"github.com/pkg/errors"
"github.com/tendermint/go-wire/data"
"github.com/tendermint/iavl"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/lite"
"github.com/tendermint/tendermint/lite/client"
@ -13,6 +12,20 @@ import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
// KeyProof represents a proof of existence or absence of a single key.
// Copied from iavl repo. TODO
type KeyProof interface {
// Verify verfies the proof is valid. To verify absence,
// the value should be nil.
Verify(key, value, root []byte) error
// Root returns the root hash of the proof.
Root() []byte
// Serialize itself
Bytes() []byte
}
// GetWithProof will query the key on the given node, and verify it has
// a valid proof, as defined by the certifier.
//
@ -21,7 +34,7 @@ import (
// If val is empty, proof should be KeyMissingProof
func GetWithProof(key []byte, reqHeight int64, node rpcclient.Client,
cert lite.Certifier) (
val data.Bytes, height int64, proof iavl.KeyProof, err error) {
val cmn.HexBytes, height int64, proof KeyProof, err error) {
if reqHeight < 0 {
err = errors.Errorf("Height cannot be negative")
@ -41,7 +54,7 @@ func GetWithProof(key []byte, reqHeight int64, node rpcclient.Client,
// GetWithProofOptions is useful if you want full access to the ABCIQueryOptions
func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOptions,
node rpcclient.Client, cert lite.Certifier) (
*ctypes.ResultABCIQuery, iavl.KeyProof, error) {
*ctypes.ResultABCIQuery, KeyProof, error) {
_resp, err := node.ABCIQueryWithOptions(path, key, opts)
if err != nil {
@ -67,13 +80,23 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption
return nil, nil, err
}
_ = commit
return &ctypes.ResultABCIQuery{Response: resp}, nil, nil
/* // TODO refactor so iavl stuff is not in tendermint core
// https://github.com/tendermint/tendermint/issues/1183
if len(resp.Value) > 0 {
// The key was found, construct a proof of existence.
eproof, err := iavl.ReadKeyExistsProof(resp.Proof)
proof, err := iavl.ReadKeyProof(resp.Proof)
if err != nil {
return nil, nil, errors.Wrap(err, "Error reading proof")
}
eproof, ok := proof.(*iavl.KeyExistsProof)
if !ok {
return nil, nil, errors.New("Expected KeyExistsProof for non-empty value")
}
// Validate the proof against the certified header to ensure data integrity.
err = eproof.Verify(resp.Key, resp.Value, commit.Header.AppHash)
if err != nil {
@ -83,17 +106,23 @@ func GetWithProofOptions(path string, key []byte, opts rpcclient.ABCIQueryOption
}
// The key wasn't found, construct a proof of non-existence.
var aproof *iavl.KeyAbsentProof
aproof, err = iavl.ReadKeyAbsentProof(resp.Proof)
proof, err := iavl.ReadKeyProof(resp.Proof)
if err != nil {
return nil, nil, errors.Wrap(err, "Error reading proof")
}
aproof, ok := proof.(*iavl.KeyAbsentProof)
if !ok {
return nil, nil, errors.New("Expected KeyAbsentProof for empty Value")
}
// Validate the proof against the certified header to ensure data integrity.
err = aproof.Verify(resp.Key, nil, commit.Header.AppHash)
if err != nil {
return nil, nil, errors.Wrap(err, "Couldn't verify proof")
}
return &ctypes.ResultABCIQuery{Response: resp}, aproof, ErrNoData()
*/
}
// GetCertifiedCommit gets the signed header for a given height


+ 3
- 3
lite/proxy/wrapper.go View File

@ -1,7 +1,7 @@
package proxy
import (
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/lite"
certclient "github.com/tendermint/tendermint/lite/client"
@ -34,7 +34,7 @@ func SecureClient(c rpcclient.Client, cert *lite.InquiringCertifier) Wrapper {
}
// ABCIQueryWithOptions exposes all options for the ABCI query and verifies the returned proof
func (w Wrapper) ABCIQueryWithOptions(path string, data data.Bytes,
func (w Wrapper) ABCIQueryWithOptions(path string, data cmn.HexBytes,
opts rpcclient.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, _, err := GetWithProofOptions(path, data, opts, w.Client, w.cert)
@ -42,7 +42,7 @@ func (w Wrapper) ABCIQueryWithOptions(path string, data data.Bytes,
}
// ABCIQuery uses default options for the ABCI query and verifies the returned proof
func (w Wrapper) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (w Wrapper) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return w.ABCIQueryWithOptions(path, data, rpcclient.DefaultABCIQueryOptions)
}


+ 1
- 1
mempool/mempool_test.go View File

@ -185,7 +185,7 @@ func TestSerialReap(t *testing.T) {
t.Errorf("Client error committing: %v", err)
}
if len(res.Data) != 8 {
t.Errorf("Error committing. Hash:%X log:%v", res.Data, res.Log)
t.Errorf("Error committing. Hash:%X", res.Data)
}
}


+ 4
- 3
node/node.go View File

@ -53,7 +53,8 @@ type DBProvider func(*DBContext) (dbm.DB, error)
// DefaultDBProvider returns a database using the DBBackend and DBDir
// specified in the ctx.Config.
func DefaultDBProvider(ctx *DBContext) (dbm.DB, error) {
return dbm.NewDB(ctx.ID, ctx.Config.DBBackend, ctx.Config.DBDir()), nil
dbType := dbm.DBBackendType(ctx.Config.DBBackend)
return dbm.NewDB(ctx.ID, dbType, ctx.Config.DBDir()), nil
}
// GenesisDocProvider returns a GenesisDoc.
@ -274,7 +275,7 @@ func NewNode(config *cfg.Config,
return err
}
if resQuery.IsErr() {
return resQuery
return fmt.Errorf("Error querying abci app: %v", resQuery)
}
return nil
})
@ -284,7 +285,7 @@ func NewNode(config *cfg.Config,
return err
}
if resQuery.IsErr() {
return resQuery
return fmt.Errorf("Error querying abci app: %v", resQuery)
}
return nil
})


+ 3
- 6
p2p/conn/connection.go View File

@ -11,14 +11,11 @@ import (
"time"
wire "github.com/tendermint/go-wire"
tmlegacy "github.com/tendermint/go-wire/nowriter/tmlegacy"
cmn "github.com/tendermint/tmlibs/common"
flow "github.com/tendermint/tmlibs/flowrate"
"github.com/tendermint/tmlibs/log"
)
var legacy = tmlegacy.TMEncoderLegacy{}
const (
numBatchMsgPackets = 10
minReadBufferSize = 1024
@ -316,12 +313,12 @@ FOR_LOOP:
}
case <-c.pingTimer.Chan():
c.Logger.Debug("Send Ping")
legacy.WriteOctet(packetTypePing, c.bufWriter, &n, &err)
wire.WriteByte(packetTypePing, c.bufWriter, &n, &err)
c.sendMonitor.Update(int(n))
c.flush()
case <-c.pong:
c.Logger.Debug("Send Pong")
legacy.WriteOctet(packetTypePong, c.bufWriter, &n, &err)
wire.WriteByte(packetTypePong, c.bufWriter, &n, &err)
c.sendMonitor.Update(int(n))
c.flush()
case <-c.quit:
@ -681,7 +678,7 @@ func (ch *Channel) writeMsgPacketTo(w io.Writer) (n int, err error) {
}
func writeMsgPacketTo(packet msgPacket, w io.Writer, n *int, err *error) {
legacy.WriteOctet(packetTypeMsg, w, n, err)
wire.WriteByte(packetTypeMsg, w, n, err)
wire.WriteBinary(packet, w, n, err)
}


+ 2
- 3
rpc/client/httpclient.go View File

@ -7,7 +7,6 @@ import (
"github.com/pkg/errors"
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/types"
@ -64,11 +63,11 @@ func (c *HTTP) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return result, nil
}
func (c *HTTP) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (c *HTTP) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
}
func (c *HTTP) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (c *HTTP) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
result := new(ctypes.ResultABCIQuery)
_, err := c.rpc.Call("abci_query",
map[string]interface{}{"path": path, "data": data, "height": opts.Height, "trusted": opts.Trusted},


+ 2
- 3
rpc/client/interface.go View File

@ -20,7 +20,6 @@ implementation.
package client
import (
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
@ -32,8 +31,8 @@ import (
type ABCIClient interface {
// reading from abci app
ABCIInfo() (*ctypes.ResultABCIInfo, error)
ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error)
ABCIQueryWithOptions(path string, data data.Bytes,
ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error)
ABCIQueryWithOptions(path string, data cmn.HexBytes,
opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error)
// writing to abci app


+ 3
- 3
rpc/client/localclient.go View File

@ -3,11 +3,11 @@ package client
import (
"context"
data "github.com/tendermint/go-wire/data"
nm "github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
tmpubsub "github.com/tendermint/tmlibs/pubsub"
)
@ -56,11 +56,11 @@ func (Local) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return core.ABCIInfo()
}
func (c *Local) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (c *Local) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, DefaultABCIQueryOptions)
}
func (Local) ABCIQueryWithOptions(path string, data data.Bytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (Local) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
}


+ 8
- 8
rpc/client/mock/abci.go View File

@ -2,11 +2,11 @@ package mock
import (
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/rpc/client"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
"github.com/tendermint/tendermint/version"
cmn "github.com/tendermint/tmlibs/common"
)
// ABCIApp will send all abci related request to the named app,
@ -26,11 +26,11 @@ func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{version.Version})}, nil
}
func (a ABCIApp) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (a ABCIApp) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return a.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
}
func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (a ABCIApp) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
return &ctypes.ResultABCIQuery{q}, nil
}
@ -81,11 +81,11 @@ func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{res.(abci.ResponseInfo)}, nil
}
func (m ABCIMock) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (m ABCIMock) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return m.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
}
func (m ABCIMock) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (m ABCIMock) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := m.Query.GetResponse(QueryArgs{path, data, opts.Height, opts.Trusted})
if err != nil {
return nil, err
@ -134,7 +134,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder {
type QueryArgs struct {
Path string
Data data.Bytes
Data cmn.HexBytes
Height int64
Trusted bool
}
@ -153,11 +153,11 @@ func (r *ABCIRecorder) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return res, err
}
func (r *ABCIRecorder) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (r *ABCIRecorder) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return r.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
}
func (r *ABCIRecorder) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (r *ABCIRecorder) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
res, err := r.Client.ABCIQueryWithOptions(path, data, opts)
r.addCall(Call{
Name: "abci_query",


+ 5
- 5
rpc/client/mock/abci_test.go View File

@ -11,11 +11,11 @@ import (
"github.com/tendermint/abci/example/dummy"
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/client/mock"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
)
func TestABCIMock(t *testing.T) {
@ -37,8 +37,8 @@ func TestABCIMock(t *testing.T) {
BroadcastCommit: mock.Call{
Args: goodTx,
Response: &ctypes.ResultBroadcastTxCommit{
CheckTx: abci.ResponseCheckTx{Data: data.Bytes("stand")},
DeliverTx: abci.ResponseDeliverTx{Data: data.Bytes("deliver")},
CheckTx: abci.ResponseCheckTx{Data: cmn.HexBytes("stand")},
DeliverTx: abci.ResponseDeliverTx{Data: cmn.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", data.Bytes("data"), client.ABCIQueryOptions{Trusted: false})
_, err = r.ABCIQueryWithOptions("path", cmn.HexBytes("data"), client.ABCIQueryOptions{Trusted: false})
assert.NotNil(err, "expected error on query")
require.Equal(2, len(r.Calls))
@ -174,7 +174,7 @@ func TestABCIApp(t *testing.T) {
assert.True(res.DeliverTx.IsOK())
// check the key
_qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
_qres, err := m.ABCIQueryWithOptions("/key", cmn.HexBytes(key), client.ABCIQueryOptions{Trusted: true})
qres := _qres.Response
require.Nil(err)
assert.EqualValues(value, qres.Value)


+ 2
- 3
rpc/client/mock/client.go View File

@ -16,7 +16,6 @@ package mock
import (
"reflect"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@ -83,11 +82,11 @@ func (c Client) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return core.ABCIInfo()
}
func (c Client) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuery, error) {
func (c Client) ABCIQuery(path string, data cmn.HexBytes) (*ctypes.ResultABCIQuery, error) {
return c.ABCIQueryWithOptions(path, data, client.DefaultABCIQueryOptions)
}
func (c Client) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
func (c Client) ABCIQueryWithOptions(path string, data cmn.HexBytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
return core.ABCIQuery(path, data, opts.Height, opts.Trusted)
}


+ 3
- 3
rpc/client/mock/status_test.go View File

@ -6,9 +6,9 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
data "github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/rpc/client/mock"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
cmn "github.com/tendermint/tmlibs/common"
)
func TestStatus(t *testing.T) {
@ -17,8 +17,8 @@ func TestStatus(t *testing.T) {
m := &mock.StatusMock{
Call: mock.Call{
Response: &ctypes.ResultStatus{
LatestBlockHash: data.Bytes("block"),
LatestAppHash: data.Bytes("app"),
LatestBlockHash: cmn.HexBytes("block"),
LatestAppHash: cmn.HexBytes("app"),
LatestBlockHeight: 10,
}},
}


+ 2
- 11
rpc/client/rpc_test.go View File

@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/iavl"
"github.com/tendermint/tendermint/rpc/client"
rpctest "github.com/tendermint/tendermint/rpc/test"
@ -204,16 +203,8 @@ func TestAppCalls(t *testing.T) {
// and we got a proof that works!
_pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
pres := _pres.Response
if assert.Nil(err) && assert.True(pres.IsOK()) {
proof, err := iavl.ReadKeyExistsProof(pres.Proof)
if assert.Nil(err) {
key := pres.Key
value := pres.Value
assert.EqualValues(appHash, proof.RootHash)
valid := proof.Verify(key, value, appHash)
assert.Nil(valid)
}
}
assert.Nil(err)
assert.True(pres.IsOK())
}
}


+ 2
- 2
rpc/core/abci.go View File

@ -2,9 +2,9 @@ package core
import (
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/version"
cmn "github.com/tendermint/tmlibs/common"
)
// Query the application for some information.
@ -47,7 +47,7 @@ import (
// | data | []byte | false | true | Data |
// | height | int64 | 0 | false | Height (0 means latest) |
// | trusted | bool | false | false | Does not include a proof of the data inclusion |
func ABCIQuery(path string, data data.Bytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error) {
func ABCIQuery(path string, data cmn.HexBytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error) {
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
Path: path,
Data: data,


+ 2
- 2
rpc/core/mempool.go View File

@ -8,9 +8,9 @@ import (
"github.com/pkg/errors"
abci "github.com/tendermint/abci/types"
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
)
//-----------------------------------------------------------------------------
@ -192,7 +192,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
deliverTxRes := deliverTxResMsg.(types.TMEventData).Unwrap().(types.EventDataTx)
// The tx was included in a block.
deliverTxR := deliverTxRes.Result
logger.Info("DeliverTx passed ", "tx", data.Bytes(tx), "response", deliverTxR)
logger.Info("DeliverTx passed ", "tx", cmn.HexBytes(tx), "response", deliverTxR)
return &ctypes.ResultBroadcastTxCommit{
CheckTx: *checkTxR,
DeliverTx: deliverTxR,


+ 3
- 3
rpc/core/status.go View File

@ -3,9 +3,9 @@ package core
import (
"time"
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
)
// Get Tendermint status including node info, pubkey, latest block
@ -59,8 +59,8 @@ func Status() (*ctypes.ResultStatus, error) {
latestHeight := blockStore.Height()
var (
latestBlockMeta *types.BlockMeta
latestBlockHash data.Bytes
latestAppHash data.Bytes
latestBlockHash cmn.HexBytes
latestAppHash cmn.HexBytes
latestBlockTimeNano int64
)
if latestHeight != 0 {


+ 9
- 8
rpc/core/types/responses.go View File

@ -6,7 +6,8 @@ import (
abci "github.com/tendermint/abci/types"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
cstypes "github.com/tendermint/tendermint/consensus/types"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/state"
@ -56,8 +57,8 @@ func NewResultCommit(header *types.Header, commit *types.Commit,
type ResultStatus struct {
NodeInfo p2p.NodeInfo `json:"node_info"`
PubKey crypto.PubKey `json:"pub_key"`
LatestBlockHash data.Bytes `json:"latest_block_hash"`
LatestAppHash data.Bytes `json:"latest_app_hash"`
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"`
Syncing bool `json:"syncing"`
@ -107,17 +108,17 @@ type ResultDumpConsensusState struct {
}
type ResultBroadcastTx struct {
Code uint32 `json:"code"`
Data data.Bytes `json:"data"`
Log string `json:"log"`
Code uint32 `json:"code"`
Data cmn.HexBytes `json:"data"`
Log string `json:"log"`
Hash data.Bytes `json:"hash"`
Hash cmn.HexBytes `json:"hash"`
}
type ResultBroadcastTxCommit struct {
CheckTx abci.ResponseCheckTx `json:"check_tx"`
DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"`
Hash data.Bytes `json:"hash"`
Hash cmn.HexBytes `json:"hash"`
Height int64 `json:"height"`
}


+ 7
- 6
rpc/lib/rpc_test.go View File

@ -17,11 +17,12 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
client "github.com/tendermint/tendermint/rpc/lib/client"
server "github.com/tendermint/tendermint/rpc/lib/server"
types "github.com/tendermint/tendermint/rpc/lib/types"
"github.com/tendermint/tmlibs/log"
)
// Client and Server should work over tcp or unix sockets
@ -47,7 +48,7 @@ type ResultEchoBytes struct {
}
type ResultEchoDataBytes struct {
Value data.Bytes `json:"value"`
Value cmn.HexBytes `json:"value"`
}
// Define some routes
@ -75,7 +76,7 @@ func EchoBytesResult(v []byte) (*ResultEchoBytes, error) {
return &ResultEchoBytes{v}, nil
}
func EchoDataBytesResult(v data.Bytes) (*ResultEchoDataBytes, error) {
func EchoDataBytesResult(v cmn.HexBytes) (*ResultEchoDataBytes, error) {
return &ResultEchoDataBytes{v}, nil
}
@ -174,7 +175,7 @@ func echoBytesViaHTTP(cl client.HTTPClient, bytes []byte) ([]byte, error) {
return result.Value, nil
}
func echoDataBytesViaHTTP(cl client.HTTPClient, bytes data.Bytes) (data.Bytes, error) {
func echoDataBytesViaHTTP(cl client.HTTPClient, bytes cmn.HexBytes) (cmn.HexBytes, error) {
params := map[string]interface{}{
"arg": bytes,
}
@ -196,7 +197,7 @@ func testWithHTTPClient(t *testing.T, cl client.HTTPClient) {
require.Nil(t, err)
assert.Equal(t, got2, val2)
val3 := data.Bytes(randBytes(t))
val3 := cmn.HexBytes(randBytes(t))
got3, err := echoDataBytesViaHTTP(cl, val3)
require.Nil(t, err)
assert.Equal(t, got3, val3)


+ 10
- 10
rpc/lib/server/parse_test.go View File

@ -6,7 +6,7 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
func TestParseJSONMap(t *testing.T) {
@ -31,7 +31,7 @@ func TestParseJSONMap(t *testing.T) {
// preloading map with values doesn't help
tmp := 0
p2 := map[string]interface{}{
"value": &data.Bytes{},
"value": &cmn.HexBytes{},
"height": &tmp,
}
err = json.Unmarshal(input, &p2)
@ -54,7 +54,7 @@ func TestParseJSONMap(t *testing.T) {
Height interface{} `json:"height"`
}{
Height: &tmp,
Value: &data.Bytes{},
Value: &cmn.HexBytes{},
}
err = json.Unmarshal(input, &p3)
if assert.Nil(err) {
@ -62,7 +62,7 @@ func TestParseJSONMap(t *testing.T) {
if assert.True(ok, "%#v", p3.Height) {
assert.Equal(22, *h)
}
v, ok := p3.Value.(*data.Bytes)
v, ok := p3.Value.(*cmn.HexBytes)
if assert.True(ok, "%#v", p3.Value) {
assert.EqualValues([]byte{0x12, 0x34}, *v)
}
@ -70,8 +70,8 @@ func TestParseJSONMap(t *testing.T) {
// simplest solution, but hard-coded
p4 := struct {
Value data.Bytes `json:"value"`
Height int `json:"height"`
Value cmn.HexBytes `json:"value"`
Height int `json:"height"`
}{}
err = json.Unmarshal(input, &p4)
if assert.Nil(err) {
@ -90,10 +90,10 @@ func TestParseJSONMap(t *testing.T) {
assert.Equal(22, h)
}
var v data.Bytes
var v cmn.HexBytes
err = json.Unmarshal(*p5["value"], &v)
if assert.Nil(err) {
assert.Equal(data.Bytes{0x12, 0x34}, v)
assert.Equal(cmn.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{}{&data.Bytes{}, &tmp}
p2 := []interface{}{&cmn.HexBytes{}, &tmp}
err = json.Unmarshal(input, &p2)
if assert.Nil(err) {
v, ok := p2[0].(*data.Bytes)
v, ok := p2[0].(*cmn.HexBytes)
if assert.True(ok, "%#v", p2[0]) {
assert.EqualValues([]byte{0x12, 0x34}, *v)
}


+ 8
- 19
state/execution.go View File

@ -141,13 +141,7 @@ func (blockExec *BlockExecutor) Commit(block *types.Block) ([]byte, error) {
blockExec.logger.Error("Client error during proxyAppConn.CommitSync", "err", err)
return nil, err
}
if res.IsErr() {
blockExec.logger.Error("Error in proxyAppConn.CommitSync", "err", res)
return nil, res
}
if res.Log != "" {
blockExec.logger.Debug("Commit.Log: " + res.Log)
}
// ResponseCommit has no error code - just data
blockExec.logger.Info("Committed state", "height", block.Height, "txs", block.NumTxs, "appHash", res.Data)
@ -198,10 +192,11 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus,
}
}
byzantineVals := make([]*abci.Evidence, len(block.Evidence.Evidence))
// TODO: determine which validators were byzantine
byzantineVals := make([]abci.Evidence, len(block.Evidence.Evidence))
for i, ev := range block.Evidence.Evidence {
byzantineVals[i] = &abci.Evidence{
PubKey: ev.Address(), // XXX/TODO
byzantineVals[i] = abci.Evidence{
PubKey: ev.Address(), // XXX
Height: ev.Height(),
}
}
@ -243,7 +238,7 @@ func execBlockOnProxyApp(logger log.Logger, proxyAppConn proxy.AppConnConsensus,
return abciResponses, nil
}
func updateValidators(currentSet *types.ValidatorSet, updates []*abci.Validator) error {
func updateValidators(currentSet *types.ValidatorSet, updates []abci.Validator) error {
// If more or equal than 1/3 of total voting power changed in one block, then
// a light client could never prove the transition externally. See
// ./lite/doc.go for details on how a light client tracks validators.
@ -293,7 +288,7 @@ func updateValidators(currentSet *types.ValidatorSet, updates []*abci.Validator)
return nil
}
func changeInVotingPowerMoreOrEqualToOneThird(currentSet *types.ValidatorSet, updates []*abci.Validator) (bool, error) {
func changeInVotingPowerMoreOrEqualToOneThird(currentSet *types.ValidatorSet, updates []abci.Validator) (bool, error) {
threshold := currentSet.TotalVotingPower() * 1 / 3
acc := int64(0)
@ -424,12 +419,6 @@ func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block
logger.Error("Client error during proxyAppConn.CommitSync", "err", res)
return nil, err
}
if res.IsErr() {
logger.Error("Error in proxyAppConn.CommitSync", "err", res)
return nil, res
}
if res.Log != "" {
logger.Info("Commit.Log: " + res.Log)
}
// ResponseCommit has no error or log, just data
return res.Data, nil
}

+ 7
- 6
state/execution_test.go View File

@ -12,6 +12,7 @@ import (
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log"
)
@ -105,11 +106,11 @@ func TestBeginBlockByzantineValidators(t *testing.T) {
testCases := []struct {
desc string
evidence []types.Evidence
expectedByzantineValidators []*abci.Evidence
expectedByzantineValidators []abci.Evidence
}{
{"none byzantine", []types.Evidence{}, []*abci.Evidence{}},
{"one byzantine", []types.Evidence{ev1}, []*abci.Evidence{{ev1.Address(), ev1.Height()}}},
{"multiple byzantine", []types.Evidence{ev1, ev2}, []*abci.Evidence{
{"none byzantine", []types.Evidence{}, []abci.Evidence{}},
{"one byzantine", []types.Evidence{ev1}, []abci.Evidence{{ev1.Address(), ev1.Height()}}},
{"multiple byzantine", []types.Evidence{ev1, ev2}, []abci.Evidence{
{ev1.Address(), ev1.Height()},
{ev2.Address(), ev2.Height()}}},
}
@ -161,7 +162,7 @@ type testApp struct {
abci.BaseApplication
AbsentValidators []int32
ByzantineValidators []*abci.Evidence
ByzantineValidators []abci.Evidence
}
func NewDummyApplication() *testApp {
@ -179,7 +180,7 @@ func (app *testApp) BeginBlock(req abci.RequestBeginBlock) abci.ResponseBeginBlo
}
func (app *testApp) DeliverTx(tx []byte) abci.ResponseDeliverTx {
return abci.ResponseDeliverTx{Tags: []*abci.KVPair{}}
return abci.ResponseDeliverTx{Tags: []cmn.KVPair{}}
}
func (app *testApp) CheckTx(tx []byte) abci.ResponseCheckTx {


+ 32
- 31
state/state_test.go View File

@ -22,7 +22,8 @@ import (
// setupTestCase does setup common to all test cases
func setupTestCase(t *testing.T) (func(t *testing.T), dbm.DB, State) {
config := cfg.ResetTestRoot("state_")
stateDB := dbm.NewDB("state", config.DBBackend, config.DBDir())
dbType := dbm.DBBackendType(config.DBBackend)
stateDB := dbm.NewDB("state", dbType, config.DBDir())
state, err := LoadStateFromDBOrGenesisFile(stateDB, config.GenesisFile())
assert.NoError(t, err, "expected no error on LoadStateFromDBOrGenesisFile")
@ -77,9 +78,9 @@ func TestABCIResponsesSaveLoad1(t *testing.T) {
// build mock responses
block := makeBlock(state, 2)
abciResponses := NewABCIResponses(block)
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: []*abci.KVPair{}}
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: []*abci.KVPair{}}
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{
abciResponses.DeliverTx[0] = &abci.ResponseDeliverTx{Data: []byte("foo"), Tags: []cmn.KVPair{}}
abciResponses.DeliverTx[1] = &abci.ResponseDeliverTx{Data: []byte("bar"), Log: "ok", Tags: []cmn.KVPair{}}
abciResponses.EndBlock = &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{
{
PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(),
Power: 10,
@ -122,9 +123,9 @@ func TestABCIResponsesSaveLoad2(t *testing.T) {
[]*abci.ResponseDeliverTx{
{Code: 383},
{Data: []byte("Gotcha!"),
Tags: []*abci.KVPair{
abci.KVPairInt("a", 1),
abci.KVPairString("build", "stuff"),
Tags: []cmn.KVPair{
cmn.KVPair{[]byte("a"), []byte{1}},
cmn.KVPair{[]byte("build"), []byte("stuff")},
}},
},
types.ABCIResults{
@ -378,44 +379,44 @@ func TestLessThanOneThirdOfVotingPowerPerBlockEnforced(t *testing.T) {
testCases := []struct {
initialValSetSize int
shouldErr bool
valUpdatesFn func(vals *types.ValidatorSet) []*abci.Validator
valUpdatesFn func(vals *types.ValidatorSet) []abci.Validator
}{
///////////// 1 val (vp: 10) => less than 3 is ok ////////////////////////
// adding 1 validator => 10
0: {1, false, func(vals *types.ValidatorSet) []*abci.Validator {
return []*abci.Validator{
0: {1, false, func(vals *types.ValidatorSet) []abci.Validator {
return []abci.Validator{
{PubKey: pk(), Power: 2},
}
}},
1: {1, true, func(vals *types.ValidatorSet) []*abci.Validator {
return []*abci.Validator{
1: {1, true, func(vals *types.ValidatorSet) []abci.Validator {
return []abci.Validator{
{PubKey: pk(), Power: 3},
}
}},
2: {1, true, func(vals *types.ValidatorSet) []*abci.Validator {
return []*abci.Validator{
2: {1, true, func(vals *types.ValidatorSet) []abci.Validator {
return []abci.Validator{
{PubKey: pk(), Power: 100},
}
}},
///////////// 3 val (vp: 30) => less than 10 is ok ////////////////////////
// adding and removing validator => 20
3: {3, true, func(vals *types.ValidatorSet) []*abci.Validator {
3: {3, true, func(vals *types.ValidatorSet) []abci.Validator {
_, firstVal := vals.GetByIndex(0)
return []*abci.Validator{
return []abci.Validator{
{PubKey: firstVal.PubKey.Bytes(), Power: 0},
{PubKey: pk(), Power: 10},
}
}},
// adding 1 validator => 10
4: {3, true, func(vals *types.ValidatorSet) []*abci.Validator {
return []*abci.Validator{
4: {3, true, func(vals *types.ValidatorSet) []abci.Validator {
return []abci.Validator{
{PubKey: pk(), Power: 10},
}
}},
// adding 2 validators => 8
5: {3, false, func(vals *types.ValidatorSet) []*abci.Validator {
return []*abci.Validator{
5: {3, false, func(vals *types.ValidatorSet) []abci.Validator {
return []abci.Validator{
{PubKey: pk(), Power: 4},
{PubKey: pk(), Power: 4},
}
@ -450,20 +451,20 @@ func TestApplyUpdates(t *testing.T) {
cases := [...]struct {
init types.ConsensusParams
updates *abci.ConsensusParams
updates abci.ConsensusParams
expected types.ConsensusParams
}{
0: {initParams, nil, initParams},
1: {initParams, &abci.ConsensusParams{}, initParams},
0: {initParams, abci.ConsensusParams{}, initParams},
1: {initParams, abci.ConsensusParams{}, initParams},
2: {initParams,
&abci.ConsensusParams{
abci.ConsensusParams{
TxSize: &abci.TxSize{
MaxBytes: 123,
},
},
makeParams(1, 2, 3, 123, 5, 6)},
3: {initParams,
&abci.ConsensusParams{
abci.ConsensusParams{
BlockSize: &abci.BlockSize{
MaxTxs: 44,
MaxGas: 55,
@ -471,7 +472,7 @@ func TestApplyUpdates(t *testing.T) {
},
makeParams(1, 44, 55, 4, 5, 6)},
4: {initParams,
&abci.ConsensusParams{
abci.ConsensusParams{
BlockSize: &abci.BlockSize{
MaxTxs: 789,
},
@ -486,7 +487,7 @@ func TestApplyUpdates(t *testing.T) {
}
for i, tc := range cases {
res := tc.init.Update(tc.updates)
res := tc.init.Update(&(tc.updates))
assert.Equal(t, tc.expected, res, "case %d", i)
}
}
@ -496,14 +497,14 @@ func makeHeaderPartsResponsesValPubKeyChange(state State, height int64,
block := makeBlock(state, height)
abciResponses := &ABCIResponses{
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{}},
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}},
}
// if the pubkey is new, remove the old and add the new
_, val := state.Validators.GetByIndex(0)
if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) {
abciResponses.EndBlock = &abci.ResponseEndBlock{
ValidatorUpdates: []*abci.Validator{
ValidatorUpdates: []abci.Validator{
{val.PubKey.Bytes(), 0},
{pubkey.Bytes(), 10},
},
@ -518,14 +519,14 @@ func makeHeaderPartsResponsesValPowerChange(state State, height int64,
block := makeBlock(state, height)
abciResponses := &ABCIResponses{
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []*abci.Validator{}},
EndBlock: &abci.ResponseEndBlock{ValidatorUpdates: []abci.Validator{}},
}
// if the pubkey is new, remove the old and add the new
_, val := state.Validators.GetByIndex(0)
if val.VotingPower != power {
abciResponses.EndBlock = &abci.ResponseEndBlock{
ValidatorUpdates: []*abci.Validator{
ValidatorUpdates: []abci.Validator{
{val.PubKey.Bytes(), power},
},
}


+ 19
- 28
state/txindex/kv/kv.go View File

@ -10,13 +10,13 @@ import (
"github.com/pkg/errors"
abci "github.com/tendermint/abci/types"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
db "github.com/tendermint/tmlibs/db"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/pubsub/query"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types"
)
const (
@ -27,13 +27,13 @@ var _ txindex.TxIndexer = (*TxIndex)(nil)
// TxIndex is the simplest possible indexer, backed by key-value storage (levelDB).
type TxIndex struct {
store db.DB
store dbm.DB
tagsToIndex []string
indexAllTags bool
}
// NewTxIndex creates new KV indexer.
func NewTxIndex(store db.DB, options ...func(*TxIndex)) *TxIndex {
func NewTxIndex(store dbm.DB, options ...func(*TxIndex)) *TxIndex {
txi := &TxIndex{store: store, tagsToIndex: make([]string, 0), indexAllTags: false}
for _, o := range options {
o(txi)
@ -87,7 +87,7 @@ func (txi *TxIndex) AddBatch(b *txindex.Batch) error {
// index tx by tags
for _, tag := range result.Result.Tags {
if txi.indexAllTags || cmn.StringInSlice(tag.Key, txi.tagsToIndex) {
if txi.indexAllTags || cmn.StringInSlice(string(tag.Key), txi.tagsToIndex) {
storeBatch.Set(keyForTag(tag, result), hash)
}
}
@ -109,7 +109,7 @@ func (txi *TxIndex) Index(result *types.TxResult) error {
// index tx by tags
for _, tag := range result.Result.Tags {
if txi.indexAllTags || cmn.StringInSlice(tag.Key, txi.tagsToIndex) {
if txi.indexAllTags || cmn.StringInSlice(string(tag.Key), txi.tagsToIndex) {
b.Set(keyForTag(tag, result), hash)
}
}
@ -270,18 +270,18 @@ func isRangeOperation(op query.Operator) bool {
func (txi *TxIndex) match(c query.Condition, startKey []byte) (hashes [][]byte) {
if c.Op == query.OpEqual {
it := txi.store.IteratorPrefix(startKey)
defer it.Release()
for it.Next() {
it := dbm.IteratePrefix(txi.store, startKey)
defer it.Close()
for ; it.Valid(); it.Next() {
hashes = append(hashes, it.Value())
}
} else if c.Op == query.OpContains {
// XXX: doing full scan because startKey does not apply here
// For example, if startKey = "account.owner=an" and search query = "accoutn.owner CONSISTS an"
// we can't iterate with prefix "account.owner=an" because we might miss keys like "account.owner=Ulan"
it := txi.store.Iterator()
defer it.Release()
for it.Next() {
it := txi.store.Iterator(nil, nil)
defer it.Close()
for ; it.Valid(); it.Next() {
if !isTagKey(it.Key()) {
continue
}
@ -296,10 +296,10 @@ func (txi *TxIndex) match(c query.Condition, startKey []byte) (hashes [][]byte)
}
func (txi *TxIndex) matchRange(r queryRange, startKey []byte) (hashes [][]byte) {
it := txi.store.IteratorPrefix(startKey)
defer it.Release()
it := dbm.IteratePrefix(txi.store, startKey)
defer it.Close()
LOOP:
for it.Next() {
for ; it.Valid(); it.Next() {
if !isTagKey(it.Key()) {
continue
}
@ -376,17 +376,8 @@ func extractValueFromKey(key []byte) string {
return parts[1]
}
func keyForTag(tag *abci.KVPair, result *types.TxResult) []byte {
switch tag.ValueType {
case abci.KVPair_STRING:
return []byte(fmt.Sprintf("%s/%v/%d/%d", tag.Key, tag.ValueString, result.Height, result.Index))
case abci.KVPair_INT:
return []byte(fmt.Sprintf("%s/%v/%d/%d", tag.Key, tag.ValueInt, result.Height, result.Index))
// case abci.KVPair_TIME:
// return []byte(fmt.Sprintf("%s/%d/%d/%d", tag.Key, tag.ValueTime.Unix(), result.Height, result.Index))
default:
panic(fmt.Sprintf("Undefined value type: %v", tag.ValueType))
}
func keyForTag(tag cmn.KVPair, result *types.TxResult) []byte {
return []byte(fmt.Sprintf("%s/%s/%d/%d", tag.Key, tag.Value, result.Height, result.Index))
}
///////////////////////////////////////////////////////////////////////////////


+ 15
- 14
state/txindex/kv/kv_test.go View File

@ -11,6 +11,7 @@ import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tendermint/state/txindex"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
db "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/pubsub/query"
)
@ -19,7 +20,7 @@ func TestTxIndex(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB())
tx := types.Tx("HELLO WORLD")
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []cmn.KVPair{}}}
hash := tx.Hash()
batch := txindex.NewBatch(1)
@ -34,7 +35,7 @@ func TestTxIndex(t *testing.T) {
assert.Equal(t, txResult, loadedTxResult)
tx2 := types.Tx("BYE BYE WORLD")
txResult2 := &types.TxResult{1, 0, tx2, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
txResult2 := &types.TxResult{1, 0, tx2, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []cmn.KVPair{}}}
hash2 := tx2.Hash()
err = indexer.Index(txResult2)
@ -49,10 +50,10 @@ func TestTxSearch(t *testing.T) {
allowedTags := []string{"account.number", "account.owner", "account.date"}
indexer := NewTxIndex(db.NewMemDB(), IndexTags(allowedTags))
txResult := txResultWithTags([]*abci.KVPair{
{Key: "account.number", ValueType: abci.KVPair_INT, ValueInt: 1},
{Key: "account.owner", ValueType: abci.KVPair_STRING, ValueString: "Ivan"},
{Key: "not_allowed", ValueType: abci.KVPair_STRING, ValueString: "Vlad"},
txResult := txResultWithTags([]cmn.KVPair{
{Key: []byte("account.number"), Value: []byte("1")},
{Key: []byte("account.owner"), Value: []byte("Ivan")},
{Key: []byte("not_allowed"), Value: []byte("Vlad")},
})
hash := txResult.Tx.Hash()
@ -106,9 +107,9 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
allowedTags := []string{"account.number"}
indexer := NewTxIndex(db.NewMemDB(), IndexTags(allowedTags))
txResult := txResultWithTags([]*abci.KVPair{
{Key: "account.number", ValueType: abci.KVPair_INT, ValueInt: 1},
{Key: "account.number", ValueType: abci.KVPair_INT, ValueInt: 2},
txResult := txResultWithTags([]cmn.KVPair{
{Key: []byte("account.number"), Value: []byte("1")},
{Key: []byte("account.number"), Value: []byte("2")},
})
err := indexer.Index(txResult)
@ -124,9 +125,9 @@ func TestTxSearchOneTxWithMultipleSameTagsButDifferentValues(t *testing.T) {
func TestIndexAllTags(t *testing.T) {
indexer := NewTxIndex(db.NewMemDB(), IndexAllTags())
txResult := txResultWithTags([]*abci.KVPair{
abci.KVPairString("account.owner", "Ivan"),
abci.KVPairInt("account.number", 1),
txResult := txResultWithTags([]cmn.KVPair{
cmn.KVPair{[]byte("account.owner"), []byte("Ivan")},
cmn.KVPair{[]byte("account.number"), []byte("1")},
})
err := indexer.Index(txResult)
@ -143,14 +144,14 @@ func TestIndexAllTags(t *testing.T) {
assert.Equal(t, []*types.TxResult{txResult}, results)
}
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
func txResultWithTags(tags []cmn.KVPair) *types.TxResult {
tx := types.Tx("HELLO WORLD")
return &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: tags}}
}
func benchmarkTxIndex(txsCount int, b *testing.B) {
tx := types.Tx("HELLO WORLD")
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []cmn.KVPair{}}}
dir, err := ioutil.TempDir("", "tx_index_db")
if err != nil {


+ 54
- 34
types/block.go View File

@ -9,9 +9,9 @@ import (
"time"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
"golang.org/x/crypto/ripemd160"
)
// Block defines the atomic unit of a Tendermint blockchain.
@ -85,7 +85,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() data.Bytes {
func (b *Block) Hash() cmn.HexBytes {
if b == nil || b.Header == nil || b.Data == nil || b.LastCommit == nil {
return nil
}
@ -160,39 +160,39 @@ type Header struct {
TotalTxs int64 `json:"total_txs"`
// hashes of block data
LastCommitHash data.Bytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash data.Bytes `json:"data_hash"` // transactions
LastCommitHash cmn.HexBytes `json:"last_commit_hash"` // commit from validators from the last block
DataHash cmn.HexBytes `json:"data_hash"` // transactions
// hashes from the app output from the prev block
ValidatorsHash data.Bytes `json:"validators_hash"` // validators for the current block
ConsensusHash data.Bytes `json:"consensus_hash"` // consensus params for current block
AppHash data.Bytes `json:"app_hash"` // state after txs from the previous block
LastResultsHash data.Bytes `json:"last_results_hash"` // root hash of all results from the txs from the previous block
ValidatorsHash cmn.HexBytes `json:"validators_hash"` // validators for the current 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
LastResultsHash cmn.HexBytes `json:"last_results_hash"` // root hash of all results from the txs from the previous block
// consensus info
EvidenceHash data.Bytes `json:"evidence_hash"` // evidence included in the block
EvidenceHash cmn.HexBytes `json:"evidence_hash"` // evidence included in the block
}
// Hash returns the hash of the header.
// Returns nil if ValidatorHash is missing.
func (h *Header) Hash() data.Bytes {
func (h *Header) Hash() cmn.HexBytes {
if len(h.ValidatorsHash) == 0 {
return nil
}
return merkle.SimpleHashFromMap(map[string]interface{}{
"ChainID": h.ChainID,
"Height": h.Height,
"Time": h.Time,
"NumTxs": h.NumTxs,
"TotalTxs": h.TotalTxs,
"LastBlockID": h.LastBlockID,
"LastCommit": h.LastCommitHash,
"Data": h.DataHash,
"Validators": h.ValidatorsHash,
"App": h.AppHash,
"Consensus": h.ConsensusHash,
"Results": h.LastResultsHash,
"Evidence": h.EvidenceHash,
return merkle.SimpleHashFromMap(map[string]merkle.Hasher{
"ChainID": wireHasher(h.ChainID),
"Height": wireHasher(h.Height),
"Time": wireHasher(h.Time),
"NumTxs": wireHasher(h.NumTxs),
"TotalTxs": wireHasher(h.TotalTxs),
"LastBlockID": wireHasher(h.LastBlockID),
"LastCommit": wireHasher(h.LastCommitHash),
"Data": wireHasher(h.DataHash),
"Validators": wireHasher(h.ValidatorsHash),
"App": wireHasher(h.AppHash),
"Consensus": wireHasher(h.ConsensusHash),
"Results": wireHasher(h.LastResultsHash),
"Evidence": wireHasher(h.EvidenceHash),
})
}
@ -245,7 +245,7 @@ type Commit struct {
// Volatile
firstPrecommit *Vote
hash data.Bytes
hash cmn.HexBytes
bitArray *cmn.BitArray
}
@ -354,13 +354,13 @@ func (commit *Commit) ValidateBasic() error {
}
// Hash returns the hash of the commit
func (commit *Commit) Hash() data.Bytes {
func (commit *Commit) Hash() cmn.HexBytes {
if commit.hash == nil {
bs := make([]interface{}, len(commit.Precommits))
bs := make([]merkle.Hasher, len(commit.Precommits))
for i, precommit := range commit.Precommits {
bs[i] = precommit
bs[i] = wireHasher(precommit)
}
commit.hash = merkle.SimpleHashFromBinaries(bs)
commit.hash = merkle.SimpleHashFromHashers(bs)
}
return commit.hash
}
@ -402,11 +402,11 @@ type Data struct {
Txs Txs `json:"txs"`
// Volatile
hash data.Bytes
hash cmn.HexBytes
}
// Hash returns the hash of the data
func (data *Data) Hash() data.Bytes {
func (data *Data) Hash() cmn.HexBytes {
if data.hash == nil {
data.hash = data.Txs.Hash() // NOTE: leaves of merkle tree are TxIDs
}
@ -440,11 +440,11 @@ type EvidenceData struct {
Evidence EvidenceList `json:"evidence"`
// Volatile
hash data.Bytes
hash cmn.HexBytes
}
// Hash returns the hash of the data.
func (data *EvidenceData) Hash() data.Bytes {
func (data *EvidenceData) Hash() cmn.HexBytes {
if data.hash == nil {
data.hash = data.Evidence.Hash()
}
@ -476,7 +476,7 @@ 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 data.Bytes `json:"hash"`
Hash cmn.HexBytes `json:"hash"`
PartsHeader PartSetHeader `json:"parts"`
}
@ -510,3 +510,23 @@ func (blockID BlockID) WriteSignBytes(w io.Writer, n *int, err *error) {
func (blockID BlockID) String() string {
return fmt.Sprintf(`%v:%v`, blockID.Hash, blockID.PartsHeader)
}
//-------------------------------------------------------
type hasher struct {
item interface{}
}
func (h hasher) Hash() []byte {
hasher, n, err := ripemd160.New(), new(int), new(error)
wire.WriteBinary(h.item, hasher, n, err)
if *err != nil {
panic(err)
}
return hasher.Sum(nil)
}
func wireHasher(item interface{}) merkle.Hasher {
return hasher{item}
}

+ 9
- 9
types/canonical_json.go View File

@ -4,7 +4,7 @@ import (
"time"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
// canonical json is go-wire's json for structs with fields in alphabetical order
@ -13,13 +13,13 @@ import (
const timeFormat = wire.RFC3339Millis
type CanonicalJSONBlockID struct {
Hash data.Bytes `json:"hash,omitempty"`
Hash cmn.HexBytes `json:"hash,omitempty"`
PartsHeader CanonicalJSONPartSetHeader `json:"parts,omitempty"`
}
type CanonicalJSONPartSetHeader struct {
Hash data.Bytes `json:"hash"`
Total int `json:"total"`
Hash cmn.HexBytes `json:"hash"`
Total int `json:"total"`
}
type CanonicalJSONProposal struct {
@ -40,11 +40,11 @@ type CanonicalJSONVote struct {
}
type CanonicalJSONHeartbeat struct {
Height int64 `json:"height"`
Round int `json:"round"`
Sequence int `json:"sequence"`
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
Round int `json:"round"`
Sequence int `json:"sequence"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
}
//------------------------------------


+ 2
- 9
types/event_bus.go View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
tmpubsub "github.com/tendermint/tmlibs/pubsub"
@ -98,17 +97,11 @@ func (b *EventBus) PublishEventTx(event EventDataTx) error {
// validate and fill tags from tx result
for _, tag := range event.Result.Tags {
// basic validation
if tag.Key == "" {
if len(tag.Key) == 0 {
b.Logger.Info("Got tag with an empty key (skipping)", "tag", tag, "tx", event.Tx)
continue
}
switch tag.ValueType {
case abci.KVPair_STRING:
tags[tag.Key] = tag.ValueString
case abci.KVPair_INT:
tags[tag.Key] = tag.ValueInt
}
tags[string(tag.Key)] = tag.Value
}
// add predefined tags


+ 4
- 2
types/evidence.go View File

@ -120,7 +120,7 @@ func (dve *DuplicateVoteEvidence) Index() int {
// Hash returns the hash of the evidence.
func (dve *DuplicateVoteEvidence) Hash() []byte {
return merkle.SimpleHashFromBinary(dve)
return wireHasher(dve).Hash()
}
// Verify returns an error if the two votes aren't conflicting.
@ -165,7 +165,9 @@ func (dve *DuplicateVoteEvidence) Equal(ev Evidence) bool {
}
// just check their hashes
return bytes.Equal(merkle.SimpleHashFromBinary(dve), merkle.SimpleHashFromBinary(ev))
dveHash := wireHasher(dve).Hash()
evHash := wireHasher(ev).Hash()
return bytes.Equal(dveHash, evHash)
}
//-----------------------------------------------------------------


+ 1
- 2
types/genesis.go View File

@ -8,7 +8,6 @@ import (
"github.com/pkg/errors"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -28,7 +27,7 @@ type GenesisDoc struct {
ChainID string `json:"chain_id"`
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
Validators []GenesisValidator `json:"validators"`
AppHash data.Bytes `json:"app_hash"`
AppHash cmn.HexBytes `json:"app_hash"`
AppOptions interface{} `json:"app_options,omitempty"`
}


+ 1
- 2
types/heartbeat.go View File

@ -6,7 +6,6 @@ import (
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -16,7 +15,7 @@ import (
// json field tags because we always want the JSON
// representation to be in its canonical form.
type Heartbeat struct {
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
Round int `json:"round"`


+ 7
- 7
types/params.go View File

@ -106,13 +106,13 @@ func (params *ConsensusParams) Validate() error {
// Hash returns a merkle hash of the parameters to store
// in the block header
func (params *ConsensusParams) Hash() []byte {
return merkle.SimpleHashFromMap(map[string]interface{}{
"block_gossip_part_size_bytes": params.BlockGossip.BlockPartSizeBytes,
"block_size_max_bytes": params.BlockSize.MaxBytes,
"block_size_max_gas": params.BlockSize.MaxGas,
"block_size_max_txs": params.BlockSize.MaxTxs,
"tx_size_max_bytes": params.TxSize.MaxBytes,
"tx_size_max_gas": params.TxSize.MaxGas,
return merkle.SimpleHashFromMap(map[string]merkle.Hasher{
"block_gossip_part_size_bytes": wireHasher(params.BlockGossip.BlockPartSizeBytes),
"block_size_max_bytes": wireHasher(params.BlockSize.MaxBytes),
"block_size_max_gas": wireHasher(params.BlockSize.MaxGas),
"block_size_max_txs": wireHasher(params.BlockSize.MaxTxs),
"tx_size_max_bytes": wireHasher(params.TxSize.MaxBytes),
"tx_size_max_gas": wireHasher(params.TxSize.MaxGas),
})
}


+ 5
- 6
types/part_set.go View File

@ -10,7 +10,6 @@ import (
"golang.org/x/crypto/ripemd160"
"github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
)
@ -22,7 +21,7 @@ var (
type Part struct {
Index int `json:"index"`
Bytes data.Bytes `json:"bytes"`
Bytes cmn.HexBytes `json:"bytes"`
Proof merkle.SimpleProof `json:"proof"`
// Cache
@ -58,8 +57,8 @@ func (part *Part) StringIndented(indent string) string {
//-------------------------------------
type PartSetHeader struct {
Total int `json:"total"`
Hash data.Bytes `json:"hash"`
Total int `json:"total"`
Hash cmn.HexBytes `json:"hash"`
}
func (psh PartSetHeader) String() string {
@ -96,7 +95,7 @@ func NewPartSetFromData(data []byte, partSize int) *PartSet {
// divide data into 4kb parts.
total := (len(data) + partSize - 1) / partSize
parts := make([]*Part, total)
parts_ := make([]merkle.Hashable, total)
parts_ := make([]merkle.Hasher, total)
partsBitArray := cmn.NewBitArray(total)
for i := 0; i < total; i++ {
part := &Part{
@ -108,7 +107,7 @@ func NewPartSetFromData(data []byte, partSize int) *PartSet {
partsBitArray.SetIndex(i, true)
}
// Compute merkle proofs
root, proofs := merkle.SimpleProofsFromHashables(parts_)
root, proofs := merkle.SimpleProofsFromHashers(parts_)
for i := 0; i < total; i++ {
parts[i].Proof = *proofs[i]
}


+ 4
- 5
types/priv_validator.go View File

@ -11,7 +11,6 @@ import (
"time"
crypto "github.com/tendermint/go-crypto"
data "github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -38,7 +37,7 @@ func voteToStep(vote *Vote) int8 {
// PrivValidator defines the functionality of a local Tendermint validator
// that signs votes, proposals, and heartbeats, and never double signs.
type PrivValidator interface {
GetAddress() data.Bytes // redundant since .PubKey().Address()
GetAddress() Address // redundant since .PubKey().Address()
GetPubKey() crypto.PubKey
SignVote(chainID string, vote *Vote) error
@ -50,13 +49,13 @@ type PrivValidator interface {
// to prevent double signing. The Signer itself can be mutated to use
// something besides the default, for instance a hardware signer.
type PrivValidatorFS struct {
Address data.Bytes `json:"address"`
Address Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
LastHeight int64 `json:"last_height"`
LastRound int `json:"last_round"`
LastStep int8 `json:"last_step"`
LastSignature crypto.Signature `json:"last_signature,omitempty"` // so we dont lose signatures
LastSignBytes data.Bytes `json:"last_signbytes,omitempty"` // so we dont lose signatures
LastSignBytes cmn.HexBytes `json:"last_signbytes,omitempty"` // so we dont lose signatures
// PrivKey should be empty if a Signer other than the default is being used.
PrivKey crypto.PrivKey `json:"priv_key"`
@ -96,7 +95,7 @@ func (ds *DefaultSigner) Sign(msg []byte) (crypto.Signature, error) {
// GetAddress returns the address of the validator.
// Implements PrivValidator.
func (pv *PrivValidatorFS) GetAddress() data.Bytes {
func (pv *PrivValidatorFS) GetAddress() Address {
return pv.Address
}


+ 1
- 2
types/priv_validator_test.go View File

@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -225,7 +224,7 @@ func TestDifferByTimestamp(t *testing.T) {
}
}
func newVote(addr data.Bytes, idx int, height int64, round int, typ byte, blockID BlockID) *Vote {
func newVote(addr Address, idx int, height int64, round int, typ byte, blockID BlockID) *Vote {
return &Vote{
ValidatorAddress: addr,
ValidatorIndex: idx,


+ 10
- 10
types/protobuf.go View File

@ -10,8 +10,8 @@ var TM2PB = tm2pb{}
type tm2pb struct{}
func (tm2pb) Header(header *Header) *types.Header {
return &types.Header{
func (tm2pb) Header(header *Header) types.Header {
return types.Header{
ChainID: header.ChainID,
Height: header.Height,
Time: header.Time.Unix(),
@ -23,29 +23,29 @@ func (tm2pb) Header(header *Header) *types.Header {
}
}
func (tm2pb) BlockID(blockID BlockID) *types.BlockID {
return &types.BlockID{
func (tm2pb) BlockID(blockID BlockID) types.BlockID {
return types.BlockID{
Hash: blockID.Hash,
Parts: TM2PB.PartSetHeader(blockID.PartsHeader),
}
}
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
return &types.PartSetHeader{
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) types.PartSetHeader {
return types.PartSetHeader{
Total: int32(partSetHeader.Total), // XXX: overflow
Hash: partSetHeader.Hash,
}
}
func (tm2pb) Validator(val *Validator) *types.Validator {
return &types.Validator{
func (tm2pb) Validator(val *Validator) types.Validator {
return types.Validator{
PubKey: val.PubKey.Bytes(),
Power: val.VotingPower,
}
}
func (tm2pb) Validators(vals *ValidatorSet) []*types.Validator {
validators := make([]*types.Validator, len(vals.Validators))
func (tm2pb) Validators(vals *ValidatorSet) []types.Validator {
validators := make([]types.Validator, len(vals.Validators))
for i, val := range vals.Validators {
validators[i] = TM2PB.Validator(val)
}


+ 9
- 9
types/results.go View File

@ -3,7 +3,7 @@ package types
import (
abci "github.com/tendermint/abci/types"
wire "github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
)
@ -12,8 +12,8 @@ import (
// ABCIResult is the deterministic component of a ResponseDeliverTx.
// TODO: add Tags
type ABCIResult struct {
Code uint32 `json:"code"`
Data data.Bytes `json:"data"`
Code uint32 `json:"code"`
Data cmn.HexBytes `json:"data"`
}
// Hash returns the canonical hash of the ABCIResult
@ -47,20 +47,20 @@ func (a ABCIResults) Bytes() []byte {
// Hash returns a merkle hash of all results
func (a ABCIResults) Hash() []byte {
return merkle.SimpleHashFromHashables(a.toHashables())
return merkle.SimpleHashFromHashers(a.toHashers())
}
// ProveResult returns a merkle proof of one result from the set
func (a ABCIResults) ProveResult(i int) merkle.SimpleProof {
_, proofs := merkle.SimpleProofsFromHashables(a.toHashables())
_, proofs := merkle.SimpleProofsFromHashers(a.toHashers())
return *proofs[i]
}
func (a ABCIResults) toHashables() []merkle.Hashable {
func (a ABCIResults) toHashers() []merkle.Hasher {
l := len(a)
hashables := make([]merkle.Hashable, l)
hashers := make([]merkle.Hasher, l)
for i := 0; i < l; i++ {
hashables[i] = a[i]
hashers[i] = a[i]
}
return hashables
return hashers
}

+ 0
- 6
types/signable.go View File

@ -5,7 +5,6 @@ import (
"io"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
)
// Signable is an interface for all signable things.
@ -23,8 +22,3 @@ func SignBytes(chainID string, o Signable) []byte {
}
return buf.Bytes()
}
// HashSignBytes is a convenience method for getting the hash of the bytes of a signable
func HashSignBytes(chainID string, o Signable) []byte {
return merkle.SimpleHashFromBinary(SignBytes(chainID, o))
}

+ 6
- 6
types/tx.go View File

@ -6,7 +6,7 @@ import (
"fmt"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/merkle"
)
@ -18,7 +18,7 @@ type Tx []byte
// Hash computes the RIPEMD160 hash of the go-wire encoded transaction.
func (tx Tx) Hash() []byte {
return merkle.SimpleHashFromBinary(tx)
return wireHasher(tx).Hash()
}
// String returns the hex-encoded transaction as a string.
@ -72,11 +72,11 @@ func (txs Txs) IndexByHash(hash []byte) int {
// TODO: optimize this!
func (txs Txs) Proof(i int) TxProof {
l := len(txs)
hashables := make([]merkle.Hashable, l)
hashers := make([]merkle.Hasher, l)
for i := 0; i < l; i++ {
hashables[i] = txs[i]
hashers[i] = txs[i]
}
root, proofs := merkle.SimpleProofsFromHashables(hashables)
root, proofs := merkle.SimpleProofsFromHashers(hashers)
return TxProof{
Index: i,
@ -90,7 +90,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 {
Index, Total int
RootHash data.Bytes
RootHash cmn.HexBytes
Data Tx
Proof merkle.SimpleProof
}


+ 4
- 5
types/validator.go View File

@ -7,7 +7,6 @@ import (
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -15,9 +14,9 @@ import (
// NOTE: The Accum is not included in Validator.Hash();
// make sure to update that method if changes are made here
type Validator struct {
Address data.Bytes `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
Address Address `json:"address"`
PubKey crypto.PubKey `json:"pub_key"`
VotingPower int64 `json:"voting_power"`
Accum int64 `json:"accum"`
}
@ -74,7 +73,7 @@ func (v *Validator) String() string {
// It excludes the Accum value, which changes with every round.
func (v *Validator) Hash() []byte {
return wire.BinaryRipemd160(struct {
Address data.Bytes
Address Address
PubKey crypto.PubKey
VotingPower int64
}{


+ 4
- 4
types/validator_set.go View File

@ -54,7 +54,7 @@ func (valSet *ValidatorSet) IncrementAccum(times int) {
for _, val := range valSet.Validators {
// check for overflow both multiplication and sum
val.Accum = safeAddClip(val.Accum, safeMulClip(val.VotingPower, int64(times)))
validatorsHeap.Push(val, accumComparable{val})
validatorsHeap.PushComparable(val, accumComparable{val})
}
// Decrement the validator with most accum times times
@ -150,11 +150,11 @@ func (valSet *ValidatorSet) Hash() []byte {
if len(valSet.Validators) == 0 {
return nil
}
hashables := make([]merkle.Hashable, len(valSet.Validators))
hashers := make([]merkle.Hasher, len(valSet.Validators))
for i, val := range valSet.Validators {
hashables[i] = val
hashers[i] = val
}
return merkle.SimpleHashFromHashables(hashables)
return merkle.SimpleHashFromHashers(hashers)
}
func (valSet *ValidatorSet) Add(val *Validator) (added bool) {


+ 4
- 2
types/vote.go View File

@ -9,7 +9,6 @@ import (
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire"
"github.com/tendermint/go-wire/data"
cmn "github.com/tendermint/tmlibs/common"
)
@ -59,9 +58,12 @@ func IsVoteTypeValid(type_ byte) bool {
}
}
// Address is hex bytes. TODO: crypto.Address
type Address = cmn.HexBytes
// Represents a prevote, precommit, or commit vote from validators for consensus.
type Vote struct {
ValidatorAddress data.Bytes `json:"validator_address"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"`
Round int `json:"round"`


Loading…
Cancel
Save