Browse Source

Merge pull request #918 from tendermint/abci-update

Abci update
pull/927/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
b37230f6db
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 142 additions and 123 deletions
  1. +2
    -2
      consensus/common_test.go
  2. +10
    -8
      consensus/mempool_test.go
  3. +3
    -3
      consensus/reactor_test.go
  4. +1
    -1
      consensus/replay.go
  5. +15
    -12
      glide.lock
  6. +2
    -2
      glide.yaml
  7. +4
    -13
      mempool/mempool.go
  8. +13
    -15
      mempool/mempool_test.go
  9. +6
    -6
      node/node.go
  10. +5
    -4
      rpc/client/event_test.go
  11. +3
    -3
      rpc/client/mock/abci.go
  12. +3
    -3
      rpc/client/mock/abci_test.go
  13. +11
    -9
      rpc/client/rpc_test.go
  14. +1
    -1
      rpc/client/types.go
  15. +3
    -3
      rpc/core/abci.go
  16. +1
    -1
      rpc/core/mempool.go
  17. +4
    -4
      rpc/core/types/responses.go
  18. +4
    -2
      state/execution.go
  19. +4
    -4
      state/txindex/kv/kv.go
  20. +4
    -4
      state/txindex/kv/kv_test.go
  21. +38
    -18
      test/app/counter_test.sh
  22. +5
    -5
      types/protobuf.go

+ 2
- 2
consensus/common_test.go View File

