Skip to content

Commit

Permalink
Merge branch 'main' into colin/176-update-client
Browse files Browse the repository at this point in the history
  • Loading branch information
colin-axner committed May 25, 2021
2 parents 250ae76 + 4570955 commit 6f10f18
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (modules/light-clients/06-solomachine) [\153](https://github.com/cosmos/ibc-go/pull/153) Fix solo machine proof height sequence mismatch bug.
* (02-client) [\#192](https://github.com/cosmos/ibc-go/pull/192) Fix IBC `query ibc client header` cli command. Support historical queries for query header/node-state commands.
* (modules/light-clients/06-solomachine) [\#153](https://github.com/cosmos/ibc-go/pull/153) Fix solo machine proof height sequence mismatch bug.
* (modules/light-clients/06-solomachine) [\#122](https://github.com/cosmos/ibc-go/pull/122) Fix solo machine merkle prefix casting bug.
* (modules/light-clients/06-solomachine) [\#120](https://github.com/cosmos/ibc-go/pull/120) Fix solo machine handshake verification bug.

Expand Down
16 changes: 13 additions & 3 deletions modules/core/02-client/client/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,19 @@ func QueryTendermintHeader(clientCtx client.Context) (ibctmtypes.Header, int64,
return ibctmtypes.Header{}, 0, err
}

height := info.Response.LastBlockHeight
var height int64
if clientCtx.Height != 0 {
height = clientCtx.Height
} else {
height = info.Response.LastBlockHeight
}

commit, err := node.Commit(context.Background(), &height)
if err != nil {
return ibctmtypes.Header{}, 0, err
}

page := 0
page := 1
count := 10_000

validators, err := node.Validators(context.Background(), &height, &page, &count)
Expand Down Expand Up @@ -173,7 +178,12 @@ func QueryNodeConsensusState(clientCtx client.Context) (*ibctmtypes.ConsensusSta
return &ibctmtypes.ConsensusState{}, 0, err
}

height := info.Response.LastBlockHeight
var height int64
if clientCtx.Height != 0 {
height = clientCtx.Height
} else {
height = info.Response.LastBlockHeight
}

commit, err := node.Commit(context.Background(), &height)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions modules/light-clients/07-tendermint/types/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func (cs ClientState) Validate() error {
if strings.TrimSpace(cs.ChainId) == "" {
return sdkerrors.Wrap(ErrInvalidChainID, "chain id cannot be empty string")
}

// NOTE: the value of tmtypes.MaxChainIDLen may change in the future.
// If this occurs, the code here must account for potential difference
// between the tendermint version being run by the counterparty chain
// and the tendermint version used by this light client.
// https://github.com/cosmos/ibc-go/issues/177
if len(cs.ChainId) > tmtypes.MaxChainIDLen {
return sdkerrors.Wrapf(ErrInvalidChainID, "chainID is too long; got: %d, max: %d", len(cs.ChainId), tmtypes.MaxChainIDLen)
}
Expand Down
20 changes: 17 additions & 3 deletions modules/light-clients/07-tendermint/types/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const (
testPortID = "testportid"
testChannelID = "testchannelid"
testSequence = 1
longChainID = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

// Do not change the length of these variables
fiftyCharChainID = "12345678901234567890123456789012345678901234567890"
fiftyOneCharChainID = "123456789012345678901234567890123456789012345678901"
)

var (
Expand Down Expand Up @@ -90,8 +93,19 @@ func (suite *TendermintTestSuite) TestValidate() {
expPass: false,
},
{
name: "invalid chainID - chainID is above maximum character length",
clientState: types.NewClientState(longChainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false),
// NOTE: if this test fails, the code must account for the change in chainID length across tendermint versions!
// Do not only fix the test, fix the code!
// https://github.com/cosmos/ibc-go/issues/177
name: "valid chainID - chainID validation failed for chainID of length 50! ",
clientState: types.NewClientState(fiftyCharChainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false),
expPass: true,
},
{
// NOTE: if this test fails, the code must account for the change in chainID length across tendermint versions!
// Do not only fix the test, fix the code!
// https://github.com/cosmos/ibc-go/issues/177
name: "invalid chainID - chainID validation did not fail for chainID of length 51! ",
clientState: types.NewClientState(fiftyOneCharChainID, types.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, height, commitmenttypes.GetSDKSpecs(), upgradePath, false, false),
expPass: false,
},
{
Expand Down

0 comments on commit 6f10f18

Please sign in to comment.