Skip to content

Commit ff2b668

Browse files
authored
fix: avoid invalid identifier error when validate genesis (#7397)
* fix: avoid invalid identifier error when validate genesis that contains localhost client * Apply suggestions from code review * skip
1 parent 3af3462 commit ff2b668

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
6464

6565
* (apps/27-interchain-accounts) [\#7277](https://github.com/cosmos/ibc-go/pull/7277) Use `GogoResolver` when populating module query safe allow list to avoid panics from unresolvable protobuf dependencies.
6666
* (core/04-channel) [\#7342](https://github.com/cosmos/ibc-go/pull/7342) Read Tx cmd flags including from address to avoid Address cannot be empty error when upgrade-channels via cli.
67+
* (core/03-connection) [\#7397](https://github.com/cosmos/ibc-go/pull/7397) Skip the genesis validation connectionID for localhost client.
6768

6869
## [v9.0.0](https://github.com/cosmos/ibc-go/releases/tag/v9.0.0) - 2024-10-01
6970

modules/core/03-connection/types/genesis.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55

66
host "github.com/cosmos/ibc-go/v9/modules/core/24-host"
7+
"github.com/cosmos/ibc-go/v9/modules/core/exported"
78
)
89

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

4748
for i, conn := range gs.Connections {
48-
sequence, err := ParseConnectionSequence(conn.Id)
49-
if err != nil {
50-
return err
51-
}
52-
53-
if sequence > maxSequence {
54-
maxSequence = sequence
49+
if conn.Id != exported.LocalhostConnectionID {
50+
sequence, err := ParseConnectionSequence(conn.Id)
51+
if err != nil {
52+
return err
53+
}
54+
if sequence > maxSequence {
55+
maxSequence = sequence
56+
}
5557
}
5658

5759
if err := conn.ValidateBasic(); err != nil {

modules/core/03-connection/types/genesis_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
"github.com/cosmos/ibc-go/v9/modules/core/03-connection/types"
99
commitmenttypes "github.com/cosmos/ibc-go/v9/modules/core/23-commitment/types"
10+
"github.com/cosmos/ibc-go/v9/modules/core/exported"
1011
ibctesting "github.com/cosmos/ibc-go/v9/testing"
1112
)
1213

@@ -91,6 +92,20 @@ func TestValidateGenesis(t *testing.T) {
9192
),
9293
expPass: false,
9394
},
95+
{
96+
name: "localhost connection identifier",
97+
genState: types.NewGenesisState(
98+
[]types.IdentifiedConnection{
99+
types.NewIdentifiedConnection(exported.LocalhostConnectionID, types.NewConnectionEnd(types.INIT, clientID, types.Counterparty{clientID2, connectionID2, commitmenttypes.NewMerklePrefix([]byte("prefix"))}, []*types.Version{ibctesting.ConnectionVersion}, 500)),
100+
},
101+
[]types.ConnectionPaths{
102+
{clientID, []string{connectionID}},
103+
},
104+
0,
105+
types.DefaultParams(),
106+
),
107+
expPass: true,
108+
},
94109
{
95110
name: "next connection sequence is not greater than maximum connection identifier sequence provided",
96111
genState: types.NewGenesisState(

0 commit comments

Comments
 (0)