From 71074e223d0f02f1690d621b88725bb2ffb4c9b1 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 11 Sep 2023 17:38:25 +0900 Subject: [PATCH 01/15] fix `Chain::SendMsgs` and introduce `Chain::GetMsgResult` Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 48 ++++- chains/tendermint/msg.go | 405 +++++++++++++++++++++++++++++++++++++ core/chain.go | 5 +- core/msg.go | 225 +++++++++++++++++++++ 4 files changed, 680 insertions(+), 3 deletions(-) create mode 100644 chains/tendermint/msg.go create mode 100644 core/msg.go diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 8cc34fd2..5ae063bc 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -2,6 +2,7 @@ package tendermint import ( "context" + "encoding/hex" "fmt" "os" "path" @@ -323,13 +324,56 @@ func CalculateGas( return simRes, uint64(txf.GasAdjustment() * float64(simRes.GasInfo.GasUsed)), nil } -func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]byte, error) { +func (c *Chain) SendMsgs(msgs []sdk.Msg) ([]core.MsgID, error) { // Broadcast those bytes res, err := c.sendMsgs(msgs) if err != nil { return nil, err } - return []byte(res.Logs.String()), nil + var msgIDs []core.MsgID + for msgIndex := range msgs { + msgIDs = append(msgIDs, &MsgID{ + txHash: res.TxHash, + msgIndex: uint32(msgIndex), + }) + } + return msgIDs, nil +} + +func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { + msgID, ok := id.(*MsgID) + if !ok { + return nil, fmt.Errorf("unexpected message id type: %T", id) + } + + txHash, err := hex.DecodeString(msgID.txHash) + if err != nil { + return nil, fmt.Errorf("failed to decode hex string: %v", err) + } + + ctx := c.CLIContext(0) + resTx, err := ctx.Client.Tx(context.TODO(), txHash, false) + if err != nil { + return nil, fmt.Errorf("failed to query tx result: %v", err) + } + + abciLogs, err := sdk.ParseABCILogs(resTx.TxResult.Log) + if err != nil { + return nil, fmt.Errorf("failed to parse ABCI logs: %v", err) + } + + events, err := parseMsgEventLogs(ctx.Codec, abciLogs, msgID.msgIndex) + if err != nil { + return nil, fmt.Errorf("failed to parse msg event log: %v", err) + } + + version := clienttypes.ParseChainID(c.ChainID()) + height := clienttypes.NewHeight(version, uint64(resTx.Height)) + return &MsgResult{ + height: height, + status: resTx.TxResult.IsOK(), + events: events, + }, nil } func (c *Chain) Send(msgs []sdk.Msg) bool { diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go new file mode 100644 index 00000000..86e27cc3 --- /dev/null +++ b/chains/tendermint/msg.go @@ -0,0 +1,405 @@ +package tendermint + +import ( + "encoding/hex" + "errors" + "fmt" + "strconv" + "strings" + "time" + + "github.com/cosmos/cosmos-sdk/codec" + sdk "github.com/cosmos/cosmos-sdk/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" + chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" + "github.com/hyperledger-labs/yui-relayer/core" +) + +var ( + _ core.MsgID = (*MsgID)(nil) + _ core.MsgResult = (*MsgResult)(nil) + _ core.MsgEventLog = (*UnparseableEventLog)(nil) +) + +type MsgID struct { + txHash string + msgIndex uint32 +} + +func (i *MsgID) IsMsgID() {} + +type MsgResult struct { + height clienttypes.Height + status bool + events []core.MsgEventLog +} + +func (r *MsgResult) BlockHeight() clienttypes.Height { + return r.height +} + +func (r *MsgResult) Status() (bool, string) { + return r.status, "" +} + +func (r *MsgResult) Events() []core.MsgEventLog { + return r.events +} + +type UnparseableEventLog struct { + sdk.StringEvent +} + +func (e *UnparseableEventLog) IsMsgEventLog() {} + +func parseMsgEventLogs(cdc codec.Codec, logs sdk.ABCIMessageLogs, msgIndex uint32) ([]core.MsgEventLog, error) { + var msgEventLogs []core.MsgEventLog + for _, log := range logs { + if msgIndex == log.MsgIndex { + for _, ev := range log.Events { + event, err := parseMsgEventLog(cdc, ev) + if err != nil { + return nil, fmt.Errorf("failed to parse msg event log: %v", err) + } + msgEventLogs = append(msgEventLogs, event) + } + } + } + return msgEventLogs, nil +} + +func parseMsgEventLog(cdc codec.Codec, ev sdk.StringEvent) (core.MsgEventLog, error) { + switch ev.Type { + case clienttypes.EventTypeCreateClient: + var event core.EventCreateClient + var err0, err1, err2 error + event.ClientID, err0 = getAttributeString(ev, clienttypes.AttributeKeyClientID) + event.ClientType, err1 = getAttributeString(ev, clienttypes.AttributeKeyClientType) + event.ConsensusHeight, err2 = getAttributeHeight(ev, clienttypes.AttributeKeyConsensusHeight) + if err := errors.Join(err0, err1, err2); err != nil { + return nil, err + } + return &event, nil + case clienttypes.EventTypeUpdateClient: + var event core.EventUpdateClient + var err0, err1, err2, err3 error + event.ClientID, err0 = getAttributeString(ev, clienttypes.AttributeKeyClientID) + event.ClientType, err1 = getAttributeString(ev, clienttypes.AttributeKeyClientType) + event.ConsensusHeights, err2 = getAttributeHeights(ev, clienttypes.AttributeKeyConsensusHeight) + event.ClientMessage, err3 = getAttributeClientMessage(cdc, ev, clienttypes.AttributeKeyHeader) + if err := errors.Join(err0, err1, err2, err3); err != nil { + return nil, err + } + return &event, nil + case conntypes.EventTypeConnectionOpenInit: + var event core.EventConnectionOpenInit + var err0, err1, err2, err3 error + event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) + event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) + event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) + event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) + if err := errors.Join(err0, err1, err2, err3); err != nil { + return nil, err + } + return &event, nil + case conntypes.EventTypeConnectionOpenTry: + var event core.EventConnectionOpenTry + var err0, err1, err2, err3 error + event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) + event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) + event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) + event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) + if err := errors.Join(err0, err1, err2, err3); err != nil { + return nil, err + } + return &event, nil + case conntypes.EventTypeConnectionOpenAck: + var event core.EventConnectionOpenAck + var err0, err1, err2, err3 error + event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) + event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) + event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) + event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) + if err := errors.Join(err0, err1, err2, err3); err != nil { + return nil, err + } + return &event, nil + case conntypes.EventTypeConnectionOpenConfirm: + var event core.EventConnectionOpenConfirm + var err0, err1, err2, err3 error + event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) + event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) + event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) + event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) + if err := errors.Join(err0, err1, err2, err3); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelOpenInit: + var event core.EventChannelOpenInit + var err0, err1, err2, err3, err4 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.ConnectionID, err3 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + event.Version, err4 = getAttributeString(ev, chantypes.AttributeVersion) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelOpenTry: + var event core.EventChannelOpenTry + var err0, err1, err2, err3, err4, err5 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + event.Version, err5 = getAttributeString(ev, chantypes.AttributeVersion) + if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelOpenAck: + var event core.EventChannelOpenAck + var err0, err1, err2, err3, err4 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelOpenConfirm: + var event core.EventChannelOpenConfirm + var err0, err1, err2, err3, err4 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelCloseInit: + var event core.EventChannelCloseInit + var err0, err1, err2, err3, err4 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelCloseConfirm: + var event core.EventChannelCloseConfirm + var err0, err1, err2, err3, err4 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeSendPacket: + var event core.EventSendPacket + var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error + event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) + event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) + event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeRecvPacket: + var event core.EventRecvPacket + var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error + event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) + event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) + event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeWriteAck: + var event core.EventWriteAck + var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error + event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) + event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.Ack, err8 = getAttributeBytes(ev, chantypes.AttributeKeyAckHex) + event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeAcknowledgePacket: + var event core.EventAcknowledgePacket + var err0, err1, err2, err3, err4, err5, err6, err7, err8 error + event.TimeoutHeight, err0 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err1 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Sequence, err2 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err3 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err4 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.DstPort, err5 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err6 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.ChannelOrdering, err7 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) + event.ConnectionID, err8 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeTimeoutPacket: + var event core.EventTimeoutPacket + var err0, err1, err2, err3, err4, err5, err6, err7, err8 error + event.TimeoutHeight, err0 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err1 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Sequence, err2 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err3 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err4 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.DstPort, err5 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err6 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.ConnectionID, err7 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) + if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8); err != nil { + return nil, err + } + return &event, nil + case chantypes.EventTypeChannelClosed: + var event core.EventChannelClosed + var err0, err1, err2, err3, err4, err5 error + event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) + event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) + event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) + event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) + event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) + event.ChannelOrdering, err5 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) + if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { + return nil, err + } + return &event, nil + default: + return &UnparseableEventLog{ev}, nil + } +} + +func getAttributeString(ev sdk.StringEvent, key string) (string, error) { + for _, attr := range ev.Attributes { + if attr.Key == key { + return attr.Value, nil + } + } + return "", fmt.Errorf("failed to find attribute of key %q", key) +} + +func getAttributeBytes(ev sdk.StringEvent, key string) ([]byte, error) { + v, err := getAttributeString(ev, key) + if err != nil { + return nil, err + } + bz, err := hex.DecodeString(v) + if err != nil { + return nil, fmt.Errorf("failed to decode hex string: %v", err) + } + return bz, nil +} + +func getAttributeHeight(ev sdk.StringEvent, key string) (clienttypes.Height, error) { + v, err := getAttributeString(ev, key) + if err != nil { + return clienttypes.Height{}, err + } + height, err := clienttypes.ParseHeight(v) + if err != nil { + return clienttypes.Height{}, fmt.Errorf("failed to parse height: %v", err) + } + return height, nil +} + +func getAttributeUint64(ev sdk.StringEvent, key string) (uint64, error) { + v, err := getAttributeString(ev, key) + if err != nil { + return 0, err + } + d, err := strconv.ParseUint(v, 10, 64) + if err != nil { + return 0, fmt.Errorf("failed to parse uint: %v", err) + } + return d, nil +} + +func getAttributeHeights(ev sdk.StringEvent, key string) ([]clienttypes.Height, error) { + v, err := getAttributeString(ev, key) + if err != nil { + return nil, err + } + var heights []clienttypes.Height + for _, s := range strings.Split(v, ",") { + height, err := clienttypes.ParseHeight(s) + if err != nil { + return nil, fmt.Errorf("failed to parse height: %v", err) + } + heights = append(heights, height) + } + return heights, nil +} + +func getAttributeClientMessage(cdc codec.Codec, ev sdk.StringEvent, key string) (exported.ClientMessage, error) { + bz, err := getAttributeBytes(ev, key) + if err != nil { + return nil, err + } + cliMsg, err := clienttypes.UnmarshalClientMessage(cdc, bz) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal client message: %v", err) + } + return cliMsg, nil +} + +func getAttributeTimestamp(ev sdk.StringEvent, key string) (time.Time, error) { + d, err := getAttributeUint64(ev, key) + if err != nil { + return time.Time{}, err + } + return time.Unix(0, int64(d)), nil +} + +func getAttributeOrder(ev sdk.StringEvent, key string) (chantypes.Order, error) { + v, err := getAttributeString(ev, key) + if err != nil { + return 0, err + } + order, found := chantypes.Order_value[v] + if !found { + return 0, fmt.Errorf("invalid order enum: %v", v) + } + return chantypes.Order(order), nil +} diff --git a/core/chain.go b/core/chain.go index 1fe02025..c1052bf2 100644 --- a/core/chain.go +++ b/core/chain.go @@ -76,7 +76,10 @@ type Chain interface { SetupForRelay(ctx context.Context) error // SendMsgs sends msgs to the chain - SendMsgs(msgs []sdk.Msg) ([]byte, error) + SendMsgs(msgs []sdk.Msg) ([]MsgID, error) + + // GetMsgResult returns the execution result of `sdk.Msg` specified by `MsgID` + GetMsgResult(id MsgID) (MsgResult, error) // Send sends msgs to the chain and logging a result of it // It returns a boolean value whether the result is success diff --git a/core/msg.go b/core/msg.go new file mode 100644 index 00000000..9ff58733 --- /dev/null +++ b/core/msg.go @@ -0,0 +1,225 @@ +package core + +import ( + "time" + + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" + chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" + "github.com/cosmos/ibc-go/v7/modules/core/exported" +) + +type MsgID interface { + IsMsgID() +} + +type MsgResult interface { + BlockHeight() clienttypes.Height + Status() (bool, string) + Events() []MsgEventLog +} + +type MsgEventLog interface { + IsMsgEventLog() +} + +var ( + _ MsgEventLog = (*EventCreateClient)(nil) + _ MsgEventLog = (*EventUpdateClient)(nil) + _ MsgEventLog = (*EventConnectionOpenInit)(nil) + _ MsgEventLog = (*EventConnectionOpenTry)(nil) + _ MsgEventLog = (*EventConnectionOpenAck)(nil) + _ MsgEventLog = (*EventConnectionOpenConfirm)(nil) + _ MsgEventLog = (*EventChannelOpenInit)(nil) + _ MsgEventLog = (*EventChannelOpenTry)(nil) + _ MsgEventLog = (*EventChannelOpenAck)(nil) + _ MsgEventLog = (*EventChannelOpenConfirm)(nil) + _ MsgEventLog = (*EventChannelCloseInit)(nil) + _ MsgEventLog = (*EventChannelCloseConfirm)(nil) + _ MsgEventLog = (*EventSendPacket)(nil) + _ MsgEventLog = (*EventRecvPacket)(nil) + _ MsgEventLog = (*EventWriteAck)(nil) + _ MsgEventLog = (*EventAcknowledgePacket)(nil) + _ MsgEventLog = (*EventTimeoutPacket)(nil) + _ MsgEventLog = (*EventChannelClosed)(nil) +) + +func (EventCreateClient) IsMsgEventLog() {} +func (EventUpdateClient) IsMsgEventLog() {} +func (EventConnectionOpenInit) IsMsgEventLog() {} +func (EventConnectionOpenTry) IsMsgEventLog() {} +func (EventConnectionOpenAck) IsMsgEventLog() {} +func (EventConnectionOpenConfirm) IsMsgEventLog() {} +func (EventChannelOpenInit) IsMsgEventLog() {} +func (EventChannelOpenTry) IsMsgEventLog() {} +func (EventChannelOpenAck) IsMsgEventLog() {} +func (EventChannelOpenConfirm) IsMsgEventLog() {} +func (EventChannelCloseInit) IsMsgEventLog() {} +func (EventChannelCloseConfirm) IsMsgEventLog() {} +func (EventSendPacket) IsMsgEventLog() {} +func (EventRecvPacket) IsMsgEventLog() {} +func (EventWriteAck) IsMsgEventLog() {} +func (EventAcknowledgePacket) IsMsgEventLog() {} +func (EventTimeoutPacket) IsMsgEventLog() {} +func (EventChannelClosed) IsMsgEventLog() {} + +type EventCreateClient struct { + ClientID string + ClientType string + ConsensusHeight clienttypes.Height +} + +type EventUpdateClient struct { + ClientID string + ClientType string + ConsensusHeights []clienttypes.Height + ClientMessage exported.ClientMessage +} + +type EventConnectionOpenInit struct { + ConnectionID string + ClientID string + CounterpartyClientID string + CounterpartyConnectionID string +} + +type EventConnectionOpenTry struct { + ConnectionID string + ClientID string + CounterpartyClientID string + CounterpartyConnectionID string +} + +type EventConnectionOpenAck struct { + ConnectionID string + ClientID string + CounterpartyClientID string + CounterpartyConnectionID string +} + +type EventConnectionOpenConfirm struct { + ConnectionID string + ClientID string + CounterpartyClientID string + CounterpartyConnectionID string +} + +type EventChannelOpenInit struct { + PortID string + ChannelID string + CounterpartyPortID string + ConnectionID string + Version string +} + +type EventChannelOpenTry struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string + Version string +} + +type EventChannelOpenAck struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string +} + +type EventChannelOpenConfirm struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string +} + +type EventChannelCloseInit struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string +} + +type EventChannelCloseConfirm struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string +} + +type EventSendPacket struct { + Data []byte + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Sequence uint64 + SrcPort string + SrcChannel string + DstPort string + DstChannel string + ChannelOrdering chantypes.Order + ConnectionID string +} + +type EventRecvPacket struct { + Data []byte + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Sequence uint64 + SrcPort string + SrcChannel string + DstPort string + DstChannel string + ChannelOrdering chantypes.Order + ConnectionID string +} + +type EventWriteAck struct { + Data []byte + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Sequence uint64 + SrcPort string + SrcChannel string + DstPort string + DstChannel string + Ack []byte + ConnectionID string +} + +type EventAcknowledgePacket struct { + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Sequence uint64 + SrcPort string + SrcChannel string + DstPort string + DstChannel string + ChannelOrdering chantypes.Order + ConnectionID string +} + +type EventTimeoutPacket struct { + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Sequence uint64 + SrcPort string + SrcChannel string + DstPort string + DstChannel string + ConnectionID string + ChannelOrdering chantypes.Order +} + +type EventChannelClosed struct { + PortID string + ChannelID string + CounterpartyPortID string + CounterpartyChannelID string + ConnectionID string + ChannelOrdering chantypes.Order +} From 37b0ab73b94e9742530b730471dbd07f2936271e Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 11 Sep 2023 21:08:21 +0900 Subject: [PATCH 02/15] redefine instances of `core.MsgEventLog` Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 2 +- chains/tendermint/msg.go | 311 ++++++------------------------------- core/msg.go | 201 ++++-------------------- 3 files changed, 81 insertions(+), 433 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 5ae063bc..5d287fe8 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -362,7 +362,7 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { return nil, fmt.Errorf("failed to parse ABCI logs: %v", err) } - events, err := parseMsgEventLogs(ctx.Codec, abciLogs, msgID.msgIndex) + events, err := parseMsgEventLogs(abciLogs, msgID.msgIndex) if err != nil { return nil, fmt.Errorf("failed to parse msg event log: %v", err) } diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go index 86e27cc3..80f6f5a8 100644 --- a/chains/tendermint/msg.go +++ b/chains/tendermint/msg.go @@ -5,22 +5,18 @@ import ( "errors" "fmt" "strconv" - "strings" "time" - "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" conntypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/cosmos/ibc-go/v7/modules/core/exported" "github.com/hyperledger-labs/yui-relayer/core" ) var ( - _ core.MsgID = (*MsgID)(nil) - _ core.MsgResult = (*MsgResult)(nil) - _ core.MsgEventLog = (*UnparseableEventLog)(nil) + _ core.MsgID = (*MsgID)(nil) + _ core.MsgResult = (*MsgResult)(nil) ) type MsgID struct { @@ -48,18 +44,12 @@ func (r *MsgResult) Events() []core.MsgEventLog { return r.events } -type UnparseableEventLog struct { - sdk.StringEvent -} - -func (e *UnparseableEventLog) IsMsgEventLog() {} - -func parseMsgEventLogs(cdc codec.Codec, logs sdk.ABCIMessageLogs, msgIndex uint32) ([]core.MsgEventLog, error) { +func parseMsgEventLogs(logs sdk.ABCIMessageLogs, msgIndex uint32) ([]core.MsgEventLog, error) { var msgEventLogs []core.MsgEventLog for _, log := range logs { if msgIndex == log.MsgIndex { for _, ev := range log.Events { - event, err := parseMsgEventLog(cdc, ev) + event, err := parseMsgEventLog(ev) if err != nil { return nil, fmt.Errorf("failed to parse msg event log: %v", err) } @@ -70,244 +60,77 @@ func parseMsgEventLogs(cdc codec.Codec, logs sdk.ABCIMessageLogs, msgIndex uint3 return msgEventLogs, nil } -func parseMsgEventLog(cdc codec.Codec, ev sdk.StringEvent) (core.MsgEventLog, error) { +func parseMsgEventLog(ev sdk.StringEvent) (core.MsgEventLog, error) { switch ev.Type { case clienttypes.EventTypeCreateClient: - var event core.EventCreateClient - var err0, err1, err2 error - event.ClientID, err0 = getAttributeString(ev, clienttypes.AttributeKeyClientID) - event.ClientType, err1 = getAttributeString(ev, clienttypes.AttributeKeyClientType) - event.ConsensusHeight, err2 = getAttributeHeight(ev, clienttypes.AttributeKeyConsensusHeight) - if err := errors.Join(err0, err1, err2); err != nil { - return nil, err - } - return &event, nil - case clienttypes.EventTypeUpdateClient: - var event core.EventUpdateClient - var err0, err1, err2, err3 error - event.ClientID, err0 = getAttributeString(ev, clienttypes.AttributeKeyClientID) - event.ClientType, err1 = getAttributeString(ev, clienttypes.AttributeKeyClientType) - event.ConsensusHeights, err2 = getAttributeHeights(ev, clienttypes.AttributeKeyConsensusHeight) - event.ClientMessage, err3 = getAttributeClientMessage(cdc, ev, clienttypes.AttributeKeyHeader) - if err := errors.Join(err0, err1, err2, err3); err != nil { - return nil, err - } - return &event, nil - case conntypes.EventTypeConnectionOpenInit: - var event core.EventConnectionOpenInit - var err0, err1, err2, err3 error - event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) - event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) - event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) - event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) - if err := errors.Join(err0, err1, err2, err3); err != nil { - return nil, err - } - return &event, nil - case conntypes.EventTypeConnectionOpenTry: - var event core.EventConnectionOpenTry - var err0, err1, err2, err3 error - event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) - event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) - event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) - event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) - if err := errors.Join(err0, err1, err2, err3); err != nil { - return nil, err - } - return &event, nil - case conntypes.EventTypeConnectionOpenAck: - var event core.EventConnectionOpenAck - var err0, err1, err2, err3 error - event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) - event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) - event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) - event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) - if err := errors.Join(err0, err1, err2, err3); err != nil { - return nil, err - } - return &event, nil - case conntypes.EventTypeConnectionOpenConfirm: - var event core.EventConnectionOpenConfirm - var err0, err1, err2, err3 error - event.ConnectionID, err0 = getAttributeString(ev, conntypes.AttributeKeyConnectionID) - event.ClientID, err1 = getAttributeString(ev, conntypes.AttributeKeyClientID) - event.CounterpartyClientID, err2 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyClientID) - event.CounterpartyConnectionID, err3 = getAttributeString(ev, conntypes.AttributeKeyCounterpartyConnectionID) - if err := errors.Join(err0, err1, err2, err3); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeChannelOpenInit: - var event core.EventChannelOpenInit - var err0, err1, err2, err3, err4 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.ConnectionID, err3 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - event.Version, err4 = getAttributeString(ev, chantypes.AttributeVersion) - if err := errors.Join(err0, err1, err2, err3, err4); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeChannelOpenTry: - var event core.EventChannelOpenTry - var err0, err1, err2, err3, err4, err5 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - event.Version, err5 = getAttributeString(ev, chantypes.AttributeVersion) - if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeChannelOpenAck: - var event core.EventChannelOpenAck - var err0, err1, err2, err3, err4 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeChannelOpenConfirm: - var event core.EventChannelOpenConfirm - var err0, err1, err2, err3, err4 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + clientID, err := getAttributeString(ev, clienttypes.AttributeKeyClientID) + if err != nil { return nil, err } - return &event, nil - case chantypes.EventTypeChannelCloseInit: - var event core.EventChannelCloseInit - var err0, err1, err2, err3, err4 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return &core.EventGenerateClientIdentifier{ID: clientID}, nil + case conntypes.EventTypeConnectionOpenInit, conntypes.EventTypeConnectionOpenTry: + connectionID, err := getAttributeString(ev, conntypes.AttributeKeyConnectionID) + if err != nil { return nil, err } - return &event, nil - case chantypes.EventTypeChannelCloseConfirm: - var event core.EventChannelCloseConfirm - var err0, err1, err2, err3, err4 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4); err != nil { + return &core.EventGenerateConnectionIdentifier{ID: connectionID}, nil + case chantypes.EventTypeChannelOpenInit, chantypes.EventTypeChannelOpenTry: + channelID, err := getAttributeString(ev, chantypes.AttributeKeyChannelID) + if err != nil { return nil, err } - return &event, nil + return &core.EventGenerateChannelIdentifier{ID: channelID}, nil case chantypes.EventTypeSendPacket: var event core.EventSendPacket - var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error - event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) - event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) - event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) - event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) - event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) - event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) - event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) - event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) - event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) - event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + var err0, err1, err2, err3, err4, err5 error + event.Sequence, err0 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err1 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err2 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.TimeoutHeight, err3 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err4 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Data, err5 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) + if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { return nil, err } return &event, nil case chantypes.EventTypeRecvPacket: var event core.EventRecvPacket - var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error - event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) - event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) - event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) - event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) - event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) - event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) - event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) - event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) - event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) - event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + var err0, err1, err2, err3, err4, err5 error + event.Sequence, err0 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.DstPort, err1 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err2 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.TimeoutHeight, err3 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err4 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + event.Data, err5 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) + if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { return nil, err } return &event, nil case chantypes.EventTypeWriteAck: - var event core.EventWriteAck - var err0, err1, err2, err3, err4, err5, err6, err7, err8, err9 error - event.Data, err0 = getAttributeBytes(ev, chantypes.AttributeKeyDataHex) - event.TimeoutHeight, err1 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) - event.TimeoutTimestamp, err2 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) - event.Sequence, err3 = getAttributeUint64(ev, chantypes.AttributeKeySequence) - event.SrcPort, err4 = getAttributeString(ev, chantypes.AttributeKeySrcPort) - event.SrcChannel, err5 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) - event.DstPort, err6 = getAttributeString(ev, chantypes.AttributeKeyDstPort) - event.DstChannel, err7 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) - event.Ack, err8 = getAttributeBytes(ev, chantypes.AttributeKeyAckHex) - event.ConnectionID, err9 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8, err9); err != nil { + var event core.EventWriteAcknowledgement + var err0, err1, err2, err3 error + event.Sequence, err0 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.DstPort, err1 = getAttributeString(ev, chantypes.AttributeKeyDstPort) + event.DstChannel, err2 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) + event.Acknowledgement, err3 = getAttributeBytes(ev, chantypes.AttributeKeyAckHex) + if err := errors.Join(err0, err1, err2, err3); err != nil { return nil, err } return &event, nil case chantypes.EventTypeAcknowledgePacket: var event core.EventAcknowledgePacket - var err0, err1, err2, err3, err4, err5, err6, err7, err8 error - event.TimeoutHeight, err0 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) - event.TimeoutTimestamp, err1 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) - event.Sequence, err2 = getAttributeUint64(ev, chantypes.AttributeKeySequence) - event.SrcPort, err3 = getAttributeString(ev, chantypes.AttributeKeySrcPort) - event.SrcChannel, err4 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) - event.DstPort, err5 = getAttributeString(ev, chantypes.AttributeKeyDstPort) - event.DstChannel, err6 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) - event.ChannelOrdering, err7 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) - event.ConnectionID, err8 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeTimeoutPacket: - var event core.EventTimeoutPacket - var err0, err1, err2, err3, err4, err5, err6, err7, err8 error - event.TimeoutHeight, err0 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) - event.TimeoutTimestamp, err1 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) - event.Sequence, err2 = getAttributeUint64(ev, chantypes.AttributeKeySequence) - event.SrcPort, err3 = getAttributeString(ev, chantypes.AttributeKeySrcPort) - event.SrcChannel, err4 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) - event.DstPort, err5 = getAttributeString(ev, chantypes.AttributeKeyDstPort) - event.DstChannel, err6 = getAttributeString(ev, chantypes.AttributeKeyDstChannel) - event.ConnectionID, err7 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - event.ChannelOrdering, err8 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) - if err := errors.Join(err0, err1, err2, err3, err4, err5, err6, err7, err8); err != nil { - return nil, err - } - return &event, nil - case chantypes.EventTypeChannelClosed: - var event core.EventChannelClosed - var err0, err1, err2, err3, err4, err5 error - event.PortID, err0 = getAttributeString(ev, chantypes.AttributeKeyPortID) - event.ChannelID, err1 = getAttributeString(ev, chantypes.AttributeKeyChannelID) - event.CounterpartyPortID, err2 = getAttributeString(ev, chantypes.AttributeCounterpartyPortID) - event.CounterpartyChannelID, err3 = getAttributeString(ev, chantypes.AttributeCounterpartyChannelID) - event.ConnectionID, err4 = getAttributeString(ev, chantypes.AttributeKeyConnectionID) - event.ChannelOrdering, err5 = getAttributeOrder(ev, chantypes.AttributeKeyChannelOrdering) - if err := errors.Join(err0, err1, err2, err3, err4, err5); err != nil { + var err0, err1, err2, err3, err4 error + event.Sequence, err0 = getAttributeUint64(ev, chantypes.AttributeKeySequence) + event.SrcPort, err1 = getAttributeString(ev, chantypes.AttributeKeySrcPort) + event.SrcChannel, err2 = getAttributeString(ev, chantypes.AttributeKeySrcChannel) + event.TimeoutHeight, err3 = getAttributeHeight(ev, chantypes.AttributeKeyTimeoutHeight) + event.TimeoutTimestamp, err4 = getAttributeTimestamp(ev, chantypes.AttributeKeyTimeoutTimestamp) + if err := errors.Join(err0, err1, err2, err3, err4); err != nil { return nil, err } return &event, nil default: - return &UnparseableEventLog{ev}, nil + return &core.EventUnknown{Value: ev}, nil } } @@ -356,34 +179,6 @@ func getAttributeUint64(ev sdk.StringEvent, key string) (uint64, error) { return d, nil } -func getAttributeHeights(ev sdk.StringEvent, key string) ([]clienttypes.Height, error) { - v, err := getAttributeString(ev, key) - if err != nil { - return nil, err - } - var heights []clienttypes.Height - for _, s := range strings.Split(v, ",") { - height, err := clienttypes.ParseHeight(s) - if err != nil { - return nil, fmt.Errorf("failed to parse height: %v", err) - } - heights = append(heights, height) - } - return heights, nil -} - -func getAttributeClientMessage(cdc codec.Codec, ev sdk.StringEvent, key string) (exported.ClientMessage, error) { - bz, err := getAttributeBytes(ev, key) - if err != nil { - return nil, err - } - cliMsg, err := clienttypes.UnmarshalClientMessage(cdc, bz) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal client message: %v", err) - } - return cliMsg, nil -} - func getAttributeTimestamp(ev sdk.StringEvent, key string) (time.Time, error) { d, err := getAttributeUint64(ev, key) if err != nil { @@ -391,15 +186,3 @@ func getAttributeTimestamp(ev sdk.StringEvent, key string) (time.Time, error) { } return time.Unix(0, int64(d)), nil } - -func getAttributeOrder(ev sdk.StringEvent, key string) (chantypes.Order, error) { - v, err := getAttributeString(ev, key) - if err != nil { - return 0, err - } - order, found := chantypes.Order_value[v] - if !found { - return 0, fmt.Errorf("invalid order enum: %v", v) - } - return chantypes.Order(order), nil -} diff --git a/core/msg.go b/core/msg.go index 9ff58733..048b9d3a 100644 --- a/core/msg.go +++ b/core/msg.go @@ -4,8 +4,6 @@ import ( "time" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - chantypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" - "github.com/cosmos/ibc-go/v7/modules/core/exported" ) type MsgID interface { @@ -19,207 +17,74 @@ type MsgResult interface { } type MsgEventLog interface { - IsMsgEventLog() + isMsgEventLog() } var ( - _ MsgEventLog = (*EventCreateClient)(nil) - _ MsgEventLog = (*EventUpdateClient)(nil) - _ MsgEventLog = (*EventConnectionOpenInit)(nil) - _ MsgEventLog = (*EventConnectionOpenTry)(nil) - _ MsgEventLog = (*EventConnectionOpenAck)(nil) - _ MsgEventLog = (*EventConnectionOpenConfirm)(nil) - _ MsgEventLog = (*EventChannelOpenInit)(nil) - _ MsgEventLog = (*EventChannelOpenTry)(nil) - _ MsgEventLog = (*EventChannelOpenAck)(nil) - _ MsgEventLog = (*EventChannelOpenConfirm)(nil) - _ MsgEventLog = (*EventChannelCloseInit)(nil) - _ MsgEventLog = (*EventChannelCloseConfirm)(nil) + _ MsgEventLog = (*EventGenerateClientIdentifier)(nil) + _ MsgEventLog = (*EventGenerateConnectionIdentifier)(nil) + _ MsgEventLog = (*EventGenerateChannelIdentifier)(nil) _ MsgEventLog = (*EventSendPacket)(nil) _ MsgEventLog = (*EventRecvPacket)(nil) - _ MsgEventLog = (*EventWriteAck)(nil) + _ MsgEventLog = (*EventWriteAcknowledgement)(nil) _ MsgEventLog = (*EventAcknowledgePacket)(nil) - _ MsgEventLog = (*EventTimeoutPacket)(nil) - _ MsgEventLog = (*EventChannelClosed)(nil) + _ MsgEventLog = (*EventUnknown)(nil) ) -func (EventCreateClient) IsMsgEventLog() {} -func (EventUpdateClient) IsMsgEventLog() {} -func (EventConnectionOpenInit) IsMsgEventLog() {} -func (EventConnectionOpenTry) IsMsgEventLog() {} -func (EventConnectionOpenAck) IsMsgEventLog() {} -func (EventConnectionOpenConfirm) IsMsgEventLog() {} -func (EventChannelOpenInit) IsMsgEventLog() {} -func (EventChannelOpenTry) IsMsgEventLog() {} -func (EventChannelOpenAck) IsMsgEventLog() {} -func (EventChannelOpenConfirm) IsMsgEventLog() {} -func (EventChannelCloseInit) IsMsgEventLog() {} -func (EventChannelCloseConfirm) IsMsgEventLog() {} -func (EventSendPacket) IsMsgEventLog() {} -func (EventRecvPacket) IsMsgEventLog() {} -func (EventWriteAck) IsMsgEventLog() {} -func (EventAcknowledgePacket) IsMsgEventLog() {} -func (EventTimeoutPacket) IsMsgEventLog() {} -func (EventChannelClosed) IsMsgEventLog() {} +func (*EventGenerateClientIdentifier) isMsgEventLog() {} +func (*EventGenerateConnectionIdentifier) isMsgEventLog() {} +func (*EventGenerateChannelIdentifier) isMsgEventLog() {} +func (*EventSendPacket) isMsgEventLog() {} +func (*EventRecvPacket) isMsgEventLog() {} +func (*EventWriteAcknowledgement) isMsgEventLog() {} +func (*EventAcknowledgePacket) isMsgEventLog() {} +func (*EventUnknown) isMsgEventLog() {} -type EventCreateClient struct { - ClientID string - ClientType string - ConsensusHeight clienttypes.Height +type EventGenerateClientIdentifier struct { + ID string } -type EventUpdateClient struct { - ClientID string - ClientType string - ConsensusHeights []clienttypes.Height - ClientMessage exported.ClientMessage +type EventGenerateConnectionIdentifier struct { + ID string } -type EventConnectionOpenInit struct { - ConnectionID string - ClientID string - CounterpartyClientID string - CounterpartyConnectionID string -} - -type EventConnectionOpenTry struct { - ConnectionID string - ClientID string - CounterpartyClientID string - CounterpartyConnectionID string -} - -type EventConnectionOpenAck struct { - ConnectionID string - ClientID string - CounterpartyClientID string - CounterpartyConnectionID string -} - -type EventConnectionOpenConfirm struct { - ConnectionID string - ClientID string - CounterpartyClientID string - CounterpartyConnectionID string -} - -type EventChannelOpenInit struct { - PortID string - ChannelID string - CounterpartyPortID string - ConnectionID string - Version string -} - -type EventChannelOpenTry struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string - Version string -} - -type EventChannelOpenAck struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string -} - -type EventChannelOpenConfirm struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string -} - -type EventChannelCloseInit struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string -} - -type EventChannelCloseConfirm struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string +type EventGenerateChannelIdentifier struct { + ID string } type EventSendPacket struct { - Data []byte - TimeoutHeight clienttypes.Height - TimeoutTimestamp time.Time Sequence uint64 SrcPort string SrcChannel string - DstPort string - DstChannel string - ChannelOrdering chantypes.Order - ConnectionID string + TimeoutHeight clienttypes.Height + TimeoutTimestamp time.Time + Data []byte } type EventRecvPacket struct { - Data []byte - TimeoutHeight clienttypes.Height - TimeoutTimestamp time.Time Sequence uint64 - SrcPort string - SrcChannel string DstPort string DstChannel string - ChannelOrdering chantypes.Order - ConnectionID string -} - -type EventWriteAck struct { - Data []byte TimeoutHeight clienttypes.Height TimeoutTimestamp time.Time - Sequence uint64 - SrcPort string - SrcChannel string - DstPort string - DstChannel string - Ack []byte - ConnectionID string + Data []byte +} + +type EventWriteAcknowledgement struct { + Sequence uint64 + DstPort string + DstChannel string + Acknowledgement []byte } type EventAcknowledgePacket struct { - TimeoutHeight clienttypes.Height - TimeoutTimestamp time.Time Sequence uint64 SrcPort string SrcChannel string - DstPort string - DstChannel string - ChannelOrdering chantypes.Order - ConnectionID string -} - -type EventTimeoutPacket struct { TimeoutHeight clienttypes.Height TimeoutTimestamp time.Time - Sequence uint64 - SrcPort string - SrcChannel string - DstPort string - DstChannel string - ConnectionID string - ChannelOrdering chantypes.Order } -type EventChannelClosed struct { - PortID string - ChannelID string - CounterpartyPortID string - CounterpartyChannelID string - ConnectionID string - ChannelOrdering chantypes.Order +type EventUnknown struct { + Value any } From 0aeb0545196fc7bccde7539d5746d187e086aa0b Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 11 Sep 2023 21:28:03 +0900 Subject: [PATCH 03/15] fix core/msg.go Signed-off-by: Masanori Yoshida --- chains/tendermint/msg.go | 4 ++-- core/msg.go | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go index 80f6f5a8..241c457b 100644 --- a/chains/tendermint/msg.go +++ b/chains/tendermint/msg.go @@ -20,12 +20,12 @@ var ( ) type MsgID struct { + core.IsMsgID + txHash string msgIndex uint32 } -func (i *MsgID) IsMsgID() {} - type MsgResult struct { height clienttypes.Height status bool diff --git a/core/msg.go b/core/msg.go index 048b9d3a..9f07a9e9 100644 --- a/core/msg.go +++ b/core/msg.go @@ -7,9 +7,15 @@ import ( ) type MsgID interface { - IsMsgID() + is_MsgID() } +type IsMsgID struct{} + +func (IsMsgID) is_MsgID() {} + +var _ MsgID = IsMsgID{} + type MsgResult interface { BlockHeight() clienttypes.Height Status() (bool, string) @@ -17,10 +23,15 @@ type MsgResult interface { } type MsgEventLog interface { - isMsgEventLog() + is_MsgEventLog() } +type isMsgEventLog struct{} + +func (isMsgEventLog) is_MsgEventLog() {} + var ( + _ MsgEventLog = isMsgEventLog{} _ MsgEventLog = (*EventGenerateClientIdentifier)(nil) _ MsgEventLog = (*EventGenerateConnectionIdentifier)(nil) _ MsgEventLog = (*EventGenerateChannelIdentifier)(nil) @@ -31,28 +42,27 @@ var ( _ MsgEventLog = (*EventUnknown)(nil) ) -func (*EventGenerateClientIdentifier) isMsgEventLog() {} -func (*EventGenerateConnectionIdentifier) isMsgEventLog() {} -func (*EventGenerateChannelIdentifier) isMsgEventLog() {} -func (*EventSendPacket) isMsgEventLog() {} -func (*EventRecvPacket) isMsgEventLog() {} -func (*EventWriteAcknowledgement) isMsgEventLog() {} -func (*EventAcknowledgePacket) isMsgEventLog() {} -func (*EventUnknown) isMsgEventLog() {} - type EventGenerateClientIdentifier struct { + isMsgEventLog + ID string } type EventGenerateConnectionIdentifier struct { + isMsgEventLog + ID string } type EventGenerateChannelIdentifier struct { + isMsgEventLog + ID string } type EventSendPacket struct { + isMsgEventLog + Sequence uint64 SrcPort string SrcChannel string @@ -62,6 +72,8 @@ type EventSendPacket struct { } type EventRecvPacket struct { + isMsgEventLog + Sequence uint64 DstPort string DstChannel string @@ -71,6 +83,8 @@ type EventRecvPacket struct { } type EventWriteAcknowledgement struct { + isMsgEventLog + Sequence uint64 DstPort string DstChannel string @@ -78,6 +92,8 @@ type EventWriteAcknowledgement struct { } type EventAcknowledgePacket struct { + isMsgEventLog + Sequence uint64 SrcPort string SrcChannel string @@ -86,5 +102,7 @@ type EventAcknowledgePacket struct { } type EventUnknown struct { + isMsgEventLog + Value any } From ade446cb407b40bd5b9389b4c96f52b6d31d7fe2 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Mon, 11 Sep 2023 21:32:47 +0900 Subject: [PATCH 04/15] delete an unused function (MustGetHeight) Signed-off-by: Masanori Yoshida --- chains/tendermint/log-chain.go | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/chains/tendermint/log-chain.go b/chains/tendermint/log-chain.go index 0d65f42a..32668277 100644 --- a/chains/tendermint/log-chain.go +++ b/chains/tendermint/log-chain.go @@ -6,8 +6,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" proto "github.com/cosmos/gogoproto/proto" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" ) // LogFailedTx takes the transaction and the messages to create it and logs the appropriate data @@ -75,15 +73,6 @@ func (c *Chain) Print(toPrint proto.Message, text, indent bool) error { return nil } -// MustGetHeight takes the height inteface and returns the actual height -func MustGetHeight(h ibcexported.Height) uint64 { - height, ok := h.(clienttypes.Height) - if !ok { - panic("height is not an instance of height! wtf") - } - return height.GetRevisionHeight() -} - func getMsgAction(msgs []sdk.Msg) string { var out string for i, msg := range msgs { From f922f865a442e038aa04baf56546f93500d00d6d Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 13 Sep 2023 03:51:56 +0900 Subject: [PATCH 05/15] delete `Chain::Send` and introduce `core.SendMsgsAndCheckResult` Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 69 ++++++++++++++++++++++++++------------ chains/tendermint/msg.go | 9 +++-- core/chain.go | 7 ++-- core/relayMsgs.go | 12 ++++--- core/send.go | 23 +++++++++++++ 5 files changed, 87 insertions(+), 33 deletions(-) create mode 100644 core/send.go diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 5d287fe8..62124538 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -9,10 +9,12 @@ import ( "sync" "time" + "cosmossdk.io/errors" "github.com/avast/retry-go" "github.com/cometbft/cometbft/libs/log" rpcclient "github.com/cometbft/cometbft/rpc/client" rpchttp "github.com/cometbft/cometbft/rpc/client/http" + coretypes "github.com/cometbft/cometbft/rpc/core/types" libclient "github.com/cometbft/cometbft/rpc/jsonrpc/client" sdkCtx "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" @@ -167,16 +169,28 @@ func (c *Chain) RegisterMsgEventListener(listener core.MsgEventListener) { } func (c *Chain) sendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, error) { + // broadcast tx res, _, err := c.rawSendMsgs(msgs) if err != nil { return nil, err + } else if res.Code != 0 { + return nil, errors.ABCIError(res.Codespace, res.Code, res.RawLog) } - if res.Code == 0 && c.msgEventListener != nil { + + // wait for tx to be committed + _ = retry.Do(func() error { + _, err = c.rawQueryTx(res.TxHash) + return err + }, rtyAtt, rtyDel, rtyErr) + + // call msgEventListener if needed + if c.msgEventListener != nil { if err := c.msgEventListener.OnSentMsg(msgs); err != nil { c.logger.Error("failed to OnSendMsg call", "msgs", msgs, "err", err) return res, nil } } + return res, nil } @@ -237,6 +251,27 @@ func (c *Chain) rawSendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, bool, error) { return res, true, nil } +func (c *Chain) rawQueryTx(hexTxHash string) (*coretypes.ResultTx, error) { + ctx := c.CLIContext(0) + + txHash, err := hex.DecodeString(hexTxHash) + if err != nil { + return nil, fmt.Errorf("failed to decode the hex string of tx hash: %v", err) + } + + node, err := ctx.GetNode() + if err != nil { + return nil, fmt.Errorf("failed to get node: %v", err) + } + + resTx, err := node.Tx(context.TODO(), txHash, false) + if err != nil { + return nil, fmt.Errorf("failed to retrieve tx: %v", err) + } + + return resTx, nil +} + func prepareFactory(clientCtx sdkCtx.Context, txf tx.Factory) (tx.Factory, error) { from := clientCtx.GetFromAddress() @@ -346,15 +381,15 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { return nil, fmt.Errorf("unexpected message id type: %T", id) } - txHash, err := hex.DecodeString(msgID.txHash) + resTx, err := c.rawQueryTx(msgID.txHash) if err != nil { - return nil, fmt.Errorf("failed to decode hex string: %v", err) + return nil, fmt.Errorf("failed to query tx: %v", err) } - ctx := c.CLIContext(0) - resTx, err := ctx.Client.Tx(context.TODO(), txHash, false) - if err != nil { - return nil, fmt.Errorf("failed to query tx result: %v", err) + var txFailureReason string + if resTx.TxResult.Code != 0 { + err := errors.ABCIError(resTx.TxResult.Codespace, resTx.TxResult.Code, resTx.TxResult.Log) + txFailureReason = err.Error() } abciLogs, err := sdk.ParseABCILogs(resTx.TxResult.Log) @@ -369,25 +404,15 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { version := clienttypes.ParseChainID(c.ChainID()) height := clienttypes.NewHeight(version, uint64(resTx.Height)) + return &MsgResult{ - height: height, - status: resTx.TxResult.IsOK(), - events: events, + height: height, + txStatus: resTx.TxResult.IsOK(), + txFailureReason: txFailureReason, + events: events, }, nil } -func (c *Chain) Send(msgs []sdk.Msg) bool { - res, err := c.sendMsgs(msgs) - if err != nil || res.Code != 0 { - c.LogFailedTx(res, err, msgs) - return false - } - // NOTE: Add more data to this such as identifiers - c.LogSuccessTx(res, msgs) - - return true -} - // ------------------------------- // func (c *Chain) Key() string { diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go index 241c457b..d910ed71 100644 --- a/chains/tendermint/msg.go +++ b/chains/tendermint/msg.go @@ -28,7 +28,12 @@ type MsgID struct { type MsgResult struct { height clienttypes.Height - status bool + + // These show the status of the tx that contains the message. + // It should be noted that the cause of the failure can be a different message. + txStatus bool + txFailureReason string + events []core.MsgEventLog } @@ -37,7 +42,7 @@ func (r *MsgResult) BlockHeight() clienttypes.Height { } func (r *MsgResult) Status() (bool, string) { - return r.status, "" + return r.txStatus, r.txFailureReason } func (r *MsgResult) Events() []core.MsgEventLog { diff --git a/core/chain.go b/core/chain.go index c1052bf2..aabb281a 100644 --- a/core/chain.go +++ b/core/chain.go @@ -75,16 +75,13 @@ type Chain interface { // SetupForRelay performs chain-specific setup before starting the relay SetupForRelay(ctx context.Context) error - // SendMsgs sends msgs to the chain + // SendMsgs sends msgs to the chain and waits for them to be included in a block. + // It should be noted that the block is not finalized at that point and can be reverted, in general. SendMsgs(msgs []sdk.Msg) ([]MsgID, error) // GetMsgResult returns the execution result of `sdk.Msg` specified by `MsgID` GetMsgResult(id MsgID) (MsgResult, error) - // Send sends msgs to the chain and logging a result of it - // It returns a boolean value whether the result is success - Send(msgs []sdk.Msg) bool - // RegisterMsgEventListener registers a given EventListener to the chain RegisterMsgEventListener(MsgEventListener) diff --git a/core/relayMsgs.go b/core/relayMsgs.go index 2f8942c2..a387f434 100644 --- a/core/relayMsgs.go +++ b/core/relayMsgs.go @@ -70,7 +70,9 @@ func (r *RelayMsgs) Send(src, dst Chain) { if r.IsMaxTx(msgLen, txSize) { // Submit the transactions to src chain and update its status - r.Succeeded = r.Succeeded && src.Send(msgs) + if SendMsgsAndCheckResult(src, msgs) != nil { + r.Succeeded = false + } // clear the current batch and reset variables msgLen, txSize = 1, uint64(len(bz)) @@ -80,7 +82,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { } // submit leftover msgs - if len(msgs) > 0 && !src.Send(msgs) { + if len(msgs) > 0 && SendMsgsAndCheckResult(src, msgs) != nil { r.Succeeded = false } @@ -100,7 +102,9 @@ func (r *RelayMsgs) Send(src, dst Chain) { if r.IsMaxTx(msgLen, txSize) { // Submit the transaction to dst chain and update its status - r.Succeeded = r.Succeeded && dst.Send(msgs) + if SendMsgsAndCheckResult(dst, msgs) != nil { + r.Succeeded = false + } // clear the current batch and reset variables msgLen, txSize = 1, uint64(len(bz)) @@ -110,7 +114,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { } // submit leftover msgs - if len(msgs) > 0 && !dst.Send(msgs) { + if len(msgs) > 0 && SendMsgsAndCheckResult(dst, msgs) != nil { r.Succeeded = false } } diff --git a/core/send.go b/core/send.go new file mode 100644 index 00000000..c2d811eb --- /dev/null +++ b/core/send.go @@ -0,0 +1,23 @@ +package core + +import ( + "fmt" + + "github.com/cosmos/cosmos-sdk/types" +) + +func SendMsgsAndCheckResult(chain Chain, msgs []types.Msg) error { + ids, err := chain.SendMsgs(msgs) + if err != nil { + return fmt.Errorf("failed to send messages: %v", err) + } + for i, id := range ids { + res, err := chain.GetMsgResult(id) + if err != nil { + return fmt.Errorf("failed to get the result of msg(%v): %v", msgs[i], err) + } else if ok, reason := res.Status(); !ok { + return fmt.Errorf("msg(%v) was successfully broadcasted, but its execution failed: failure_reason=%v", msgs[i], reason) + } + } + return nil +} From 21970e2adb2c5677f881ddd13dde12de388c0f31 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 13 Sep 2023 10:57:58 +0900 Subject: [PATCH 06/15] add comments to core/msg.go Signed-off-by: Masanori Yoshida --- core/msg.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/msg.go b/core/msg.go index 9f07a9e9..27d77a36 100644 --- a/core/msg.go +++ b/core/msg.go @@ -6,26 +6,39 @@ import ( clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" ) +// MsgID represents an identifier of `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgID interface { is_MsgID() } +// IsMsgID must be embedded in implementation of the `MsgID` interface. +// This struct is exported, so each chain module can implement the `MsgID` interface. type IsMsgID struct{} func (IsMsgID) is_MsgID() {} var _ MsgID = IsMsgID{} +// MsgResult represents a execution result of `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgResult interface { + // BlockHeight returns the height that the message is included. BlockHeight() clienttypes.Height + + // Status returns true if the execution of the message is successful. + // If it fails, this function returns false with the second return value that provides additional information. Status() (bool, string) + + // Events returns events emitted by the message. Events() []MsgEventLog } +// MsgEventLog represents an event emitted by `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgEventLog interface { is_MsgEventLog() } +// isMsgEventLog must be embedded in implementation of the `MsgEventLog` interface. +// It should be noted that the `MsgEventLog` interface cannot be implemented outside this package because `isMsgEventLog` is unexported. type isMsgEventLog struct{} func (isMsgEventLog) is_MsgEventLog() {} @@ -42,24 +55,28 @@ var ( _ MsgEventLog = (*EventUnknown)(nil) ) +// EventGenerateClientIdentifier is an implementation of `MsgEventLog` that represents the client id generated by `createClient` operation. type EventGenerateClientIdentifier struct { isMsgEventLog ID string } +// EventGenerateConnectionIdentifier is an implementation of `MsgEventLog` that represents the connection id generated by `connOpenInit` or `connOpenTry` operation. type EventGenerateConnectionIdentifier struct { isMsgEventLog ID string } +// EventGenerateChannelIdentifier is an implementation of `MsgEventLog` that represents the channel id generated by `chanOpenInit` or `chanOpenTry` operation. type EventGenerateChannelIdentifier struct { isMsgEventLog ID string } +// EventSendPacket is an implementation of `MsgEventLog` that represents the information of a `sendPacket` operation. type EventSendPacket struct { isMsgEventLog @@ -71,6 +88,7 @@ type EventSendPacket struct { Data []byte } +// EventRecvPacket is an implementation of `MsgEventLog` that represents the information of a `recvPacket` operation. type EventRecvPacket struct { isMsgEventLog @@ -82,6 +100,7 @@ type EventRecvPacket struct { Data []byte } +// EventWriteAcknowledgement is an implementation of `MsgEventLog` that represents the information of a `writeAcknowledgement` operation. type EventWriteAcknowledgement struct { isMsgEventLog @@ -91,6 +110,7 @@ type EventWriteAcknowledgement struct { Acknowledgement []byte } +// EventAcknowledgePacket is an implementation of `MsgEventLog` that represents the information of a `acknowledgePacket` operation. type EventAcknowledgePacket struct { isMsgEventLog @@ -101,6 +121,7 @@ type EventAcknowledgePacket struct { TimeoutTimestamp time.Time } +// EventUnknown is an implementation of `MsgEventLog` that represents another event. type EventUnknown struct { isMsgEventLog From 236f8d37ed099600627a1ae46bedc6e32933d48f Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 13 Sep 2023 11:23:35 +0900 Subject: [PATCH 07/15] add utility funciton `GetFinalizedMsgResult` Signed-off-by: Masanori Yoshida --- core/send.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/core/send.go b/core/send.go index c2d811eb..294ed109 100644 --- a/core/send.go +++ b/core/send.go @@ -3,9 +3,11 @@ package core import ( "fmt" + retry "github.com/avast/retry-go" "github.com/cosmos/cosmos-sdk/types" ) +// SendMsgsAndCheckResult is an utility function that executes `Chain::SendMsgs` and checks the results of all the messages. func SendMsgsAndCheckResult(chain Chain, msgs []types.Msg) error { ids, err := chain.SendMsgs(msgs) if err != nil { @@ -21,3 +23,34 @@ func SendMsgsAndCheckResult(chain Chain, msgs []types.Msg) error { } return nil } + +// GetFinalizedMsgResult is an utility function that waits for the finalization of the message execution and then returns the result. +func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID) (MsgResult, error) { + var msgRes MsgResult + if err := retry.Do(func() error { + var err error + + // query LFH for each retry because it can proceed. + header, err := chain.GetLatestFinalizedHeader() + if err != nil { + return fmt.Errorf("failed to get latest finalized header: %v", err) + } + + // query MsgResult for each retry because it can be included in a different block because of reorg + msgRes, err = chain.GetMsgResult(msgID) + if err != nil { + return fmt.Errorf("failed to get messge result: %v", err) + } + + // check whether the block that includes the message has been finalized, or not + if msgRes.BlockHeight().GT(header.GetHeight()) { + return fmt.Errorf("message_height(%v) > latest_finalized_height(%v)", msgRes.BlockHeight(), header.GetHeight()) + } + + return nil + }, rtyAtt, rtyDel, rtyErr); err != nil { + return nil, err + } else { + return msgRes, nil + } +} From d0e7c5a0b47898744da7c5e1131abc52b89b0715 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 13 Sep 2023 12:06:05 +0900 Subject: [PATCH 08/15] fix `core.GetFinalizedMsgResult` Signed-off-by: Masanori Yoshida --- core/send.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/core/send.go b/core/send.go index 294ed109..5482fbd7 100644 --- a/core/send.go +++ b/core/send.go @@ -2,6 +2,7 @@ package core import ( "fmt" + "time" retry "github.com/avast/retry-go" "github.com/cosmos/cosmos-sdk/types" @@ -25,13 +26,13 @@ func SendMsgsAndCheckResult(chain Chain, msgs []types.Msg) error { } // GetFinalizedMsgResult is an utility function that waits for the finalization of the message execution and then returns the result. -func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID) (MsgResult, error) { +func GetFinalizedMsgResult(chain ProvableChain, averageBlockTime time.Duration, msgID MsgID) (MsgResult, error) { var msgRes MsgResult if err := retry.Do(func() error { var err error // query LFH for each retry because it can proceed. - header, err := chain.GetLatestFinalizedHeader() + lfHeader, err := chain.GetLatestFinalizedHeader() if err != nil { return fmt.Errorf("failed to get latest finalized header: %v", err) } @@ -43,8 +44,18 @@ func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID) (MsgResult, error) } // check whether the block that includes the message has been finalized, or not - if msgRes.BlockHeight().GT(header.GetHeight()) { - return fmt.Errorf("message_height(%v) > latest_finalized_height(%v)", msgRes.BlockHeight(), header.GetHeight()) + msgHeight := msgRes.BlockHeight() + lfHeight := lfHeader.GetHeight() + if msgHeight.GT(lfHeight) { + var waitTime time.Duration + if msgHeight.GetRevisionNumber() != lfHeight.GetRevisionNumber() { + // TODO: should return an unrecoverable error? + waitTime = averageBlockTime + } else { + waitTime = averageBlockTime * time.Duration(msgHeight.GetRevisionHeight()-lfHeight.GetRevisionHeight()) + } + time.Sleep(waitTime) + return fmt.Errorf("message_height(%v) > latest_finalized_height(%v)", msgHeight, lfHeight) } return nil From 4f397c7c22845a4390d89846c08784ebe2405b45 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 20 Sep 2023 04:30:27 +0900 Subject: [PATCH 09/15] change the design of SendMsgs/GetMsgResult and implement them for tendermint Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 66 ++++++++++++++++++++++++++++---------- chains/tendermint/msg.go | 4 +++ core/chain.go | 14 ++++++-- core/msg.go | 5 ++- core/relayMsgs.go | 12 +++---- core/send.go | 49 +++++++++------------------- log/slog.go | 10 ++++++ 7 files changed, 99 insertions(+), 61 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 62124538..46068898 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -39,6 +39,8 @@ var ( rtyAtt = retry.Attempts(rtyAttNum) rtyDel = retry.Delay(time.Millisecond * 400) rtyErr = retry.LastErrorOnly(true) + + rtyAttCommit = retry.Attempts(25) // 400msec * 25 = 10sec ) // Chain represents the necessary data for connecting to and indentifying a chain and its counterparites @@ -174,14 +176,17 @@ func (c *Chain) sendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, error) { if err != nil { return nil, err } else if res.Code != 0 { - return nil, errors.ABCIError(res.Codespace, res.Code, res.RawLog) + // CheckTx failed + return nil, fmt.Errorf("CheckTx failed: %v", errors.ABCIError(res.Codespace, res.Code, res.RawLog)) } - // wait for tx to be committed - _ = retry.Do(func() error { - _, err = c.rawQueryTx(res.TxHash) - return err - }, rtyAtt, rtyDel, rtyErr) + // wait for tx being committed + if resTx, err := c.waitForCommit(res.TxHash); err != nil { + return nil, err + } else if resTx.TxResult.IsErr() { + // DeliverTx failed + return nil, fmt.Errorf("DeliverTx failed: %v", errors.ABCIError(res.Codespace, res.Code, res.RawLog)) + } // call msgEventListener if needed if c.msgEventListener != nil { @@ -251,6 +256,25 @@ func (c *Chain) rawSendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, bool, error) { return res, true, nil } +func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { + var resTx *coretypes.ResultTx + + if err := retry.Do(func() error { + var err error + resTx, err = c.rawQueryTx(txHash) + if err != nil { + return err + } + return nil + }, rtyAttCommit, rtyDel, rtyErr); err != nil { + return resTx, fmt.Errorf("failed to make sure that tx is committed: %v", err) + } + + return resTx, nil +} + +// rawQueryTx returns a tx of which hash equals to `hexTxHash`. +// If the RPC is successful but the tx is not found, this returns nil with nil error. func (c *Chain) rawQueryTx(hexTxHash string) (*coretypes.ResultTx, error) { ctx := c.CLIContext(0) @@ -381,35 +405,43 @@ func (c *Chain) GetMsgResult(id core.MsgID) (core.MsgResult, error) { return nil, fmt.Errorf("unexpected message id type: %T", id) } - resTx, err := c.rawQueryTx(msgID.txHash) + // find tx + resTx, err := c.waitForCommit(msgID.txHash) if err != nil { return nil, fmt.Errorf("failed to query tx: %v", err) } - var txFailureReason string - if resTx.TxResult.Code != 0 { + // check height of the delivered tx + version := clienttypes.ParseChainID(c.ChainID()) + height := clienttypes.NewHeight(version, uint64(resTx.Height)) + + // check if the tx execution succeeded + if resTx.TxResult.IsErr() { err := errors.ABCIError(resTx.TxResult.Codespace, resTx.TxResult.Code, resTx.TxResult.Log) - txFailureReason = err.Error() + txFailureReason := err.Error() + return &MsgResult{ + height: height, + txStatus: false, + txFailureReason: txFailureReason, + }, nil } + // parse the log into ABCI logs abciLogs, err := sdk.ParseABCILogs(resTx.TxResult.Log) if err != nil { return nil, fmt.Errorf("failed to parse ABCI logs: %v", err) } + // parse the ABCI logs into core.MsgEventLog's events, err := parseMsgEventLogs(abciLogs, msgID.msgIndex) if err != nil { return nil, fmt.Errorf("failed to parse msg event log: %v", err) } - version := clienttypes.ParseChainID(c.ChainID()) - height := clienttypes.NewHeight(version, uint64(resTx.Height)) - return &MsgResult{ - height: height, - txStatus: resTx.TxResult.IsOK(), - txFailureReason: txFailureReason, - events: events, + height: height, + txStatus: true, + events: events, }, nil } diff --git a/chains/tendermint/msg.go b/chains/tendermint/msg.go index d910ed71..9a9292a0 100644 --- a/chains/tendermint/msg.go +++ b/chains/tendermint/msg.go @@ -26,6 +26,10 @@ type MsgID struct { msgIndex uint32 } +func (i *MsgID) String() string { + return fmt.Sprintf("%s:%d", i.txHash, i.msgIndex) +} + type MsgResult struct { height clienttypes.Height diff --git a/core/chain.go b/core/chain.go index aabb281a..994b1bee 100644 --- a/core/chain.go +++ b/core/chain.go @@ -75,11 +75,13 @@ type Chain interface { // SetupForRelay performs chain-specific setup before starting the relay SetupForRelay(ctx context.Context) error - // SendMsgs sends msgs to the chain and waits for them to be included in a block. - // It should be noted that the block is not finalized at that point and can be reverted, in general. + // SendMsgs sends msgs to the chain and waits for them to be included in blocks. + // This function returns err=nil only if all the msgs executed successfully at the blocks. + // It should be noted that the block is not finalized at that point and can be reverted afterwards. SendMsgs(msgs []sdk.Msg) ([]MsgID, error) // GetMsgResult returns the execution result of `sdk.Msg` specified by `MsgID` + // If the msg is not included in any block, this function waits for inclusion. GetMsgResult(id MsgID) (MsgResult, error) // RegisterMsgEventListener registers a given EventListener to the chain @@ -197,6 +199,14 @@ func (qc queryContext) Height() ibcexported.Height { return qc.height } +func GetChainLogger(chain ChainInfo) *log.RelayLogger { + return log.GetLogger(). + WithChain( + chain.ChainID(), + ). + WithModule("core.chain") +} + func GetChainPairLogger(src, dst ChainInfo) *log.RelayLogger { return log.GetLogger(). WithChainPair( diff --git a/core/msg.go b/core/msg.go index 27d77a36..7148ef2a 100644 --- a/core/msg.go +++ b/core/msg.go @@ -1,6 +1,7 @@ package core import ( + "fmt" "time" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -8,6 +9,7 @@ import ( // MsgID represents an identifier of `sdk.Msg` that has been sent to a chain by `Chain::SendMsgs`. type MsgID interface { + fmt.Stringer is_MsgID() } @@ -15,7 +17,8 @@ type MsgID interface { // This struct is exported, so each chain module can implement the `MsgID` interface. type IsMsgID struct{} -func (IsMsgID) is_MsgID() {} +func (IsMsgID) is_MsgID() {} +func (IsMsgID) String() string { panic("MsgID::String must be overridden.") } var _ MsgID = IsMsgID{} diff --git a/core/relayMsgs.go b/core/relayMsgs.go index a387f434..66e05890 100644 --- a/core/relayMsgs.go +++ b/core/relayMsgs.go @@ -70,9 +70,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { if r.IsMaxTx(msgLen, txSize) { // Submit the transactions to src chain and update its status - if SendMsgsAndCheckResult(src, msgs) != nil { - r.Succeeded = false - } + r.Succeeded = r.Succeeded && SendCheckMsgs(src, msgs) // clear the current batch and reset variables msgLen, txSize = 1, uint64(len(bz)) @@ -82,7 +80,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { } // submit leftover msgs - if len(msgs) > 0 && SendMsgsAndCheckResult(src, msgs) != nil { + if len(msgs) > 0 && !SendCheckMsgs(src, msgs) { r.Succeeded = false } @@ -102,9 +100,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { if r.IsMaxTx(msgLen, txSize) { // Submit the transaction to dst chain and update its status - if SendMsgsAndCheckResult(dst, msgs) != nil { - r.Succeeded = false - } + r.Succeeded = r.Succeeded && SendCheckMsgs(dst, msgs) // clear the current batch and reset variables msgLen, txSize = 1, uint64(len(bz)) @@ -114,7 +110,7 @@ func (r *RelayMsgs) Send(src, dst Chain) { } // submit leftover msgs - if len(msgs) > 0 && SendMsgsAndCheckResult(dst, msgs) != nil { + if len(msgs) > 0 && !SendCheckMsgs(dst, msgs) { r.Succeeded = false } } diff --git a/core/send.go b/core/send.go index 5482fbd7..e5523e9a 100644 --- a/core/send.go +++ b/core/send.go @@ -8,29 +8,20 @@ import ( "github.com/cosmos/cosmos-sdk/types" ) -// SendMsgsAndCheckResult is an utility function that executes `Chain::SendMsgs` and checks the results of all the messages. -func SendMsgsAndCheckResult(chain Chain, msgs []types.Msg) error { - ids, err := chain.SendMsgs(msgs) - if err != nil { - return fmt.Errorf("failed to send messages: %v", err) +// SendCheckMsgs is an utility function that executes `Chain::SendMsgs` and checks the execution results of all the messages. +func SendCheckMsgs(chain Chain, msgs []types.Msg) bool { + if _, err := chain.SendMsgs(msgs); err != nil { + GetChainLogger(chain).Error("failed to send msgs", err) + return false } - for i, id := range ids { - res, err := chain.GetMsgResult(id) - if err != nil { - return fmt.Errorf("failed to get the result of msg(%v): %v", msgs[i], err) - } else if ok, reason := res.Status(); !ok { - return fmt.Errorf("msg(%v) was successfully broadcasted, but its execution failed: failure_reason=%v", msgs[i], reason) - } - } - return nil + return true } // GetFinalizedMsgResult is an utility function that waits for the finalization of the message execution and then returns the result. -func GetFinalizedMsgResult(chain ProvableChain, averageBlockTime time.Duration, msgID MsgID) (MsgResult, error) { +func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID, retryInterval time.Duration, maxRetry uint) (MsgResult, error) { var msgRes MsgResult - if err := retry.Do(func() error { - var err error + if err := retry.Do(func() error { // query LFH for each retry because it can proceed. lfHeader, err := chain.GetLatestFinalizedHeader() if err != nil { @@ -40,28 +31,20 @@ func GetFinalizedMsgResult(chain ProvableChain, averageBlockTime time.Duration, // query MsgResult for each retry because it can be included in a different block because of reorg msgRes, err = chain.GetMsgResult(msgID) if err != nil { - return fmt.Errorf("failed to get messge result: %v", err) + return retry.Unrecoverable(fmt.Errorf("failed to get message result: %v", err)) + } else if ok, failureReason := msgRes.Status(); !ok { + return retry.Unrecoverable(fmt.Errorf("msg(id=%v) execution failed: %v", msgID, failureReason)) } // check whether the block that includes the message has been finalized, or not - msgHeight := msgRes.BlockHeight() - lfHeight := lfHeader.GetHeight() - if msgHeight.GT(lfHeight) { - var waitTime time.Duration - if msgHeight.GetRevisionNumber() != lfHeight.GetRevisionNumber() { - // TODO: should return an unrecoverable error? - waitTime = averageBlockTime - } else { - waitTime = averageBlockTime * time.Duration(msgHeight.GetRevisionHeight()-lfHeight.GetRevisionHeight()) - } - time.Sleep(waitTime) - return fmt.Errorf("message_height(%v) > latest_finalized_height(%v)", msgHeight, lfHeight) + if msgHeight, lfHeight := msgRes.BlockHeight(), lfHeader.GetHeight(); msgHeight.GT(lfHeight) { + return fmt.Errorf("msg(id=%v) not finalied: msg.height(%v) > lfh.height(%v)", msgID, msgHeight, lfHeight) } return nil - }, rtyAtt, rtyDel, rtyErr); err != nil { + }, retry.Attempts(maxRetry), retry.Delay(retryInterval), rtyErr); err != nil { return nil, err - } else { - return msgRes, nil } + + return msgRes, nil } diff --git a/log/slog.go b/log/slog.go index 396ec650..80580f6b 100644 --- a/log/slog.go +++ b/log/slog.go @@ -80,6 +80,16 @@ func GetLogger() *RelayLogger { return relayLogger } +func (rl *RelayLogger) WithChain( + chainID string, +) *RelayLogger { + return &RelayLogger{ + rl.Logger.With( + "chain_id", chainID, + ), + } +} + func (rl *RelayLogger) WithChainPair( srcChainID string, dstChainID string, From dd7419a8c680cd20ccd7b2c4e7554f8f55c9b940 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Wed, 20 Sep 2023 10:14:02 +0900 Subject: [PATCH 10/15] tendermint: make settings configurable to wait for tx commits Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 7 +- chains/tendermint/config.pb.go | 116 +++++++++++++----- go.mod | 2 +- .../chains/tendermint/config/config.proto | 2 + tests/cases/tm2tm/configs/demo/ibc-0.json | 4 +- tests/cases/tm2tm/configs/demo/ibc-1.json | 4 +- .../tmmock2tmmock/configs/demo/ibc-0.json | 4 +- .../tmmock2tmmock/configs/demo/ibc-1.json | 4 +- 8 files changed, 107 insertions(+), 36 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index 46068898..d28c81dd 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -39,8 +39,6 @@ var ( rtyAtt = retry.Attempts(rtyAttNum) rtyDel = retry.Delay(time.Millisecond * 400) rtyErr = retry.LastErrorOnly(true) - - rtyAttCommit = retry.Attempts(25) // 400msec * 25 = 10sec ) // Chain represents the necessary data for connecting to and indentifying a chain and its counterparites @@ -259,6 +257,9 @@ func (c *Chain) rawSendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, bool, error) { func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { var resTx *coretypes.ResultTx + retryInterval := time.Duration(c.config.RetryIntervalMsec) * time.Millisecond + maxRetry := uint(c.config.MaxRetryForCommit) + if err := retry.Do(func() error { var err error resTx, err = c.rawQueryTx(txHash) @@ -266,7 +267,7 @@ func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { return err } return nil - }, rtyAttCommit, rtyDel, rtyErr); err != nil { + }, retry.Attempts(maxRetry), retry.Delay(retryInterval), rtyErr); err != nil { return resTx, fmt.Errorf("failed to make sure that tx is committed: %v", err) } diff --git a/chains/tendermint/config.pb.go b/chains/tendermint/config.pb.go index 1f5edc24..5b5230f7 100644 --- a/chains/tendermint/config.pb.go +++ b/chains/tendermint/config.pb.go @@ -25,12 +25,14 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type ChainConfig struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - RpcAddr string `protobuf:"bytes,3,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` - AccountPrefix string `protobuf:"bytes,4,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` - GasAdjustment float64 `protobuf:"fixed64,5,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` - GasPrices string `protobuf:"bytes,6,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + RpcAddr string `protobuf:"bytes,3,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` + AccountPrefix string `protobuf:"bytes,4,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` + GasAdjustment float64 `protobuf:"fixed64,5,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` + GasPrices string `protobuf:"bytes,6,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` + RetryIntervalMsec uint64 `protobuf:"varint,7,opt,name=retry_interval_msec,json=retryIntervalMsec,proto3" json:"retry_interval_msec,omitempty"` + MaxRetryForCommit uint64 `protobuf:"varint,8,opt,name=max_retry_for_commit,json=maxRetryForCommit,proto3" json:"max_retry_for_commit,omitempty"` } func (m *ChainConfig) Reset() { *m = ChainConfig{} } @@ -113,28 +115,32 @@ func init() { } var fileDescriptor_d67cd47cbc86ecb1 = []byte{ - // 331 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x91, 0xb1, 0x4e, 0xeb, 0x30, - 0x14, 0x86, 0xe3, 0xdb, 0x7b, 0x7b, 0xa9, 0xa1, 0x05, 0x45, 0x0c, 0x01, 0x89, 0xa8, 0xaa, 0x84, - 0xe8, 0xd2, 0x64, 0x60, 0x40, 0x8c, 0xa5, 0x13, 0x5b, 0xd4, 0x05, 0x89, 0x25, 0x72, 0x6d, 0xd7, - 0x35, 0xb4, 0xb6, 0x75, 0xec, 0x20, 0xf2, 0x16, 0x3c, 0x13, 0x53, 0xc7, 0x8e, 0x8c, 0xd0, 0xbe, - 0x08, 0x8a, 0x13, 0x60, 0x62, 0xf2, 0xf1, 0x77, 0xbe, 0x73, 0xa4, 0xdf, 0xc6, 0x23, 0xe0, 0x4b, - 0x52, 0x72, 0x48, 0xe9, 0x82, 0x48, 0x65, 0x53, 0xc7, 0x15, 0xe3, 0xb0, 0x92, 0xca, 0xa5, 0x54, - 0xab, 0xb9, 0x14, 0xcd, 0x91, 0x18, 0xd0, 0x4e, 0x87, 0xfd, 0x46, 0x4f, 0x6a, 0x3d, 0xf9, 0xd1, - 0x93, 0xda, 0x3b, 0x3d, 0x16, 0x5a, 0x68, 0x2f, 0xa7, 0x55, 0x55, 0xcf, 0x0d, 0x5e, 0x11, 0xde, - 0x9f, 0x54, 0x23, 0x13, 0x6f, 0x85, 0x47, 0xb8, 0xf5, 0xc8, 0xcb, 0x08, 0xf5, 0xd1, 0xb0, 0x33, - 0xad, 0xca, 0xf0, 0x04, 0xef, 0xf9, 0x9d, 0xb9, 0x64, 0xd1, 0x1f, 0x8f, 0xff, 0xfb, 0xfb, 0x2d, - 0xab, 0x5a, 0x60, 0x68, 0x4e, 0x18, 0x83, 0xa8, 0x55, 0xb7, 0xc0, 0xd0, 0x31, 0x63, 0x10, 0x9e, - 0xe3, 0x1e, 0xa1, 0x54, 0x17, 0xca, 0xe5, 0x06, 0xf8, 0x5c, 0x3e, 0x47, 0x7f, 0xbd, 0xd0, 0x6d, - 0x68, 0xe6, 0x61, 0xa5, 0x09, 0x62, 0x73, 0xc2, 0x1e, 0x0a, 0xeb, 0x56, 0x5c, 0xb9, 0xe8, 0x5f, - 0x1f, 0x0d, 0xd1, 0xb4, 0x2b, 0x88, 0x1d, 0x7f, 0xc3, 0xf0, 0x0c, 0xe3, 0x4a, 0x33, 0x20, 0x29, - 0xb7, 0x51, 0xdb, 0x6f, 0xea, 0x08, 0x62, 0x33, 0x0f, 0x06, 0x57, 0xf8, 0x20, 0x03, 0xfd, 0xc4, - 0xa1, 0x09, 0x71, 0x81, 0x0f, 0x1d, 0x14, 0xd6, 0x49, 0x25, 0x72, 0xc3, 0x41, 0x6a, 0xd6, 0x04, - 0xea, 0x7d, 0xe1, 0xcc, 0xd3, 0x9b, 0xbb, 0xf5, 0x47, 0x1c, 0xac, 0xb7, 0x31, 0xda, 0x6c, 0x63, - 0xf4, 0xbe, 0x8d, 0xd1, 0xcb, 0x2e, 0x0e, 0x36, 0xbb, 0x38, 0x78, 0xdb, 0xc5, 0xc1, 0xfd, 0xb5, - 0x90, 0x6e, 0x51, 0xcc, 0x12, 0xaa, 0x57, 0xe9, 0xa2, 0x34, 0x1c, 0x96, 0x9c, 0x09, 0x0e, 0xa3, - 0x25, 0x99, 0xd9, 0xb4, 0x2c, 0xe4, 0xef, 0x5f, 0x34, 0x6b, 0xfb, 0xd7, 0xbd, 0xfc, 0x0c, 0x00, - 0x00, 0xff, 0xff, 0xa9, 0xcb, 0x98, 0xae, 0xc6, 0x01, 0x00, 0x00, + // 395 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xbf, 0x8e, 0xd4, 0x30, + 0x10, 0xc6, 0xd7, 0x77, 0xc7, 0xfd, 0x31, 0xdc, 0x01, 0xe1, 0x0a, 0x83, 0x44, 0xb4, 0x3a, 0x09, + 0xb1, 0xcd, 0x25, 0x05, 0x05, 0xa2, 0x3c, 0x56, 0x42, 0xba, 0x02, 0x69, 0x95, 0x06, 0x89, 0xc6, + 0xf2, 0xda, 0xb3, 0x5e, 0x43, 0x6c, 0x47, 0x63, 0xe7, 0xb4, 0x79, 0x0b, 0xde, 0x81, 0x97, 0xb9, + 0x72, 0x4b, 0x4a, 0xd8, 0x7d, 0x11, 0x14, 0x27, 0x40, 0x45, 0x95, 0xc9, 0xef, 0xfb, 0x7d, 0x53, + 0x4c, 0x42, 0xaf, 0x11, 0x6a, 0xd1, 0x01, 0x96, 0x72, 0x2d, 0x8c, 0x0b, 0x65, 0x04, 0xa7, 0x00, + 0xad, 0x71, 0xb1, 0x94, 0xde, 0xad, 0x8c, 0x1e, 0x1f, 0x45, 0x83, 0x3e, 0xfa, 0x6c, 0x3a, 0xea, + 0xc5, 0xa0, 0x17, 0xff, 0xf4, 0x62, 0xf0, 0x5e, 0x5c, 0x6a, 0xaf, 0x7d, 0x92, 0xcb, 0x7e, 0x1a, + 0x7a, 0x57, 0xdf, 0x0f, 0xe8, 0xc3, 0x79, 0x5f, 0x99, 0x27, 0x2b, 0x7b, 0x42, 0x0f, 0xbf, 0x42, + 0xc7, 0xc8, 0x94, 0xcc, 0xce, 0xaa, 0x7e, 0xcc, 0x9e, 0xd3, 0xd3, 0xb4, 0x93, 0x1b, 0xc5, 0x0e, + 0x12, 0x3e, 0x49, 0xef, 0xb7, 0xaa, 0x8f, 0xb0, 0x91, 0x5c, 0x28, 0x85, 0xec, 0x70, 0x88, 0xb0, + 0x91, 0x37, 0x4a, 0x61, 0xf6, 0x8a, 0x5e, 0x08, 0x29, 0x7d, 0xeb, 0x22, 0x6f, 0x10, 0x56, 0x66, + 0xc3, 0x8e, 0x92, 0x70, 0x3e, 0xd2, 0x45, 0x82, 0xbd, 0xa6, 0x45, 0xe0, 0x42, 0x7d, 0x69, 0x43, + 0xb4, 0xe0, 0x22, 0x7b, 0x30, 0x25, 0x33, 0x52, 0x9d, 0x6b, 0x11, 0x6e, 0xfe, 0xc2, 0xec, 0x25, + 0xa5, 0xbd, 0xd6, 0xa0, 0x91, 0x10, 0xd8, 0x71, 0xda, 0x74, 0xa6, 0x45, 0x58, 0x24, 0x90, 0x15, + 0xf4, 0x19, 0x42, 0xc4, 0x8e, 0x1b, 0x17, 0x01, 0xef, 0x44, 0xcd, 0x6d, 0x00, 0xc9, 0x4e, 0xa6, + 0x64, 0x76, 0x54, 0x3d, 0x4d, 0xd1, 0xed, 0x98, 0x7c, 0x0c, 0x20, 0xb3, 0x92, 0x5e, 0x5a, 0xb1, + 0xe1, 0x43, 0x67, 0xe5, 0x91, 0x4b, 0x6f, 0xad, 0x89, 0xec, 0x74, 0x28, 0x58, 0xb1, 0xa9, 0xfa, + 0xe8, 0x83, 0xc7, 0x79, 0x0a, 0xae, 0xde, 0xd2, 0x47, 0x0b, 0xf4, 0x77, 0x80, 0xe3, 0x95, 0x5e, + 0xd3, 0xc7, 0x11, 0xdb, 0x10, 0x8d, 0xd3, 0xbc, 0x01, 0x34, 0x5e, 0x8d, 0x17, 0xbb, 0xf8, 0x83, + 0x17, 0x89, 0xbe, 0xff, 0x74, 0xff, 0x2b, 0x9f, 0xdc, 0xef, 0x72, 0xb2, 0xdd, 0xe5, 0xe4, 0xe7, + 0x2e, 0x27, 0xdf, 0xf6, 0xf9, 0x64, 0xbb, 0xcf, 0x27, 0x3f, 0xf6, 0xf9, 0xe4, 0xf3, 0x3b, 0x6d, + 0xe2, 0xba, 0x5d, 0x16, 0xd2, 0xdb, 0x72, 0xdd, 0x35, 0x80, 0x35, 0x28, 0x0d, 0x78, 0x5d, 0x8b, + 0x65, 0x28, 0xbb, 0xd6, 0xfc, 0xff, 0x1f, 0x58, 0x1e, 0xa7, 0xcf, 0xf7, 0xe6, 0x77, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x2e, 0x04, 0xf2, 0x8c, 0x27, 0x02, 0x00, 0x00, } func (m *ChainConfig) Marshal() (dAtA []byte, err error) { @@ -157,6 +163,16 @@ func (m *ChainConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if m.MaxRetryForCommit != 0 { + i = encodeVarintConfig(dAtA, i, uint64(m.MaxRetryForCommit)) + i-- + dAtA[i] = 0x40 + } + if m.RetryIntervalMsec != 0 { + i = encodeVarintConfig(dAtA, i, uint64(m.RetryIntervalMsec)) + i-- + dAtA[i] = 0x38 + } if len(m.GasPrices) > 0 { i -= len(m.GasPrices) copy(dAtA[i:], m.GasPrices) @@ -271,6 +287,12 @@ func (m *ChainConfig) Size() (n int) { if l > 0 { n += 1 + l + sovConfig(uint64(l)) } + if m.RetryIntervalMsec != 0 { + n += 1 + sovConfig(uint64(m.RetryIntervalMsec)) + } + if m.MaxRetryForCommit != 0 { + n += 1 + sovConfig(uint64(m.MaxRetryForCommit)) + } return n } @@ -493,6 +515,44 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } m.GasPrices = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex + case 7: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field RetryIntervalMsec", wireType) + } + m.RetryIntervalMsec = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.RetryIntervalMsec |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 8: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field MaxRetryForCommit", wireType) + } + m.MaxRetryForCommit = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowConfig + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.MaxRetryForCommit |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipConfig(dAtA[iNdEx:]) diff --git a/go.mod b/go.mod index 568c955f..e57abbc8 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/hyperledger-labs/yui-relayer go 1.20 require ( + cosmossdk.io/errors v1.0.0-beta.7 github.com/avast/retry-go v3.0.0+incompatible github.com/cockroachdb/errors v1.9.1 github.com/cometbft/cometbft v0.37.2 @@ -33,7 +34,6 @@ require ( cosmossdk.io/api v0.3.1 // indirect cosmossdk.io/core v0.5.1 // indirect cosmossdk.io/depinject v1.0.0-alpha.3 // indirect - cosmossdk.io/errors v1.0.0-beta.7 // indirect cosmossdk.io/log v1.1.0 // indirect cosmossdk.io/math v1.0.1 // indirect cosmossdk.io/tools/rosetta v0.2.1 // indirect diff --git a/proto/relayer/chains/tendermint/config/config.proto b/proto/relayer/chains/tendermint/config/config.proto index 287a797c..3ed604da 100644 --- a/proto/relayer/chains/tendermint/config/config.proto +++ b/proto/relayer/chains/tendermint/config/config.proto @@ -13,6 +13,8 @@ message ChainConfig { string account_prefix = 4; double gas_adjustment = 5; string gas_prices = 6; + uint64 retry_interval_msec = 7; + uint64 max_retry_for_commit = 8; } message ProverConfig { diff --git a/tests/cases/tm2tm/configs/demo/ibc-0.json b/tests/cases/tm2tm/configs/demo/ibc-0.json index 141967b0..1b139a76 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-0.json +++ b/tests/cases/tm2tm/configs/demo/ibc-0.json @@ -6,7 +6,9 @@ "rpc_addr": "http://localhost:26657", "account_prefix": "cosmos", "gas_adjustment": 1.5, - "gas_prices": "0.025stake" + "gas_prices": "0.025stake", + "retry_interval_msec": 400, + "max_retry_for_commit": 25 }, "prover": { "@type": "/relayer.chains.tendermint.config.ProverConfig", diff --git a/tests/cases/tm2tm/configs/demo/ibc-1.json b/tests/cases/tm2tm/configs/demo/ibc-1.json index cf061755..e8f895ea 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-1.json +++ b/tests/cases/tm2tm/configs/demo/ibc-1.json @@ -6,7 +6,9 @@ "rpc_addr": "http://localhost:26557", "account_prefix": "cosmos", "gas_adjustment": 1.5, - "gas_prices": "0.025stake" + "gas_prices": "0.025stake", + "retry_interval_msec": 400, + "max_retry_for_commit": 25 }, "prover": { "@type": "/relayer.chains.tendermint.config.ProverConfig", diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json index 4bce9a83..013fc1be 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json @@ -6,7 +6,9 @@ "rpc_addr": "http://localhost:26657", "account_prefix": "cosmos", "gas_adjustment": 1.5, - "gas_prices": "0.025stake" + "gas_prices": "0.025stake", + "retry_interval_msec": 400, + "max_retry_for_commit": 25 }, "prover": { "@type": "/relayer.provers.mock.config.ProverConfig", diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json index 1b8b55eb..9751fe75 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json @@ -6,7 +6,9 @@ "rpc_addr": "http://localhost:26557", "account_prefix": "cosmos", "gas_adjustment": 1.5, - "gas_prices": "0.025stake" + "gas_prices": "0.025stake", + "retry_interval_msec": 400, + "max_retry_for_commit": 25 }, "prover": { "@type": "/relayer.provers.mock.config.ProverConfig", From 13174fc8ef4e103dff94f86886c40795b5899d6e Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Thu, 21 Sep 2023 18:01:13 +0900 Subject: [PATCH 11/15] add `Chain::CommitWaitTime` to the `Chain` interface Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 4 ++++ core/chain.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index d28c81dd..b926378a 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -163,6 +163,10 @@ func (c *Chain) Timestamp(height ibcexported.Height) (time.Time, error) { } } +func (c *Chain) CommitWaitTime() time.Duration { + return time.Duration(c.config.RetryIntervalMsec) * time.Millisecond * time.Duration(c.config.MaxRetryForCommit) +} + // RegisterMsgEventListener registers a given EventListener to the chain func (c *Chain) RegisterMsgEventListener(listener core.MsgEventListener) { c.msgEventListener = listener diff --git a/core/chain.go b/core/chain.go index 994b1bee..cb16c03b 100644 --- a/core/chain.go +++ b/core/chain.go @@ -105,6 +105,12 @@ type ChainInfo interface { // Timestamp returns the block timestamp Timestamp(ibcexported.Height) (time.Time, error) + + // CommitWaitTime returns enough time to wait for tx to be commited in a block + // + // NOTE: Basically this value is much longer than "average block time". + // For example, this value might be defined as 10 times the average block time. + CommitWaitTime() time.Duration } // MsgEventListener is a listener that listens a msg send to the chain From e56e42f87e27e27f493dc2af92f098a0089c7af2 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Thu, 21 Sep 2023 18:24:16 +0900 Subject: [PATCH 12/15] tendermint: give up to wait for tx to be committed if rawQueryTx returns an unrecoverable error Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index b926378a..b339fcf9 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "path" + "strings" "sync" "time" @@ -266,9 +267,14 @@ func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { if err := retry.Do(func() error { var err error - resTx, err = c.rawQueryTx(txHash) + var recoverable bool + resTx, recoverable, err = c.rawQueryTx(txHash) if err != nil { - return err + if recoverable { + return err + } else { + return retry.Unrecoverable(err) + } } return nil }, retry.Attempts(maxRetry), retry.Delay(retryInterval), rtyErr); err != nil { @@ -280,25 +286,26 @@ func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { // rawQueryTx returns a tx of which hash equals to `hexTxHash`. // If the RPC is successful but the tx is not found, this returns nil with nil error. -func (c *Chain) rawQueryTx(hexTxHash string) (*coretypes.ResultTx, error) { +func (c *Chain) rawQueryTx(hexTxHash string) (*coretypes.ResultTx, bool, error) { ctx := c.CLIContext(0) txHash, err := hex.DecodeString(hexTxHash) if err != nil { - return nil, fmt.Errorf("failed to decode the hex string of tx hash: %v", err) + return nil, false, fmt.Errorf("failed to decode the hex string of tx hash: %v", err) } node, err := ctx.GetNode() if err != nil { - return nil, fmt.Errorf("failed to get node: %v", err) + return nil, false, fmt.Errorf("failed to get node: %v", err) } resTx, err := node.Tx(context.TODO(), txHash, false) if err != nil { - return nil, fmt.Errorf("failed to retrieve tx: %v", err) + recoverable := !strings.Contains(err.Error(), "transaction indexing is disabled") + return nil, recoverable, fmt.Errorf("failed to retrieve tx: %v", err) } - return resTx, nil + return resTx, false, nil } func prepareFactory(clientCtx sdkCtx.Context, txf tx.Factory) (tx.Factory, error) { From 5718210e3196283206ec8e12108538176b8a0636 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Thu, 21 Sep 2023 18:35:26 +0900 Subject: [PATCH 13/15] add msgs to to the error log output in `SendCheckMsgs` Signed-off-by: Masanori Yoshida --- core/send.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/send.go b/core/send.go index e5523e9a..2658651d 100644 --- a/core/send.go +++ b/core/send.go @@ -11,7 +11,7 @@ import ( // SendCheckMsgs is an utility function that executes `Chain::SendMsgs` and checks the execution results of all the messages. func SendCheckMsgs(chain Chain, msgs []types.Msg) bool { if _, err := chain.SendMsgs(msgs); err != nil { - GetChainLogger(chain).Error("failed to send msgs", err) + GetChainLogger(chain).Error("failed to send msgs", err, "msgs", msgs) return false } return true From 7028cf5d3d7e3280d578d24b4878b7f916ab8f4f Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Fri, 22 Sep 2023 17:36:45 +0900 Subject: [PATCH 14/15] replace `Chain::CommitWaitTime` with `Chain::AverageBlockTime` and fix `GetFinalizedMsgResult` using this new function Signed-off-by: Masanori Yoshida --- chains/tendermint/chain.go | 6 +- chains/tendermint/config.pb.go | 83 ++++++++++--------- core/chain.go | 7 +- core/send.go | 14 +++- .../chains/tendermint/config/config.proto | 2 +- 5 files changed, 60 insertions(+), 52 deletions(-) diff --git a/chains/tendermint/chain.go b/chains/tendermint/chain.go index b339fcf9..63ddea70 100644 --- a/chains/tendermint/chain.go +++ b/chains/tendermint/chain.go @@ -164,8 +164,8 @@ func (c *Chain) Timestamp(height ibcexported.Height) (time.Time, error) { } } -func (c *Chain) CommitWaitTime() time.Duration { - return time.Duration(c.config.RetryIntervalMsec) * time.Millisecond * time.Duration(c.config.MaxRetryForCommit) +func (c *Chain) AverageBlockTime() time.Duration { + return time.Duration(c.config.AverageBlockTimeMsec) * time.Millisecond } // RegisterMsgEventListener registers a given EventListener to the chain @@ -262,7 +262,7 @@ func (c *Chain) rawSendMsgs(msgs []sdk.Msg) (*sdk.TxResponse, bool, error) { func (c *Chain) waitForCommit(txHash string) (*coretypes.ResultTx, error) { var resTx *coretypes.ResultTx - retryInterval := time.Duration(c.config.RetryIntervalMsec) * time.Millisecond + retryInterval := c.AverageBlockTime() maxRetry := uint(c.config.MaxRetryForCommit) if err := retry.Do(func() error { diff --git a/chains/tendermint/config.pb.go b/chains/tendermint/config.pb.go index 5b5230f7..a4aa9f33 100644 --- a/chains/tendermint/config.pb.go +++ b/chains/tendermint/config.pb.go @@ -25,14 +25,14 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type ChainConfig struct { - Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` - ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` - RpcAddr string `protobuf:"bytes,3,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` - AccountPrefix string `protobuf:"bytes,4,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` - GasAdjustment float64 `protobuf:"fixed64,5,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` - GasPrices string `protobuf:"bytes,6,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` - RetryIntervalMsec uint64 `protobuf:"varint,7,opt,name=retry_interval_msec,json=retryIntervalMsec,proto3" json:"retry_interval_msec,omitempty"` - MaxRetryForCommit uint64 `protobuf:"varint,8,opt,name=max_retry_for_commit,json=maxRetryForCommit,proto3" json:"max_retry_for_commit,omitempty"` + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + ChainId string `protobuf:"bytes,2,opt,name=chain_id,json=chainId,proto3" json:"chain_id,omitempty"` + RpcAddr string `protobuf:"bytes,3,opt,name=rpc_addr,json=rpcAddr,proto3" json:"rpc_addr,omitempty"` + AccountPrefix string `protobuf:"bytes,4,opt,name=account_prefix,json=accountPrefix,proto3" json:"account_prefix,omitempty"` + GasAdjustment float64 `protobuf:"fixed64,5,opt,name=gas_adjustment,json=gasAdjustment,proto3" json:"gas_adjustment,omitempty"` + GasPrices string `protobuf:"bytes,6,opt,name=gas_prices,json=gasPrices,proto3" json:"gas_prices,omitempty"` + AverageBlockTimeMsec uint64 `protobuf:"varint,7,opt,name=average_block_time_msec,json=averageBlockTimeMsec,proto3" json:"average_block_time_msec,omitempty"` + MaxRetryForCommit uint64 `protobuf:"varint,8,opt,name=max_retry_for_commit,json=maxRetryForCommit,proto3" json:"max_retry_for_commit,omitempty"` } func (m *ChainConfig) Reset() { *m = ChainConfig{} } @@ -115,32 +115,33 @@ func init() { } var fileDescriptor_d67cd47cbc86ecb1 = []byte{ - // 395 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xbf, 0x8e, 0xd4, 0x30, - 0x10, 0xc6, 0xd7, 0x77, 0xc7, 0xfd, 0x31, 0xdc, 0x01, 0xe1, 0x0a, 0x83, 0x44, 0xb4, 0x3a, 0x09, - 0xb1, 0xcd, 0x25, 0x05, 0x05, 0xa2, 0x3c, 0x56, 0x42, 0xba, 0x02, 0x69, 0x95, 0x06, 0x89, 0xc6, - 0xf2, 0xda, 0xb3, 0x5e, 0x43, 0x6c, 0x47, 0x63, 0xe7, 0xb4, 0x79, 0x0b, 0xde, 0x81, 0x97, 0xb9, - 0x72, 0x4b, 0x4a, 0xd8, 0x7d, 0x11, 0x14, 0x27, 0x40, 0x45, 0x95, 0xc9, 0xef, 0xfb, 0x7d, 0x53, - 0x4c, 0x42, 0xaf, 0x11, 0x6a, 0xd1, 0x01, 0x96, 0x72, 0x2d, 0x8c, 0x0b, 0x65, 0x04, 0xa7, 0x00, - 0xad, 0x71, 0xb1, 0x94, 0xde, 0xad, 0x8c, 0x1e, 0x1f, 0x45, 0x83, 0x3e, 0xfa, 0x6c, 0x3a, 0xea, - 0xc5, 0xa0, 0x17, 0xff, 0xf4, 0x62, 0xf0, 0x5e, 0x5c, 0x6a, 0xaf, 0x7d, 0x92, 0xcb, 0x7e, 0x1a, - 0x7a, 0x57, 0xdf, 0x0f, 0xe8, 0xc3, 0x79, 0x5f, 0x99, 0x27, 0x2b, 0x7b, 0x42, 0x0f, 0xbf, 0x42, - 0xc7, 0xc8, 0x94, 0xcc, 0xce, 0xaa, 0x7e, 0xcc, 0x9e, 0xd3, 0xd3, 0xb4, 0x93, 0x1b, 0xc5, 0x0e, - 0x12, 0x3e, 0x49, 0xef, 0xb7, 0xaa, 0x8f, 0xb0, 0x91, 0x5c, 0x28, 0x85, 0xec, 0x70, 0x88, 0xb0, - 0x91, 0x37, 0x4a, 0x61, 0xf6, 0x8a, 0x5e, 0x08, 0x29, 0x7d, 0xeb, 0x22, 0x6f, 0x10, 0x56, 0x66, - 0xc3, 0x8e, 0x92, 0x70, 0x3e, 0xd2, 0x45, 0x82, 0xbd, 0xa6, 0x45, 0xe0, 0x42, 0x7d, 0x69, 0x43, - 0xb4, 0xe0, 0x22, 0x7b, 0x30, 0x25, 0x33, 0x52, 0x9d, 0x6b, 0x11, 0x6e, 0xfe, 0xc2, 0xec, 0x25, - 0xa5, 0xbd, 0xd6, 0xa0, 0x91, 0x10, 0xd8, 0x71, 0xda, 0x74, 0xa6, 0x45, 0x58, 0x24, 0x90, 0x15, - 0xf4, 0x19, 0x42, 0xc4, 0x8e, 0x1b, 0x17, 0x01, 0xef, 0x44, 0xcd, 0x6d, 0x00, 0xc9, 0x4e, 0xa6, - 0x64, 0x76, 0x54, 0x3d, 0x4d, 0xd1, 0xed, 0x98, 0x7c, 0x0c, 0x20, 0xb3, 0x92, 0x5e, 0x5a, 0xb1, - 0xe1, 0x43, 0x67, 0xe5, 0x91, 0x4b, 0x6f, 0xad, 0x89, 0xec, 0x74, 0x28, 0x58, 0xb1, 0xa9, 0xfa, - 0xe8, 0x83, 0xc7, 0x79, 0x0a, 0xae, 0xde, 0xd2, 0x47, 0x0b, 0xf4, 0x77, 0x80, 0xe3, 0x95, 0x5e, - 0xd3, 0xc7, 0x11, 0xdb, 0x10, 0x8d, 0xd3, 0xbc, 0x01, 0x34, 0x5e, 0x8d, 0x17, 0xbb, 0xf8, 0x83, - 0x17, 0x89, 0xbe, 0xff, 0x74, 0xff, 0x2b, 0x9f, 0xdc, 0xef, 0x72, 0xb2, 0xdd, 0xe5, 0xe4, 0xe7, - 0x2e, 0x27, 0xdf, 0xf6, 0xf9, 0x64, 0xbb, 0xcf, 0x27, 0x3f, 0xf6, 0xf9, 0xe4, 0xf3, 0x3b, 0x6d, - 0xe2, 0xba, 0x5d, 0x16, 0xd2, 0xdb, 0x72, 0xdd, 0x35, 0x80, 0x35, 0x28, 0x0d, 0x78, 0x5d, 0x8b, - 0x65, 0x28, 0xbb, 0xd6, 0xfc, 0xff, 0x1f, 0x58, 0x1e, 0xa7, 0xcf, 0xf7, 0xe6, 0x77, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x2e, 0x04, 0xf2, 0x8c, 0x27, 0x02, 0x00, 0x00, + // 404 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x74, 0x92, 0xcf, 0x8a, 0x14, 0x31, + 0x10, 0x87, 0x27, 0xbb, 0xeb, 0xfe, 0x89, 0xee, 0xaa, 0xcd, 0x80, 0x51, 0xb0, 0x19, 0x16, 0xc4, + 0xb9, 0x6c, 0xf7, 0x41, 0x44, 0x3c, 0xee, 0x0e, 0x08, 0x1e, 0x84, 0x61, 0x10, 0x04, 0x2f, 0x21, + 0x93, 0xd4, 0x64, 0xe2, 0x76, 0x3a, 0x4d, 0x25, 0xbd, 0x4c, 0xbf, 0x85, 0xcf, 0xe1, 0x93, 0xec, + 0x71, 0x8f, 0x1e, 0x75, 0xe6, 0x45, 0x24, 0xe9, 0x56, 0x4f, 0x7b, 0x4a, 0xe5, 0xfb, 0x7d, 0x55, + 0x87, 0x4a, 0xe8, 0x05, 0x42, 0x25, 0x3a, 0xc0, 0x52, 0xae, 0x85, 0xa9, 0x7d, 0x19, 0xa0, 0x56, + 0x80, 0xd6, 0xd4, 0xa1, 0x94, 0xae, 0x5e, 0x19, 0x3d, 0x1c, 0x45, 0x83, 0x2e, 0xb8, 0x6c, 0x32, + 0xe8, 0x45, 0xaf, 0x17, 0xff, 0xf5, 0xa2, 0xf7, 0x5e, 0x8c, 0xb5, 0xd3, 0x2e, 0xc9, 0x65, 0xac, + 0xfa, 0xbe, 0xf3, 0x1f, 0x7b, 0xf4, 0xe1, 0x2c, 0xb6, 0xcc, 0x92, 0x95, 0x3d, 0xa1, 0xfb, 0xd7, + 0xd0, 0x31, 0x32, 0x21, 0xd3, 0x93, 0x45, 0x2c, 0xb3, 0xe7, 0xf4, 0x38, 0xcd, 0xe4, 0x46, 0xb1, + 0xbd, 0x84, 0x8f, 0xd2, 0xfd, 0xa3, 0x8a, 0x11, 0x36, 0x92, 0x0b, 0xa5, 0x90, 0xed, 0xf7, 0x11, + 0x36, 0xf2, 0x52, 0x29, 0xcc, 0x5e, 0xd1, 0x33, 0x21, 0xa5, 0x6b, 0xeb, 0xc0, 0x1b, 0x84, 0x95, + 0xd9, 0xb0, 0x83, 0x24, 0x9c, 0x0e, 0x74, 0x9e, 0x60, 0xd4, 0xb4, 0xf0, 0x5c, 0xa8, 0x6f, 0xad, + 0x0f, 0x16, 0xea, 0xc0, 0x1e, 0x4c, 0xc8, 0x94, 0x2c, 0x4e, 0xb5, 0xf0, 0x97, 0xff, 0x60, 0xf6, + 0x92, 0xd2, 0xa8, 0x35, 0x68, 0x24, 0x78, 0x76, 0x98, 0x26, 0x9d, 0x68, 0xe1, 0xe7, 0x09, 0x64, + 0x6f, 0xe9, 0x33, 0x71, 0x03, 0x28, 0x34, 0xf0, 0x65, 0xe5, 0xe4, 0x35, 0x0f, 0xc6, 0x02, 0xb7, + 0x1e, 0x24, 0x3b, 0x9a, 0x90, 0xe9, 0xc1, 0x62, 0x3c, 0xc4, 0x57, 0x31, 0xfd, 0x6c, 0x2c, 0x7c, + 0xf2, 0x20, 0xb3, 0x92, 0x8e, 0xad, 0xd8, 0x70, 0x84, 0x80, 0x1d, 0x5f, 0x39, 0xe4, 0xd2, 0x59, + 0x6b, 0x02, 0x3b, 0x4e, 0x3d, 0x4f, 0xad, 0xd8, 0x2c, 0x62, 0xf4, 0xc1, 0xe1, 0x2c, 0x05, 0xe7, + 0xef, 0xe8, 0xa3, 0x39, 0xba, 0x1b, 0xc0, 0x61, 0x59, 0xaf, 0xe9, 0xe3, 0x80, 0xad, 0x0f, 0xa6, + 0xd6, 0xbc, 0x01, 0x34, 0x4e, 0x0d, 0x8b, 0x3b, 0xfb, 0x8b, 0xe7, 0x89, 0x5e, 0x7d, 0xb9, 0xfd, + 0x9d, 0x8f, 0x6e, 0xb7, 0x39, 0xb9, 0xdb, 0xe6, 0xe4, 0xd7, 0x36, 0x27, 0xdf, 0x77, 0xf9, 0xe8, + 0x6e, 0x97, 0x8f, 0x7e, 0xee, 0xf2, 0xd1, 0xd7, 0xf7, 0xda, 0x84, 0x75, 0xbb, 0x2c, 0xa4, 0xb3, + 0xe5, 0xba, 0x6b, 0x00, 0x2b, 0x50, 0x1a, 0xf0, 0xa2, 0x12, 0x4b, 0x5f, 0x76, 0xad, 0xb9, 0xff, + 0x2b, 0x2c, 0x0f, 0xd3, 0x2b, 0xbe, 0xf9, 0x13, 0x00, 0x00, 0xff, 0xff, 0x71, 0x84, 0x9b, 0xb4, + 0x2e, 0x02, 0x00, 0x00, } func (m *ChainConfig) Marshal() (dAtA []byte, err error) { @@ -168,8 +169,8 @@ func (m *ChainConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x40 } - if m.RetryIntervalMsec != 0 { - i = encodeVarintConfig(dAtA, i, uint64(m.RetryIntervalMsec)) + if m.AverageBlockTimeMsec != 0 { + i = encodeVarintConfig(dAtA, i, uint64(m.AverageBlockTimeMsec)) i-- dAtA[i] = 0x38 } @@ -287,8 +288,8 @@ func (m *ChainConfig) Size() (n int) { if l > 0 { n += 1 + l + sovConfig(uint64(l)) } - if m.RetryIntervalMsec != 0 { - n += 1 + sovConfig(uint64(m.RetryIntervalMsec)) + if m.AverageBlockTimeMsec != 0 { + n += 1 + sovConfig(uint64(m.AverageBlockTimeMsec)) } if m.MaxRetryForCommit != 0 { n += 1 + sovConfig(uint64(m.MaxRetryForCommit)) @@ -517,9 +518,9 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 7: if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field RetryIntervalMsec", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field AverageBlockTimeMsec", wireType) } - m.RetryIntervalMsec = 0 + m.AverageBlockTimeMsec = 0 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowConfig @@ -529,7 +530,7 @@ func (m *ChainConfig) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.RetryIntervalMsec |= uint64(b&0x7F) << shift + m.AverageBlockTimeMsec |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/core/chain.go b/core/chain.go index cb16c03b..31506580 100644 --- a/core/chain.go +++ b/core/chain.go @@ -106,11 +106,8 @@ type ChainInfo interface { // Timestamp returns the block timestamp Timestamp(ibcexported.Height) (time.Time, error) - // CommitWaitTime returns enough time to wait for tx to be commited in a block - // - // NOTE: Basically this value is much longer than "average block time". - // For example, this value might be defined as 10 times the average block time. - CommitWaitTime() time.Duration + // AverageBlockTime returns the average time required for each new block to be committed + AverageBlockTime() time.Duration } // MsgEventListener is a listener that listens a msg send to the chain diff --git a/core/send.go b/core/send.go index 2658651d..06ccd67a 100644 --- a/core/send.go +++ b/core/send.go @@ -18,9 +18,11 @@ func SendCheckMsgs(chain Chain, msgs []types.Msg) bool { } // GetFinalizedMsgResult is an utility function that waits for the finalization of the message execution and then returns the result. -func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID, retryInterval time.Duration, maxRetry uint) (MsgResult, error) { +func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID) (MsgResult, error) { var msgRes MsgResult + avgBlockTime := chain.AverageBlockTime() + if err := retry.Do(func() error { // query LFH for each retry because it can proceed. lfHeader, err := chain.GetLatestFinalizedHeader() @@ -38,11 +40,19 @@ func GetFinalizedMsgResult(chain ProvableChain, msgID MsgID, retryInterval time. // check whether the block that includes the message has been finalized, or not if msgHeight, lfHeight := msgRes.BlockHeight(), lfHeader.GetHeight(); msgHeight.GT(lfHeight) { + // wait for the block including the msg to be finalized + var waitTime time.Duration + if msgHeight.GetRevisionNumber() != lfHeight.GetRevisionNumber() { + waitTime = avgBlockTime //TODO: is there better default value? + } else { + waitTime = avgBlockTime * time.Duration(msgHeight.GetRevisionHeight()-lfHeight.GetRevisionHeight()) + } + time.Sleep(waitTime) return fmt.Errorf("msg(id=%v) not finalied: msg.height(%v) > lfh.height(%v)", msgID, msgHeight, lfHeight) } return nil - }, retry.Attempts(maxRetry), retry.Delay(retryInterval), rtyErr); err != nil { + }, rtyAtt, rtyDel, rtyErr); err != nil { return nil, err } diff --git a/proto/relayer/chains/tendermint/config/config.proto b/proto/relayer/chains/tendermint/config/config.proto index 3ed604da..ee22b793 100644 --- a/proto/relayer/chains/tendermint/config/config.proto +++ b/proto/relayer/chains/tendermint/config/config.proto @@ -13,7 +13,7 @@ message ChainConfig { string account_prefix = 4; double gas_adjustment = 5; string gas_prices = 6; - uint64 retry_interval_msec = 7; + uint64 average_block_time_msec = 7; uint64 max_retry_for_commit = 8; } From 690c60ec6e9324bbe8c70192090b0f87a548f5e4 Mon Sep 17 00:00:00 2001 From: Masanori Yoshida Date: Fri, 22 Sep 2023 17:42:13 +0900 Subject: [PATCH 15/15] fix test case configs Signed-off-by: Masanori Yoshida --- tests/cases/tm2tm/configs/demo/ibc-0.json | 4 ++-- tests/cases/tm2tm/configs/demo/ibc-1.json | 4 ++-- tests/cases/tmmock2tmmock/configs/demo/ibc-0.json | 4 ++-- tests/cases/tmmock2tmmock/configs/demo/ibc-1.json | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/cases/tm2tm/configs/demo/ibc-0.json b/tests/cases/tm2tm/configs/demo/ibc-0.json index 1b139a76..e9058559 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-0.json +++ b/tests/cases/tm2tm/configs/demo/ibc-0.json @@ -7,8 +7,8 @@ "account_prefix": "cosmos", "gas_adjustment": 1.5, "gas_prices": "0.025stake", - "retry_interval_msec": 400, - "max_retry_for_commit": 25 + "average_block_time_msec": 1000, + "max_retry_for_commit": 5 }, "prover": { "@type": "/relayer.chains.tendermint.config.ProverConfig", diff --git a/tests/cases/tm2tm/configs/demo/ibc-1.json b/tests/cases/tm2tm/configs/demo/ibc-1.json index e8f895ea..b072ec76 100644 --- a/tests/cases/tm2tm/configs/demo/ibc-1.json +++ b/tests/cases/tm2tm/configs/demo/ibc-1.json @@ -7,8 +7,8 @@ "account_prefix": "cosmos", "gas_adjustment": 1.5, "gas_prices": "0.025stake", - "retry_interval_msec": 400, - "max_retry_for_commit": 25 + "average_block_time_msec": 1000, + "max_retry_for_commit": 5 }, "prover": { "@type": "/relayer.chains.tendermint.config.ProverConfig", diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json index 013fc1be..123ff9e8 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-0.json @@ -7,8 +7,8 @@ "account_prefix": "cosmos", "gas_adjustment": 1.5, "gas_prices": "0.025stake", - "retry_interval_msec": 400, - "max_retry_for_commit": 25 + "average_block_time_msec": 1000, + "max_retry_for_commit": 5 }, "prover": { "@type": "/relayer.provers.mock.config.ProverConfig", diff --git a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json index 9751fe75..7ca744da 100644 --- a/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json +++ b/tests/cases/tmmock2tmmock/configs/demo/ibc-1.json @@ -7,8 +7,8 @@ "account_prefix": "cosmos", "gas_adjustment": 1.5, "gas_prices": "0.025stake", - "retry_interval_msec": 400, - "max_retry_for_commit": 25 + "average_block_time_msec": 1000, + "max_retry_for_commit": 5 }, "prover": { "@type": "/relayer.provers.mock.config.ProverConfig",