-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
message_handlers.go
104 lines (96 loc) · 3.98 KB
/
message_handlers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package mock
import (
"fmt"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/cosmos/relayer/v2/relayer/processor"
"github.com/cosmos/relayer/v2/relayer/provider"
"go.uber.org/zap"
)
type msgHandlerParams struct {
mcp *MockChainProcessor
height int64
packetInfo *chantypes.Packet
ibcMessagesCache processor.IBCMessagesCache
}
var messageHandlers = map[string]func(msgHandlerParams){
chantypes.EventTypeSendPacket: handleMsgTransfer,
chantypes.EventTypeRecvPacket: handleMsgRecvPacket,
chantypes.EventTypeAcknowledgePacket: handleMsgAcknowledgement,
// TODO handlers for packet timeout, client, channel, and connection messages
}
func handleMsgTransfer(p msgHandlerParams) {
channelKey := processor.ChannelKey{
ChannelID: p.packetInfo.SourceChannel,
PortID: p.packetInfo.SourcePort,
CounterpartyChannelID: p.packetInfo.DestinationChannel,
CounterpartyPortID: p.packetInfo.DestinationPort,
}
p.ibcMessagesCache.PacketFlow.Retain(channelKey, chantypes.EventTypeSendPacket, provider.PacketInfo{
Height: uint64(p.height),
Sequence: p.packetInfo.Sequence,
Data: p.packetInfo.Data,
TimeoutHeight: p.packetInfo.TimeoutHeight,
SourcePort: p.packetInfo.SourcePort,
SourceChannel: p.packetInfo.SourceChannel,
DestPort: p.packetInfo.DestinationPort,
DestChannel: p.packetInfo.DestinationChannel,
})
p.mcp.log.Debug("observed MsgTransfer",
zap.String("chain_id", p.mcp.chainID),
zap.Uint64("sequence", p.packetInfo.Sequence),
zap.String("src_channel", p.packetInfo.SourceChannel),
zap.String("src_port", p.packetInfo.SourcePort),
zap.String("timeout_height", fmt.Sprintf("%d-%d", p.packetInfo.TimeoutHeight.RevisionNumber, p.packetInfo.TimeoutHeight.RevisionHeight)),
zap.Uint64("timeout_timestamp", p.packetInfo.TimeoutTimestamp),
)
}
func handleMsgRecvPacket(p msgHandlerParams) {
channelKey := processor.ChannelKey{
ChannelID: p.packetInfo.DestinationChannel,
PortID: p.packetInfo.DestinationPort,
CounterpartyChannelID: p.packetInfo.SourceChannel,
CounterpartyPortID: p.packetInfo.SourcePort,
}
p.ibcMessagesCache.PacketFlow.Retain(channelKey, chantypes.EventTypeRecvPacket, provider.PacketInfo{
Height: uint64(p.height),
Sequence: p.packetInfo.Sequence,
Data: p.packetInfo.Data,
SourcePort: p.packetInfo.SourcePort,
SourceChannel: p.packetInfo.SourceChannel,
DestPort: p.packetInfo.DestinationPort,
DestChannel: p.packetInfo.DestinationChannel,
})
p.mcp.log.Debug("observed MsgRecvPacket",
zap.String("chain_id", p.mcp.chainID),
zap.Uint64("sequence", p.packetInfo.Sequence),
zap.String("src_channel", p.packetInfo.SourceChannel),
zap.String("src_port", p.packetInfo.SourcePort),
zap.String("dst_channel", p.packetInfo.DestinationChannel),
zap.String("dst_port", p.packetInfo.DestinationPort),
)
}
func handleMsgAcknowledgement(p msgHandlerParams) {
channelKey := processor.ChannelKey{
ChannelID: p.packetInfo.SourceChannel,
PortID: p.packetInfo.SourcePort,
CounterpartyChannelID: p.packetInfo.DestinationChannel,
CounterpartyPortID: p.packetInfo.DestinationPort,
}
p.ibcMessagesCache.PacketFlow.Retain(channelKey, chantypes.EventTypeAcknowledgePacket, provider.PacketInfo{
Height: uint64(p.height),
Sequence: p.packetInfo.Sequence,
Data: p.packetInfo.Data,
SourcePort: p.packetInfo.SourcePort,
SourceChannel: p.packetInfo.SourceChannel,
DestPort: p.packetInfo.DestinationPort,
DestChannel: p.packetInfo.DestinationChannel,
})
p.mcp.log.Debug("observed MsgAcknowledgement",
zap.String("chain_id", p.mcp.chainID),
zap.Uint64("sequence", p.packetInfo.Sequence),
zap.String("src_channel", p.packetInfo.SourceChannel),
zap.String("src_port", p.packetInfo.SourcePort),
zap.String("dst_channel", p.packetInfo.DestinationChannel),
zap.String("dst_port", p.packetInfo.DestinationPort),
)
}