mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-11 20:31:20 +00:00
@ -59,7 +59,7 @@ type validatorStub struct {
|
|||||||
types.PrivValidator
|
types.PrivValidator
|
||||||
}
|
}
|
||||||
|
|
||||||
var testMinPower = 10
|
var testMinPower int64 = 10
|
||||||
|
|
||||||
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
|
||||||
return &validatorStub{
|
return &validatorStub{
|
||||||
@ -372,7 +372,7 @@ func randConsensusNet(nValidators int, testName string, tickerFunc func() Timeou
|
|||||||
|
|
||||||
// nPeers = nValidators + nNotValidator
|
// nPeers = nValidators + nNotValidator
|
||||||
func randConsensusNetWithPeers(nValidators, nPeers int, testName string, tickerFunc func() TimeoutTicker, appFunc func() abci.Application) []*ConsensusState {
|
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)
|
css := make([]*ConsensusState, nPeers)
|
||||||
logger := consensusLogger()
|
logger := consensusLogger()
|
||||||
for i := 0; i < nPeers; i++ {
|
for i := 0; i < nPeers; i++ {
|
||||||
|
@ -8,9 +8,11 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/tendermint/abci/example/code"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -135,7 +137,7 @@ func TestRmBadTx(t *testing.T) {
|
|||||||
// CheckTx should not err, but the app should return a bad abci code
|
// CheckTx should not err, but the app should return a bad abci code
|
||||||
// and the tx should get removed from the pool
|
// and the tx should get removed from the pool
|
||||||
err := cs.mempool.CheckTx(txBytes, func(r *abci.Response) {
|
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)
|
t.Fatalf("expected checktx to return bad nonce, got %v", r)
|
||||||
}
|
}
|
||||||
checkTxRespCh <- struct{}{}
|
checkTxRespCh <- struct{}{}
|
||||||
@ -193,22 +195,22 @@ func (app *CounterApplication) DeliverTx(tx []byte) abci.ResponseDeliverTx {
|
|||||||
txValue := txAsUint64(tx)
|
txValue := txAsUint64(tx)
|
||||||
if txValue != uint64(app.txCount) {
|
if txValue != uint64(app.txCount) {
|
||||||
return abci.ResponseDeliverTx{
|
return abci.ResponseDeliverTx{
|
||||||
Code: abci.CodeType_BadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)}
|
||||||
}
|
}
|
||||||
app.txCount += 1
|
app.txCount += 1
|
||||||
return abci.ResponseDeliverTx{Code: abci.CodeType_OK}
|
return abci.ResponseDeliverTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx {
|
func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx {
|
||||||
txValue := txAsUint64(tx)
|
txValue := txAsUint64(tx)
|
||||||
if txValue != uint64(app.mempoolTxCount) {
|
if txValue != uint64(app.mempoolTxCount) {
|
||||||
return abci.ResponseCheckTx{
|
return abci.ResponseCheckTx{
|
||||||
Code: abci.CodeType_BadNonce,
|
Code: code.CodeTypeBadNonce,
|
||||||
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)}
|
Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)}
|
||||||
}
|
}
|
||||||
app.mempoolTxCount += 1
|
app.mempoolTxCount += 1
|
||||||
return abci.ResponseCheckTx{Code: abci.CodeType_OK}
|
return abci.ResponseCheckTx{Code: code.CodeTypeOK}
|
||||||
}
|
}
|
||||||
|
|
||||||
func txAsUint64(tx []byte) uint64 {
|
func txAsUint64(tx []byte) uint64 {
|
||||||
@ -220,10 +222,10 @@ func txAsUint64(tx []byte) uint64 {
|
|||||||
func (app *CounterApplication) Commit() abci.ResponseCommit {
|
func (app *CounterApplication) Commit() abci.ResponseCommit {
|
||||||
app.mempoolTxCount = app.txCount
|
app.mempoolTxCount = app.txCount
|
||||||
if app.txCount == 0 {
|
if app.txCount == 0 {
|
||||||
return abci.ResponseCommit{Code: abci.CodeType_OK}
|
return abci.ResponseCommit{Code: code.CodeTypeOK}
|
||||||
} else {
|
} else {
|
||||||
hash := make([]byte, 8)
|
hash := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
|
||||||
return abci.ResponseCommit{Code: abci.CodeType_OK, Data: hash}
|
return abci.ResponseCommit{Code: code.CodeTypeOK, Data: hash}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func TestValidatorSetChanges(t *testing.T) {
|
|||||||
t.Log("---------------------------- Testing adding one validator")
|
t.Log("---------------------------- Testing adding one validator")
|
||||||
|
|
||||||
newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
|
newValidatorPubKey1 := css[nVals].privValidator.GetPubKey()
|
||||||
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), uint64(testMinPower))
|
newValidatorTx1 := dummy.MakeValSetChangeTx(newValidatorPubKey1.Bytes(), testMinPower)
|
||||||
|
|
||||||
// wait till everyone makes block 2
|
// wait till everyone makes block 2
|
||||||
// ensure the commit includes all validators
|
// ensure the commit includes all validators
|
||||||
@ -251,10 +251,10 @@ func TestValidatorSetChanges(t *testing.T) {
|
|||||||
t.Log("---------------------------- Testing adding two validators at once")
|
t.Log("---------------------------- Testing adding two validators at once")
|
||||||
|
|
||||||
newValidatorPubKey2 := css[nVals+1].privValidator.GetPubKey()
|
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()
|
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, newValidatorTx2, newValidatorTx3)
|
||||||
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css)
|
waitForAndValidateBlock(t, nPeers, activeVals, eventChans, css)
|
||||||
|
@ -400,5 +400,5 @@ func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mock *mockProxyApp) Commit() abci.ResponseCommit {
|
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}
|
||||||
}
|
}
|
||||||
|
27
glide.lock
generated
27
glide.lock
generated
@ -1,8 +1,8 @@
|
|||||||
hash: 8c38726da2666831affa40474117d3cef5dad083176e81fb013d7e8493b83e6f
|
hash: b0397f8c86e8131753fce91514314fe871ffb2562452a9f2125dbcd3cea600c8
|
||||||
updated: 2017-12-01T02:14:22.08770964Z
|
updated: 2017-12-02T23:34:41.775549968-05:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/btcsuite/btcd
|
- name: github.com/btcsuite/btcd
|
||||||
version: 8cea3866d0f7fb12d567a20744942c0d078c7d15
|
version: 2e60448ffcc6bf78332d1fe590260095f554dd78
|
||||||
subpackages:
|
subpackages:
|
||||||
- btcec
|
- btcec
|
||||||
- name: github.com/ebuchman/fail-test
|
- name: github.com/ebuchman/fail-test
|
||||||
@ -28,7 +28,9 @@ imports:
|
|||||||
- name: github.com/gogo/protobuf
|
- name: github.com/gogo/protobuf
|
||||||
version: 342cbe0a04158f6dcb03ca0079991a51a4248c02
|
version: 342cbe0a04158f6dcb03ca0079991a51a4248c02
|
||||||
subpackages:
|
subpackages:
|
||||||
|
- gogoproto
|
||||||
- proto
|
- proto
|
||||||
|
- protoc-gen-gogo/descriptor
|
||||||
- name: github.com/golang/protobuf
|
- name: github.com/golang/protobuf
|
||||||
version: 1e59b77b52bf8e4b449a57e6f79f21226d571845
|
version: 1e59b77b52bf8e4b449a57e6f79f21226d571845
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -67,7 +69,7 @@ imports:
|
|||||||
- name: github.com/pkg/errors
|
- name: github.com/pkg/errors
|
||||||
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
version: 645ef00459ed84a119197bfb8d8205042c6df63d
|
||||||
- name: github.com/rcrowley/go-metrics
|
- name: github.com/rcrowley/go-metrics
|
||||||
version: 1f30fe9094a513ce4c700b9a54458bbb0c96996c
|
version: e181e095bae94582363434144c61a9653aff6e50
|
||||||
- name: github.com/spf13/afero
|
- name: github.com/spf13/afero
|
||||||
version: 8d919cbe7e2627e417f3e45c3c0e489a5b7e2536
|
version: 8d919cbe7e2627e417f3e45c3c0e489a5b7e2536
|
||||||
subpackages:
|
subpackages:
|
||||||
@ -98,9 +100,10 @@ imports:
|
|||||||
- leveldb/table
|
- leveldb/table
|
||||||
- leveldb/util
|
- leveldb/util
|
||||||
- name: github.com/tendermint/abci
|
- name: github.com/tendermint/abci
|
||||||
version: 22b491bb1952125dd2fb0730d6ca8e59e310547c
|
version: 48413b4839781c5c4bf96049a4b39f210ceb88c3
|
||||||
subpackages:
|
subpackages:
|
||||||
- client
|
- client
|
||||||
|
- example/code
|
||||||
- example/counter
|
- example/counter
|
||||||
- example/dummy
|
- example/dummy
|
||||||
- server
|
- server
|
||||||
@ -113,7 +116,7 @@ imports:
|
|||||||
- name: github.com/tendermint/go-crypto
|
- name: github.com/tendermint/go-crypto
|
||||||
version: dd20358a264c772b4a83e477b0cfce4c88a7001d
|
version: dd20358a264c772b4a83e477b0cfce4c88a7001d
|
||||||
- name: github.com/tendermint/go-wire
|
- name: github.com/tendermint/go-wire
|
||||||
version: 5ab49b4c6ad674da6b81442911cf713ef0afb544
|
version: 217a3c439f6497890d232ff5ed24084b43d9bfb3
|
||||||
subpackages:
|
subpackages:
|
||||||
- data
|
- data
|
||||||
- data/base58
|
- data/base58
|
||||||
@ -138,7 +141,7 @@ imports:
|
|||||||
- pubsub/query
|
- pubsub/query
|
||||||
- test
|
- test
|
||||||
- name: golang.org/x/crypto
|
- name: golang.org/x/crypto
|
||||||
version: 9f005a07e0d31d45e6656d241bb5c0f2efd4bc94
|
version: 94eea52f7b742c7cbe0b03b22f0c4c8631ece122
|
||||||
subpackages:
|
subpackages:
|
||||||
- curve25519
|
- curve25519
|
||||||
- nacl/box
|
- nacl/box
|
||||||
@ -149,7 +152,7 @@ imports:
|
|||||||
- ripemd160
|
- ripemd160
|
||||||
- salsa20/salsa
|
- salsa20/salsa
|
||||||
- name: golang.org/x/net
|
- name: golang.org/x/net
|
||||||
version: 9dfe39835686865bff950a07b394c12a98ddc811
|
version: a8b9294777976932365dabb6640cf1468d95c70f
|
||||||
subpackages:
|
subpackages:
|
||||||
- context
|
- context
|
||||||
- http2
|
- http2
|
||||||
@ -159,22 +162,22 @@ imports:
|
|||||||
- lex/httplex
|
- lex/httplex
|
||||||
- trace
|
- trace
|
||||||
- name: golang.org/x/sys
|
- name: golang.org/x/sys
|
||||||
version: b98136db334ff9cb24f28a68e3be3cb6608f7630
|
version: 8b4580aae2a0dd0c231a45d3ccb8434ff533b840
|
||||||
subpackages:
|
subpackages:
|
||||||
- unix
|
- unix
|
||||||
- name: golang.org/x/text
|
- name: golang.org/x/text
|
||||||
version: 88f656faf3f37f690df1a32515b479415e1a6769
|
version: 75cc3cad82b5f47d3fb229ddda8c5167da14f294
|
||||||
subpackages:
|
subpackages:
|
||||||
- secure/bidirule
|
- secure/bidirule
|
||||||
- transform
|
- transform
|
||||||
- unicode/bidi
|
- unicode/bidi
|
||||||
- unicode/norm
|
- unicode/norm
|
||||||
- name: google.golang.org/genproto
|
- name: google.golang.org/genproto
|
||||||
version: 891aceb7c239e72692819142dfca057bdcbfcb96
|
version: 7f0da29060c682909f650ad8ed4e515bd74fa12a
|
||||||
subpackages:
|
subpackages:
|
||||||
- googleapis/rpc/status
|
- googleapis/rpc/status
|
||||||
- name: google.golang.org/grpc
|
- name: google.golang.org/grpc
|
||||||
version: f7bf885db0b7479a537ec317c6e48ce53145f3db
|
version: 401e0e00e4bb830a10496d64cd95e068c5bf50de
|
||||||
subpackages:
|
subpackages:
|
||||||
- balancer
|
- balancer
|
||||||
- codes
|
- codes
|
||||||
|
@ -18,7 +18,7 @@ import:
|
|||||||
- package: github.com/spf13/viper
|
- package: github.com/spf13/viper
|
||||||
version: v1.0.0
|
version: v1.0.0
|
||||||
- package: github.com/tendermint/abci
|
- package: github.com/tendermint/abci
|
||||||
version: 22b491bb1952125dd2fb0730d6ca8e59e310547c
|
version: develop
|
||||||
subpackages:
|
subpackages:
|
||||||
- client
|
- client
|
||||||
- example/dummy
|
- example/dummy
|
||||||
@ -55,7 +55,7 @@ import:
|
|||||||
subpackages:
|
subpackages:
|
||||||
- context
|
- context
|
||||||
- package: google.golang.org/grpc
|
- package: google.golang.org/grpc
|
||||||
version: v1.7.0
|
version: v1.7.3
|
||||||
testImport:
|
testImport:
|
||||||
- package: github.com/go-kit/kit
|
- package: github.com/go-kit/kit
|
||||||
subpackages:
|
subpackages:
|
||||||
|
@ -3,6 +3,7 @@ package mempool
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"container/list"
|
"container/list"
|
||||||
|
"fmt"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -191,17 +192,7 @@ func (mem *Mempool) CheckTx(tx types.Tx, cb func(*abci.Response)) (err error) {
|
|||||||
|
|
||||||
// CACHE
|
// CACHE
|
||||||
if mem.cache.Exists(tx) {
|
if mem.cache.Exists(tx) {
|
||||||
if cb != nil {
|
return fmt.Errorf("Tx already exists in cache")
|
||||||
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 (?)
|
|
||||||
}
|
}
|
||||||
mem.cache.Push(tx)
|
mem.cache.Push(tx)
|
||||||
// END CACHE
|
// END CACHE
|
||||||
@ -245,7 +236,7 @@ func (mem *Mempool) resCbNormal(req *abci.Request, res *abci.Response) {
|
|||||||
switch r := res.Value.(type) {
|
switch r := res.Value.(type) {
|
||||||
case *abci.Response_CheckTx:
|
case *abci.Response_CheckTx:
|
||||||
tx := req.GetCheckTx().Tx
|
tx := req.GetCheckTx().Tx
|
||||||
if r.CheckTx.Code == abci.CodeType_OK {
|
if r.CheckTx.Code == abci.CodeTypeOK {
|
||||||
mem.counter++
|
mem.counter++
|
||||||
memTx := &mempoolTx{
|
memTx := &mempoolTx{
|
||||||
counter: mem.counter,
|
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"+
|
cmn.PanicSanity(cmn.Fmt("Unexpected tx response from proxy during recheck\n"+
|
||||||
"Expected %X, got %X", r.CheckTx.Data, memTx.tx))
|
"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.
|
// Good, nothing to do.
|
||||||
} else {
|
} else {
|
||||||
// Tx became invalidated due to newly committed block.
|
// Tx became invalidated due to newly committed block.
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/tendermint/abci/example/counter"
|
"github.com/tendermint/abci/example/counter"
|
||||||
"github.com/tendermint/abci/example/dummy"
|
"github.com/tendermint/abci/example/dummy"
|
||||||
abci "github.com/tendermint/abci/types"
|
abci "github.com/tendermint/abci/types"
|
||||||
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
"github.com/tendermint/tmlibs/log"
|
"github.com/tendermint/tmlibs/log"
|
||||||
|
|
||||||
cfg "github.com/tendermint/tendermint/config"
|
cfg "github.com/tendermint/tendermint/config"
|
||||||
@ -122,10 +123,10 @@ func TestSerialReap(t *testing.T) {
|
|||||||
mempool := newMempoolWithApp(cc)
|
mempool := newMempoolWithApp(cc)
|
||||||
appConnCon, _ := cc.NewABCIClient()
|
appConnCon, _ := cc.NewABCIClient()
|
||||||
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
|
appConnCon.SetLogger(log.TestingLogger().With("module", "abci-client", "connection", "consensus"))
|
||||||
if err := appConnCon.Start(); err != nil {
|
err := appConnCon.Start()
|
||||||
t.Fatalf("Error starting ABCI client: %v", err.Error())
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
|
cacheMap := make(map[string]struct{})
|
||||||
deliverTxsRange := func(start, end int) {
|
deliverTxsRange := func(start, end int) {
|
||||||
// Deliver some txs.
|
// Deliver some txs.
|
||||||
for i := start; i < end; i++ {
|
for i := start; i < end; i++ {
|
||||||
@ -134,26 +135,23 @@ func TestSerialReap(t *testing.T) {
|
|||||||
txBytes := make([]byte, 8)
|
txBytes := make([]byte, 8)
|
||||||
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
binary.BigEndian.PutUint64(txBytes, uint64(i))
|
||||||
err := mempool.CheckTx(txBytes, nil)
|
err := mempool.CheckTx(txBytes, nil)
|
||||||
if err != nil {
|
_, cached := cacheMap[string(txBytes)]
|
||||||
t.Fatalf("Error after CheckTx: %v", err)
|
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)
|
// Duplicates are cached and should return error
|
||||||
// However, error should still be nil.
|
|
||||||
// It just won't show up on Reap().
|
|
||||||
err = mempool.CheckTx(txBytes, nil)
|
err = mempool.CheckTx(txBytes, nil)
|
||||||
if err != nil {
|
require.NotNil(t, err, "Expected error after CheckTx on duplicated tx")
|
||||||
t.Fatalf("Error after CheckTx: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reapCheck := func(exp int) {
|
reapCheck := func(exp int) {
|
||||||
txs := mempool.Reap(-1)
|
txs := mempool.Reap(-1)
|
||||||
if len(txs) != exp {
|
require.Equal(t, len(txs), exp, cmn.Fmt("Expected to reap %v txs but got %v", exp, len(txs)))
|
||||||
t.Fatalf("Expected to reap %v txs but got %v", exp, len(txs))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
updateRange := func(start, end int) {
|
updateRange := func(start, end int) {
|
||||||
|
12
node/node.go
12
node/node.go
@ -256,20 +256,20 @@ func NewNode(config *cfg.Config,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resQuery.Code.IsOK() {
|
if resQuery.IsErr() {
|
||||||
return nil
|
return resQuery
|
||||||
}
|
}
|
||||||
return errors.New(resQuery.Code.String())
|
return nil
|
||||||
})
|
})
|
||||||
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
|
sw.SetPubKeyFilter(func(pubkey crypto.PubKeyEd25519) error {
|
||||||
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
|
resQuery, err := proxyApp.Query().QuerySync(abci.RequestQuery{Path: cmn.Fmt("/p2p/filter/pubkey/%X", pubkey.Bytes())})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if resQuery.Code.IsOK() {
|
if resQuery.IsErr() {
|
||||||
return nil
|
return resQuery
|
||||||
}
|
}
|
||||||
return errors.New(resQuery.Code.String())
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
cmn "github.com/tendermint/tmlibs/common"
|
cmn "github.com/tendermint/tmlibs/common"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
@ -90,7 +91,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
|||||||
// send async
|
// send async
|
||||||
txres, err := c.BroadcastTxAsync(tx)
|
txres, err := c.BroadcastTxAsync(tx)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
require.True(txres.Code.IsOK())
|
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
|
|
||||||
// and wait for confirmation
|
// and wait for confirmation
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
@ -100,7 +101,7 @@ func TestTxEventsSentWithBroadcastTxAsync(t *testing.T) {
|
|||||||
require.True(ok, "%d: %#v", i, evt)
|
require.True(ok, "%d: %#v", i, evt)
|
||||||
// make sure this is the proper tx
|
// make sure this is the proper tx
|
||||||
require.EqualValues(tx, txe.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
|
// send sync
|
||||||
txres, err := c.BroadcastTxSync(tx)
|
txres, err := c.BroadcastTxSync(tx)
|
||||||
require.Nil(err, "%+v", err)
|
require.Nil(err, "%+v", err)
|
||||||
require.True(txres.Code.IsOK())
|
require.Equal(txres.Code, abci.CodeTypeOK) // FIXME
|
||||||
|
|
||||||
// and wait for confirmation
|
// and wait for confirmation
|
||||||
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
evt, err := client.WaitForOneEvent(c, evtTyp, waitForEventTimeout)
|
||||||
@ -132,6 +133,6 @@ func TestTxEventsSentWithBroadcastTxSync(t *testing.T) {
|
|||||||
require.True(ok, "%d: %#v", i, evt)
|
require.True(ok, "%d: %#v", i, evt)
|
||||||
// make sure this is the proper tx
|
// make sure this is the proper tx
|
||||||
require.EqualValues(tx, txe.Tx)
|
require.EqualValues(tx, txe.Tx)
|
||||||
require.True(txe.Result.Code.IsOK())
|
require.True(txe.Result.IsOK())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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) {
|
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})
|
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) {
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
resQuery := res.(abci.ResponseQuery)
|
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) {
|
func (m ABCIMock) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
||||||
@ -135,7 +135,7 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder {
|
|||||||
type QueryArgs struct {
|
type QueryArgs struct {
|
||||||
Path string
|
Path string
|
||||||
Data data.Bytes
|
Data data.Bytes
|
||||||
Height uint64
|
Height int64
|
||||||
Trusted bool
|
Trusted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ func TestABCIMock(t *testing.T) {
|
|||||||
assert, require := assert.New(t), require.New(t)
|
assert, require := assert.New(t), require.New(t)
|
||||||
|
|
||||||
key, value := []byte("foo"), []byte("bar")
|
key, value := []byte("foo"), []byte("bar")
|
||||||
height := uint64(10)
|
height := int64(10)
|
||||||
goodTx := types.Tx{0x01, 0xff}
|
goodTx := types.Tx{0x01, 0xff}
|
||||||
badTx := types.Tx{0x12, 0x21}
|
badTx := types.Tx{0x12, 0x21}
|
||||||
|
|
||||||
@ -168,9 +168,9 @@ func TestABCIApp(t *testing.T) {
|
|||||||
tx := fmt.Sprintf("%s=%s", key, value)
|
tx := fmt.Sprintf("%s=%s", key, value)
|
||||||
res, err := m.BroadcastTxCommit(types.Tx(tx))
|
res, err := m.BroadcastTxCommit(types.Tx(tx))
|
||||||
require.Nil(err)
|
require.Nil(err)
|
||||||
assert.True(res.CheckTx.Code.IsOK())
|
assert.True(res.CheckTx.IsOK())
|
||||||
require.NotNil(res.DeliverTx)
|
require.NotNil(res.DeliverTx)
|
||||||
assert.True(res.DeliverTx.Code.IsOK())
|
assert.True(res.DeliverTx.IsOK())
|
||||||
|
|
||||||
// check the key
|
// check the key
|
||||||
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
|
qres, err := m.ABCIQueryWithOptions("/key", data.Bytes(key), client.ABCIQueryOptions{Trusted: true})
|
||||||
|
@ -8,7 +8,9 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
abci "github.com/tendermint/abci/types"
|
||||||
"github.com/tendermint/iavl"
|
"github.com/tendermint/iavl"
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/rpc/client"
|
"github.com/tendermint/tendermint/rpc/client"
|
||||||
rpctest "github.com/tendermint/tendermint/rpc/test"
|
rpctest "github.com/tendermint/tendermint/rpc/test"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
@ -110,7 +112,7 @@ func TestABCIQuery(t *testing.T) {
|
|||||||
// wait before querying
|
// wait before querying
|
||||||
client.WaitForHeight(c, apph, nil)
|
client.WaitForHeight(c, apph, nil)
|
||||||
qres, err := c.ABCIQuery("/key", k)
|
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)
|
assert.EqualValues(t, v, qres.Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -136,7 +138,7 @@ func TestAppCalls(t *testing.T) {
|
|||||||
k, v, tx := MakeTxKV()
|
k, v, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxCommit(tx)
|
bres, err := c.BroadcastTxCommit(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(err, "%d: %+v", i, err)
|
||||||
require.True(bres.DeliverTx.Code.IsOK())
|
require.True(bres.DeliverTx.IsOK())
|
||||||
txh := bres.Height
|
txh := bres.Height
|
||||||
apph := txh + 1 // this is where the tx will be applied to the state
|
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)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
qres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: true})
|
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.Equal(k, data.GetKey()) // only returned for proofs
|
||||||
assert.EqualValues(v, qres.Value)
|
assert.EqualValues(v, qres.Value)
|
||||||
}
|
}
|
||||||
@ -193,7 +195,7 @@ func TestAppCalls(t *testing.T) {
|
|||||||
|
|
||||||
// and we got a proof that works!
|
// and we got a proof that works!
|
||||||
pres, err := c.ABCIQueryWithOptions("/key", k, client.ABCIQueryOptions{Trusted: false})
|
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)
|
proof, err := iavl.ReadKeyExistsProof(pres.Proof)
|
||||||
if assert.Nil(err) {
|
if assert.Nil(err) {
|
||||||
key := pres.Key
|
key := pres.Key
|
||||||
@ -216,7 +218,7 @@ func TestBroadcastTxSync(t *testing.T) {
|
|||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxSync(tx)
|
bres, err := c.BroadcastTxSync(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
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())
|
require.Equal(initMempoolSize+1, mempool.Size())
|
||||||
|
|
||||||
@ -234,8 +236,8 @@ func TestBroadcastTxCommit(t *testing.T) {
|
|||||||
_, _, tx := MakeTxKV()
|
_, _, tx := MakeTxKV()
|
||||||
bres, err := c.BroadcastTxCommit(tx)
|
bres, err := c.BroadcastTxCommit(tx)
|
||||||
require.Nil(err, "%d: %+v", i, err)
|
require.Nil(err, "%d: %+v", i, err)
|
||||||
require.True(bres.CheckTx.Code.IsOK())
|
require.True(bres.CheckTx.IsOK())
|
||||||
require.True(bres.DeliverTx.Code.IsOK())
|
require.True(bres.DeliverTx.IsOK())
|
||||||
|
|
||||||
require.Equal(0, mempool.Size())
|
require.Equal(0, mempool.Size())
|
||||||
}
|
}
|
||||||
@ -284,7 +286,7 @@ func TestTx(t *testing.T) {
|
|||||||
assert.EqualValues(txHeight, ptx.Height)
|
assert.EqualValues(txHeight, ptx.Height)
|
||||||
assert.EqualValues(tx, ptx.Tx)
|
assert.EqualValues(tx, ptx.Tx)
|
||||||
assert.Zero(ptx.Index)
|
assert.Zero(ptx.Index)
|
||||||
assert.True(ptx.TxResult.Code.IsOK())
|
assert.True(ptx.TxResult.IsOK())
|
||||||
|
|
||||||
// time to verify the proof
|
// time to verify the proof
|
||||||
proof := ptx.Proof
|
proof := ptx.Proof
|
||||||
@ -321,7 +323,7 @@ func TestTxSearch(t *testing.T) {
|
|||||||
assert.EqualValues(t, txHeight, ptx.Height)
|
assert.EqualValues(t, txHeight, ptx.Height)
|
||||||
assert.EqualValues(t, tx, ptx.Tx)
|
assert.EqualValues(t, tx, ptx.Tx)
|
||||||
assert.Zero(t, ptx.Index)
|
assert.Zero(t, ptx.Index)
|
||||||
assert.True(t, ptx.TxResult.Code.IsOK())
|
assert.True(t, ptx.TxResult.IsOK())
|
||||||
|
|
||||||
// time to verify the proof
|
// time to verify the proof
|
||||||
proof := ptx.Proof
|
proof := ptx.Proof
|
||||||
|
@ -3,7 +3,7 @@ package client
|
|||||||
// ABCIQueryOptions can be used to provide options for ABCIQuery call other
|
// ABCIQueryOptions can be used to provide options for ABCIQuery call other
|
||||||
// than the DefaultABCIQueryOptions.
|
// than the DefaultABCIQueryOptions.
|
||||||
type ABCIQueryOptions struct {
|
type ABCIQueryOptions struct {
|
||||||
Height uint64
|
Height int64
|
||||||
Trusted bool
|
Trusted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,9 +45,9 @@ import (
|
|||||||
// |-----------+--------+---------+----------+------------------------------------------------|
|
// |-----------+--------+---------+----------+------------------------------------------------|
|
||||||
// | path | string | false | false | Path to the data ("/a/b/c") |
|
// | path | string | false | false | Path to the data ("/a/b/c") |
|
||||||
// | data | []byte | false | true | Data |
|
// | 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 |
|
// | 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{
|
resQuery, err := proxyAppQuery.QuerySync(abci.RequestQuery{
|
||||||
Path: path,
|
Path: path,
|
||||||
Data: data,
|
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)
|
logger.Info("ABCIQuery", "path", path, "data", data, "result", resQuery)
|
||||||
return &ctypes.ResultABCIQuery{
|
return &ctypes.ResultABCIQuery{
|
||||||
resQuery.Result(),
|
resQuery,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) {
|
|||||||
}
|
}
|
||||||
checkTxRes := <-checkTxResCh
|
checkTxRes := <-checkTxResCh
|
||||||
checkTxR := checkTxRes.GetCheckTx()
|
checkTxR := checkTxRes.GetCheckTx()
|
||||||
if checkTxR.Code != abci.CodeType_OK {
|
if checkTxR.Code != abci.CodeTypeOK {
|
||||||
// CheckTx failed!
|
// CheckTx failed!
|
||||||
return &ctypes.ResultBroadcastTxCommit{
|
return &ctypes.ResultBroadcastTxCommit{
|
||||||
CheckTx: *checkTxR,
|
CheckTx: *checkTxR,
|
||||||
|
@ -96,9 +96,9 @@ type ResultDumpConsensusState struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResultBroadcastTx struct {
|
type ResultBroadcastTx struct {
|
||||||
Code abci.CodeType `json:"code"`
|
Code uint32 `json:"code"`
|
||||||
Data data.Bytes `json:"data"`
|
Data data.Bytes `json:"data"`
|
||||||
Log string `json:"log"`
|
Log string `json:"log"`
|
||||||
|
|
||||||
Hash data.Bytes `json:"hash"`
|
Hash data.Bytes `json:"hash"`
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ type ResultABCIInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ResultABCIQuery struct {
|
type ResultABCIQuery struct {
|
||||||
*abci.ResultQuery `json:"response"`
|
*abci.ResponseQuery `json:"response"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultUnsafeFlushMempool struct{}
|
type ResultUnsafeFlushMempool struct{}
|
||||||
|
@ -54,7 +54,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
// Blocks may include invalid txs.
|
// Blocks may include invalid txs.
|
||||||
// reqDeliverTx := req.(abci.RequestDeliverTx)
|
// reqDeliverTx := req.(abci.RequestDeliverTx)
|
||||||
txResult := r.DeliverTx
|
txResult := r.DeliverTx
|
||||||
if txResult.Code == abci.CodeType_OK {
|
if txResult.Code == abci.CodeTypeOK {
|
||||||
validTxs++
|
validTxs++
|
||||||
} else {
|
} else {
|
||||||
logger.Debug("Invalid tx", "code", txResult.Code, "log", txResult.Log)
|
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{
|
_, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{
|
||||||
block.Hash(),
|
block.Hash(),
|
||||||
types.TM2PB.Header(block.Header),
|
types.TM2PB.Header(block.Header),
|
||||||
|
nil,
|
||||||
|
nil,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
|
logger.Error("Error in proxyAppConn.BeginBlock", "err", err)
|
||||||
@ -95,7 +97,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p
|
|||||||
}
|
}
|
||||||
|
|
||||||
// End block
|
// End block
|
||||||
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{uint64(block.Height)})
|
abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{block.Height})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
|
logger.Error("Error in proxyAppConn.EndBlock", "err", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -211,10 +211,10 @@ func lookForHash(conditions []query.Condition) (hash []byte, err error, ok bool)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func lookForHeight(conditions []query.Condition) (height uint64, index int) {
|
func lookForHeight(conditions []query.Condition) (height int64, index int) {
|
||||||
for i, c := range conditions {
|
for i, c := range conditions {
|
||||||
if c.Tag == types.TxHeightKey {
|
if c.Tag == types.TxHeightKey {
|
||||||
return uint64(c.Operand.(int64)), i
|
return c.Operand.(int64), i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, -1
|
return 0, -1
|
||||||
@ -330,7 +330,7 @@ LOOP:
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Keys
|
// Keys
|
||||||
|
|
||||||
func startKey(c query.Condition, height uint64) []byte {
|
func startKey(c query.Condition, height int64) []byte {
|
||||||
var key string
|
var key string
|
||||||
if height > 0 {
|
if height > 0 {
|
||||||
key = fmt.Sprintf("%s/%v/%d", c.Tag, c.Operand, height)
|
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)
|
return []byte(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
func startKeyForRange(r queryRange, height uint64) []byte {
|
func startKeyForRange(r queryRange, height int64) []byte {
|
||||||
if r.lowerBound == nil {
|
if r.lowerBound == nil {
|
||||||
return []byte(fmt.Sprintf("%s", r.key))
|
return []byte(fmt.Sprintf("%s", r.key))
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ func TestTxIndex(t *testing.T) {
|
|||||||
indexer := NewTxIndex(db.NewMemDB())
|
indexer := NewTxIndex(db.NewMemDB())
|
||||||
|
|
||||||
tx := types.Tx("HELLO WORLD")
|
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()
|
hash := tx.Hash()
|
||||||
|
|
||||||
batch := txindex.NewBatch(1)
|
batch := txindex.NewBatch(1)
|
||||||
@ -34,7 +34,7 @@ func TestTxIndex(t *testing.T) {
|
|||||||
assert.Equal(t, txResult, loadedTxResult)
|
assert.Equal(t, txResult, loadedTxResult)
|
||||||
|
|
||||||
tx2 := types.Tx("BYE BYE WORLD")
|
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()
|
hash2 := tx2.Hash()
|
||||||
|
|
||||||
err = indexer.Index(txResult2)
|
err = indexer.Index(txResult2)
|
||||||
@ -145,12 +145,12 @@ func TestIndexAllTags(t *testing.T) {
|
|||||||
|
|
||||||
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
|
func txResultWithTags(tags []*abci.KVPair) *types.TxResult {
|
||||||
tx := types.Tx("HELLO WORLD")
|
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) {
|
func benchmarkTxIndex(txsCount int, b *testing.B) {
|
||||||
tx := types.Tx("HELLO WORLD")
|
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")
|
dir, err := ioutil.TempDir("", "tx_index_db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,20 +14,41 @@ TESTNAME=$1
|
|||||||
# Send some txs
|
# Send some txs
|
||||||
|
|
||||||
function getCode() {
|
function getCode() {
|
||||||
|
set +u
|
||||||
R=$1
|
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
|
# protobuf auto adds `omitempty` to everything so code OK and empty data/log
|
||||||
# will not even show when marshalled into json
|
# will not even show when marshalled into json
|
||||||
# apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
|
# apparently we can use github.com/golang/protobuf/jsonpb to do the marshalling ...
|
||||||
echo 0
|
echo 0
|
||||||
else
|
|
||||||
# this wont actually work if theres an error ...
|
|
||||||
echo "$R" | jq .code
|
|
||||||
fi
|
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() {
|
function sendTx() {
|
||||||
TX=$1
|
TX=$1
|
||||||
|
set +u
|
||||||
|
SHOULD_ERR=$2
|
||||||
|
if [ "$SHOULD_ERR" == "" ]; then
|
||||||
|
SHOULD_ERR=false
|
||||||
|
fi
|
||||||
|
set -u
|
||||||
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
|
if [[ "$GRPC_BROADCAST_TX" == "" ]]; then
|
||||||
RESPONSE=$(curl -s localhost:46657/broadcast_tx_commit?tx=0x"$TX")
|
RESPONSE=$(curl -s localhost:46657/broadcast_tx_commit?tx=0x"$TX")
|
||||||
IS_ERR=$(echo "$RESPONSE" | jq 'has("error")')
|
IS_ERR=$(echo "$RESPONSE" | jq 'has("error")')
|
||||||
@ -36,11 +57,6 @@ function sendTx() {
|
|||||||
|
|
||||||
RESPONSE=$(echo "$RESPONSE" | jq '.result')
|
RESPONSE=$(echo "$RESPONSE" | jq '.result')
|
||||||
else
|
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")
|
RESPONSE=$(./grpc_client "$TX")
|
||||||
IS_ERR=false
|
IS_ERR=false
|
||||||
ERROR=""
|
ERROR=""
|
||||||
@ -64,11 +80,20 @@ function sendTx() {
|
|||||||
echo "TX $TX"
|
echo "TX $TX"
|
||||||
echo "RESPONSE $RESPONSE"
|
echo "RESPONSE $RESPONSE"
|
||||||
echo "ERROR $ERROR"
|
echo "ERROR $ERROR"
|
||||||
|
echo "IS_ERR $IS_ERR"
|
||||||
echo "----"
|
echo "----"
|
||||||
|
|
||||||
if $IS_ERR; then
|
if $SHOULD_ERR; then
|
||||||
echo "Unexpected error sending tx ($TX): $ERROR"
|
if [[ "$IS_ERR" != "true" ]]; then
|
||||||
exit 1
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +111,7 @@ fi
|
|||||||
echo "... sending tx. expect error"
|
echo "... sending tx. expect error"
|
||||||
|
|
||||||
# second time should get rejected by the mempool (return error and non-zero code)
|
# second time should get rejected by the mempool (return error and non-zero code)
|
||||||
sendTx $TX
|
sendTx $TX true
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
echo "... sending tx. expect no error"
|
echo "... sending tx. expect no error"
|
||||||
|
@ -13,9 +13,9 @@ type tm2pb struct{}
|
|||||||
func (tm2pb) Header(header *Header) *types.Header {
|
func (tm2pb) Header(header *Header) *types.Header {
|
||||||
return &types.Header{
|
return &types.Header{
|
||||||
ChainId: header.ChainID,
|
ChainId: header.ChainID,
|
||||||
Height: uint64(header.Height),
|
Height: header.Height,
|
||||||
Time: uint64(header.Time.Unix()),
|
Time: header.Time.Unix(),
|
||||||
NumTxs: uint64(header.NumTxs),
|
NumTxs: int32(header.NumTxs), // XXX: overflow
|
||||||
LastBlockId: TM2PB.BlockID(header.LastBlockID),
|
LastBlockId: TM2PB.BlockID(header.LastBlockID),
|
||||||
LastCommitHash: header.LastCommitHash,
|
LastCommitHash: header.LastCommitHash,
|
||||||
DataHash: header.DataHash,
|
DataHash: header.DataHash,
|
||||||
@ -32,7 +32,7 @@ func (tm2pb) BlockID(blockID BlockID) *types.BlockID {
|
|||||||
|
|
||||||
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
|
func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
|
||||||
return &types.PartSetHeader{
|
return &types.PartSetHeader{
|
||||||
Total: uint64(partSetHeader.Total),
|
Total: int32(partSetHeader.Total), // XXX: overflow
|
||||||
Hash: partSetHeader.Hash,
|
Hash: partSetHeader.Hash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +40,7 @@ func (tm2pb) PartSetHeader(partSetHeader PartSetHeader) *types.PartSetHeader {
|
|||||||
func (tm2pb) Validator(val *Validator) *types.Validator {
|
func (tm2pb) Validator(val *Validator) *types.Validator {
|
||||||
return &types.Validator{
|
return &types.Validator{
|
||||||
PubKey: val.PubKey.Bytes(),
|
PubKey: val.PubKey.Bytes(),
|
||||||
Power: uint64(val.VotingPower),
|
Power: val.VotingPower,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user