diff --git a/client/provider.go b/client/provider.go index c7c4d017..3f2b66ce 100644 --- a/client/provider.go +++ b/client/provider.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "github.com/cosmos/cosmos-sdk/crypto/keyring" "math" "reflect" "strconv" @@ -113,13 +114,19 @@ func (cc *ChainClient) Timeout() string { // Address returns the chains configured address as a string func (cc *ChainClient) Address() (string, error) { var ( - acc sdk.AccAddress - err error + err error + info keyring.Info ) - if acc, err = cc.GetKeyAddress(); err != nil { + info, err = cc.Keybase.Key(cc.Config.Key) + if err != nil { + return "", err + } + out, err := cc.EncodeBech32AccAddr(info.GetAddress()) + if err != nil { return "", err } - return acc.String(), nil + + return out, err } func (cc *ChainClient) TrustingPeriod() (time.Duration, error) { @@ -127,19 +134,21 @@ func (cc *ChainClient) TrustingPeriod() (time.Duration, error) { if err != nil { return 0, err } + integer, _ := math.Modf(res.UnbondingTime.Hours() * 0.7) trustingStr := fmt.Sprintf("%vh", integer) tp, err := time.ParseDuration(trustingStr) if err != nil { return 0, nil } + return tp, nil } // CreateClient creates an sdk.Msg to update the client on src with consensus state from dst func (cc *ChainClient) CreateClient(clientState ibcexported.ClientState, dstHeader ibcexported.Header) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) if err := dstHeader.ValidateBasic(); err != nil { @@ -151,20 +160,30 @@ func (cc *ChainClient) CreateClient(clientState ibcexported.ClientState, dstHead return nil, fmt.Errorf("got data of type %T but wanted tmclient.Header \n", dstHeader) } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg, err := clienttypes.NewMsgCreateClient( - clientState, - tmHeader.ConsensusState(), - acc.String(), - ) + anyClientState, err := clienttypes.PackClientState(clientState) + if err != nil { + return nil, err + } + + anyConsensusState, err := clienttypes.PackConsensusState(tmHeader.ConsensusState()) + if err != nil { + return nil, err + } + + msg := &clienttypes.MsgCreateClient{ + ClientState: anyClientState, + ConsensusState: anyConsensusState, + Signer: acc, + } if err != nil { return nil, err } - return NewCosmosMessage(msg), msg.ValidateBasic() + return NewCosmosMessage(msg), nil } func (cc *ChainClient) SubmitMisbehavior( /*TBD*/ ) (provider.RelayerMessage, error) { @@ -173,29 +192,36 @@ func (cc *ChainClient) SubmitMisbehavior( /*TBD*/ ) (provider.RelayerMessage, er func (cc *ChainClient) UpdateClient(srcClientId string, dstHeader ibcexported.Header) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) if err := dstHeader.ValidateBasic(); err != nil { return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg, err := clienttypes.NewMsgUpdateClient( - srcClientId, - dstHeader, - acc.String(), - ) + + anyHeader, err := clienttypes.PackHeader(dstHeader) + if err != nil { + return nil, err + } + + msg := &clienttypes.MsgUpdateClient{ + ClientId: srcClientId, + Header: anyHeader, + Signer: acc, + } + if err != nil { return nil, err } - return NewCosmosMessage(msg), msg.ValidateBasic() + return NewCosmosMessage(msg), nil } func (cc *ChainClient) ConnectionOpenInit(srcClientId, dstClientId string, dstHeader ibcexported.Header) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error version *conntypes.Version ) @@ -204,24 +230,29 @@ func (cc *ChainClient) ConnectionOpenInit(srcClientId, dstClientId string, dstHe return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := conntypes.NewMsgConnectionOpenInit( - srcClientId, - dstClientId, - defaultChainPrefix, - version, - defaultDelayPeriod, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + counterparty := conntypes.Counterparty{ + ClientId: dstClientId, + ConnectionId: "", + Prefix: defaultChainPrefix, + } + msg := &conntypes.MsgConnectionOpenInit{ + ClientId: srcClientId, + Counterparty: counterparty, + Version: version, + DelayPeriod: defaultDelayPeriod, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ConnectionOpenTry(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, srcClientId, dstClientId, srcConnId, dstConnId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -239,34 +270,46 @@ func (cc *ChainClient) ConnectionOpenTry(dstQueryProvider provider.QueryProvider return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - // TODO: Get DelayPeriod from counterparty connection rather than using default value - msg := conntypes.NewMsgConnectionOpenTry( - srcConnId, - srcClientId, - dstConnId, - dstClientId, - clientState, - defaultChainPrefix, - conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()), - defaultDelayPeriod, - connStateProof, - clientStateProof, - consensusStateProof, - clienttypes.NewHeight(proofHeight.GetRevisionNumber(), proofHeight.GetRevisionHeight()), - clientState.GetLatestHeight().(clienttypes.Height), - acc.String(), - ) + csAny, err := clienttypes.PackClientState(clientState) + if err != nil { + return nil, err + } + + counterparty := conntypes.Counterparty{ + ClientId: dstClientId, + ConnectionId: dstConnId, + Prefix: defaultChainPrefix, + } - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + // TODO: Get DelayPeriod from counterparty connection rather than using default value + msg := &conntypes.MsgConnectionOpenTry{ + ClientId: srcClientId, + PreviousConnectionId: srcConnId, + ClientState: csAny, + Counterparty: counterparty, + DelayPeriod: defaultDelayPeriod, + CounterpartyVersions: conntypes.ExportedVersionsToProto(conntypes.GetCompatibleVersions()), + ProofHeight: clienttypes.Height{ + RevisionNumber: proofHeight.GetRevisionNumber(), + RevisionHeight: proofHeight.GetRevisionHeight(), + }, + ProofInit: connStateProof, + ProofClient: clientStateProof, + ProofConsensus: consensusStateProof, + ConsensusHeight: clientState.GetLatestHeight().(clienttypes.Height), + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ConnectionOpenAck(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, srcClientId, srcConnId, dstClientId, dstConnId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) @@ -285,28 +328,37 @@ func (cc *ChainClient) ConnectionOpenAck(dstQueryProvider provider.QueryProvider return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := conntypes.NewMsgConnectionOpenAck( - srcConnId, - dstConnId, - clientState, - connStateProof, - clientStateProof, - consensusStateProof, - clienttypes.NewHeight(proofHeight.GetRevisionNumber(), proofHeight.GetRevisionHeight()), - clientState.GetLatestHeight().(clienttypes.Height), - conntypes.DefaultIBCVersion, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + csAny, err := clienttypes.PackClientState(clientState) + if err != nil { + return nil, err + } + + msg := &conntypes.MsgConnectionOpenAck{ + ConnectionId: srcConnId, + CounterpartyConnectionId: dstConnId, + Version: conntypes.DefaultIBCVersion, + ClientState: csAny, + ProofHeight: clienttypes.Height{ + RevisionNumber: proofHeight.GetRevisionNumber(), + RevisionHeight: proofHeight.GetRevisionHeight(), + }, + ProofTry: connStateProof, + ProofClient: clientStateProof, + ProofConsensus: consensusStateProof, + ConsensusHeight: clientState.GetLatestHeight().(clienttypes.Height), + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ConnectionOpenConfirm(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, dstConnId, srcClientId, srcConnId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -323,22 +375,23 @@ func (cc *ChainClient) ConnectionOpenConfirm(dstQueryProvider provider.QueryProv return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := conntypes.NewMsgConnectionOpenConfirm( - srcConnId, - counterpartyConnState.Proof, - counterpartyConnState.ProofHeight, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + msg := &conntypes.MsgConnectionOpenConfirm{ + ConnectionId: srcConnId, + ProofAck: counterpartyConnState.Proof, + ProofHeight: counterpartyConnState.ProofHeight, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ChannelOpenInit(srcClientId, srcConnId, srcPortId, srcVersion, dstPortId string, order chantypes.Order, dstHeader ibcexported.Header) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -346,24 +399,31 @@ func (cc *ChainClient) ChannelOpenInit(srcClientId, srcConnId, srcPortId, srcVer return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := chantypes.NewMsgChannelOpenInit( - srcPortId, - srcVersion, - order, - []string{srcConnId}, - dstPortId, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + msg := &chantypes.MsgChannelOpenInit{ + PortId: srcPortId, + Channel: chantypes.Channel{ + State: chantypes.INIT, + Ordering: order, + Counterparty: chantypes.Counterparty{ + PortId: dstPortId, + ChannelId: "", + }, + ConnectionHops: []string{srcConnId}, + Version: srcVersion, + }, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ChannelOpenTry(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, srcPortId, dstPortId, srcChanId, dstChanId, srcVersion, srcConnectionId, srcClientId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -380,29 +440,35 @@ func (cc *ChainClient) ChannelOpenTry(dstQueryProvider provider.QueryProvider, d return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := chantypes.NewMsgChannelOpenTry( - srcPortId, - srcChanId, - srcVersion, - counterpartyChannelRes.Channel.Ordering, - []string{srcConnectionId}, - dstPortId, - dstChanId, - counterpartyChannelRes.Channel.Version, - counterpartyChannelRes.Proof, - counterpartyChannelRes.ProofHeight, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + msg := &chantypes.MsgChannelOpenTry{ + PortId: srcPortId, + PreviousChannelId: srcChanId, + Channel: chantypes.Channel{ + State: chantypes.TRYOPEN, + Ordering: counterpartyChannelRes.Channel.Ordering, + Counterparty: chantypes.Counterparty{ + PortId: dstPortId, + ChannelId: dstChanId, + }, + ConnectionHops: []string{srcConnectionId}, + Version: srcVersion, + }, + CounterpartyVersion: counterpartyChannelRes.Channel.Version, + ProofInit: counterpartyChannelRes.Proof, + ProofHeight: counterpartyChannelRes.ProofHeight, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ChannelOpenAck(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, srcClientId, srcPortId, srcChanId, dstChanId, dstPortId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -420,25 +486,26 @@ func (cc *ChainClient) ChannelOpenAck(dstQueryProvider provider.QueryProvider, d return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := chantypes.NewMsgChannelOpenAck( - srcPortId, - srcChanId, - dstChanId, - counterpartyChannelRes.Channel.Version, - counterpartyChannelRes.Proof, - counterpartyChannelRes.ProofHeight, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + msg := &chantypes.MsgChannelOpenAck{ + PortId: srcPortId, + ChannelId: srcChanId, + CounterpartyChannelId: dstChanId, + CounterpartyVersion: counterpartyChannelRes.Channel.Version, + ProofTry: counterpartyChannelRes.Proof, + ProofHeight: counterpartyChannelRes.ProofHeight, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ChannelOpenConfirm(dstQueryProvider provider.QueryProvider, dstHeader ibcexported.Header, srcClientId, srcPortId, srcChanId, dstPortId, dstChanId string) ([]provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) updateMsg, err := cc.UpdateClient(srcClientId, dstHeader) @@ -455,38 +522,42 @@ func (cc *ChainClient) ChannelOpenConfirm(dstQueryProvider provider.QueryProvide return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - msg := chantypes.NewMsgChannelOpenConfirm( - srcPortId, - srcChanId, - counterpartyChanState.Proof, - counterpartyChanState.ProofHeight, - acc.String(), - ) - return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, msg.ValidateBasic() + msg := &chantypes.MsgChannelOpenConfirm{ + PortId: srcPortId, + ChannelId: srcChanId, + ProofAck: counterpartyChanState.Proof, + ProofHeight: counterpartyChanState.ProofHeight, + Signer: acc, + } + + return []provider.RelayerMessage{updateMsg, NewCosmosMessage(msg)}, nil } func (cc *ChainClient) ChannelCloseInit(srcPortId, srcChanId string) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - return NewCosmosMessage(chantypes.NewMsgChannelCloseInit( - srcPortId, - srcChanId, - acc.String(), - )), nil + + msg := &chantypes.MsgChannelCloseInit{ + PortId: srcPortId, + ChannelId: srcChanId, + Signer: acc, + } + + return NewCosmosMessage(msg), nil } func (cc *ChainClient) ChannelCloseConfirm(dstQueryProvider provider.QueryProvider, dsth int64, dstChanId, dstPortId, srcPortId, srcChanId string) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) dstChanResp, err := dstQueryProvider.QueryChannel(dsth, dstChanId, dstPortId) @@ -494,16 +565,19 @@ func (cc *ChainClient) ChannelCloseConfirm(dstQueryProvider provider.QueryProvid return nil, err } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } - return NewCosmosMessage(chantypes.NewMsgChannelCloseConfirm( - srcPortId, - srcChanId, - dstChanResp.Proof, - dstChanResp.ProofHeight, - acc.String(), - )), nil + + msg := &chantypes.MsgChannelCloseConfirm{ + PortId: srcPortId, + ChannelId: srcChanId, + ProofInit: dstChanResp.Proof, + ProofHeight: dstChanResp.ProofHeight, + Signer: acc, + } + + return NewCosmosMessage(msg), nil } // GetIBCUpdateHeader updates the off chain tendermint light client and @@ -525,10 +599,12 @@ func (cc *ChainClient) GetLightSignedHeaderAtHeight(h int64) (ibcexported.Header if h == 0 { return nil, errors.New("height cannot be 0") } + lightBlock, err := cc.LightProvider.LightBlock(context.Background(), h) if err != nil { return nil, err } + protoVal, err := tmtypes.NewValidatorSet(lightBlock.ValidatorSet.Validators).ToProto() if err != nil { return nil, err @@ -554,7 +630,7 @@ func (cc *ChainClient) InjectTrustedFields(header ibcexported.Header, dst provid } // retrieve dst client from src chain - // this is the client that will updated + // this is the client that will be updated cs, err := dst.QueryClientState(0, dstClientId) if err != nil { return nil, err @@ -571,7 +647,7 @@ func (cc *ChainClient) InjectTrustedFields(header ibcexported.Header, dst provid // place where we need to fix the upstream query proof issue? var trustedHeader *tmclient.Header if err := retry.Do(func() error { - tmpHeader, err := cc.GetLightSignedHeaderAtHeight(int64(h.TrustedHeight.RevisionHeight) + 1) + tmpHeader, err := cc.GetLightSignedHeaderAtHeight(int64(h.TrustedHeight.RevisionHeight + 1)) th, ok := tmpHeader.(*tmclient.Header) if !ok { err = errors.New("non-tm client header") @@ -594,7 +670,7 @@ func (cc *ChainClient) InjectTrustedFields(header ibcexported.Header, dst provid // The counterparty represents the receiving chain where the acknowledgement would be stored. func (cc *ChainClient) MsgRelayAcknowledgement(dst provider.ChainProvider, dstChanId, dstPortId, srcChanId, srcPortId string, dsth int64, packet provider.RelayPacket) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) msgPacketAck, ok := packet.(*relayMsgPacketAck) @@ -602,7 +678,7 @@ func (cc *ChainClient) MsgRelayAcknowledgement(dst provider.ChainProvider, dstCh return nil, fmt.Errorf("got data of type %T but wanted relayMsgPacketAck \n", packet) } - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } @@ -615,44 +691,53 @@ func (cc *ChainClient) MsgRelayAcknowledgement(dst provider.ChainProvider, dstCh case ackRes == nil: return nil, fmt.Errorf("ack packet [%s]seq{%d} has no associated proofs", dst.ChainId(), packet.Seq()) default: - return NewCosmosMessage(chantypes.NewMsgAcknowledgement( - chantypes.NewPacket( - packet.Data(), - packet.Seq(), - srcPortId, - srcChanId, - dstPortId, - dstChanId, - packet.Timeout(), - packet.TimeoutStamp(), - ), - msgPacketAck.ack, - ackRes.Proof, - ackRes.ProofHeight, - acc.String())), nil + msg := &chantypes.MsgAcknowledgement{ + Packet: chantypes.Packet{ + Sequence: packet.Seq(), + SourcePort: srcPortId, + SourceChannel: srcChanId, + DestinationPort: dstPortId, + DestinationChannel: dstChanId, + Data: packet.Data(), + TimeoutHeight: packet.Timeout(), + TimeoutTimestamp: packet.TimeoutStamp(), + }, + Acknowledgement: msgPacketAck.ack, + ProofAcked: ackRes.Proof, + ProofHeight: ackRes.ProofHeight, + Signer: acc, + } + + return NewCosmosMessage(msg), nil } } // MsgTransfer creates a new transfer message func (cc *ChainClient) MsgTransfer(amount sdk.Coin, dstChainId, dstAddr, srcPortId, srcChanId string, timeoutHeight, timeoutTimestamp uint64) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } version := clienttypes.ParseChainID(dstChainId) - return NewCosmosMessage(transfertypes.NewMsgTransfer( - srcPortId, - srcChanId, - amount, - acc.String(), - dstAddr, - clienttypes.NewHeight(version, timeoutHeight), - timeoutTimestamp, - )), nil + + msg := &transfertypes.MsgTransfer{ + SourcePort: srcPortId, + SourceChannel: srcChanId, + Token: amount, + Sender: acc, + Receiver: dstAddr, + TimeoutHeight: clienttypes.Height{ + RevisionNumber: version, + RevisionHeight: timeoutHeight, + }, + TimeoutTimestamp: timeoutTimestamp, + } + + return NewCosmosMessage(msg), nil } // MsgRelayTimeout constructs the MsgTimeout which is to be sent to the sending chain. @@ -660,10 +745,10 @@ func (cc *ChainClient) MsgTransfer(amount sdk.Coin, dstChainId, dstAddr, srcPort // stored. func (cc *ChainClient) MsgRelayTimeout(dst provider.ChainProvider, dsth int64, packet provider.RelayPacket, dstChanId, dstPortId, srcChanId, srcPortId string) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } @@ -676,22 +761,24 @@ func (cc *ChainClient) MsgRelayTimeout(dst provider.ChainProvider, dsth int64, p case recvRes == nil: return nil, fmt.Errorf("timeout packet [%s]seq{%d} has no associated proofs", cc.Config.ChainID, packet.Seq()) default: - return NewCosmosMessage(chantypes.NewMsgTimeout( - chantypes.NewPacket( - packet.Data(), - packet.Seq(), - srcPortId, - srcChanId, - dstPortId, - dstChanId, - packet.Timeout(), - packet.TimeoutStamp(), - ), - packet.Seq(), - recvRes.Proof, - recvRes.ProofHeight, - acc.String(), - )), nil + msg := &chantypes.MsgTimeout{ + Packet: chantypes.Packet{ + Sequence: packet.Seq(), + SourcePort: srcPortId, + SourceChannel: srcChanId, + DestinationPort: dstPortId, + DestinationChannel: dstChanId, + Data: packet.Data(), + TimeoutHeight: packet.Timeout(), + TimeoutTimestamp: packet.TimeoutStamp(), + }, + ProofUnreceived: recvRes.Proof, + ProofHeight: recvRes.ProofHeight, + NextSequenceRecv: packet.Seq(), + Signer: acc, + } + + return NewCosmosMessage(msg), nil } } @@ -699,10 +786,10 @@ func (cc *ChainClient) MsgRelayTimeout(dst provider.ChainProvider, dsth int64, p // The counterparty represents the sending chain where the packet commitment would be stored. func (cc *ChainClient) MsgRelayRecvPacket(dst provider.ChainProvider, dsth int64, packet provider.RelayPacket, dstChanId, dstPortId, srcChanId, srcPortId string) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } @@ -715,21 +802,23 @@ func (cc *ChainClient) MsgRelayRecvPacket(dst provider.ChainProvider, dsth int64 case comRes == nil: return nil, fmt.Errorf("receive packet [%s]seq{%d} has no associated proofs", cc.Config.ChainID, packet.Seq()) default: - return NewCosmosMessage(chantypes.NewMsgRecvPacket( - chantypes.NewPacket( - packet.Data(), - packet.Seq(), - dstPortId, - dstChanId, - srcPortId, - srcChanId, - packet.Timeout(), - packet.TimeoutStamp(), - ), - comRes.Proof, - comRes.ProofHeight, - acc.String(), - )), nil + msg := &chantypes.MsgRecvPacket{ + Packet: chantypes.Packet{ + Sequence: packet.Seq(), + SourcePort: dstPortId, + SourceChannel: dstChanId, + DestinationPort: srcPortId, + DestinationChannel: srcChanId, + Data: packet.Data(), + TimeoutHeight: packet.Timeout(), + TimeoutTimestamp: packet.TimeoutStamp(), + }, + ProofCommitment: comRes.Proof, + ProofHeight: comRes.ProofHeight, + Signer: acc, + } + + return NewCosmosMessage(msg), nil } } @@ -983,15 +1072,15 @@ func acknowledgementsFromResultTx(dstChanId, dstPortId, srcChanId, srcPortId str func (cc *ChainClient) MsgUpgradeClient(srcClientId string, consRes *clienttypes.QueryConsensusStateResponse, clientRes *clienttypes.QueryClientStateResponse) (provider.RelayerMessage, error) { var ( - acc sdk.AccAddress + acc string err error ) - if acc, err = cc.GetKeyAddress(); err != nil { + if acc, err = cc.Address(); err != nil { return nil, err } return NewCosmosMessage(&clienttypes.MsgUpgradeClient{ClientId: srcClientId, ClientState: clientRes.ClientState, ConsensusState: consRes.ConsensusState, ProofUpgradeClient: consRes.GetProof(), - ProofUpgradeConsensusState: consRes.ConsensusState.Value, Signer: acc.String()}), nil + ProofUpgradeConsensusState: consRes.ConsensusState.Value, Signer: acc}), nil } // AutoUpdateClient update client automatically to prevent expiry @@ -1196,7 +1285,11 @@ func (cc *ChainClient) QueryConsensusStateABCI(clientID string, height ibcexport return nil, err } - return clienttypes.NewQueryConsensusStateResponse(anyConsensusState, proofBz, proofHeight), nil + return &clienttypes.QueryConsensusStateResponse{ + ConsensusState: anyConsensusState, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // isMatchingClient determines if the two provided clients match in all fields diff --git a/client/query.go b/client/query.go index 3fdac174..cb6461c5 100644 --- a/client/query.go +++ b/client/query.go @@ -73,32 +73,26 @@ func (cc *ChainClient) QueryTxs(page, limit int, events []string) ([]*ctypes.Res // QueryBalance returns the amount of coins in the relayer account func (cc *ChainClient) QueryBalance(keyName string) (sdk.Coins, error) { var ( - addr sdk.AccAddress + addr string err error ) if keyName == "" { - addr, err = cc.GetKeyAddress() + addr, err = cc.Address() } else { cc.Config.Key = keyName - addr, err = cc.GetKeyAddress() + addr, err = cc.Address() } if err != nil { return nil, err } - return cc.QueryBalanceWithAddress(addr.String()) + return cc.QueryBalanceWithAddress(addr) } // QueryBalanceWithAddress returns the amount of coins in the relayer account with address as input // TODO add pagination support func (cc *ChainClient) QueryBalanceWithAddress(address string) (sdk.Coins, error) { - addr, err := sdk.AccAddressFromBech32(address) - if err != nil { - return nil, err - } - - p := bankTypes.NewQueryAllBalancesRequest(addr, DefaultPageRequest()) - + p := &bankTypes.QueryAllBalancesRequest{Address: address, Pagination: DefaultPageRequest()} queryClient := bankTypes.NewQueryClient(cc) res, err := queryClient.AllBalances(context.Background(), p) @@ -109,25 +103,9 @@ func (cc *ChainClient) QueryBalanceWithAddress(address string) (sdk.Coins, error return res.Balances, nil } -// QueryBalanceWithAddress returns the amount of coins in the relayer account with address as input -//func (cc *ChainClient) QueryBalanceWithAddress(ctx context.Context, address sdk.AccAddress, pageReq *query.PageRequest) (sdk.Coins, error) { -// addr, err := cc.EncodeBech32AccAddr(address) -// if err != nil { -// return nil, err -// } -// params := &bankTypes.QueryAllBalancesRequest{Address: addr, Pagination: pageReq} -// res, err := bankTypes.NewQueryClient(cc).AllBalances(ctx, params) -// if err != nil { -// return nil, err -// } -// -// return res.Balances, nil -//} - // QueryUnbondingPeriod returns the unbonding period of the chain func (cc *ChainClient) QueryUnbondingPeriod() (time.Duration, error) { req := stakingtypes.QueryParamsRequest{} - queryClient := stakingtypes.NewQueryClient(cc) res, err := queryClient.Params(context.Background(), &req) @@ -216,11 +194,14 @@ func (cc *ChainClient) QueryClientStateResponse(height int64, srcClientId string return nil, err } - clientStateRes := clienttypes.NewQueryClientStateResponse(anyClientState, proofBz, proofHeight) - return clientStateRes, nil + return &clienttypes.QueryClientStateResponse{ + ClientState: anyClientState, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } -// QueryClientState retrevies the latest consensus state for a client in state at a given height +// QueryClientState retrieves the latest consensus state for a client in state at a given height // and unpacks it to exported client state interface func (cc *ChainClient) QueryClientState(height int64, clientid string) (ibcexported.ClientState, error) { clientStateRes, err := cc.QueryClientStateResponse(height, clientid) @@ -262,7 +243,11 @@ func (cc *ChainClient) QueryClientConsensusState(chainHeight int64, clientid str return nil, err } - return clienttypes.NewQueryConsensusStateResponse(anyConsensusState, proofBz, proofHeight), nil + return &clienttypes.QueryConsensusStateResponse{ + ConsensusState: anyConsensusState, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } //DefaultUpgradePath is the default IBC upgrade path set for an on-chain light client @@ -273,19 +258,21 @@ func (cc *ChainClient) NewClientState(dstUpdateHeader ibcexported.Header, dstTru if !ok { return nil, fmt.Errorf("got data of type %T but wanted tmclient.Header \n", dstUpdateHeader) } + // Create the ClientState we want on 'c' tracking 'dst' - return tmclient.NewClientState( - dstTmHeader.GetHeader().GetChainID(), - tmclient.NewFractionFromTm(light.DefaultTrustLevel), - dstTrustingPeriod, - dstUbdPeriod, - time.Minute*10, - dstUpdateHeader.GetHeight().(clienttypes.Height), - committypes.GetSDKSpecs(), - defaultUpgradePath, - allowUpdateAfterExpiry, - allowUpdateAfterMisbehaviour, - ), nil + return &tmclient.ClientState{ + ChainId: dstTmHeader.GetHeader().GetChainID(), + TrustLevel: tmclient.NewFractionFromTm(light.DefaultTrustLevel), + TrustingPeriod: dstTrustingPeriod, + UnbondingPeriod: dstUbdPeriod, + MaxClockDrift: time.Minute * 10, + FrozenHeight: clienttypes.ZeroHeight(), + LatestHeight: dstUpdateHeader.GetHeight().(clienttypes.Height), + ProofSpecs: committypes.GetSDKSpecs(), + UpgradePath: defaultUpgradePath, + AllowUpdateAfterExpiry: allowUpdateAfterExpiry, + AllowUpdateAfterMisbehaviour: allowUpdateAfterMisbehaviour, + }, nil } // QueryUpgradeProof performs an abci query with the given key and returns the proto encoded merkle proof @@ -316,7 +303,10 @@ func (cc *ChainClient) QueryUpgradeProof(key []byte, height uint64) ([]byte, cli // proof height + 1 is returned as the proof created corresponds to the height the proof // was created in the IAVL tree. Tendermint and subsequently the clients that rely on it // have heights 1 above the IAVL tree. Thus we return proof height + 1 - return proof, clienttypes.NewHeight(revision, uint64(res.Height+1)), nil + return proof, clienttypes.Height{ + RevisionNumber: revision, + RevisionHeight: uint64(res.Height + 1), + }, nil } // QueryUpgradedClient returns upgraded client info @@ -416,18 +406,21 @@ func (cc *ChainClient) QueryClients() (clienttypes.IdentifiedClientStates, error func (cc *ChainClient) QueryConnection(height int64, connectionid string) (*conntypes.QueryConnectionResponse, error) { res, err := cc.queryConnectionABCI(height, connectionid) if err != nil && strings.Contains(err.Error(), "not found") { - return conntypes.NewQueryConnectionResponse( - conntypes.NewConnectionEnd( - conntypes.UNINITIALIZED, - "client", - conntypes.NewCounterparty( - "client", - "connection", - committypes.NewMerklePrefix([]byte{}), - ), - []*conntypes.Version{}, - 0, - ), []byte{}, clienttypes.NewHeight(0, 0)), nil + return &conntypes.QueryConnectionResponse{ + Connection: &conntypes.ConnectionEnd{ + ClientId: "client", + Versions: []*conntypes.Version{}, + State: conntypes.UNINITIALIZED, + Counterparty: conntypes.Counterparty{ + ClientId: "client", + ConnectionId: "connection", + Prefix: committypes.MerklePrefix{KeyPrefix: []byte{}}, + }, + DelayPeriod: 0, + }, + Proof: []byte{}, + ProofHeight: clienttypes.Height{RevisionNumber: 0, RevisionHeight: 0}, + }, nil } else if err != nil { return nil, err } @@ -454,7 +447,11 @@ func (cc *ChainClient) queryConnectionABCI(height int64, connectionID string) (* return nil, err } - return conntypes.NewQueryConnectionResponse(connection, proofBz, proofHeight), nil + return &conntypes.QueryConnectionResponse{ + Connection: &connection, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // QueryConnections gets any connections on a chain @@ -520,19 +517,24 @@ func (cc *ChainClient) GenerateConnHandshakeProof(height int64, clientId, connId func (cc *ChainClient) QueryChannel(height int64, channelid, portid string) (chanRes *chantypes.QueryChannelResponse, err error) { res, err := cc.queryChannelABCI(height, portid, channelid) if err != nil && strings.Contains(err.Error(), "not found") { - return chantypes.NewQueryChannelResponse( - chantypes.NewChannel( - chantypes.UNINITIALIZED, - chantypes.UNORDERED, - chantypes.NewCounterparty( - "port", - "channel", - ), - []string{}, - "version", - ), - []byte{}, - clienttypes.NewHeight(0, 0)), nil + + return &chantypes.QueryChannelResponse{ + Channel: &chantypes.Channel{ + State: chantypes.UNINITIALIZED, + Ordering: chantypes.UNORDERED, + Counterparty: chantypes.Counterparty{ + PortId: "port", + ChannelId: "channel", + }, + ConnectionHops: []string{}, + Version: "version", + }, + Proof: []byte{}, + ProofHeight: clienttypes.Height{ + RevisionNumber: 0, + RevisionHeight: 0, + }, + }, nil } else if err != nil { return nil, err } @@ -559,7 +561,11 @@ func (cc *ChainClient) queryChannelABCI(height int64, portID, channelID string) return nil, err } - return chantypes.NewQueryChannelResponse(channel, proofBz, proofHeight), nil + return &chantypes.QueryChannelResponse{ + Channel: &channel, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // QueryChannelClient returns the client state of the client supporting a given channel @@ -675,7 +681,11 @@ func (cc *ChainClient) QueryNextSeqRecv(height int64, channelid, portid string) sequence := binary.BigEndian.Uint64(value) - return chantypes.NewQueryNextSequenceReceiveResponse(sequence, proofBz, proofHeight), nil + return &chantypes.QueryNextSequenceReceiveResponse{ + NextSequenceReceive: sequence, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // QueryPacketCommitment returns the packet commitment proof at a given height @@ -692,7 +702,11 @@ func (cc *ChainClient) QueryPacketCommitment(height int64, channelid, portid str return nil, sdkerrors.Wrapf(chantypes.ErrPacketCommitmentNotFound, "portID (%s), channelID (%s), sequence (%d)", portid, channelid, seq) } - return chantypes.NewQueryPacketCommitmentResponse(value, proofBz, proofHeight), nil + return &chantypes.QueryPacketCommitmentResponse{ + Commitment: value, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // QueryPacketAcknowledgement returns the packet ack proof at a given height @@ -708,7 +722,11 @@ func (cc *ChainClient) QueryPacketAcknowledgement(height int64, channelid, porti return nil, sdkerrors.Wrapf(chantypes.ErrInvalidAcknowledgement, "portID (%s), channelID (%s), sequence (%d)", portid, channelid, seq) } - return chantypes.NewQueryPacketAcknowledgementResponse(value, proofBz, proofHeight), nil + return &chantypes.QueryPacketAcknowledgementResponse{ + Acknowledgement: value, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } // QueryPacketReceipt returns the packet receipt proof at a given height @@ -720,7 +738,11 @@ func (cc *ChainClient) QueryPacketReceipt(height int64, channelid, portid string return nil, err } - return chantypes.NewQueryPacketReceiptResponse(value != nil, proofBz, proofHeight), nil + return &chantypes.QueryPacketReceiptResponse{ + Received: value != nil, + Proof: proofBz, + ProofHeight: proofHeight, + }, nil } func (cc *ChainClient) QueryLatestHeight() (int64, error) { diff --git a/client/relayer_packets.go b/client/relayer_packets.go index 74181ac3..a698fd0b 100644 --- a/client/relayer_packets.go +++ b/client/relayer_packets.go @@ -61,22 +61,24 @@ func (rp relayMsgTimeout) Msg(src provider.ChainProvider, srcPortId, srcChanId, if err != nil { return nil, err } - msg := chantypes.NewMsgTimeout( - chantypes.NewPacket( - rp.packetData, - rp.seq, - srcPortId, - srcChanId, - dstPortId, - dstChanId, - rp.timeout, - rp.timeoutStamp, - ), - rp.seq, - rp.dstRecvRes.Proof, - rp.dstRecvRes.ProofHeight, - addr, - ) + + msg := &chantypes.MsgTimeout{ + Packet: chantypes.Packet{ + Sequence: rp.seq, + SourcePort: srcPortId, + SourceChannel: srcChanId, + DestinationPort: dstPortId, + DestinationChannel: dstChanId, + Data: rp.packetData, + TimeoutHeight: rp.timeout, + TimeoutTimestamp: rp.timeoutStamp, + }, + ProofUnreceived: rp.dstRecvRes.Proof, + ProofHeight: rp.dstRecvRes.ProofHeight, + NextSequenceRecv: rp.seq, + Signer: addr, + } + return NewCosmosMessage(msg), nil } @@ -141,22 +143,22 @@ func (rp relayMsgRecvPacket) Msg(src provider.ChainProvider, srcPortId, srcChanI return nil, err } - packet := chantypes.NewPacket( - rp.packetData, - rp.seq, - dstPortId, - dstChanId, - srcPortId, - srcChanId, - rp.timeout, - rp.timeoutStamp, - ) - msg := chantypes.NewMsgRecvPacket( - packet, - rp.dstComRes.Proof, - rp.dstComRes.ProofHeight, - addr, - ) + msg := &chantypes.MsgRecvPacket{ + Packet: chantypes.Packet{ + Sequence: rp.seq, + SourcePort: dstPortId, + SourceChannel: dstChanId, + DestinationPort: srcPortId, + DestinationChannel: srcChanId, + Data: rp.packetData, + TimeoutHeight: rp.timeout, + TimeoutTimestamp: rp.timeoutStamp, + }, + ProofCommitment: rp.dstComRes.Proof, + ProofHeight: rp.dstComRes.ProofHeight, + Signer: addr, + } + return NewCosmosMessage(msg), nil } @@ -195,22 +197,23 @@ func (rp relayMsgPacketAck) Msg(src provider.ChainProvider, srcPortId, srcChanId return nil, err } - msg := chantypes.NewMsgAcknowledgement( - chantypes.NewPacket( - rp.packetData, - rp.seq, - srcPortId, - srcChanId, - dstPortId, - dstChanId, - rp.timeout, - rp.timeoutStamp, - ), - rp.ack, - rp.dstComRes.Proof, - rp.dstComRes.ProofHeight, - addr, - ) + msg := &chantypes.MsgAcknowledgement{ + Packet: chantypes.Packet{ + Sequence: rp.seq, + SourcePort: srcPortId, + SourceChannel: srcChanId, + DestinationPort: dstPortId, + DestinationChannel: dstChanId, + Data: rp.packetData, + TimeoutHeight: rp.timeout, + TimeoutTimestamp: rp.timeoutStamp, + }, + Acknowledgement: rp.ack, + ProofAcked: rp.dstComRes.Proof, + ProofHeight: rp.dstComRes.ProofHeight, + Signer: addr, + } + return NewCosmosMessage(msg), nil }