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: fix linter issues #42

Open
wants to merge 7 commits into
base: polymer/multihop-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions e2e/tests/wasm/grandpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() {

// set the trusting period to a value which will still be valid upon client creation, but invalid before the first update
// the contract uses 1600s as the unbonding period with the trusting period evaluating to (unbonding period / 3)
var modifiedTrustingPeriod = (1600 * time.Second) / 3
modifiedTrustingPeriod := (1600 * time.Second) / 3

chainA, chainB := s.GetGrandpaTestChains()

Expand Down Expand Up @@ -449,7 +449,7 @@ func (s *GrandpaTestSuite) TestRecoverClient_Succeeds_GrandpaContract() {
// wait the bad trusting period
time.Sleep(modifiedTrustingPeriod)

// create client pair with substitue
// create client pair with substitute
substituteClientID := clienttypes.FormatClientIdentifier(ibcexported.Wasm, 1)
s.SetupClients(ctx, r, ibc.DefaultClientOpts())

Expand Down
6 changes: 3 additions & 3 deletions modules/core/02-client/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (k Keeper) ConsensusState(c context.Context, req *types.QueryConsensusState
}

// NextConsensusState implements the Query/GetNextConsensusState gRPC method
func (q Keeper) NextConsensusStateHeight(c context.Context, req *types.QueryNextConsensusStateHeightRequest) (*types.QueryNextConsensusStateHeightResponse, error) {
func (k Keeper) NextConsensusStateHeight(c context.Context, req *types.QueryNextConsensusStateHeightRequest) (*types.QueryNextConsensusStateHeightResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}
Expand All @@ -163,8 +163,8 @@ func (q Keeper) NextConsensusStateHeight(c context.Context, req *types.QueryNext
return nil, status.Error(codes.InvalidArgument, "consensus state height cannot be 0")
}

clientStore := q.ClientStore(ctx, req.ClientId)
consensusStateHeight, _ := tm.GetNextConsensusStateHeight(clientStore, q.cdc, height)
clientStore := k.ClientStore(ctx, req.ClientId)
consensusStateHeight, _ := tm.GetNextConsensusStateHeight(clientStore, k.cdc, height)

var resp types.QueryNextConsensusStateHeightResponse
if consensusStateHeight != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/02-client/migrations/v7/solomachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,6 @@ func (ConsensusState) ValidateBasic() error {
}

// GetRoot panics!
func (cs ConsensusState) GetRoot() exported.Root {
func (ConsensusState) GetRoot() exported.Root {
panic("legacy solo machine is deprecated!")
}
48 changes: 24 additions & 24 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,20 @@ func (k Keeper) ChanOpenAck(
ctx, connectionEnd, proofHeight, proofTry,
channel.ConnectionHops, kvGenerator)

} else {
counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}
expectedCounterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
types.TRYOPEN, channel.Ordering, expectedCounterparty,
counterpartyHops, counterpartyVersion,
)

return k.connectionKeeper.VerifyChannelState(
ctx, connectionEnd, proofHeight, proofTry,
channel.Counterparty.PortId, counterpartyChannelID,
expectedChannel,
)
}

counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}
expectedCounterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
types.TRYOPEN, channel.Ordering, expectedCounterparty,
counterpartyHops, counterpartyVersion,
)

return k.connectionKeeper.VerifyChannelState(
ctx, connectionEnd, proofHeight, proofTry,
channel.Counterparty.PortId, counterpartyChannelID,
expectedChannel,
)
}

// WriteOpenAckChannel writes an updated channel state for the successful OpenAck handshake step.
Expand Down Expand Up @@ -419,18 +419,18 @@ func (k Keeper) ChanOpenConfirm(
ctx, connectionEnd, proofHeight, proofAck,
channel.ConnectionHops, kvGenerator)

} else {
counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}
counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
types.OPEN, channel.Ordering, counterparty,
counterpartyHops, channel.Version)

return k.connectionKeeper.VerifyChannelState(
ctx, connectionEnd, proofHeight, proofAck,
channel.Counterparty.PortId, channel.Counterparty.ChannelId,
expectedChannel)
}

counterpartyHops := []string{connectionEnd.GetCounterparty().GetConnectionID()}
counterparty := types.NewCounterparty(portID, channelID)
expectedChannel := types.NewChannel(
types.OPEN, channel.Ordering, counterparty,
counterpartyHops, channel.Version)

return k.connectionKeeper.VerifyChannelState(
ctx, connectionEnd, proofHeight, proofAck,
channel.Counterparty.PortId, channel.Counterparty.ChannelId,
expectedChannel)
}

