diff --git a/consensus/mempool_test.go b/consensus/mempool_test.go index e4d09c95..089d7b3f 100644 --- a/consensus/mempool_test.go +++ b/consensus/mempool_test.go @@ -2,6 +2,7 @@ package consensus import ( "encoding/binary" + "fmt" "testing" "time" @@ -188,33 +189,41 @@ func (app *CounterApplication) Info(req abci.RequestInfo) abci.ResponseInfo { return abci.ResponseInfo{Data: cmn.Fmt("txs:%v", app.txCount)} } -func (app *CounterApplication) DeliverTx(tx []byte) abci.Result { - return runTx(tx, &app.txCount) +func (app *CounterApplication) DeliverTx(tx []byte) abci.ResponseDeliverTx { + txValue := txAsUint64(tx) + if txValue != uint64(app.txCount) { + return abci.ResponseDeliverTx{ + Code: abci.CodeType_BadNonce, + Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.txCount, txValue)} + } + app.txCount += 1 + return abci.ResponseDeliverTx{Code: abci.CodeType_OK} } -func (app *CounterApplication) CheckTx(tx []byte) abci.Result { - return runTx(tx, &app.mempoolTxCount) +func (app *CounterApplication) CheckTx(tx []byte) abci.ResponseCheckTx { + txValue := txAsUint64(tx) + if txValue != uint64(app.mempoolTxCount) { + return abci.ResponseCheckTx{ + Code: abci.CodeType_BadNonce, + Log: fmt.Sprintf("Invalid nonce. Expected %v, got %v", app.mempoolTxCount, txValue)} + } + app.mempoolTxCount += 1 + return abci.ResponseCheckTx{Code: abci.CodeType_OK} } -func runTx(tx []byte, countPtr *int) abci.Result { - count := *countPtr +func txAsUint64(tx []byte) uint64 { tx8 := make([]byte, 8) copy(tx8[len(tx8)-len(tx):], tx) - txValue := binary.BigEndian.Uint64(tx8) - if txValue != uint64(count) { - return abci.ErrBadNonce.AppendLog(cmn.Fmt("Invalid nonce. Expected %v, got %v", count, txValue)) - } - *countPtr += 1 - return abci.OK + return binary.BigEndian.Uint64(tx8) } -func (app *CounterApplication) Commit() abci.Result { +func (app *CounterApplication) Commit() abci.ResponseCommit { app.mempoolTxCount = app.txCount if app.txCount == 0 { - return abci.OK + return abci.ResponseCommit{Code: abci.CodeType_OK} } else { hash := make([]byte, 8) binary.BigEndian.PutUint64(hash, uint64(app.txCount)) - return abci.NewResultOK(hash, "") + return abci.ResponseCommit{Code: abci.CodeType_OK, Data: hash} } } diff --git a/consensus/replay.go b/consensus/replay.go index 38a5eef3..853d3a8d 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -385,22 +385,17 @@ type mockProxyApp struct { abciResponses *sm.ABCIResponses } -func (mock *mockProxyApp) DeliverTx(tx []byte) abci.Result { +func (mock *mockProxyApp) DeliverTx(tx []byte) abci.ResponseDeliverTx { r := mock.abciResponses.DeliverTx[mock.txCount] mock.txCount += 1 - return abci.Result{ - r.Code, - r.Data, - r.Log, - r.Tags, - } + return *r } func (mock *mockProxyApp) EndBlock(height uint64) abci.ResponseEndBlock { mock.txCount = 0 - return mock.abciResponses.EndBlock + return *mock.abciResponses.EndBlock } -func (mock *mockProxyApp) Commit() abci.Result { - return abci.NewResultOK(mock.appHash, "") +func (mock *mockProxyApp) Commit() abci.ResponseCommit { + return abci.ResponseCommit{Code: abci.CodeType_OK, Data: mock.appHash} } diff --git a/glide.lock b/glide.lock index ccb74759..09f9ad2b 100644 --- a/glide.lock +++ b/glide.lock @@ -98,7 +98,7 @@ imports: - leveldb/table - leveldb/util - name: github.com/tendermint/abci - version: 6b47155e08732f46dafdcef185d23f0ff9ff24a5 + version: 2cfad8523a54d64271d7cbc69a39433eab918aa0 subpackages: - client - example/counter diff --git a/glide.yaml b/glide.yaml index 19485fb6..a20e76db 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: 6b47155e08732f46dafdcef185d23f0ff9ff24a5 + version: 2cfad8523a54d64271d7cbc69a39433eab918aa0 subpackages: - client - example/dummy diff --git a/mempool/mempool_test.go b/mempool/mempool_test.go index 2bbf9944..aa19e380 100644 --- a/mempool/mempool_test.go +++ b/mempool/mempool_test.go @@ -172,13 +172,19 @@ func TestSerialReap(t *testing.T) { for i := start; i < end; i++ { txBytes := make([]byte, 8) binary.BigEndian.PutUint64(txBytes, uint64(i)) - res := appConnCon.DeliverTxSync(txBytes) - if !res.IsOK() { + res, err := appConnCon.DeliverTxSync(txBytes) + if err != nil { + t.Errorf("Client error committing tx: %v", err) + } + if res.IsErr() { t.Errorf("Error committing tx. Code:%v result:%X log:%v", res.Code, res.Data, res.Log) } } - res := appConnCon.CommitSync() + res, err := appConnCon.CommitSync() + if err != nil { + t.Errorf("Client error committing: %v", err) + } if len(res.Data) != 8 { t.Errorf("Error committing. Hash:%X log:%v", res.Data, res.Log) } diff --git a/proxy/app_conn.go b/proxy/app_conn.go index 9121e8db..49c88a37 100644 --- a/proxy/app_conn.go +++ b/proxy/app_conn.go @@ -12,12 +12,12 @@ type AppConnConsensus interface { SetResponseCallback(abcicli.Callback) Error() error - InitChainSync(types.RequestInitChain) (err error) + InitChainSync(types.RequestInitChain) error - BeginBlockSync(types.RequestBeginBlock) (err error) + BeginBlockSync(types.RequestBeginBlock) error DeliverTxAsync(tx []byte) *abcicli.ReqRes - EndBlockSync(height uint64) (types.ResponseEndBlock, error) - CommitSync() (res types.Result) + EndBlockSync(height uint64) (*types.ResponseEndBlock, error) + CommitSync() (*types.ResponseCommit, error) } type AppConnMempool interface { @@ -33,9 +33,9 @@ type AppConnMempool interface { type AppConnQuery interface { Error() error - EchoSync(string) (res types.Result) - InfoSync(types.RequestInfo) (types.ResponseInfo, error) - QuerySync(types.RequestQuery) (types.ResponseQuery, error) + EchoSync(string) (*types.ResponseEcho, error) + InfoSync(types.RequestInfo) (*types.ResponseInfo, error) + QuerySync(types.RequestQuery) (*types.ResponseQuery, error) // SetOptionSync(key string, value string) (res types.Result) } @@ -61,11 +61,11 @@ func (app *appConnConsensus) Error() error { return app.appConn.Error() } -func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) (err error) { +func (app *appConnConsensus) InitChainSync(req types.RequestInitChain) error { return app.appConn.InitChainSync(req) } -func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) (err error) { +func (app *appConnConsensus) BeginBlockSync(req types.RequestBeginBlock) error { return app.appConn.BeginBlockSync(req) } @@ -73,11 +73,11 @@ func (app *appConnConsensus) DeliverTxAsync(tx []byte) *abcicli.ReqRes { return app.appConn.DeliverTxAsync(tx) } -func (app *appConnConsensus) EndBlockSync(height uint64) (types.ResponseEndBlock, error) { +func (app *appConnConsensus) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) { return app.appConn.EndBlockSync(height) } -func (app *appConnConsensus) CommitSync() (res types.Result) { +func (app *appConnConsensus) CommitSync() (*types.ResponseCommit, error) { return app.appConn.CommitSync() } @@ -131,14 +131,14 @@ func (app *appConnQuery) Error() error { return app.appConn.Error() } -func (app *appConnQuery) EchoSync(msg string) (res types.Result) { +func (app *appConnQuery) EchoSync(msg string) (*types.ResponseEcho, error) { return app.appConn.EchoSync(msg) } -func (app *appConnQuery) InfoSync(req types.RequestInfo) (types.ResponseInfo, error) { +func (app *appConnQuery) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) { return app.appConn.InfoSync(req) } -func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (types.ResponseQuery, error) { +func (app *appConnQuery) QuerySync(reqQuery types.RequestQuery) (*types.ResponseQuery, error) { return app.appConn.QuerySync(reqQuery) } diff --git a/proxy/app_conn_test.go b/proxy/app_conn_test.go index 3c00f1ae..0fbad602 100644 --- a/proxy/app_conn_test.go +++ b/proxy/app_conn_test.go @@ -17,7 +17,7 @@ import ( type AppConnTest interface { EchoAsync(string) *abcicli.ReqRes FlushSync() error - InfoSync(types.RequestInfo) (types.ResponseInfo, error) + InfoSync(types.RequestInfo) (*types.ResponseInfo, error) } type appConnTest struct { @@ -36,7 +36,7 @@ func (app *appConnTest) FlushSync() error { return app.appConn.FlushSync() } -func (app *appConnTest) InfoSync(req types.RequestInfo) (types.ResponseInfo, error) { +func (app *appConnTest) InfoSync(req types.RequestInfo) (*types.ResponseInfo, error) { return app.appConn.InfoSync(req) } diff --git a/rpc/client/mock/abci.go b/rpc/client/mock/abci.go index e935a282..2ffa9269 100644 --- a/rpc/client/mock/abci.go +++ b/rpc/client/mock/abci.go @@ -38,7 +38,7 @@ func (a ABCIApp) ABCIQueryWithOptions(path string, data data.Bytes, opts client. func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { res := ctypes.ResultBroadcastTxCommit{} res.CheckTx = a.App.CheckTx(tx) - if !res.CheckTx.IsOK() { + if res.CheckTx.IsErr() { return &res, nil } res.DeliverTx = a.App.DeliverTx(tx) @@ -48,7 +48,7 @@ func (a ABCIApp) BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit func (a ABCIApp) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { c := a.App.CheckTx(tx) // and this gets written in a background thread... - if c.IsOK() { + if !c.IsErr() { go func() { a.App.DeliverTx(tx) }() // nolint: errcheck } return &ctypes.ResultBroadcastTx{c.Code, c.Data, c.Log, tx.Hash()}, nil @@ -57,7 +57,7 @@ func (a ABCIApp) BroadcastTxAsync(tx types.Tx) (*ctypes.ResultBroadcastTx, error func (a ABCIApp) BroadcastTxSync(tx types.Tx) (*ctypes.ResultBroadcastTx, error) { c := a.App.CheckTx(tx) // and this gets written in a background thread... - if c.IsOK() { + if !c.IsErr() { go func() { a.App.DeliverTx(tx) }() // nolint: errcheck } return &ctypes.ResultBroadcastTx{c.Code, c.Data, c.Log, tx.Hash()}, nil diff --git a/rpc/client/mock/abci_test.go b/rpc/client/mock/abci_test.go index 36a45791..216bd7c2 100644 --- a/rpc/client/mock/abci_test.go +++ b/rpc/client/mock/abci_test.go @@ -37,8 +37,8 @@ func TestABCIMock(t *testing.T) { BroadcastCommit: mock.Call{ Args: goodTx, Response: &ctypes.ResultBroadcastTxCommit{ - CheckTx: abci.Result{Data: data.Bytes("stand")}, - DeliverTx: abci.Result{Data: data.Bytes("deliver")}, + CheckTx: abci.ResponseCheckTx{Data: data.Bytes("stand")}, + DeliverTx: abci.ResponseDeliverTx{Data: data.Bytes("deliver")}, }, Error: errors.New("bad tx"), }, diff --git a/rpc/core/abci.go b/rpc/core/abci.go index 564c0bc6..a64c3d29 100644 --- a/rpc/core/abci.go +++ b/rpc/core/abci.go @@ -93,5 +93,5 @@ func ABCIInfo() (*ctypes.ResultABCIInfo, error) { if err != nil { return nil, err } - return &ctypes.ResultABCIInfo{resInfo}, nil + return &ctypes.ResultABCIInfo{*resInfo}, nil } diff --git a/rpc/core/mempool.go b/rpc/core/mempool.go index 72cf2865..857ea75b 100644 --- a/rpc/core/mempool.go +++ b/rpc/core/mempool.go @@ -177,8 +177,8 @@ func BroadcastTxCommit(tx types.Tx) (*ctypes.ResultBroadcastTxCommit, error) { if checkTxR.Code != abci.CodeType_OK { // CheckTx failed! return &ctypes.ResultBroadcastTxCommit{ - CheckTx: checkTxR.Result(), - DeliverTx: abci.Result{}, + CheckTx: *checkTxR, + DeliverTx: abci.ResponseDeliverTx{}, Hash: tx.Hash(), }, nil } @@ -191,23 +191,23 @@ 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{ + deliverTxR := abci.ResponseDeliverTx{ Code: deliverTxRes.Result.Code, Data: deliverTxRes.Result.Data, Log: deliverTxRes.Result.Log, } logger.Info("DeliverTx passed ", "tx", data.Bytes(tx), "response", deliverTxR) return &ctypes.ResultBroadcastTxCommit{ - CheckTx: checkTxR.Result(), - DeliverTx: deliverTxR.Result(), + CheckTx: *checkTxR, + DeliverTx: deliverTxR, Hash: tx.Hash(), Height: deliverTxRes.Height, }, nil case <-timer.C: logger.Error("failed to include tx") return &ctypes.ResultBroadcastTxCommit{ - CheckTx: checkTxR.Result(), - DeliverTx: abci.Result{}, + CheckTx: *checkTxR, + DeliverTx: abci.ResponseDeliverTx{}, Hash: tx.Hash(), }, fmt.Errorf("Timed out waiting for transaction to be included in a block") } diff --git a/rpc/core/tx.go b/rpc/core/tx.go index dc842e62..80d1cb32 100644 --- a/rpc/core/tx.go +++ b/rpc/core/tx.go @@ -94,7 +94,7 @@ func Tx(hash []byte, prove bool) (*ctypes.ResultTx, error) { return &ctypes.ResultTx{ Height: height, Index: index, - TxResult: r.Result.Result(), + TxResult: r.Result, Tx: r.Tx, Proof: proof, }, nil diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index e4c5d8fc..a1b7e36f 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -104,18 +104,18 @@ type ResultBroadcastTx struct { } type ResultBroadcastTxCommit struct { - CheckTx abci.Result `json:"check_tx"` - DeliverTx abci.Result `json:"deliver_tx"` - Hash data.Bytes `json:"hash"` - Height uint64 `json:"height"` + CheckTx abci.ResponseCheckTx `json:"check_tx"` + DeliverTx abci.ResponseDeliverTx `json:"deliver_tx"` + Hash data.Bytes `json:"hash"` + Height uint64 `json:"height"` } type ResultTx struct { - Height uint64 `json:"height"` - Index uint32 `json:"index"` - TxResult abci.Result `json:"tx_result"` - Tx types.Tx `json:"tx"` - Proof types.TxProof `json:"proof,omitempty"` + Height uint64 `json:"height"` + Index uint32 `json:"index"` + TxResult abci.ResponseDeliverTx `json:"tx_result"` + Tx types.Tx `json:"tx"` + Proof types.TxProof `json:"proof,omitempty"` } type ResultUnconfirmedTxs struct { diff --git a/state/execution.go b/state/execution.go index be09b2b2..5b324eff 100644 --- a/state/execution.go +++ b/state/execution.go @@ -248,7 +248,11 @@ func (s *State) CommitStateUpdateMempool(proxyAppConn proxy.AppConnConsensus, bl defer mempool.Unlock() // Commit block, get hash back - res := proxyAppConn.CommitSync() + res, err := proxyAppConn.CommitSync() + if err != nil { + s.logger.Error("Client error during proxyAppConn.CommitSync", "err", err) + return err + } if res.IsErr() { s.logger.Error("Error in proxyAppConn.CommitSync", "err", res) return res @@ -275,7 +279,11 @@ func ExecCommitBlock(appConnConsensus proxy.AppConnConsensus, block *types.Block return nil, err } // Commit block, get hash back - res := appConnConsensus.CommitSync() + res, err := appConnConsensus.CommitSync() + if err != nil { + 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 diff --git a/state/state.go b/state/state.go index 1c2b3efe..e1f16835 100644 --- a/state/state.go +++ b/state/state.go @@ -279,7 +279,7 @@ type ABCIResponses struct { Height int DeliverTx []*abci.ResponseDeliverTx - EndBlock abci.ResponseEndBlock + EndBlock *abci.ResponseEndBlock txs types.Txs // reference for indexing results by hash } diff --git a/state/state_test.go b/state/state_test.go index b60f1546..7fff0774 100644 --- a/state/state_test.go +++ b/state/state_test.go @@ -80,7 +80,7 @@ func TestABCIResponsesSaveLoad(t *testing.T) { 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{Diffs: []*abci.Validator{ + abciResponses.EndBlock = &abci.ResponseEndBlock{Diffs: []*abci.Validator{ { PubKey: crypto.GenPrivKeyEd25519().PubKey().Bytes(), Power: 10, @@ -198,12 +198,13 @@ func makeHeaderPartsResponses(state *State, height int, block := makeBlock(height, state) _, val := state.Validators.GetByIndex(0) abciResponses := &ABCIResponses{ - Height: height, + Height: height, + EndBlock: &abci.ResponseEndBlock{Diffs: []*abci.Validator{}}, } // if the pubkey is new, remove the old and add the new if !bytes.Equal(pubkey.Bytes(), val.PubKey.Bytes()) { - abciResponses.EndBlock = abci.ResponseEndBlock{ + abciResponses.EndBlock = &abci.ResponseEndBlock{ Diffs: []*abci.Validator{ {val.PubKey.Bytes(), 0}, {pubkey.Bytes(), 10},