From 01fa8249ee395a5589c795d0b0f51b7df94f01fe Mon Sep 17 00:00:00 2001 From: Giuseppe Valente Date: Thu, 20 Apr 2023 17:22:21 -0700 Subject: [PATCH] fix: use last hop height for proof height --- relayer/chains/cosmos/multihop.go | 8 ++++++++ relayer/chains/cosmos/tx.go | 26 ++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/relayer/chains/cosmos/multihop.go b/relayer/chains/cosmos/multihop.go index 64c0aab761..f59dc03d9f 100644 --- a/relayer/chains/cosmos/multihop.go +++ b/relayer/chains/cosmos/multihop.go @@ -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" @@ -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 } diff --git a/relayer/chains/cosmos/tx.go b/relayer/chains/cosmos/tx.go index a17747d0e3..184d427419 100644 --- a/relayer/chains/cosmos/tx.go +++ b/relayer/chains/cosmos/tx.go @@ -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 } @@ -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 }