-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
relayer_packets.go
232 lines (200 loc) · 6.19 KB
/
relayer_packets.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
package penumbra
import (
"context"
"fmt"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
"github.com/cosmos/relayer/v2/relayer/provider"
)
var (
_ provider.RelayPacket = relayMsgTimeout{}
_ provider.RelayPacket = relayMsgRecvPacket{}
_ provider.RelayPacket = relayMsgPacketAck{}
)
type relayMsgTimeout struct {
packetData []byte
seq uint64
timeout clienttypes.Height
timeoutStamp uint64
dstRecvRes *chantypes.QueryPacketReceiptResponse
pass bool
}
func (rp relayMsgTimeout) Data() []byte {
return rp.packetData
}
func (rp relayMsgTimeout) Seq() uint64 {
return rp.seq
}
func (rp relayMsgTimeout) Timeout() clienttypes.Height {
return rp.timeout
}
func (rp relayMsgTimeout) TimeoutStamp() uint64 {
return rp.timeoutStamp
}
func (rp relayMsgTimeout) FetchCommitResponse(ctx context.Context, dst provider.ChainProvider, queryHeight uint64, dstChanId, dstPortId string) error {
dstRecvRes, err := dst.QueryPacketReceipt(ctx, int64(queryHeight)-1, dstChanId, dstPortId, rp.seq)
switch {
case err != nil:
return err
case dstRecvRes.Proof == nil:
return fmt.Errorf("timeout packet receipt proof seq(%d) is nil", rp.seq)
default:
rp.dstRecvRes = dstRecvRes
return nil
}
}
func (rp relayMsgTimeout) Msg(src provider.ChainProvider, srcPortId, srcChanId, dstPortId, dstChanId string) (provider.RelayerMessage, error) {
if rp.dstRecvRes == nil {
return nil, fmt.Errorf("timeout packet [%s]seq{%d} has no associated proofs", src.ChainId(), rp.seq)
}
addr, err := src.Address()
if err != nil {
return nil, err
}
msg := &chantypes.MsgTimeout{
Packet: chantypes.Packet{
Sequence: rp.seq,
SourcePort: srcPortId,
SourceChannel: srcChanId,
DestinationPort: dstPortId,
DestinationChannel: dstChanId,
Data: rp.packetData,
TimeoutHeight: rp.timeout,
TimeoutTimestamp: rp.timeoutStamp,
},
ProofUnreceived: rp.dstRecvRes.Proof,
ProofHeight: rp.dstRecvRes.ProofHeight,
NextSequenceRecv: rp.seq,
Signer: addr,
}
return NewPenumbraMessage(msg), nil
}
type relayMsgRecvPacket struct {
packetData []byte
seq uint64
timeout clienttypes.Height
timeoutStamp uint64
dstComRes *chantypes.QueryPacketCommitmentResponse
}
func (rp relayMsgRecvPacket) timeoutPacket() *relayMsgTimeout {
return &relayMsgTimeout{
packetData: rp.packetData,
seq: rp.seq,
timeout: rp.timeout,
timeoutStamp: rp.timeoutStamp,
dstRecvRes: nil,
pass: false,
}
}
func (rp relayMsgRecvPacket) Data() []byte {
return rp.packetData
}
func (rp relayMsgRecvPacket) Seq() uint64 {
return rp.seq
}
func (rp relayMsgRecvPacket) Timeout() clienttypes.Height {
return rp.timeout
}
func (rp relayMsgRecvPacket) TimeoutStamp() uint64 {
return rp.timeoutStamp
}
func (rp relayMsgRecvPacket) FetchCommitResponse(ctx context.Context, dst provider.ChainProvider, queryHeight uint64, dstChanId, dstPortId string) error {
dstCommitRes, err := dst.QueryPacketCommitment(ctx, int64(queryHeight)-1, dstChanId, dstPortId, rp.seq)
switch {
case err != nil:
return err
case dstCommitRes.Proof == nil:
return fmt.Errorf("recv packet commitment proof seq(%d) is nil", rp.seq)
case dstCommitRes.Commitment == nil:
return fmt.Errorf("recv packet commitment query seq(%d) is nil", rp.seq)
default:
rp.dstComRes = dstCommitRes
return nil
}
}
func (rp relayMsgRecvPacket) Msg(src provider.ChainProvider, srcPortId, srcChanId, dstPortId, dstChanId string) (provider.RelayerMessage, error) {
if rp.dstComRes == nil {
return nil, fmt.Errorf("receive packet [%s]seq{%d} has no associated proofs", src.ChainId(), rp.seq)
}
addr, err := src.Address()
if err != nil {
return nil, err
}
msg := &chantypes.MsgRecvPacket{
Packet: chantypes.Packet{
Sequence: rp.seq,
SourcePort: dstPortId,
SourceChannel: dstChanId,
DestinationPort: srcPortId,
DestinationChannel: srcChanId,
Data: rp.packetData,
TimeoutHeight: rp.timeout,
TimeoutTimestamp: rp.timeoutStamp,
},
ProofCommitment: rp.dstComRes.Proof,
ProofHeight: rp.dstComRes.ProofHeight,
Signer: addr,
}
return NewPenumbraMessage(msg), nil
}
type relayMsgPacketAck struct {
packetData []byte
ack []byte
seq uint64
timeout clienttypes.Height
timeoutStamp uint64
dstComRes *chantypes.QueryPacketAcknowledgementResponse
pass bool
}
func (rp relayMsgPacketAck) Data() []byte {
return rp.packetData
}
func (rp relayMsgPacketAck) Seq() uint64 {
return rp.seq
}
func (rp relayMsgPacketAck) Timeout() clienttypes.Height {
return rp.timeout
}
func (rp relayMsgPacketAck) TimeoutStamp() uint64 {
return rp.timeoutStamp
}
func (rp relayMsgPacketAck) Msg(src provider.ChainProvider, srcPortId, srcChanId, dstPortId, dstChanId string) (provider.RelayerMessage, error) {
if rp.dstComRes == nil {
return nil, fmt.Errorf("ack packet [%s]seq{%d} has no associated proofs", src.ChainId(), rp.seq)
}
addr, err := src.Address()
if err != nil {
return nil, err
}
msg := &chantypes.MsgAcknowledgement{
Packet: chantypes.Packet{
Sequence: rp.seq,
SourcePort: srcPortId,
SourceChannel: srcChanId,
DestinationPort: dstPortId,
DestinationChannel: dstChanId,
Data: rp.packetData,
TimeoutHeight: rp.timeout,
TimeoutTimestamp: rp.timeoutStamp,
},
Acknowledgement: rp.ack,
ProofAcked: rp.dstComRes.Proof,
ProofHeight: rp.dstComRes.ProofHeight,
Signer: addr,
}
return NewPenumbraMessage(msg), nil
}
func (rp relayMsgPacketAck) FetchCommitResponse(ctx context.Context, dst provider.ChainProvider, queryHeight uint64, dstChanId, dstPortId string) error {
dstCommitRes, err := dst.QueryPacketAcknowledgement(ctx, int64(queryHeight)-1, dstChanId, dstPortId, rp.seq)
switch {
case err != nil:
return err
case dstCommitRes.Proof == nil:
return fmt.Errorf("ack packet acknowledgement proof seq(%d) is nil", rp.seq)
case dstCommitRes.Acknowledgement == nil:
return fmt.Errorf("ack packet acknowledgement query seq(%d) is nil", rp.seq)
default:
rp.dstComRes = dstCommitRes
return nil
}
}