@ -59,7 +59,7 @@ type validatorStub struct {
types.PrivValidator
}
var testMinPower = 10
var testMinPower int64 = 10
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
return &validatorStub{
@ -372,7 +372,7 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
// nPeers = nValidators + nNotValidator
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
genDoc, privVals := randGenesisDoc(nValidators, false, int64(testMinPower))
genDoc, privVals := randGenesisDoc(nValidators, false, testMinPower)
css := make([]*ConsensusState, nPeers)
logger := consensusLogger()
for i := 0; i < nPeers; i++ {


+ 10
- 8
consensus/mempool_test.go View File

@ -8,9 +8,11 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tendermint/abci/example/code"
abci "github.com/tendermint/abci/types"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/types"
)
func init() {
@ -135,7 +137,7 @@ func TestRmBadTx(t *testing.T) {
// CheckTx should not err, but the app should return a bad abci code
// and the tx should get removed from the pool
err := cs.mempool.CheckTx(txBytes, func(r *abci.Response) {
if r.GetCheckTx().Code != abci.CodeType_BadNonce {
if r.GetCheckTx().Code != code.CodeTypeBadNonce {
t.Fatalf("expected checktx to return bad nonce, got %v", r)
}
checkTxRespCh <- struct{}{}
@ -193,22 +195,22 @@ func (app *CounterApplication) DeliverTx(tx []byte) abci.ResponseDeliverTx {
txValue := txAsUint64(tx)
if txValue != uint64(app.txCount) {
return abci.ResponseDeliverTx{
Code: abci.CodeType_BadNonce,
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
}
app.txCount += 1
return abci.ResponseDeliverTx{Code: abci.CodeType_OK}
return abci.ResponseDeliverTx{Code: code.CodeTypeOK}
}
func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx {
txValue := txAsUint64(tx)
if txValue != uint64(app.mempoolTxCount) {
return abci.ResponseCheckTx{
Code: abci.CodeType_BadNonce,
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)}
}
app.mempoolTxCount += 1
return abci.ResponseCheckTx{Code: abci.CodeType_OK}
return abci.ResponseCheckTx{Code: code.CodeTypeOK}
}
func txAsUint64(tx []byte) uint64 {
@ -220,10 +222,10 @@ func txAsUint64(tx []byte) uint64 {
func (app *CounterApplication) Commit() abci.ResponseCommit {
app.mempoolTxCount = app.txCount
if app.txCount == 0 {
return abci.ResponseCommit{Code: abci.CodeType_OK}
return abci.ResponseCommit{Code: code.CodeTypeOK}
} else {
hash := make([]byte, 8)
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return abci.ResponseCommit{Code: abci.CodeType_OK, Data: hash}
return abci.ResponseCommit{Code: code.CodeTypeOK, Data: hash}
}
}

+ 3
- 3
consensus/reactor_test.go View File

@ -209,7 +209,7 @@ func TestValidatorSetChanges(t *testing.T) {
t.Log("---------------------------- Testing adding one validator")
newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), uint64(testMinPower))
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), testMinPower)
// wait till everyone makes block 2
// ensure the commit includes all validators
@ -251,10 +251,10 @@ func TestValidatorSetChanges(t *testing.T) {
t.Log("---------------------------- Testing adding two validators at once")
newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
newValidatorTx2 := dummy.MakeValSetChangeTx(newValidatorPubKey2.Bytes(), uint64(testMinPower))
newValidatorTx2 := dummy.MakeValSetChangeTx(newValidatorPubKey2.Bytes(), testMinPower)
newValidatorPubKey3 := css[nVals+2].privValidator.GetPubKey()
newValidatorTx3 := dummy.MakeValSetChangeTx(newValidatorPubKey3.Bytes(), uint64(testMinPower))
newValidatorTx3 := dummy.MakeValSetChangeTx(newValidatorPubKey3.Bytes(), testMinPower)
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css, newValidatorTx2, newValidatorTx3)
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css)


+ 1
- 1
consensus/replay.go View File

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

+ 15
- 12
glide.lock View File

@ -1,8 +1,8 @@
hash: 8c38726da2666831affa40474117d3cef5dad083176e81fb013d7e8493b83e6f
updated: 2017-12-01T02:14:22.08770964Z
hash: b0397f8c86e8131753fce91514314fe871ffb2562452a9f2125dbcd3cea600c8
updated: 2017-12-02T23:34:41.775549968-05:00
imports:
- name: github.com/btcsuite/btcd
version: 8cea3866d0f7fb12d567a20744942c0d078c7d15
version: 2e60448ffcc6bf78332d1fe590260095f554dd78
subpackages:
- btcec
- name: github.com/ebuchman/fail-test
@ -28,7 +28,9 @@ imports:
- name: github.com/gogo/protobuf
version: 342cbe0a04158f6dcb03ca0079991a51a4248c02
subpackages:
- gogoproto
- proto
- protoc-gen-gogo/descriptor
- name: github.com/golang/protobuf
version: 1e59b77b52bf8e4b449a57e6f79f21226d571845
subpackages:
@ -67,7 +69,7 @@ imports:
- name: github.com/pkg/errors
version: 645ef00459ed84a119197bfb8d8205042c6df63d
- name: github.com/rcrowley/go-metrics
version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c
version: e181e095bae94582363434144c61a9653aff6e50
- name: github.com/spf13/afero
version: 8d919cbe7e2627e417f3e45c3c0e489a5b7e2536
subpackages:
@ -98,9 +100,10 @@ imports:
- leveldb/table
- leveldb/util
- name: github.com/tendermint/abci
version: 22b491bb1952125dd2fb0730d6ca8e59e310547c
version: 48413b4839781c5c4bf96049a4b39f210ceb88c3
subpackages:
- client
- example/code
- example/counter
- example/dummy
- server
@ -113,7 +116,7 @@ imports:
- name: github.com/tendermint/go-crypto
version: dd20358a264c772b4a83e477b0cfce4c88a7001d
- name: github.com/tendermint/go-wire
version: 5ab49b4c6ad674da6b81442911cf713ef0afb544
version: 217a3c439f6497890d232ff5ed24084b43d9bfb3
subpackages:
- data
- data/base58
@ -138,7 +141,7 @@ imports:
- pubsub/query
- test
- name: golang.org/x/crypto
version: 9f005a07e0d31d45e6656d241bb5c0f2efd4bc94
version: 94eea52f7b742c7cbe0b03b22f0c4c8631ece122
subpackages:
- curve25519
- nacl/box
@ -149,7 +152,7 @@ imports:
- ripemd160
- salsa20/salsa
- name: golang.org/x/net
version: 9dfe39835686865bff950a07b394c12a98ddc811
version: a8b9294777976932365dabb6640cf1468d95c70f
subpackages:
- context
- http2
@ -159,22 +162,22 @@ imports:
- lex/httplex
- trace
- name: golang.org/x/sys
version: b98136db334ff9cb24f28a68e3be3cb6608f7630
version: 8b4580aae2a0dd0c231a45d3ccb8434ff533b840
subpackages:
- unix
- name: golang.org/x/text
version: 88f656faf3f37f690df1a32515b479415e1a6769
version: 75cc3cad82b5f47d3fb229ddda8c5167da14f294
subpackages:
- secure/bidirule
- transform
- unicode/bidi
- unicode/norm
- name: google.golang.org/genproto
version: 891aceb7c239e72692819142dfca057bdcbfcb96
version: 7f0da29060c682909f650ad8ed4e515bd74fa12a
subpackages:
- googleapis/rpc/status
- name: google.golang.org/grpc
version: f7bf885db0b7479a537ec317c6e48ce53145f3db
version: 401e0e00e4bb830a10496d64cd95e068c5bf50de
subpackages:
- balancer
- codes


+ 2
- 2
glide.yaml View File

@ -18,7 +18,7 @@ import:
- package: github.com/spf13/viper
version: v1.0.0
- package: github.com/tendermint/abci
version: 22b491bb1952125dd2fb0730d6ca8e59e310547c
version: develop
subpackages:
- client
- example/dummy
@ -55,7 +55,7 @@ import:
subpackages:
- context
- package: google.golang.org/grpc
version: v1.7.0
version: v1.7.3
testImport:
- package: github.com/go-kit/kit
subpackages:


+ 4
- 13
mempool/mempool.go View File

@ -3,6 +3,7 @@ package mempool
import (
"bytes"
"container/list"
"fmt"
"sync"
"sync/atomic"
"time"
@ -191,17 +192,7 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
// CACHE
if mem.cache.Exists(tx) {
if cb != nil {
cb(&abci.Response{
Value: &abci.Response_CheckTx{
&abci.ResponseCheckTx{
Code: abci.CodeType_BadNonce, // TODO or duplicate tx
Log: "Duplicate transaction (ignored)",
},
},
})
}
return nil // TODO: return an error (?)
return fmt.Errorf("Tx already exists in cache")
}
mem.cache.Push(tx)
// END CACHE
@ -245,7 +236,7 @@ func (mem *Mempool) resCbNormal(req *abci.Request, res *abci.Response) {
switch r := res.Value.(type) {
case *abci.Response_CheckTx:
tx := req.GetCheckTx().Tx
if r.CheckTx.Code == abci.CodeType_OK {
if r.CheckTx.Code == abci.CodeTypeOK {
mem.counter++
memTx := &mempoolTx{
counter: mem.counter,
@ -277,7 +268,7 @@ func (mem *Mempool) resCbRecheck(req *abci.Request, res *abci.Response) {
cmn.PanicSanity(cmn.Fmt("Unexpected tx response from proxy during recheck\n"+
"Expected %X, got %X", r.CheckTx.Data, memTx.tx))
}
if r.CheckTx.Code == abci.CodeType_OK {
if r.CheckTx.Code == abci.CodeTypeOK {
// Good, nothing to do.
} else {
// Tx became invalidated due to newly committed block.


+ 13
- 15
mempool/mempool_test.go View File

@ -14,6 +14,7 @@ import (
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/example/dummy"
abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
cfg "github.com/tendermint/tendermint/config"
@ -122,10 +123,10 @@ func TestSerialReap(t *testing.T) {
mempool := newMempoolWithApp(cc)
appConnCon, _ := cc.NewABCIClient()
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
if err := appConnCon.Start(); err != nil {
t.Fatalf("Error starting ABCI client: %v", err.Error())
}
err := appConnCon.Start()
require.Nil(t, err)
cacheMap := make(map[string]struct{})
deliverTxsRange := func(start, end int) {
// Deliver some txs.
for i := start; i < end; i++ {
@ -134,26 +135,23 @@ func TestSerialReap(t *testing.T) {
txBytes := make([]byte, 8)
binary.BigEndian.PutUint64(txBytes, uint64(i))
err := mempool.CheckTx(txBytes, nil)
if err != nil {
t.Fatalf("Error after CheckTx: %v", err)
_, cached := cacheMap[string(txBytes)]
if cached {
require.NotNil(t, err, "expected error for cached tx")
} else {
require.Nil(t, err, "expected no err for uncached tx")
}
cacheMap[string(txBytes)] = struct{}{}
// This will fail because not serial (incrementing)
// However, error should still be nil.
// It just won't show up on Reap().
// Duplicates are cached and should return error
err = mempool.CheckTx(txBytes, nil)
if err != nil {
t.Fatalf("Error after CheckTx: %v", err)
}
require.NotNil(t, err, "Expected error after CheckTx on duplicated tx")
}
}
reapCheck := func(exp int) {
txs := mempool.Reap(-1)
if len(txs) != exp {
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
}
require.Equal(t, len(txs), exp, cmn.Fmt("Expected to reap %v txs but got %v", exp, len(txs)))
}
updateRange := func(start, end int) {


+ 6
- 6
node/node.go View File

@ -256,20 +256,20 @@ func NewNode(config *cfg.Config,
if err != nil {
return err
}
if resQuery.Code.IsOK() {
return nil
if resQuery.IsErr() {
return resQuery
}
return errors.New(resQuery.Code.String())
return nil
})
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
if err != nil {
return err
}
if resQuery.Code.IsOK() {
return nil
if resQuery.IsErr() {
return resQuery
}
return errors.New(resQuery.Code.String())
return nil
})
}


+ 5
- 4
rpc/client/event_test.go View File

@ -6,6 +6,7 @@ import (
"github.com/stretchr/testify/require"
abci "github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/rpc/client"
@ -90,7 +91,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
// send async
txres, err := c.BroadcastTxAsync(tx)
require.Nil(err, "%+v", err)
require.True(txres.Code.IsOK())
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
// and wait for confirmation
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
@ -100,7 +101,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
require.True(ok, "%d: %#v", i, evt)
// make sure this is the proper tx
require.EqualValues(tx, txe.Tx)
require.True(txe.Result.Code.IsOK())
require.True(txe.Result.IsOK())
}
}
@ -122,7 +123,7 @@ func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
// send sync
txres, err := c.BroadcastTxSync(tx)
require.Nil(err, "%+v", err)
require.True(txres.Code.IsOK())
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
// and wait for confirmation
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
@ -132,6 +133,6 @@ func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
require.True(ok, "%d: %#v", i, evt)
// make sure this is the proper tx
require.EqualValues(tx, txe.Tx)
require.True(txe.Result.Code.IsOK())
require.True(txe.Result.IsOK())
}
}

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

@ -32,7 +32,7 @@ func (a ABCIApp) ABCIQuery(path string, data data.Bytes) (*ctypes.ResultABCIQuer
func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client.ABCIQueryOptions) (*ctypes.ResultABCIQuery, error) {
q := a.App.Query(abci.RequestQuery{data, path, opts.Height, opts.Trusted})
return &ctypes.ResultABCIQuery{q.Result()}, nil
return &ctypes.ResultABCIQuery{&q}, nil
}
func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
@ -91,7 +91,7 @@ func (m ABCIMock) ABCIQueryWithOptions(path string, data data.Bytes, opts client
return nil, err
}
resQuery := res.(abci.ResponseQuery)
return &ctypes.ResultABCIQuery{resQuery.Result()}, nil
return &ctypes.ResultABCIQuery{&resQuery}, nil
}
func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
@ -135,7 +135,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder {
type QueryArgs struct {
Path string
Data data.Bytes
Height uint64
Height int64
Trusted bool
}


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

@ -22,7 +22,7 @@ func TestABCIMock(t *testing.T) {
assert, require := assert.New(t), require.New(t)
key, value := []byte("foo"), []byte("bar")
height := uint64(10)
height := int64(10)
goodTx := types.Tx{0x01, 0xff}
badTx := types.Tx{0x12, 0x21}
@ -168,9 +168,9 @@ func TestABCIApp(t *testing.T) {
tx := fmt.Sprintf("%s=%s", key, value)
res, err := m.BroadcastTxCommit(types.Tx(tx))
require.Nil(err)
assert.True(res.CheckTx.Code.IsOK())
assert.True(res.CheckTx.IsOK())
require.NotNil(res.DeliverTx)
assert.True(res.DeliverTx.Code.IsOK())
assert.True(res.DeliverTx.IsOK())
// check the key
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})


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

@ -8,7 +8,9 @@ import (
"github.com/stretchr/testify/assert"
"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"
"github.com/tendermint/tendermint/types"
@ -110,7 +112,7 @@ func TestABCIQuery(t *testing.T) {
// wait before querying
client.WaitForHeight(c, apph, nil)
qres, err := c.ABCIQuery("/key", k)
if assert.Nil(t, err) && assert.True(t, qres.Code.IsOK()) {
if assert.Nil(t, err) && assert.True(t, qres.IsOK()) {
assert.EqualValues(t, v, qres.Value)
}
}
@ -136,7 +138,7 @@ func TestAppCalls(t *testing.T) {
k, v, tx := MakeTxKV()
bres, err := c.BroadcastTxCommit(tx)
require.Nil(err, "%d: %+v", i, err)
require.True(bres.DeliverTx.Code.IsOK())
require.True(bres.DeliverTx.IsOK())
txh := bres.Height
apph := txh + 1 // this is where the tx will be applied to the state
@ -145,7 +147,7 @@ func TestAppCalls(t *testing.T) {
t.Error(err)
}
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: true})
if assert.Nil(err) && assert.True(qres.Code.IsOK()) {
if assert.Nil(err) && assert.True(qres.IsOK()) {
// assert.Equal(k, data.GetKey()) // only returned for proofs
assert.EqualValues(v, qres.Value)
}
@ -193,7 +195,7 @@ func TestAppCalls(t *testing.T) {
// and we got a proof that works!
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
if assert.Nil(err) && assert.True(pres.Code.IsOK()) {
if assert.Nil(err) && assert.True(pres.IsOK()) {
proof, err := iavl.ReadKeyExistsProof(pres.Proof)
if assert.Nil(err) {
key := pres.Key
@ -216,7 +218,7 @@ func TestBroadcastTxSync(t *testing.T) {
_, _, tx := MakeTxKV()
bres, err := c.BroadcastTxSync(tx)
require.Nil(err, "%d: %+v", i, err)
require.True(bres.Code.IsOK())
require.Equal(bres.Code, abci.CodeTypeOK) // FIXME
require.Equal(initMempoolSize+1, mempool.Size())
@ -234,8 +236,8 @@ func TestBroadcastTxCommit(t *testing.T) {
_, _, tx := MakeTxKV()
bres, err := c.BroadcastTxCommit(tx)
require.Nil(err, "%d: %+v", i, err)
require.True(bres.CheckTx.Code.IsOK())
require.True(bres.DeliverTx.Code.IsOK())
require.True(bres.CheckTx.IsOK())
require.True(bres.DeliverTx.IsOK())
require.Equal(0, mempool.Size())
}
@ -284,7 +286,7 @@ func TestTx(t *testing.T) {
assert.EqualValues(txHeight, ptx.Height)
assert.EqualValues(tx, ptx.Tx)
assert.Zero(ptx.Index)
assert.True(ptx.TxResult.Code.IsOK())
assert.True(ptx.TxResult.IsOK())
// time to verify the proof
proof := ptx.Proof
@ -321,7 +323,7 @@ func TestTxSearch(t *testing.T) {
assert.EqualValues(t, txHeight, ptx.Height)
assert.EqualValues(t, tx, ptx.Tx)
assert.Zero(t, ptx.Index)
assert.True(t, ptx.TxResult.Code.IsOK())
assert.True(t, ptx.TxResult.IsOK())
// time to verify the proof
proof := ptx.Proof


+ 1
- 1
rpc/client/types.go View File

@ -3,7 +3,7 @@ package client
// ABCIQueryOptions can be used to provide options for ABCIQuery call other
// than the DefaultABCIQueryOptions.
type ABCIQueryOptions struct {
Height uint64
Height int64
Trusted bool
}


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

@ -45,9 +45,9 @@ import (
// |-----------+--------+---------+----------+------------------------------------------------|
// | path | string | false | false | Path to the data ("/a/b/c") |
// | data | []byte | false | true | Data |
// | height | uint64 | 0 | false | Height (0 means latest) |
// | 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 uint64, trusted bool) (*ctypes.ResultABCIQuery, error) {
func ABCIQuery(path string, data data.Bytes, height int64, trusted bool) (*ctypes.ResultABCIQuery, error) {
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
Path: path,
Data: data,
@ -59,7 +59,7 @@ func ABCIQuery(path string, data data.Bytes, height uint64, trusted bool) (*ctyp
}
logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
return &ctypes.ResultABCIQuery{
resQuery.Result(),
resQuery,
}, nil
}


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

@ -174,7 +174,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
}
checkTxRes := <-checkTxResCh
checkTxR := checkTxRes.GetCheckTx()
if checkTxR.Code != abci.CodeType_OK {
if checkTxR.Code != abci.CodeTypeOK {
// CheckTx failed!
return &ctypes.ResultBroadcastTxCommit{
CheckTx: *checkTxR,


+ 4
- 4
rpc/core/types/responses.go View File

@ -96,9 +96,9 @@ type ResultDumpConsensusState struct {
}
type ResultBroadcastTx struct {
Code abci.CodeType `json:"code"`
Data data.Bytes `json:"data"`
Log string `json:"log"`
Code uint32 `json:"code"`
Data data.Bytes `json:"data"`
Log string `json:"log"`
Hash data.Bytes `json:"hash"`
}
@ -128,7 +128,7 @@ type ResultABCIInfo struct {
}
type ResultABCIQuery struct {
*abci.ResultQuery `json:"response"`
*abci.ResponseQuery `json:"response"`
}
type ResultUnsafeFlushMempool struct{}


+ 4
- 2
state/execution.go View File

@ -54,7 +54,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
// Blocks may include invalid txs.
// reqDeliverTx := req.(abci.RequestDeliverTx)
txResult := r.DeliverTx
if txResult.Code == abci.CodeType_OK {
if txResult.Code == abci.CodeTypeOK {
validTxs++
} else {
logger.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
@ -80,6 +80,8 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
block.Hash(),
types.TM2PB.Header(block.Header),
nil,
nil,
})
if err != nil {
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
@ -95,7 +97,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
}
// End block
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{uint64(block.Height)})
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{block.Height})
if err != nil {
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
return nil, err


+ 4
- 4
state/txindex/kv/kv.go View File

@ -211,10 +211,10 @@ func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool)
return
}
func lookForHeight(conditions []query.Condition) (height uint64, index int) {
func lookForHeight(conditions []query.Condition) (height int64, index int) {
for i, c := range conditions {
if c.Tag == types.TxHeightKey {
return uint64(c.Operand.(int64)), i
return c.Operand.(int64), i
}
}
return 0, -1
@ -330,7 +330,7 @@ LOOP:
///////////////////////////////////////////////////////////////////////////////
// Keys
func startKey(c query.Condition, height uint64) []byte {
func startKey(c query.Condition, height int64) []byte {
var key string
if height > 0 {
key = fmt.Sprintf("%s/%v/%d", c.Tag, c.Operand, height)
@ -340,7 +340,7 @@ func startKey(c query.Condition, height uint64) []byte {
return []byte(key)
}
func startKeyForRange(r queryRange, height uint64) []byte {
func startKeyForRange(r queryRange, height int64) []byte {
if r.lowerBound == nil {
return []byte(fmt.Sprintf("%s", r.key))
}


+ 4
- 4
state/txindex/kv/kv_test.go View File

@ -19,7 +19,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.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
hash := tx.Hash()
batch := txindex.NewBatch(1)
@ -34,7 +34,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.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
txResult2 := &types.TxResult{1, 0, tx2, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
hash2 := tx2.Hash()
err = indexer.Index(txResult2)
@ -145,12 +145,12 @@ func TestIndexAllTags(t *testing.T) {
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
tx := types.Tx("HELLO WORLD")
return &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeType_OK, Log: "", Tags: tags}}
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.CodeType_OK, Log: "", Tags: []*abci.KVPair{}}}
txResult := &types.TxResult{1, 0, tx, abci.ResponseDeliverTx{Data: []byte{0}, Code: abci.CodeTypeOK, Log: "", Tags: []*abci.KVPair{}}}
dir, err := ioutil.TempDir("", "tx_index_db")
if err != nil {


+ 38
- 18
test/app/counter_test.sh View File

@ -14,20 +14,41 @@ TESTNAME=$1
# Send some txs
function getCode() {
set +u
R=$1
if [[ "$R" == "{}" ]]; then
set -u
if [[ "$R" == "" ]]; then
echo -1
fi
if [[ $(echo $R | jq 'has("code")') == "true" ]]; then
# this wont actually work if theres an error ...
echo "$R" | jq ".code"
else
# protobuf auto adds `omitempty` to everything so code OK and empty data/log
# will not even show when marshalled into json
# apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
echo 0
else
# this wont actually work if theres an error ...
echo "$R" | jq .code
fi
}
# build grpc client if needed
if [[ "$GRPC_BROADCAST_TX" != "" ]]; then
if [ -f grpc_client ]; then
rm grpc_client
fi
echo "... building grpc_client"
go build -o grpc_client grpc_client.go
fi
function sendTx() {
TX=$1
set +u
SHOULD_ERR=$2
if [ "$SHOULD_ERR" == "" ]; then
SHOULD_ERR=false
fi
set -u
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
RESPONSE=$(curl -s localhost:46657/broadcast_tx_commit?tx=0x"$TX")
IS_ERR=$(echo "$RESPONSE" | jq 'has("error")')
@ -36,11 +57,6 @@ function sendTx() {
RESPONSE=$(echo "$RESPONSE" | jq '.result')
else
if [ -f grpc_client ]; then
rm grpc_client
fi
echo "... building grpc_client"
go build -o grpc_client grpc_client.go
RESPONSE=$(./grpc_client "$TX")
IS_ERR=false
ERROR=""
@ -64,11 +80,20 @@ function sendTx() {
echo "TX $TX"
echo "RESPONSE $RESPONSE"
echo "ERROR $ERROR"
echo "IS_ERR $IS_ERR"
echo "----"
if $IS_ERR; then
echo "Unexpected error sending tx ($TX): $ERROR"
exit 1
if $SHOULD_ERR; then
if [[ "$IS_ERR" != "true" ]]; then
echo "Expected error sending tx ($TX)"
exit 1
fi
else
if [[ "$IS_ERR" == "true" ]]; then
echo "Unexpected error sending tx ($TX)"
exit 1
fi
fi
}
@ -86,12 +111,7 @@ fi
echo "... sending tx. expect error"
# second time should get rejected by the mempool (return error and non-zero code)
sendTx $TX
echo "CHECKTX CODE: $CHECK_TX_CODE"
if [[ "$CHECK_TX_CODE" == 0 ]]; then
echo "Got zero exit code for $TX. Expected tx to be rejected by mempool. $RESPONSE"
exit 1
fi
sendTx $TX true
echo "... sending tx. expect no error"


+ 5
- 5
types/protobuf.go View File

@ -13,9 +13,9 @@ type tm2pb struct{}
func (tm2pb) Header(header *Header) *types.Header {
return &types.Header{
ChainId: header.ChainID,
Height: uint64(header.Height),
Time: uint64(header.Time.Unix()),
NumTxs: uint64(header.NumTxs),
Height: header.Height,
Time: header.Time.Unix(),
NumTxs: int32(header.NumTxs), // XXX: overflow
LastBlockId: TM2PB.BlockID(header.LastBlockID),
LastCommitHash: header.LastCommitHash,
DataHash: header.DataHash,
@ -32,7 +32,7 @@ func (tm2pb) BlockID(blockID BlockID) *types.BlockID {
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
return &types.PartSetHeader{
Total: uint64(partSetHeader.Total),
Total: int32(partSetHeader.Total), // XXX: overflow
Hash: partSetHeader.Hash,
}
}
@ -40,7 +40,7 @@ func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
func (tm2pb) Validator(val *Validator) *types.Validator {
return &types.Validator{
PubKey: val.PubKey.Bytes(),
Power: uint64(val.VotingPower),
Power: val.VotingPower,
}
}


Loading…
Cancel
Save