Skip to content

Commit

Permalink
feat: implement UpdatePath for hermes so it works with ics [BP #1026] (
Browse files Browse the repository at this point in the history
  • Loading branch information
fastfadingviolets authored Jul 24, 2024
1 parent 190bf2d commit 54e5595
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 10 deletions.
28 changes: 21 additions & 7 deletions examples/ibc/ics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,29 @@ func TestICS(t *testing.T) {
icsVersions = []string{ver}
}

relayers := []struct {
rly ibc.RelayerImplementation
name string
}{
{rly: ibc.Hermes, name: "hermes"},
{rly: ibc.CosmosRly, name: "rly"},
}

for _, version := range icsVersions {
version := version
testName := "ics_" + strings.ReplaceAll(version, ".", "_")

t.Run(testName, func(t *testing.T) {
t.Parallel()
icsTest(t, version)
})
for _, rly := range relayers {
t.Run(testName+"_"+rly.name, func(t *testing.T) {
t.Parallel()
icsTest(t, version, rly.rly)
})
}
}

}

func icsTest(t *testing.T, version string) {
func icsTest(t *testing.T, version string, rly ibc.RelayerImplementation) {
ctx := context.Background()

consumerBechPrefix := "cosmos"
Expand Down Expand Up @@ -78,7 +88,7 @@ func icsTest(t *testing.T, version string) {
// Relayer Factory
client, network := interchaintest.DockerSetup(t)
r := interchaintest.NewBuiltinRelayerFactory(
ibc.CosmosRly,
rly,
zaptest.NewLogger(t),
relayer.StartupFlags("--block-history", "100"),
).Build(t, client, network)
Expand Down Expand Up @@ -184,7 +194,11 @@ func icsTest(t *testing.T, version string) {

func getTransferChannel(channels []ibc.ChannelOutput) (string, error) {
for _, channel := range channels {
if channel.PortID == "transfer" && channel.State == ibcconntypes.OPEN.String() {
state := channel.State
if !strings.HasPrefix(state, "STATE_") {
state = "STATE_" + strings.ToUpper(state)
}
if channel.PortID == "transfer" && state == ibcconntypes.OPEN.String() {
return channel.ChannelID, nil
}
}
Expand Down
3 changes: 1 addition & 2 deletions relayer/hermes/hermes_commander.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ func (c commander) CreateWallet(keyName, address, mnemonic string) ibc.Wallet {
}

func (c commander) UpdatePath(pathName, homeDir string, opts ibc.PathUpdateOptions) []string {
// TODO: figure out how to implement this.
panic("implement me")
panic("update path implemented in hermes relayer not the commander")
}

// the following methods do not have a single command that cleanly maps to a single hermes command without
Expand Down
43 changes: 42 additions & 1 deletion relayer/hermes/hermes_relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,50 @@ func (r *Relayer) RestoreKey(ctx context.Context, rep ibc.RelayerExecReporter, c
return nil
}

func (r *Relayer) UpdatePath(ctx context.Context, rep ibc.RelayerExecReporter, pathName string, opts ibc.PathUpdateOptions) error {
// the concept of paths doesn't exist in hermes, but update our in-memory paths so we can use them elsewhere
path, ok := r.paths[pathName]
if !ok {
return fmt.Errorf("path %s not found", pathName)
}
if opts.SrcChainID != nil {
path.chainA.chainID = *opts.SrcChainID
}
if opts.DstChainID != nil {
path.chainB.chainID = *opts.DstChainID
}
if opts.SrcClientID != nil {
path.chainA.clientID = *opts.SrcClientID
}
if opts.DstClientID != nil {
path.chainB.clientID = *opts.DstClientID
}
if opts.SrcConnID != nil {
path.chainA.connectionID = *opts.SrcConnID
}
if opts.DstConnID != nil {
path.chainB.connectionID = *opts.DstConnID
}
return nil
}

func (r *Relayer) Flush(ctx context.Context, rep ibc.RelayerExecReporter, pathName string, channelID string) error {
path := r.paths[pathName]
cmd := []string{hermes, "clear", "packets", "--chain", path.chainA.chainID, "--channel", channelID, "--port", path.chainA.portID}
channels, err := r.GetChannels(ctx, rep, path.chainA.chainID)
if err != nil {
return err
}
var portID string
for _, ch := range channels {
if ch.ChannelID == channelID {
portID = ch.PortID
break
}
}
if portID == "" {
return fmt.Errorf("channel %s not found on chain %s", channelID, path.chainA.chainID)
}
cmd := []string{hermes, "clear", "packets", "--chain", path.chainA.chainID, "--channel", channelID, "--port", portID}
res := r.Exec(ctx, rep, cmd, nil)
return res.Err
}
Expand Down

0 comments on commit 54e5595

Please sign in to comment.