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

chore: address linter issues in 04-channel, 06-solomachines, 09-localhost #6130

Merged
merged 12 commits into from
Apr 12, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,8 @@ func (suite *SoloMachineTestSuite) TestVerifyMembership() {
// Grab fresh client state after updates.
cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID)
suite.Require().True(found)
clientState = cs.(*solomachine.ClientState)
clientState, ok = cs.(*solomachine.ClientState)
suite.Require().True(ok)
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved

suite.Require().NoError(err)
// clientState.Sequence is the most recent view of state.
Expand Down Expand Up @@ -907,7 +908,8 @@ func (suite *SoloMachineTestSuite) TestVerifyNonMembership() {
// Grab fresh client state after updates.
cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), clientID)
suite.Require().True(found)
clientState = cs.(*solomachine.ClientState)
clientState, ok = cs.(*solomachine.ClientState)
suite.Require().True(ok)
DimitrisJim marked this conversation as resolved.
Show resolved Hide resolved

suite.Require().NoError(err)
suite.Require().Equal(expSeq, clientState.Sequence)
Expand Down Expand Up @@ -1005,7 +1007,8 @@ func (suite *SoloMachineTestSuite) TestRecoverClient() {
// assert that status of subject client is now Active
clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, subjectClientID)
bz = clientStore.Get(host.ClientStateKey())
smClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState)
smClientState, ok := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, bz).(*solomachine.ClientState)
suite.Require().True(ok)

suite.Require().Equal(substituteClientState.ConsensusState, smClientState.ConsensusState)
suite.Require().Equal(substituteClientState.Sequence, smClientState.Sequence)
Expand Down
4 changes: 3 additions & 1 deletion modules/light-clients/06-solomachine/solomachine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ func (suite *SoloMachineTestSuite) GetSequenceFromStore() uint64 {
err := suite.chainA.Codec.UnmarshalInterface(bz, &clientState)
suite.Require().NoError(err)

smClientState := clientState.(*solomachine.ClientState)
smClientState, ok := clientState.(*solomachine.ClientState)
suite.Require().True(ok)

return smClientState.Sequence
}

Expand Down
10 changes: 9 additions & 1 deletion modules/light-clients/06-solomachine/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package solomachine

import (
"fmt"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -18,5 +20,11 @@
}

clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz)
return clientStateI.(*ClientState), true
var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T to %T", clientStateI, clientState))
Fixed Show fixed Hide fixed

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
Copy link
Contributor

@crodriguezvega crodriguezvega Apr 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess if we wanted to avoid the panic we could return nil, false, but that's stretching maybe a bit too much the semantics of the function signature...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that nil, false would probably hide the issue. The other way would be to change the signature to return an error, but it seems this would become a much broader PR

}

return clientState, true
bznein marked this conversation as resolved.
Show resolved Hide resolved
}
16 changes: 14 additions & 2 deletions modules/light-clients/07-tendermint/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import (
"bytes"
"encoding/binary"
"fmt"

"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -59,7 +60,12 @@
}

clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz)
return clientStateI.(*ClientState), true
var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
return clientState, true
}

// setConsensusState stores the consensus state at the given height.
Expand All @@ -78,7 +84,13 @@
}

consensusStateI := clienttypes.MustUnmarshalConsensusState(cdc, bz)
return consensusStateI.(*ConsensusState), true
var consensusState *ConsensusState
consensusState, ok := consensusStateI.(*ConsensusState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", consensusStateI, consensusState))
Fixed Show fixed Hide fixed

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

return consensusState, true
}

// deleteConsensusState deletes the consensus state at the given height
Expand Down
5 changes: 4 additions & 1 deletion modules/light-clients/07-tendermint/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@
return []exported.Height{header.GetHeight()}
}

height := header.GetHeight().(clienttypes.Height)
height, ok := header.GetHeight().(clienttypes.Height)
if !ok {
panic(fmt.Errorf("cannot convert %T to %T", header.GetHeight(), &clienttypes.Height{}))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
if height.GT(cs.LatestHeight) {
cs.LatestHeight = height
}
Expand Down
4 changes: 3 additions & 1 deletion modules/light-clients/09-localhost/client_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func (suite *LocalhostTestSuite) TestUpdateState() {
expHeight := clienttypes.NewHeight(1, uint64(suite.chain.GetContext().BlockHeight()))
suite.Require().True(heights[0].EQ(expHeight))

clientState = suite.chain.GetClientState(exported.LocalhostClientID).(*localhost.ClientState)
var ok bool
clientState, ok = suite.chain.GetClientState(exported.LocalhostClientID).(*localhost.ClientState)
suite.Require().True(ok)
suite.Require().True(heights[0].EQ(clientState.LatestHeight))
}
10 changes: 9 additions & 1 deletion modules/light-clients/09-localhost/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package localhost

import (
"fmt"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
Expand All @@ -18,5 +20,11 @@
}

clientStateI := clienttypes.MustUnmarshalClientState(cdc, bz)
return clientStateI.(*ClientState), true
var clientState *ClientState
clientState, ok := clientStateI.(*ClientState)
if !ok {
panic(fmt.Errorf("cannot convert %T into %T", clientStateI, clientState))
Fixed Show fixed Hide fixed

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}

return clientState, true
}
Loading