Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/interchaintest/github.…
Browse files Browse the repository at this point in the history
…com/cometbft/cometbft-0.38.5
  • Loading branch information
jtieri authored Feb 28, 2024
2 parents 8dcad37 + 2cc152b commit 1f15f65
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/prometheus/client_golang v1.17.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.18.1
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6
github.com/strangelove-ventures/cometbft-client v0.1.0
github.com/stretchr/testify v1.8.4
github.com/tyler-smith/go-bip39 v1.1.0
go.uber.org/multierr v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1056,8 +1056,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM=
github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6 h1:+GBtxz0ZdS/UiGl9mK+g9P6k9MDpLxhw7reBIDyIm+Q=
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6/go.mod h1:QzThgjzvsGgUNVNpGPitmxOWMIhp6a0oqf80nCRNt/0=
github.com/strangelove-ventures/cometbft-client v0.1.0 h1:fcA652QaaR0LDnyJOZVjZKtuyAawnVXaq/p1MWJSYD4=
github.com/strangelove-ventures/cometbft-client v0.1.0/go.mod h1:QzThgjzvsGgUNVNpGPitmxOWMIhp6a0oqf80nCRNt/0=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down
2 changes: 1 addition & 1 deletion interchaintest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ require (
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.18.1 // indirect
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6 // indirect
github.com/strangelove-ventures/cometbft-client v0.1.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
4 changes: 2 additions & 2 deletions interchaintest/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1151,8 +1151,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM=
github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk=
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6 h1:+GBtxz0ZdS/UiGl9mK+g9P6k9MDpLxhw7reBIDyIm+Q=
github.com/strangelove-ventures/cometbft-client v0.0.0-20240122193328-9503d3144af6/go.mod h1:QzThgjzvsGgUNVNpGPitmxOWMIhp6a0oqf80nCRNt/0=
github.com/strangelove-ventures/cometbft-client v0.1.0 h1:fcA652QaaR0LDnyJOZVjZKtuyAawnVXaq/p1MWJSYD4=
github.com/strangelove-ventures/cometbft-client v0.1.0/go.mod h1:QzThgjzvsGgUNVNpGPitmxOWMIhp6a0oqf80nCRNt/0=
github.com/strangelove-ventures/interchaintest/v8 v8.0.1-0.20231114192524-e3719592933b h1:VDe2ofJ2xiiLwkJ6qhcF2gvg75gB4WVpXO8lFzhYQOU=
github.com/strangelove-ventures/interchaintest/v8 v8.0.1-0.20231114192524-e3719592933b/go.mod h1:TbVaBTSa9Y7/Jj/JeqoH79fAcyQiHloz1zxXxKjtCFA=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
Expand Down
7 changes: 6 additions & 1 deletion relayer/chains/cosmos/cosmos_chain_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,14 @@ func (ccp *CosmosChainProcessor) initializeConnectionState(ctx context.Context)

// initializeChannelState will bootstrap the channelStateCache with the open channel state.
func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, queryStateTimeout)
ctx, cancel := context.WithCancel(ctx)
defer cancel()

channels, err := ccp.chainProvider.QueryChannels(ctx)
if err != nil {
return fmt.Errorf("error querying channels: %w", err)
}

for _, ch := range channels {
if len(ch.ConnectionHops) != 1 {
ccp.log.Error("Found channel using multiple connection hops. Not currently supported, ignoring.",
Expand All @@ -322,15 +324,18 @@ func (ccp *CosmosChainProcessor) initializeChannelState(ctx context.Context) err
)
continue
}

ccp.channelConnections[ch.ChannelId] = ch.ConnectionHops[0]
k := processor.ChannelKey{
ChannelID: ch.ChannelId,
PortID: ch.PortId,
CounterpartyChannelID: ch.Counterparty.ChannelId,
CounterpartyPortID: ch.Counterparty.PortId,
}

ccp.channelStateCache.SetOpen(k, ch.State == chantypes.OPEN, ch.Ordering)
}

return nil
}

Expand Down
25 changes: 13 additions & 12 deletions relayer/chains/cosmos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,36 +882,38 @@ func (cc *CosmosProvider) QueryConnectionChannels(ctx context.Context, height in
return channels, nil
}

// QueryChannels returns all the channels that are registered on a chain
// QueryChannels returns all the channels that are registered on a chain.
func (cc *CosmosProvider) QueryChannels(ctx context.Context) ([]*chantypes.IdentifiedChannel, error) {
qc := chantypes.NewQueryClient(cc)
p := DefaultPageRequest()
chans := []*chantypes.IdentifiedChannel{}

for {
res, err := qc.Channels(ctx, &chantypes.QueryChannelsRequest{
Pagination: p,
})
res, next, err := cc.QueryChannelsPaginated(ctx, p)
if err != nil {
return nil, err
}

chans = append(chans, res.Channels...)
next := res.GetPagination().GetNextKey()
chans = append(chans, res...)
if len(next) == 0 {
break
}

time.Sleep(PaginationDelay)
p.Key = next
}

return chans, nil
}

