From 4e5c2b5e8fa0783321dc8662f770a528298987ec Mon Sep 17 00:00:00 2001 From: Sam Kleinman Date: Wed, 19 Jan 2022 16:58:12 -0500 Subject: [PATCH] consensus: use delivertxsync (#7616) --- internal/consensus/replay_test.go | 30 +++++++++------------ internal/proxy/app_conn.go | 10 +++---- internal/proxy/mocks/app_conn_consensus.go | 10 +++---- internal/state/execution.go | 31 +++++++--------------- rpc/client/mocks/client.go | 14 +++++----- 5 files changed, 39 insertions(+), 56 deletions(-) diff --git a/internal/consensus/replay_test.go b/internal/consensus/replay_test.go index fd276d4d7..9f8d31714 100644 --- a/internal/consensus/replay_test.go +++ b/internal/consensus/replay_test.go @@ -684,26 +684,20 @@ func TestMockProxyApp(t *testing.T) { abciRes := new(tmstate.ABCIResponses) abciRes.DeliverTxs = make([]*abci.ResponseDeliverTx, len(loadedAbciRes.DeliverTxs)) - // Execute transactions and get hash. - proxyCb := func(req *abci.Request, res *abci.Response) { - if r, ok := res.Value.(*abci.Response_DeliverTx); ok { - // TODO: make use of res.Log - // TODO: make use of this info - // Blocks may include invalid txs. - txRes := r.DeliverTx - if txRes.Code == abci.CodeTypeOK { - validTxs++ - } else { - invalidTxs++ - } - abciRes.DeliverTxs[txIndex] = txRes - txIndex++ - } - } - mock.SetResponseCallback(proxyCb) someTx := []byte("tx") - _, err = mock.DeliverTxAsync(ctx, abci.RequestDeliverTx{Tx: someTx}) + resp, err := mock.DeliverTx(ctx, abci.RequestDeliverTx{Tx: someTx}) + // TODO: make use of res.Log + // TODO: make use of this info + // Blocks may include invalid txs. + if resp.Code == abci.CodeTypeOK { + validTxs++ + } else { + invalidTxs++ + } + abciRes.DeliverTxs[txIndex] = resp + txIndex++ + assert.NoError(t, err) }) assert.True(t, validTxs == 1) diff --git a/internal/proxy/app_conn.go b/internal/proxy/app_conn.go index d154e030a..1a7c9af52 100644 --- a/internal/proxy/app_conn.go +++ b/internal/proxy/app_conn.go @@ -21,7 +21,7 @@ type AppConnConsensus interface { InitChain(context.Context, types.RequestInitChain) (*types.ResponseInitChain, error) BeginBlock(context.Context, types.RequestBeginBlock) (*types.ResponseBeginBlock, error) - DeliverTxAsync(context.Context, types.RequestDeliverTx) (*abciclient.ReqRes, error) + DeliverTx(context.Context, types.RequestDeliverTx) (*types.ResponseDeliverTx, error) EndBlock(context.Context, types.RequestEndBlock) (*types.ResponseEndBlock, error) Commit(context.Context) (*types.ResponseCommit, error) } @@ -93,12 +93,12 @@ func (app *appConnConsensus) BeginBlock( return app.appConn.BeginBlock(ctx, req) } -func (app *appConnConsensus) DeliverTxAsync( +func (app *appConnConsensus) DeliverTx( ctx context.Context, req types.RequestDeliverTx, -) (*abciclient.ReqRes, error) { - defer addTimeSample(app.metrics.MethodTiming.With("method", "deliver_tx", "type", "async"))() - return app.appConn.DeliverTxAsync(ctx, req) +) (*types.ResponseDeliverTx, error) { + defer addTimeSample(app.metrics.MethodTiming.With("method", "deliver_tx", "type", "sync"))() + return app.appConn.DeliverTx(ctx, req) } func (app *appConnConsensus) EndBlock( diff --git a/internal/proxy/mocks/app_conn_consensus.go b/internal/proxy/mocks/app_conn_consensus.go index aaf082059..4be489163 100644 --- a/internal/proxy/mocks/app_conn_consensus.go +++ b/internal/proxy/mocks/app_conn_consensus.go @@ -63,16 +63,16 @@ func (_m *AppConnConsensus) Commit(_a0 context.Context) (*types.ResponseCommit, return r0, r1 } -// DeliverTxAsync provides a mock function with given fields: _a0, _a1 -func (_m *AppConnConsensus) DeliverTxAsync(_a0 context.Context, _a1 types.RequestDeliverTx) (*abciclient.ReqRes, error) { +// DeliverTx provides a mock function with given fields: _a0, _a1 +func (_m *AppConnConsensus) DeliverTx(_a0 context.Context, _a1 types.RequestDeliverTx) (*types.ResponseDeliverTx, error) { ret := _m.Called(_a0, _a1) - var r0 *abciclient.ReqRes - if rf, ok := ret.Get(0).(func(context.Context, types.RequestDeliverTx) *abciclient.ReqRes); ok { + var r0 *types.ResponseDeliverTx + if rf, ok := ret.Get(0).(func(context.Context, types.RequestDeliverTx) *types.ResponseDeliverTx); ok { r0 = rf(_a0, _a1) } else { if ret.Get(0) != nil { - r0 = ret.Get(0).(*abciclient.ReqRes) + r0 = ret.Get(0).(*types.ResponseDeliverTx) } } diff --git a/internal/state/execution.go b/internal/state/execution.go index 8bd280ca5..96a680a5b 100644 --- a/internal/state/execution.go +++ b/internal/state/execution.go @@ -302,26 +302,6 @@ func execBlockOnProxyApp( dtxs := make([]*abci.ResponseDeliverTx, len(block.Txs)) abciResponses.DeliverTxs = dtxs - // Execute transactions and get hash. - proxyCb := func(req *abci.Request, res *abci.Response) { - if r, ok := res.Value.(*abci.Response_DeliverTx); ok { - // TODO: make use of res.Log - // TODO: make use of this info - // Blocks may include invalid txs. - txRes := r.DeliverTx - if txRes.Code == abci.CodeTypeOK { - validTxs++ - } else { - logger.Debug("invalid tx", "code", txRes.Code, "log", txRes.Log) - invalidTxs++ - } - - abciResponses.DeliverTxs[txIndex] = txRes - txIndex++ - } - } - proxyAppConn.SetResponseCallback(proxyCb) - commitInfo := getBeginBlockValidatorInfo(block, store, initialHeight) byzVals := make([]abci.Evidence, 0) @@ -352,10 +332,19 @@ func execBlockOnProxyApp( // run txs of block for _, tx := range block.Txs { - _, err = proxyAppConn.DeliverTxAsync(ctx, abci.RequestDeliverTx{Tx: tx}) + resp, err := proxyAppConn.DeliverTx(ctx, abci.RequestDeliverTx{Tx: tx}) if err != nil { return nil, err } + if resp.Code == abci.CodeTypeOK { + validTxs++ + } else { + logger.Debug("invalid tx", "code", resp.Code, "log", resp.Log) + invalidTxs++ + } + + abciResponses.DeliverTxs[txIndex] = resp + txIndex++ } abciResponses.EndBlock, err = proxyAppConn.EndBlock(ctx, abci.RequestEndBlock{Height: block.Height}) diff --git a/rpc/client/mocks/client.go b/rpc/client/mocks/client.go index e638980a8..a74b6438f 100644 --- a/rpc/client/mocks/client.go +++ b/rpc/client/mocks/client.go @@ -713,13 +713,13 @@ func (_m *Client) TxSearch(ctx context.Context, query string, prove bool, page * return r0, r1 } -// UnconfirmedTxs provides a mock function with given fields: ctx, limit -func (_m *Client) UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.ResultUnconfirmedTxs, error) { - ret := _m.Called(ctx, limit) +// UnconfirmedTxs provides a mock function with given fields: ctx, page, perPage +func (_m *Client) UnconfirmedTxs(ctx context.Context, page *int, perPage *int) (*coretypes.ResultUnconfirmedTxs, error) { + ret := _m.Called(ctx, page, perPage) var r0 *coretypes.ResultUnconfirmedTxs - if rf, ok := ret.Get(0).(func(context.Context, *int) *coretypes.ResultUnconfirmedTxs); ok { - r0 = rf(ctx, limit) + if rf, ok := ret.Get(0).(func(context.Context, *int, *int) *coretypes.ResultUnconfirmedTxs); ok { + r0 = rf(ctx, page, perPage) } else { if ret.Get(0) != nil { r0 = ret.Get(0).(*coretypes.ResultUnconfirmedTxs) @@ -727,8 +727,8 @@ func (_m *Client) UnconfirmedTxs(ctx context.Context, limit *int) (*coretypes.Re } var r1 error - if rf, ok := ret.Get(1).(func(context.Context, *int) error); ok { - r1 = rf(ctx, limit) + if rf, ok := ret.Get(1).(func(context.Context, *int, *int) error); ok { + r1 = rf(ctx, page, perPage) } else { r1 = ret.Error(1) }