cosmos / interchain-security

Interchain Security is an open sourced IBC application which allows cosmos blockchains to lease their proof-of-stake security to one another.
https://cosmos.github.io/interchain-security/
Other
154 stars 119 forks source link

Cannot relay acknowledgement from the first empty VSC packet back to provider #240

Closed danwt closed 2 years ago

danwt commented 2 years ago

When I test acknowledgements, there is an error delivering the first ACK from the consumer back to the provider. That is: the first empty VSC packet is required in order to complete the init handshake. The ack for this fails to be delivered using the ibc-go testing framework.

I need to debug more but this is not a priority. Here is the ack data

github.com/cosmos/interchain-security/x/ccv/difftest_test.Ack {ack: []uint8 len: 17, cap: 24, [123,34,114,101,115,117,108,116,34,58,34,65,81,61,61,34,125], packet: github.com/cosmos/ibc-go/v3/modules/core/04-channel/types.Packet {Sequence: 1, SourcePort: "provider", SourceChannel: "channel-0", DestinationPort: "consumer", DestinationChannel: "channel-0", Data: []uint8 len: 64, cap: 64, [123,34,118,97,108,105,100,97,116,111,114,95,117,112,100,97,116,101,115,34,58,91,93,44,34,118,97,108,115,101,116,95,117,112,100,97,116,101,95,105,100,34,58,34,49,54,34,44,34,115,108,97,115,104,95,97,99,107,115,34,58,91,93,125], TimeoutHeight: (*"github.com/cosmos/ibc-go/v3/modules/core/02-client/types.Height")(0x140010be5f0), TimeoutTimestamp: 1580342545000000000}, commits: 2}

here is the error

--- FAIL: TestDTTestSuite (0.07s)
    --- FAIL: TestDTTestSuite/TestAssumptions (0.07s)
        test_helpers.go:260:
                Error Trace:    test_helpers.go:260
                                            relay.go:89
                                            diff_test.go:531
                                            diff_test.go:610
                                            diff_test.go:649
                                            diff_test.go:390
                                            suite.go:148
                Error:          Received unexpected error:

                                github.com/cosmos/cosmos-sdk/x/capability/keeper.ScopedKeeper.LookupModules
                                    /Users/danwt/Documents/work/cosmos-sdk/x/capability/keeper/keeper.go:440
                                github.com/cosmos/ibc-go/v3/modules/core/04-channel/keeper.Keeper.LookupModuleByChannel
                                    /Users/danwt/Documents/work/informal-ibc-go/modules/core/04-channel/keeper/keeper.go:435
                                github.com/cosmos/ibc-go/v3/modules/core/keeper.Keeper.Acknowledgement
                                    /Users/danwt/Documents/work/informal-ibc-go/modules/core/keeper/msg_server.go:590
                                github.com/cosmos/ibc-go/v3/modules/core/04-channel/types._Msg_Acknowledgement_Handler.func1
                                    /Users/danwt/Documents/work/informal-ibc-go/modules/core/04-channel/types/tx.pb.go:1360
                                github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2.1
                                    /Users/danwt/Documents/work/cosmos-sdk/baseapp/msg_service_router.go:113
                                github.com/cosmos/ibc-go/v3/modules/core/04-channel/types._Msg_Acknowledgement_Handler
                                    /Users/danwt/Documents/work/informal-ibc-go/modules/core/04-channel/types/tx.pb.go:1362
                                github.com/cosmos/cosmos-sdk/baseapp.(*MsgServiceRouter).RegisterService.func2
                                    /Users/danwt/Documents/work/cosmos-sdk/baseapp/msg_service_router.go:117
                                github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runMsgs
                                    /Users/danwt/Documents/work/cosmos-sdk/baseapp/baseapp.go:720
                                github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).runTx
                                    /Users/danwt/Documents/work/cosmos-sdk/baseapp/baseapp.go:677
                                github.com/cosmos/cosmos-sdk/baseapp.(*BaseApp).Deliver
                                    /Users/danwt/Documents/work/cosmos-sdk/baseapp/test_helpers.go:33
                                github.com/cosmos/ibc-go/v3/testing/simapp.SignAndDeliver
                                    /Users/danwt/Documents/work/informal-ibc-go/testing/simapp/test_helpers.go:257
                                github.com/cosmos/interchain-security/x/ccv/difftest.TryRecvAck
                                    /Users/danwt/Documents/work/interchain-security/x/ccv/difftest/relay.go:89
                                command-line-arguments_test.(*DTTestSuite).idempotentDeliverAcks
                                    /Users/danwt/Documents/work/interchain-security/x/ccv/difftest/diff_test.go:531
                                command-line-arguments_test.(*DTTestSuite).endBlock
                                    /Users/danwt/Documents/work/interchain-security/x/ccv/difftest/diff_test.go:610
                                command-line-arguments_test.(*DTTestSuite).jumpNBlocks
                                    /Users/danwt/Documents/work/interchain-security/x/ccv/difftest/diff_test.go:649
                                command-line-arguments_test.(*DTTestSuite).SetupTest
                                    /Users/danwt/Documents/work/interchain-security/x/ccv/difftest/diff_test.go:390
                                github.com/stretchr/testify/suite.Run.func1
                                    /Users/danwt/go/pkg/mod/github.com/stretchr/testify@v1.7.0/suite/suite.go:148
                                failed to execute message; message index: 0: could not retrieve module from port-id: capabilities/ports/provider/channels/channel-0: capability not found
                Test:           TestDTTestSuite/TestAssumptions