// WriteOpenConfirmChannel writes an updated channel state for the successful OpenConfirm handshake step.
Expand Down
3 changes: 0 additions & 3 deletions modules/core/04-channel/keeper/multihop_handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand All @@ -16,7 +15,6 @@ import (

// TestChannOpenInit tests the OpenInit handshake call for multihop channels.
func (suite *MultihopTestSuite) TestChanOpenInit() {

var (
features []string
portCap *capabilitytypes.Capability
Expand Down Expand Up @@ -721,7 +719,6 @@ func (suite *MultihopTestSuite) TestChanCloseFrozenMultihop() {

testCases := []testCase{
{"success", func() {

var clientState exported.ClientState

suite.SetupChannels()
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/multihop_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

errorsmod "cosmossdk.io/errors"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down
28 changes: 15 additions & 13 deletions modules/core/04-channel/keeper/multihop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ package keeper_test
import (
"testing"

testifysuite "github.com/stretchr/testify/suite"

ibctesting "github.com/cosmos/ibc-go/v8/testing"
"github.com/stretchr/testify/suite"
)

// TestMultihopMultihopTestSuite runs all multihop related tests.
func TestMultihopTestSuite(t *testing.T) {
suite.Run(t, new(MultihopTestSuite))
testifysuite.Run(t, new(MultihopTestSuite))
}

// MultihopTestSuite is a testing suite to test keeper functions.
type MultihopTestSuite struct {
suite.Suite
testifysuite.Suite
// multihop channel path
chanPath *ibctesting.PathM
coord *ibctesting.CoordinatorM
Expand All @@ -29,26 +30,27 @@ func (suite *MultihopTestSuite) SetupTest(numChains int) {
}

// SetupConnections creates connections between each pair of chains in the multihop path.
func (s *MultihopTestSuite) SetupConnections() {
s.coord.SetupConnections(s.chanPath)
func (suite *MultihopTestSuite) SetupConnections() {
suite.coord.SetupConnections(suite.chanPath)
}

// SetupConnections creates connections between each pair of chains in the multihop path.
func (s *MultihopTestSuite) SetupAllButTheSpecifiedConnection(index int) {
s.coord.SetupAllButTheSpecifiedConnection(s.chanPath, index)
func (suite *MultihopTestSuite) SetupAllButTheSpecifiedConnection(index int) {
err := suite.coord.SetupAllButTheSpecifiedConnection(suite.chanPath, index)
suite.Require().NoError(err)
}

// SetupChannels create a multihop channel after creating all its preprequisites in order, ie. clients, connections.
func (s *MultihopTestSuite) SetupChannels() {
s.coord.SetupChannels(s.chanPath)
func (suite *MultihopTestSuite) SetupChannels() {
suite.coord.SetupChannels(suite.chanPath)
}

// A returns the one endpoint of the multihop channel.
func (s *MultihopTestSuite) A() *ibctesting.EndpointM {
return s.chanPath.EndpointA
func (suite *MultihopTestSuite) A() *ibctesting.EndpointM {
return suite.chanPath.EndpointA
}

// Z returns the other endpoint of the multihop channel.
func (s *MultihopTestSuite) Z() *ibctesting.EndpointM {
return s.chanPath.EndpointZ
func (suite *MultihopTestSuite) Z() *ibctesting.EndpointM {
return suite.chanPath.EndpointZ
}
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/multihop_timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"

errorsmod "cosmossdk.io/errors"
capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"

capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
Expand Down
6 changes: 4 additions & 2 deletions modules/core/04-channel/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
"github.com/cosmos/ibc-go/v8/modules/core/exported"
)

type KeyValueGenFunc func(*MsgMultihopProofs, *connectiontypes.ConnectionEnd) (string, []byte, error)
type KeyGenFunc func(*MsgMultihopProofs, *connectiontypes.ConnectionEnd) (string, error)
type (
KeyValueGenFunc func(*MsgMultihopProofs, *connectiontypes.ConnectionEnd) (string, []byte, error)
KeyGenFunc func(*MsgMultihopProofs, *connectiontypes.ConnectionEnd) (string, error)
)

// ClientKeeper expected account IBC client keeper
type ClientKeeper interface {
Expand Down
2 changes: 2 additions & 0 deletions modules/core/04-channel/types/multihop.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package types

import (
errorsmod "cosmossdk.io/errors"

"github.com/cosmos/cosmos-sdk/codec"

connectiontypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
ibcerrors "github.com/cosmos/ibc-go/v8/modules/core/errors"
"github.com/cosmos/ibc-go/v8/modules/core/exported"
Expand Down
52 changes: 31 additions & 21 deletions modules/core/33-multihop/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,40 +96,45 @@ func (p ChanPath) QueryMultihopProof(
keyHeight exported.Height,
includeKeyValue bool,
) (
multihopProof channeltypes.MsgMultihopProofs,
multihopProofHeight exported.Height,
err error,
channeltypes.MsgMultihopProofs,
exported.Height,
error,
) {
var (
multihopProof channeltypes.MsgMultihopProofs
multihopProofHeight exported.Height
err error
)

if len(p.Paths) < 1 {
err = fmt.Errorf("multihop proof query requires channel path length >= 1")
return
return multihopProof, multihopProofHeight, err
}

// calculate proof heights along channel path
proofHeights := make([]*ProofHeights, len(p.Paths))
if err = p.calcProofHeights(0, keyHeight, proofHeights); err != nil {
return
return multihopProof, multihopProofHeight, err
}

// the consensus state height of the proving chain's counterparty
// this is where multi-hop proof verification begins
multihopProofHeight, ok := proofHeights[len(proofHeights)-1].consensusHeight.Decrement()
if !ok {
err = fmt.Errorf("failed to decrement consensusHeight for multihop proof height")
return
return multihopProof, multihopProofHeight, err
}

// the key/value proof height is the height of the consensusState on the first chain
keyHeight, ok = proofHeights[0].consensusHeight.Decrement()
if !ok {
err = fmt.Errorf("failed to decrement consensusHeight for key height")
return
return multihopProof, multihopProofHeight, err
}

// query the proof of the key/value on the source chain
if multihopProof.KeyProof, err = queryProof(p.Source(), key, keyHeight, false, includeKeyValue); err != nil {
return
return multihopProof, multihopProofHeight, err
}

// query proofs of consensus/connection states on intermediate chains
Expand All @@ -139,21 +144,25 @@ func (p ChanPath) QueryMultihopProof(
len(p.Paths)-2, proofHeights,
multihopProof.ConsensusProofs,
multihopProof.ConnectionProofs); err != nil {
return
return multihopProof, multihopProofHeight, err
}

return
return multihopProof, multihopProofHeight, nil
}

// calcProofHeights calculates the optimal proof heights to generate a multi-hop proof along the channel path
// and performs client updates as needed.
func (p ChanPath) calcProofHeights(pathIdx int, consensusHeight exported.Height, proofHeights []*ProofHeights) (err error) {
var height ProofHeights
func (p ChanPath) calcProofHeights(pathIdx int, consensusHeight exported.Height, proofHeights []*ProofHeights) error {
var (
err error
height ProofHeights
)

chain := p.Paths[pathIdx].EndpointB

// find minimum consensus height provable on the next chain
if height.proofHeight, height.consensusHeight, err = chain.QueryMinimumConsensusHeight(consensusHeight, 3); err != nil {
return
return err
}

// optimized consensus height query
Expand All @@ -168,7 +177,7 @@ func (p ChanPath) calcProofHeights(pathIdx int, consensusHeight exported.Height,
// on subsequent chains.
if height.proofHeight == nil {
if err = chain.UpdateClient(); err != nil {
return
return err
}

height.proofHeight = chain.GetLatestHeight()
Expand All @@ -178,16 +187,16 @@ func (p ChanPath) calcProofHeights(pathIdx int, consensusHeight exported.Height,
// stop on the next to last path segment
if pathIdx == len(p.Paths)-1 {
proofHeights[pathIdx] = &height
return
return err
}

// use the proofHeight as the next consensus height
if err = p.calcProofHeights(pathIdx+1, height.proofHeight, proofHeights); err != nil {
return
return err
}

proofHeights[pathIdx] = &height
return
return nil
}

// queryIntermediateProofs recursively queries intermediate chains in a multi-hop channel path for consensus state
Expand All @@ -198,24 +207,25 @@ func (p ChanPath) queryIntermediateProofs(
proofHeights []*ProofHeights,
consensusProofs []*channeltypes.MultihopProof,
connectionProofs []*channeltypes.MultihopProof,
) (err error) {
) error {
var err error

// no need to query proofs on final chain since the clientState is already known
if proofIdx < 0 {
return
return nil
}

chain := p.Paths[proofIdx].EndpointB
ph := proofHeights[proofIdx]

// query proof of the consensusState
if consensusProofs[len(p.Paths)-proofIdx-2], err = queryConsensusStateProof(chain, ph.proofHeight, ph.consensusHeight); err != nil {
return
return err
}

// query proof of the connectionEnd
if connectionProofs[len(p.Paths)-proofIdx-2], err = queryConnectionProof(chain, ph.proofHeight); err != nil {
return
return err
}

// continue querying proofs on the next chain in the path
Expand Down
Loading
Loading