Skip to content

Commit

Permalink
fix: use last hop height for proof height
Browse files Browse the repository at this point in the history
  • Loading branch information
Giuseppe Valente committed Apr 21, 2023
1 parent 0a05f9a commit 01fa824
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
8 changes: 8 additions & 0 deletions relayer/chains/cosmos/multihop.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"

"go.uber.org/zap"

"github.com/cosmos/cosmos-sdk/codec"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
"github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
Expand Down Expand Up @@ -153,6 +155,12 @@ func (e endpoint) UpdateClient() error {
if !success {
return fmt.Errorf("client update execution failed")
}
e.provider.log.Info(
"Client updated for multihop proof",
zap.String("chain_id", e.ChainID()),
zap.String("client_id", e.ClientID()),
zap.String("height", e.GetConsensusHeight().String()),
)
return nil
}

Expand Down
26 changes: 16 additions & 10 deletions relayer/chains/cosmos/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,30 +540,36 @@ func (cc *CosmosProvider) ValidatePacket(msgTransfer provider.PacketInfo, latest
return nil
}

func (cc *CosmosProvider) newProof(proof []byte, connectionHops []string) ([]byte, error) {
func (cc *CosmosProvider) newProof(proof []byte, height clienttypes.Height, connectionHops []string) ([]byte,
clienttypes.Height, error,
) {
if len(connectionHops) < 2 {
return proof, nil
return proof, height, nil
}
// The proof code gets called on the source chain, but the connection hops are for the dst chain so do the reverse
// lookup here
chanPath := cc.GetCounterpartyChanPath(connectionHops)
if chanPath == nil {
return nil, fmt.Errorf("unable to find channel path for connection hops: %v", connectionHops)
return nil, clienttypes.Height{}, fmt.Errorf("unable to find channel path for connection hops: %v", connectionHops)
}
if err := chanPath.UpdateClient(); err != nil {
return nil, fmt.Errorf("error updating channel path client: %w", err)
return nil, clienttypes.Height{}, fmt.Errorf("error updating channel path client: %w", err)
}
multihopProof, err := chanPath.GenerateProof(proof, nil, false)
if err != nil {
return nil, fmt.Errorf("error generating multihop proof: %w", err)
return nil, clienttypes.Height{}, fmt.Errorf("error generating multihop proof: %w", err)
}
proof, err = multihopProof.Marshal()
if err != nil {
return nil, clienttypes.Height{}, fmt.Errorf("error marshaling multihop proof: %w", err)
}
return multihopProof.Marshal()
return proof, chanPath.Paths[len(chanPath.Paths)-1].EndpointB.GetConsensusHeight().(clienttypes.Height), nil
}

func (cc *CosmosProvider) newChannelProof(key []byte, height clienttypes.Height, version string, ordering chantypes.Order,
connectionHops []string,
) (provider.ChannelProof, error) {
proof, err := cc.newProof(key, connectionHops)
proof, height, err := cc.newProof(key, height, connectionHops)
if err != nil {
return provider.ChannelProof{}, err
}
Expand All @@ -575,14 +581,14 @@ func (cc *CosmosProvider) newChannelProof(key []byte, height clienttypes.Height,
}, nil
}

func (cc *CosmosProvider) newPacketProof(key []byte, proofHeight clienttypes.Height, connectionHops []string) (provider.PacketProof, error) {
proof, err := cc.newProof(key, connectionHops)
func (cc *CosmosProvider) newPacketProof(key []byte, height clienttypes.Height, connectionHops []string) (provider.PacketProof, error) {
proof, height, err := cc.newProof(key, height, connectionHops)
if err != nil {
return provider.PacketProof{}, err
}
return provider.PacketProof{
Proof: proof,
ProofHeight: proofHeight,
ProofHeight: height,
}, nil
}

Expand Down

0 comments on commit 01fa824

Please sign in to comment.