FAIL
FAIL    command-line-arguments  0.558s

here is the relevant code

https://github.com/cosmos/cosmos-sdk/blob/c99a6318143ddc5c66c7ad9ec6f6c1dca2170b8c/x/capability/keeper/keeper.go#L435-L445

and here is the capability name and ctx

"capabilities/ports/provider/channels/channel-0"
github.com/cosmos/cosmos-sdk/types.Context {ctx: context.Context(*context.emptyCtx) *0, ms: github.com/cosmos/cosmos-sdk/store/types.MultiStore(github.com/cosmos/cosmos-sdk/store/cachemulti.Store) {db: github.com/cosmos/cosmos-sdk/store/types.CacheKVStore(*github.com/cosmos/cosmos-sdk/store/cachekv.Store) ..., stores: map[github.com/cosmos/cosmos-sdk/store/types.StoreKey]github.com/cosmos/cosmos-sdk/store/types.CacheWrap [...], keys: map[string]github.com/cosmos/cosmos-sdk/store/types.StoreKey nil, traceWriter: io.Writer nil, traceContext: github.com/cosmos/cosmos-sdk/store/types.TraceContext nil, listeners: map[github.com/cosmos/cosmos-sdk/store/types.StoreKey][]github.com/cosmos/cosmos-sdk/store/types.WriteListener []}, header: github.com/tendermint/tendermint/proto/tendermint/types.Header {Version: (*"github.com/tendermint/tendermint/proto/tendermint/version.Consensus")(0x140010b9c08), ChainID: "testchain1", Height: 20, Time: (*time.Time)(0x140010b9c30), LastBlockId: (*"github.com/tendermint/tendermint/proto/tendermint/types.BlockID")(0x140010b9c48), LastCommitHash: []uint8 len: 0, cap: 0, nil, DataHash: []uint8 len: 0, cap: 0, nil, ValidatorsHash: []uint8 len: 32, cap: 32, [8,86,137,25,164,165,8,153,55,61,217,145,113,69,42,182,31,138,56,217,118,77,151,15,119,174,251,215,184,207,190,99], NextValidatorsHash: []uint8 len: 32, cap: 32, [8,86,137,25,164,165,8,153,55,61,217,145,113,69,42,182,31,138,56,217,118,77,151,15,119,174,251,215,184,207,190,99], ConsensusHash: []uint8 len: 0, cap: 0, nil, AppHash: []uint8 len: 32, cap: 32, [133,97,132,167,232,77,82,98,146,218,42,183,97,76,195,20,184,80,36,225,139,62,168,192,137,166,176,83,161,222,101,43], LastResultsHash: []uint8 len: 0, cap: 0, nil, EvidenceHash: []uint8 len: 0, cap: 0, nil, ProposerAddress: []uint8 len: 0, cap: 0, nil}, headerHash: github.com/tendermint/tendermint/libs/bytes.HexBytes len: 0, cap: 0, [], chainID: "testchain1", txBytes: []uint8 len: 1104, cap: 1104, [10,165,7,10,128,7,10,39,47,105,98,99,46,99,111,114,101,46,99,104,97,110,110,101,108,46,118,49,46,77,115,103,65,99,107,110,111,119,108,101,100,103,101,109,101,110,116,18,212,6,10,122,8,1,18,8,112,114,111,118,105,100,101,114,...+1040 more], logger: github.com/tendermint/tendermint/libs/log.Logger(*github.com/tendermint/tendermint/libs/log.nopLogger) *{}, voteInfo: []github.com/tendermint/tendermint/abci/types.VoteInfo len: 0, cap: 0, nil, gasMeter: github.com/cosmos/cosmos-sdk/store/types.GasMeter(*github.com/cosmos/cosmos-sdk/store/types.basicGasMeter) *{limit: 1000000, consumed: 50982}, blockGasMeter: github.com/cosmos/cosmos-sdk/store/types.GasMeter(*github.com/cosmos/cosmos-sdk/store/types.basicGasMeter) *{limit: 2000000, consumed: 95890}, checkTx: false, recheckTx: false, minGasPrice: github.com/cosmos/cosmos-sdk/types.DecCoins len: 0, cap: 0, [], consParams: *github.com/tendermint/tendermint/abci/types.ConsensusParams {Block: *(*"github.com/tendermint/tendermint/abci/types.BlockParams")(0x140013d2010), Evidence: *(*"github.com/tendermint/tendermint/proto/tendermint/types.EvidenceParams")(0x14001356060), Validator: *(*"github.com/tendermint/tendermint/proto/tendermint/types.ValidatorParams")(0x140016fc0d8), Version: *github.com/tendermint/tendermint/proto/tendermint/types.VersionParams nil}, eventManager: *github.com/cosmos/cosmos-sdk/types.EventManager {events: github.com/cosmos/cosmos-sdk/types.Events len: 0, cap: 0, []}}
danwt commented 2 years ago

