From 942d3e8d0708abbb24ab554541916d83a24145c4 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 20 Sep 2022 16:02:59 +0800 Subject: [PATCH 1/4] fix: streaming listeners are not called for deliver tx event (#13334) * Problem: streaming listeners are not called for deliver tx event it was removed accidentally, add back. * Update CHANGELOG.md * try to fix e2e test by wait for one more block (cherry picked from commit 822900b69f4b62f118dc1ffd42b6a9e44054eef0) # Conflicts: # CHANGELOG.md # x/auth/tx/service_test.go --- CHANGELOG.md | 15 ++++++++ baseapp/abci.go | 10 ++++- x/auth/tx/service_test.go | 80 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ee98b7f3d91..71d01546cb6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,21 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/group) [#12888](https://github.com/cosmos/cosmos-sdk/pull/12888) Fix event propagation to the current context of `x/group` message execution `[]sdk.Result`. * (x/upgrade) [#12906](https://github.com/cosmos/cosmos-sdk/pull/12906) Fix upgrade failure by moving downgrade verification logic after store migration. +<<<<<<< HEAD +======= +* (store) [#12945](https://github.com/cosmos/cosmos-sdk/pull/12945) Fix nil end semantics in store/cachekv/iterator when iterating a dirty cache. +* (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression. +* (x/gov) [#13051](https://github.com/cosmos/cosmos-sdk/pull/13051) In SubmitPropsal, when a legacy msg fails it's handler call, wrap the error as ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists). +* (x/gov) [#13045](https://github.com/cosmos/cosmos-sdk/pull/13045) Fix gov migrations for v3(0.46). +* (Store) [#13334](https://github.com/cosmos/cosmos-sdk/pull/13334) Call streaming listeners for deliver tx event, it was removed accidentally. + +### Deprecated + +* (x/bank) [#11859](https://github.com/cosmos/cosmos-sdk/pull/11859) The Params.SendEnabled field is deprecated and unusable. + The information can now be accessed using the BankKeeper. + Setting can be done using MsgSetSendEnabled as a governance proposal. + A SendEnabled query has been added to both GRPC and CLI. +>>>>>>> 822900b69 (fix: streaming listeners are not called for deliver tx event (#13334)) ## [v0.46.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0) - 2022-07-26 diff --git a/baseapp/abci.go b/baseapp/abci.go index 6c6bd2f81ea3..b187ab49c2a2 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -278,10 +278,18 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx { // Otherwise, the ResponseDeliverTx will contain releveant error information. // Regardless of tx execution outcome, the ResponseDeliverTx will contain relevant // gas execution context. -func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) abci.ResponseDeliverTx { +func (app *BaseApp) DeliverTx(req abci.RequestDeliverTx) (res abci.ResponseDeliverTx) { gInfo := sdk.GasInfo{} resultStr := "successful" + defer func() { + for _, streamingListener := range app.abciListeners { + if err := streamingListener.ListenDeliverTx(app.deliverState.ctx, req, res); err != nil { + app.logger.Error("DeliverTx listening hook failed", "err", err) + } + } + }() + defer func() { telemetry.IncrCounter(1, "tx", "count") telemetry.IncrCounter(1, "tx", resultStr) diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index ca1a0186e333..7798e3d52a17 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/suite" + "cosmossdk.io/simapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clienttx "github.com/cosmos/cosmos-sdk/client/tx" @@ -111,6 +112,85 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } +<<<<<<< HEAD:x/auth/tx/service_test.go +======= +func (s *IntegrationTestSuite) TestQueryBySig() { + // broadcast tx + txb := s.mkTxBuilder() + txbz, err := s.cfg.TxConfig.TxEncoder()(txb.GetTx()) + s.Require().NoError(err) + resp, err := s.queryClient.BroadcastTx(context.Background(), &tx.BroadcastTxRequest{TxBytes: txbz, Mode: tx.BroadcastMode_BROADCAST_MODE_SYNC}) + s.Require().NoError(err) + s.Require().NotEmpty(resp.TxResponse.TxHash) + + s.Require().NoError(s.network.WaitForNextBlock()) + s.Require().NoError(s.network.WaitForNextBlock()) + + // get the signature out of the builder + sigs, err := txb.GetTx().GetSignaturesV2() + s.Require().NoError(err) + s.Require().Len(sigs, 1) + sig, ok := sigs[0].Data.(*signing.SingleSignatureData) + s.Require().True(ok) + + // encode, format, query + b64Sig := base64.StdEncoding.EncodeToString(sig.Signature) + sigFormatted := fmt.Sprintf("%s.%s='%s'", sdk.EventTypeTx, sdk.AttributeKeySignature, b64Sig) + res, err := s.queryClient.GetTxsEvent(context.Background(), &tx.GetTxsEventRequest{ + Events: []string{sigFormatted}, + OrderBy: 0, + Page: 0, + Limit: 10, + }) + s.Require().NoError(err) + s.Require().Len(res.Txs, 1) + s.Require().Len(res.Txs[0].Signatures, 1) + s.Require().Equal(res.Txs[0].Signatures[0], sig.Signature) + + // bad format should error + _, err = s.queryClient.GetTxsEvent(context.Background(), &tx.GetTxsEventRequest{Events: []string{"tx.foo.bar='baz'"}}) + s.Require().ErrorContains(err, "invalid event;") +} + +func TestEventRegex(t *testing.T) { + t.Parallel() + + testCases := []struct { + name string + event string + match bool + }{ + { + name: "valid: with quotes", + event: "tx.message='something'", + match: true, + }, + { + name: "valid: no quotes", + event: "tx.message=something", + match: true, + }, + { + name: "invalid: too many separators", + event: "tx.message.foo='bar'", + match: false, + }, + { + name: "valid: symbols ok", + event: "tx.signature='foobar/baz123=='", + match: true, + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + match := authtx.EventRegex.Match([]byte(tc.event)) + require.Equal(t, tc.match, match) + }) + } +} + +>>>>>>> 822900b69 (fix: streaming listeners are not called for deliver tx event (#13334)):tests/e2e/tx/service_test.go func (s IntegrationTestSuite) TestSimulateTx_GRPC() { val := s.network.Validators[0] txBuilder := s.mkTxBuilder() From 802bc60dda9f18c569cd92dd350474c37ec1f205 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 20 Sep 2022 16:12:11 +0800 Subject: [PATCH 2/4] Update CHANGELOG.md --- CHANGELOG.md | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71d01546cb6a..ce3e525f3cab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,21 +80,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/group) [#12888](https://github.com/cosmos/cosmos-sdk/pull/12888) Fix event propagation to the current context of `x/group` message execution `[]sdk.Result`. * (x/upgrade) [#12906](https://github.com/cosmos/cosmos-sdk/pull/12906) Fix upgrade failure by moving downgrade verification logic after store migration. -<<<<<<< HEAD -======= -* (store) [#12945](https://github.com/cosmos/cosmos-sdk/pull/12945) Fix nil end semantics in store/cachekv/iterator when iterating a dirty cache. -* (export) [#13029](https://github.com/cosmos/cosmos-sdk/pull/13029) Fix exporting the blockParams regression. -* (x/gov) [#13051](https://github.com/cosmos/cosmos-sdk/pull/13051) In SubmitPropsal, when a legacy msg fails it's handler call, wrap the error as ErrInvalidProposalContent (instead of ErrNoProposalHandlerExists). -* (x/gov) [#13045](https://github.com/cosmos/cosmos-sdk/pull/13045) Fix gov migrations for v3(0.46). -* (Store) [#13334](https://github.com/cosmos/cosmos-sdk/pull/13334) Call streaming listeners for deliver tx event, it was removed accidentally. - -### Deprecated - -* (x/bank) [#11859](https://github.com/cosmos/cosmos-sdk/pull/11859) The Params.SendEnabled field is deprecated and unusable. - The information can now be accessed using the BankKeeper. - Setting can be done using MsgSetSendEnabled as a governance proposal. - A SendEnabled query has been added to both GRPC and CLI. ->>>>>>> 822900b69 (fix: streaming listeners are not called for deliver tx event (#13334)) +* (store) [#13336](https://github.com/cosmos/cosmos-sdk/pull/13336) Call streaming listeners for deliver tx event, it was removed accidentally, backport #13334. ## [v0.46.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0) - 2022-07-26 From 60d178c166fcb7bf945d60b7bd5bf7d1d4fde63e Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 20 Sep 2022 16:13:11 +0800 Subject: [PATCH 3/4] Update x/auth/tx/service_test.go --- x/auth/tx/service_test.go | 79 --------------------------------------- 1 file changed, 79 deletions(-) diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index 7798e3d52a17..be09f7fbc78d 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -112,85 +112,6 @@ func (s *IntegrationTestSuite) TearDownSuite() { s.network.Cleanup() } -<<<<<<< HEAD:x/auth/tx/service_test.go -======= -func (s *IntegrationTestSuite) TestQueryBySig() { - // broadcast tx - txb := s.mkTxBuilder() - txbz, err := s.cfg.TxConfig.TxEncoder()(txb.GetTx()) - s.Require().NoError(err) - resp, err := s.queryClient.BroadcastTx(context.Background(), &tx.BroadcastTxRequest{TxBytes: txbz, Mode: tx.BroadcastMode_BROADCAST_MODE_SYNC}) - s.Require().NoError(err) - s.Require().NotEmpty(resp.TxResponse.TxHash) - - s.Require().NoError(s.network.WaitForNextBlock()) - s.Require().NoError(s.network.WaitForNextBlock()) - - // get the signature out of the builder - sigs, err := txb.GetTx().GetSignaturesV2() - s.Require().NoError(err) - s.Require().Len(sigs, 1) - sig, ok := sigs[0].Data.(*signing.SingleSignatureData) - s.Require().True(ok) - - // encode, format, query - b64Sig := base64.StdEncoding.EncodeToString(sig.Signature) - sigFormatted := fmt.Sprintf("%s.%s='%s'", sdk.EventTypeTx, sdk.AttributeKeySignature, b64Sig) - res, err := s.queryClient.GetTxsEvent(context.Background(), &tx.GetTxsEventRequest{ - Events: []string{sigFormatted}, - OrderBy: 0, - Page: 0, - Limit: 10, - }) - s.Require().NoError(err) - s.Require().Len(res.Txs, 1) - s.Require().Len(res.Txs[0].Signatures, 1) - s.Require().Equal(res.Txs[0].Signatures[0], sig.Signature) - - // bad format should error - _, err = s.queryClient.GetTxsEvent(context.Background(), &tx.GetTxsEventRequest{Events: []string{"tx.foo.bar='baz'"}}) - s.Require().ErrorContains(err, "invalid event;") -} - -func TestEventRegex(t *testing.T) { - t.Parallel() - - testCases := []struct { - name string - event string - match bool - }{ - { - name: "valid: with quotes", - event: "tx.message='something'", - match: true, - }, - { - name: "valid: no quotes", - event: "tx.message=something", - match: true, - }, - { - name: "invalid: too many separators", - event: "tx.message.foo='bar'", - match: false, - }, - { - name: "valid: symbols ok", - event: "tx.signature='foobar/baz123=='", - match: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - match := authtx.EventRegex.Match([]byte(tc.event)) - require.Equal(t, tc.match, match) - }) - } -} - ->>>>>>> 822900b69 (fix: streaming listeners are not called for deliver tx event (#13334)):tests/e2e/tx/service_test.go func (s IntegrationTestSuite) TestSimulateTx_GRPC() { val := s.network.Validators[0] txBuilder := s.mkTxBuilder() From 5289d31c2cc3f52768792847e6fb1fb61c23bd88 Mon Sep 17 00:00:00 2001 From: yihuang Date: Tue, 20 Sep 2022 16:13:27 +0800 Subject: [PATCH 4/4] Update x/auth/tx/service_test.go --- x/auth/tx/service_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/auth/tx/service_test.go b/x/auth/tx/service_test.go index be09f7fbc78d..ca1a0186e333 100644 --- a/x/auth/tx/service_test.go +++ b/x/auth/tx/service_test.go @@ -10,7 +10,6 @@ import ( "github.com/stretchr/testify/suite" - "cosmossdk.io/simapp" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" clienttx "github.com/cosmos/cosmos-sdk/client/tx"