From 7df9ebd316e7175683861667b787519d450c40a6 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:02:36 +0200 Subject: [PATCH] fix: avoid invalid identifier error when validate genesis (backport #7397) (#7403) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 (cherry picked from commit ff2b668cfd270dc15ab698667ca1442fc590eab4) # Conflicts: # CHANGELOG.md # modules/core/03-connection/types/genesis.go # modules/core/03-connection/types/genesis_test.go * chore: changelog cleanup * chore: fix imports --------- Co-authored-by: mmsqe Co-authored-by: Colin Axnér <25233464+colin-axner@users.noreply.github.com> --- CHANGELOG.md | 2 ++ modules/core/03-connection/types/genesis.go | 16 +++++++++------- modules/core/03-connection/types/genesis_test.go | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 200cd0fbb55..e2518d7e85d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/modules/core/03-connection/types/genesis.go b/modules/core/03-connection/types/genesis.go index c273f82e363..8536c08ea19 100644 --- a/modules/core/03-connection/types/genesis.go +++ b/modules/core/03-connection/types/genesis.go @@ -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. @@ -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 { diff --git a/modules/core/03-connection/types/genesis_test.go b/modules/core/03-connection/types/genesis_test.go index 6e5a0ce1170..b61dc97f892 100644 --- a/modules/core/03-connection/types/genesis_test.go +++ b/modules/core/03-connection/types/genesis_test.go @@ -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" ) @@ -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(