This could be a false positive or a problem with the way the test is setup.

danwt commented 2 years ago

Replication commit

cd x/ccv/difftest go test -run TestDTTestSuite/TestAssumptions diff_test.go

mpoke commented 2 years ago

When I test acknowledgements, there is an error delivering the first ACK from the consumer back to the provider. That is: the first empty VSC packet is required in order to complete the init handshake. The ack for this fails to be delivered using the ibc-go testing framework.

Why "the first empty VSC packet"?

The first VSC packet is sent either here https://github.com/cosmos/interchain-security/blob/10c19a090536e3373f66a8131c833cdafb7abd43/x/ccv/provider/keeper/relay.go#L130 (in case there are pending VSCs) or here https://github.com/cosmos/interchain-security/blob/10c19a090536e3373f66a8131c833cdafb7abd43/x/ccv/provider/keeper/relay.go#L152 once GetChainToChannel(ctx, chainID) returns a channelID, which is set here https://github.com/cosmos/interchain-security/blob/10c19a090536e3373f66a8131c833cdafb7abd43/x/ccv/provider/module.go#L311

danwt commented 2 years ago

Hey I will look into this again. I was using an empty vsc packet in the tests to explicitly complete the last step of the handshake.

I will check if this is a real bug or if it's just because of the way the test is written.

danwt commented 2 years ago

I had a single character typo.