From 1e198605852fac70b65a74ed9e6f4f64c4ff2c29 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 29 Nov 2017 11:22:52 -0600 Subject: [PATCH] fixes from my own review --- consensus/replay.go | 4 ++-- consensus/replay_test.go | 4 ++-- glide.lock | 8 +++++--- glide.yaml | 2 +- mempool/mempool_test.go | 3 ++- proxy/app_conn.go | 14 +++++++------- rpc/core/mempool.go | 6 +----- state/execution.go | 4 ++-- state/txindex/indexer_service.go | 1 + state/txindex/kv/kv.go | 4 ++++ 10 files changed, 27 insertions(+), 23 deletions(-) diff --git a/consensus/replay.go b/consensus/replay.go index 853d3a8d9..da68df51f 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -236,7 +236,7 @@ func (h *Handshaker) ReplayBlocks(appHash []byte, appBlockHeight int, proxyApp p // If appBlockHeight == 0 it means that we are at genesis and hence should send InitChain if appBlockHeight == 0 { validators := types.TM2PB.Validators(h.state.Validators) - if err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { + if _, err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { return nil, err } } @@ -391,7 +391,7 @@ func (mock *mockProxyApp) DeliverTx(tx []byte) abci.ResponseDeliverTx { return *r } -func (mock *mockProxyApp) EndBlock(height uint64) abci.ResponseEndBlock { +func (mock *mockProxyApp) EndBlock(req abci.RequestEndBlock) abci.ResponseEndBlock { mock.txCount = 0 return *mock.abciResponses.EndBlock } diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 381c9021c..25fdf4dba 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -411,7 +411,7 @@ func buildAppStateFromChain(proxyApp proxy.AppConns, } validators := types.TM2PB.Validators(state.Validators) - if err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { + if _, err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { panic(err) } @@ -447,7 +447,7 @@ func buildTMStateFromChain(config *cfg.Config, state *sm.State, chain []*types.B defer proxyApp.Stop() validators := types.TM2PB.Validators(state.Validators) - if err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { + if _, err := proxyApp.Consensus().InitChainSync(abci.RequestInitChain{validators}); err != nil { panic(err) } diff --git a/glide.lock b/glide.lock index 31f1aaa92..18a5d6a70 100644 --- a/glide.lock +++ b/glide.lock @@ -1,5 +1,5 @@ -hash: e279cca35a5cc9a68bb266015dc6a57da749b28dabca3994b2c5dbe02309f470 -updated: 2017-11-28T00:53:04.816567531Z +hash: ffe610ffb74c1ea5cbe8da5d0d3ae30d2640c7426fe9a889a60218ea36daaf53 +updated: 2017-11-29T17:21:18.25916493Z imports: - name: github.com/btcsuite/btcd version: 8cea3866d0f7fb12d567a20744942c0d078c7d15 @@ -98,7 +98,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 2cfad8523a54d64271d7cbc69a39433eab918aa0 + version: 5c29adc081795b04f9d046fb51d76903c22cfa6d subpackages: - client - example/counter @@ -160,6 +160,8 @@ imports: - trace - name: golang.org/x/sys version: b98136db334ff9cb24f28a68e3be3cb6608f7630 + subpackages: + - unix - name: golang.org/x/text version: 88f656faf3f37f690df1a32515b479415e1a6769 subpackages: diff --git a/glide.yaml b/glide.yaml index a20e76dbd..62c06fc9d 100644 --- a/glide.yaml +++ b/glide.yaml @@ -18,7 +18,7 @@ import: - package: github.com/spf13/viper version: v1.0.0 - package: github.com/tendermint/abci - version: 2cfad8523a54d64271d7cbc69a39433eab918aa0 + version: 5c29adc081795b04f9d046fb51d76903c22cfa6d subpackages: - client - example/dummy diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index aa19e3809..e26ef966d 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -13,6 +13,7 @@ import ( "github.com/tendermint/abci/example/counter" "github.com/tendermint/abci/example/dummy" + abci "github.com/tendermint/abci/types" "github.com/tendermint/tmlibs/log" cfg "github.com/tendermint/tendermint/config" @@ -115,7 +116,7 @@ func TestTxsAvailable(t *testing.T) { func TestSerialReap(t *testing.T) { app := counter.NewCounterApplication(true) - app.SetOption("serial", "on") + app.SetOption(abci.RequestSetOption{"serial", "on"}) cc := proxy.NewLocalClientCreator(app) mempool := newMempoolWithApp(cc) diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 49c88a377..2319fed82 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -12,11 +12,11 @@ type AppConnConsensus interface { SetResponseCallback(abcicli.Callback) Error() error - InitChainSync(types.RequestInitChain) error + InitChainSync(types.RequestInitChain) (*types.ResponseInitChain, error) - BeginBlockSync(types.RequestBeginBlock) error + BeginBlockSync(types.RequestBeginBlock) (*types.ResponseBeginBlock, error) DeliverTxAsync(tx []byte) *abcicli.ReqRes - EndBlockSync(height uint64) (*types.ResponseEndBlock, error) + EndBlockSync(types.RequestEndBlock) (*types.ResponseEndBlock, error) CommitSync() (*types.ResponseCommit, error) } @@ -61,11 +61,11 @@ func (app *appConnConsensus) Error() error { return app.appConn.Error() } -func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) error { +func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) { return app.appConn.InitChainSync(req) } -func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) error { +func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) { return app.appConn.BeginBlockSync(req) } @@ -73,8 +73,8 @@ func (app *appConnConsensus) DeliverTxAsync(tx []byte) *abcicli.ReqRes { return app.appConn.DeliverTxAsync(tx) } -func (app *appConnConsensus) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) { - return app.appConn.EndBlockSync(height) +func (app *appConnConsensus) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) { + return app.appConn.EndBlockSync(req) } func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) { diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index 857ea75b3..c2e5d2f9b 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -191,11 +191,7 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { case deliverTxResMsg := <-deliverTxResCh: deliverTxRes := deliverTxResMsg.(types.TMEventData).Unwrap().(types.EventDataTx) // The tx was included in a block. - deliverTxR := abci.ResponseDeliverTx{ - Code: deliverTxRes.Result.Code, - Data: deliverTxRes.Result.Data, - Log: deliverTxRes.Result.Log, - } + deliverTxR := deliverTxRes.Result logger.Info("DeliverTx passed ", "tx", data.Bytes(tx), "response", deliverTxR) return &ctypes.ResultBroadcastTxCommit{ CheckTx: *checkTxR, diff --git a/state/execution.go b/state/execution.go index 5b324eff9..3622a663c 100644 --- a/state/execution.go +++ b/state/execution.go @@ -77,7 +77,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p proxyAppConn.SetResponseCallback(proxyCb) // Begin block - err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{ + _, err := proxyAppConn.BeginBlockSync(abci.RequestBeginBlock{ block.Hash(), types.TM2PB.Header(block.Header), }) @@ -95,7 +95,7 @@ func execBlockOnProxyApp(txEventPublisher types.TxEventPublisher, proxyAppConn p } // End block - abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(uint64(block.Height)) + abciResponses.EndBlock, err = proxyAppConn.EndBlockSync(abci.RequestEndBlock{uint64(block.Height)}) if err != nil { logger.Error("Error in proxyAppConn.EndBlock", "err", err) return nil, err diff --git a/state/txindex/indexer_service.go b/state/txindex/indexer_service.go index 80f12fd35..3e5fab127 100644 --- a/state/txindex/indexer_service.go +++ b/state/txindex/indexer_service.go @@ -41,6 +41,7 @@ func (is *IndexerService) OnStart() error { return nil } +// OnStop implements cmn.Service by unsubscribing from all transactions. func (is *IndexerService) OnStop() { if is.eventBus.IsRunning() { _ = is.eventBus.UnsubscribeAll(context.Background(), subscriber) diff --git a/state/txindex/kv/kv.go b/state/txindex/kv/kv.go index ae320cc1d..53d07325f 100644 --- a/state/txindex/kv/kv.go +++ b/state/txindex/kv/kv.go @@ -186,6 +186,8 @@ func lookForHeight(conditions []query.Condition) (height uint64, index int) { return 0, -1 } +// special map to hold range conditions +// Example: account.number => queryRange{lowerBound: 1, upperBound: 5} type queryRanges map[string]queryRange type queryRange struct { @@ -241,6 +243,8 @@ func (txi *TxIndex) match(c query.Condition, startKey []byte) (hashes [][]byte) } } 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() {