// QueryChannels returns all the channels that are registered on a chain
func (cc *CosmosProvider) QueryChannelsPaginated(ctx context.Context, pageRequest *querytypes.PageRequest) ([]*chantypes.IdentifiedChannel, []byte, error) {
// QueryChannelsPaginated returns all the channels for a particular paginated request that are registered on a chain.
func (cc *CosmosProvider) QueryChannelsPaginated(
ctx context.Context,
pageRequest *querytypes.PageRequest,
) ([]*chantypes.IdentifiedChannel, []byte, error) {
qc := chantypes.NewQueryClient(cc)
chans := []*chantypes.IdentifiedChannel{}

ctx, cancel := context.WithTimeout(ctx, time.Second*10)
defer cancel()

res, err := qc.Channels(ctx, &chantypes.QueryChannelsRequest{
Pagination: pageRequest,
Expand All @@ -920,10 +922,9 @@ func (cc *CosmosProvider) QueryChannelsPaginated(ctx context.Context, pageReques
return nil, nil, err
}

chans = append(chans, res.Channels...)
next := res.GetPagination().GetNextKey()

return chans, next, nil
return res.Channels, next, nil
}

// QueryPacketCommitments returns an array of packet commitments
Expand Down
5 changes: 3 additions & 2 deletions relayer/codecs/injective/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package injective
import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
)

Expand All @@ -20,10 +21,10 @@ func RegisterInterfaces(registry codectypes.InterfaceRegistry) {
registry.RegisterImplementations((*cryptotypes.PubKey)(nil), &PubKey{})
registry.RegisterImplementations((*cryptotypes.PrivKey)(nil), &PrivKey{})

registry.RegisterInterface("injective.types.v1beta1.EthAccount", (*authtypes.AccountI)(nil))
registry.RegisterInterface("injective.types.v1beta1.EthAccount", (*types.AccountI)(nil))

registry.RegisterImplementations(
(*authtypes.AccountI)(nil),
(*types.AccountI)(nil),
&EthAccount{},
)

Expand Down
19 changes: 17 additions & 2 deletions relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (mp *messageProcessor) processMessages(
var needsClientUpdate bool

// Localhost IBC does not permit client updates
if src.clientState.ClientID != ibcexported.LocalhostClientID && dst.clientState.ClientID != ibcexported.LocalhostConnectionID {
if !isLocalhostClient(src.clientState.ClientID, dst.clientState.ClientID) {
var err error
needsClientUpdate, err = mp.shouldUpdateClientNow(ctx, src, dst)
if err != nil {
Expand All @@ -117,13 +117,22 @@ func (mp *messageProcessor) processMessages(
return mp.trackAndSendMessages(ctx, src, dst, needsClientUpdate)
}

func isLocalhostClient(srcClientID, dstClientID string) bool {
if srcClientID == ibcexported.LocalhostClientID && dstClientID == ibcexported.LocalhostConnectionID {
return true
}

return false
}

// shouldUpdateClientNow determines if an update client message should be sent
// even if there are no messages to be sent now. It will not be attempted if
// there has not been enough blocks since the last client update attempt.
// Otherwise, it will be attempted if either 2/3 of the trusting period
// or the configured client update threshold duration has passed.
func (mp *messageProcessor) shouldUpdateClientNow(ctx context.Context, src, dst *pathEndRuntime) (bool, error) {
var consensusHeightTime time.Time

if dst.clientState.ConsensusTime.IsZero() {
h, err := src.chainProvider.QueryIBCHeader(ctx, int64(dst.clientState.ConsensusHeight.RevisionHeight))
if err != nil {
Expand Down Expand Up @@ -246,6 +255,7 @@ func (mp *messageProcessor) assembleMsgUpdateClient(ctx context.Context, src, ds
clientID := dst.info.ClientID
clientConsensusHeight := dst.clientState.ConsensusHeight
trustedConsensusHeight := dst.clientTrustedState.ClientState.ConsensusHeight

var trustedNextValidatorsHash []byte
if dst.clientTrustedState.IBCHeader != nil {
trustedNextValidatorsHash = dst.clientTrustedState.IBCHeader.NextValidatorsHash()
Expand All @@ -260,11 +270,13 @@ func (mp *messageProcessor) assembleMsgUpdateClient(ctx context.Context, src, ds
return fmt.Errorf("observed client trusted height: %d does not equal latest client state height: %d",
trustedConsensusHeight.RevisionHeight, clientConsensusHeight.RevisionHeight)
}

header, err := src.chainProvider.QueryIBCHeader(ctx, int64(clientConsensusHeight.RevisionHeight+1))
if err != nil {
return fmt.Errorf("error getting IBC header at height: %d for chain_id: %s, %w",
clientConsensusHeight.RevisionHeight+1, src.info.ChainID, err)
}

mp.log.Debug("Had to query for client trusted IBC header",
zap.String("path_name", src.info.PathName),
zap.String("chain_id", src.info.ChainID),
Expand All @@ -273,10 +285,12 @@ func (mp *messageProcessor) assembleMsgUpdateClient(ctx context.Context, src, ds
zap.Uint64("height", clientConsensusHeight.RevisionHeight+1),
zap.Uint64("latest_height", src.latestBlock.Height),
)

dst.clientTrustedState = provider.ClientTrustedState{
ClientState: dst.clientState,
IBCHeader: header,
}

trustedConsensusHeight = clientConsensusHeight
trustedNextValidatorsHash = header.NextValidatorsHash()
}
Expand Down Expand Up @@ -346,7 +360,7 @@ func (mp *messageProcessor) trackAndSendMessages(
return nil
}

if needsClientUpdate {
if needsClientUpdate && mp.msgUpdateClient != nil {
go mp.sendClientUpdate(ctx, src, dst)
return nil
}
Expand Down Expand Up @@ -421,6 +435,7 @@ func (mp *messageProcessor) sendBatchMessages(
// messages are batch with appended MsgUpdateClient
msgs = make([]provider.RelayerMessage, 1+len(batch))
msgs[0] = mp.msgUpdateClient

for i, t := range batch {
msgs[i+1] = t.assembledMsg()
fields = append(fields, zap.Object(fmt.Sprintf("msg_%d", i), t))
Expand Down

0 comments on commit 1f15f65

Please sign in to comment.