Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid invalid identifier error when validate genesis (backport #7397) #7403

Merged
merged 3 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (core/03-connection) [\#7397](https://github.com/cosmos/ibc-go/pull/7397) Skip the genesis validation connectionID for localhost client.

## [v8.5.1](https://github.com/cosmos/ibc-go/releases/tag/v8.5.1) - 2024-09-13

### Bug Fixes
Expand Down
16 changes: 9 additions & 7 deletions modules/core/03-connection/types/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

host "github.com/cosmos/ibc-go/v8/modules/core/24-host"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
)

// NewConnectionPaths creates a ConnectionPaths instance.
Expand Down Expand Up @@ -45,13 +46,14 @@ func (gs GenesisState) Validate() error {
var maxSequence uint64

for i, conn := range gs.Connections {
sequence, err := ParseConnectionSequence(conn.Id)
if err != nil {
return err
}

if sequence > maxSequence {
maxSequence = sequence
if conn.Id != exported.LocalhostConnectionID {
sequence, err := ParseConnectionSequence(conn.Id)
if err != nil {
return err
}
if sequence > maxSequence {
maxSequence = sequence
}
}

if err := conn.ValidateBasic(); err != nil {
Expand Down
15 changes: 15 additions & 0 deletions modules/core/03-connection/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

Expand Down Expand Up @@ -91,6 +92,20 @@ func TestValidateGenesis(t *testing.T) {
),
expPass: false,
},
{
name: "localhost connection identifier",
genState: types.NewGenesisState(
[]types.IdentifiedConnection{
types.NewIdentifiedConnection(exported.LocalhostConnectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion}, 500)),
},
[]types.ConnectionPaths{
{clientID, []string{connectionID}},
},
0,
types.DefaultParams(),
),
expPass: true,
},
{
name: "next connection sequence is not greater than maximum connection identifier sequence provided",
genState: types.NewGenesisState(
Expand Down
Loading