/
provider.go
576 lines (466 loc) · 24.1 KB
/
provider.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
package provider
import (
"context"
"fmt"
"time"
"github.com/cometbft/cometbft/proto/tendermint/crypto"
"github.com/cometbft/cometbft/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/gogoproto/proto"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types"
conntypes "github.com/cosmos/ibc-go/v8/modules/core/03-connection/types"
chantypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types"
ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported"
tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
type BroadcastMode string
const (
BroadcastModeSingle BroadcastMode = "single"
BroadcastModeBatch BroadcastMode = "batch"
)
type ProviderConfig interface {
NewProvider(log *zap.Logger, homepath string, debug bool, chainName string) (ChainProvider, error)
Validate() error
BroadcastMode() BroadcastMode
}
type RelayerMessage interface {
Type() string
MsgBytes() ([]byte, error)
}
type RelayerTxResponse struct {
Height int64
TxHash string
Codespace string
Code uint32
Data string
Events []RelayerEvent
}
type RelayerEvent struct {
EventType string
Attributes map[string]string
}
type LatestBlock struct {
Height uint64
Time time.Time
}
type IBCHeader interface {
Height() uint64
ConsensusState() ibcexported.ConsensusState
NextValidatorsHash() []byte
}
// ClientState holds the current state of a client from a single chain's perspective
type ClientState struct {
ClientID string
ConsensusHeight clienttypes.Height
TrustingPeriod time.Duration
ConsensusTime time.Time
Header []byte
}
// ClientTrustedState holds the current state of a client from the perspective of both involved chains,
// i.e. ClientState enriched with the trusted IBC header of the counterparty chain.
type ClientTrustedState struct {
ClientState ClientState
IBCHeader IBCHeader
}
// PacketInfo contains any relevant properties from packet flow messages
// which may be necessary to construct the next message in the packet flow.
type PacketInfo struct {
Height uint64
Sequence uint64
SourcePort string
SourceChannel string
DestPort string
DestChannel string
ChannelOrder string
Data []byte
TimeoutHeight clienttypes.Height
TimeoutTimestamp uint64
Ack []byte
}
func (pi PacketInfo) Packet() chantypes.Packet {
return chantypes.Packet{
Sequence: pi.Sequence,
SourcePort: pi.SourcePort,
SourceChannel: pi.SourceChannel,
DestinationPort: pi.DestPort,
DestinationChannel: pi.DestChannel,
Data: pi.Data,
TimeoutHeight: pi.TimeoutHeight,
TimeoutTimestamp: pi.TimeoutTimestamp,
}
}
// ConnectionInfo contains relevant properties from connection handshake messages
// which may be necessary to construct the next message for the counterparty chain.
type ConnectionInfo struct {
Height uint64
ConnID string
ClientID string
CounterpartyClientID string
CounterpartyConnID string
CounterpartyCommitmentPrefix commitmenttypes.MerklePrefix
}
// ChannelInfo contains relevant properties from channel handshake messages
// which may be necessary to construct the next message for the counterparty chain.
type ChannelInfo struct {
Height uint64
PortID string
ChannelID string
CounterpartyPortID string
CounterpartyChannelID string
ConnID string
// CounterpartyConnID doesn't come from any events, but is needed for
// MsgChannelOpenTry, so should be added manually for MsgChannelOpenInit.
CounterpartyConnID string
Order chantypes.Order
Version string
}
// ClientICQQueryID string wrapper for query ID.
type ClientICQQueryID string
// ClientICQInfo contains relevant properties from client ICQ messages.
// Client ICQ implementation does not use IBC connections and channels.
type ClientICQInfo struct {
Source string
Connection string
Chain string
QueryID ClientICQQueryID
Type string
Request []byte
Height uint64
}
// PacketProof includes all of the proof parameters needed for packet flows.
type PacketProof struct {
Proof []byte
ProofHeight clienttypes.Height
}
// ConnectionProof includes all of the proof parameters needed for the connection handshake.
type ConnectionProof struct {
ConsensusStateProof []byte
ConnectionStateProof []byte
ClientStateProof []byte
ProofHeight clienttypes.Height
ClientState ibcexported.ClientState
}
type ChannelProof struct {
Proof []byte
ProofHeight clienttypes.Height
Ordering chantypes.Order
Version string
}
type ICQProof struct {
Result []byte
ProofOps *crypto.ProofOps // TODO swap out tendermint type for third party chains.
Height int64
}
// loggableEvents is an unexported wrapper type for a slice of RelayerEvent,
// to satisfy the zapcore.ArrayMarshaler interface.
type loggableEvents []RelayerEvent
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
func (e RelayerEvent) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddString("event_type", e.EventType)
for k, v := range e.Attributes {
enc.AddString("event_attr: "+k, v)
}
return nil
}
// MarshalLogArray satisfies the zapcore.ArrayMarshaler interface.
func (es loggableEvents) MarshalLogArray(enc zapcore.ArrayEncoder) error {
for _, e := range es {
enc.AppendObject(e)
}
return nil
}
// MarshalLogObject satisfies the zapcore.ObjectMarshaler interface.
func (r RelayerTxResponse) MarshalLogObject(enc zapcore.ObjectEncoder) error {
enc.AddInt64("height", r.Height)
enc.AddString("tx_hash", r.TxHash)
enc.AddString("codespace", r.Codespace)
enc.AddUint32("code", r.Code)
enc.AddString("data", r.Data)
enc.AddArray("events", loggableEvents(r.Events))
return nil
}
type KeyProvider interface {
CreateKeystore(path string) error
KeystoreCreated(path string) bool
AddKey(name string, coinType uint32, signingAlgorithm string) (output *KeyOutput, err error)
UseKey(key string) error
RestoreKey(name, mnemonic string, coinType uint32, signingAlgorithm string) (address string, err error)
ShowAddress(name string) (address string, err error)
ListAddresses() (map[string]string, error)
DeleteKey(name string) error
KeyExists(name string) bool
ExportPrivKeyArmor(keyName string) (armor string, err error)
}
type ChainProvider interface {
QueryProvider
KeyProvider
Init(ctx context.Context) error
// [Begin] Client IBC message assembly functions
NewClientState(dstChainID string, dstIBCHeader IBCHeader, dstTrustingPeriod, dstUbdPeriod, maxClockDrift time.Duration, allowUpdateAfterExpiry, allowUpdateAfterMisbehaviour bool) (ibcexported.ClientState, error)
MsgCreateClient(clientState ibcexported.ClientState, consensusState ibcexported.ConsensusState) (RelayerMessage, error)
MsgUpgradeClient(srcClientId string, consRes *clienttypes.QueryConsensusStateResponse, clientRes *clienttypes.QueryClientStateResponse) (RelayerMessage, error)
MsgSubmitMisbehaviour(clientID string, misbehaviour ibcexported.ClientMessage) (RelayerMessage, error)
// [End] Client IBC message assembly functions
// ValidatePacket makes sure packet is valid to be relayed.
// It should return TimeoutHeightError, TimeoutTimestampError, or TimeoutOnCloseError
// for packet timeout scenarios so that timeout message can be written to other chain.
ValidatePacket(msgTransfer PacketInfo, latestBlock LatestBlock) error
// [Begin] Packet flow IBC message assembly functions
// These functions query the proof of the packet state on the chain.
// PacketCommitment queries for proof that a MsgTransfer has been committed on the chain.
PacketCommitment(ctx context.Context, msgTransfer PacketInfo, height uint64) (PacketProof, error)
// PacketAcknowledgement queries for proof that a MsgRecvPacket has been committed on the chain.
PacketAcknowledgement(ctx context.Context, msgRecvPacket PacketInfo, height uint64) (PacketProof, error)
// PacketReceipt queries for proof that a MsgRecvPacket has not been committed to the chain.
PacketReceipt(ctx context.Context, msgTransfer PacketInfo, height uint64) (PacketProof, error)
// NextSeqRecv queries for the appropriate proof required to prove the next expected packet sequence number
// for a given counterparty channel. This is used in ORDERED channels to ensure packets are being delivered in the
// exact same order as they were sent over the wire.
NextSeqRecv(ctx context.Context, msgTransfer PacketInfo, height uint64) (PacketProof, error)
// MsgTransfer constructs a MsgTransfer message ready to write to the chain.
MsgTransfer(dstAddr string, amount sdk.Coin, info PacketInfo) (RelayerMessage, error)
// MsgRecvPacket takes the packet information from a MsgTransfer along with the packet commitment,
// and assembles a full MsgRecvPacket ready to write to the chain.
MsgRecvPacket(msgTransfer PacketInfo, proof PacketProof) (RelayerMessage, error)
// MsgAcknowledgement takes the packet information from a MsgRecvPacket along with the packet acknowledgement,
// and assembles a full MsgAcknowledgement ready to write to the chain.
MsgAcknowledgement(msgRecvPacket PacketInfo, proofAcked PacketProof) (RelayerMessage, error)
// MsgTimeout takes the packet information from a MsgTransfer along
// with the packet receipt to prove that the packet was never relayed,
// i.e. that the MsgRecvPacket was never written to the counterparty chain,
// and assembles a full MsgTimeout ready to write to the chain,
// i.e. the chain where the MsgTransfer was committed.
MsgTimeout(msgTransfer PacketInfo, proofUnreceived PacketProof) (RelayerMessage, error)
// MsgTimeoutOnClose takes the packet information from a MsgTransfer along
// with the packet receipt to prove that the packet was never relayed,
// i.e. that the MsgRecvPacket was never written to the counterparty chain,
// and assembles a full MsgTimeoutOnClose ready to write to the chain,
// i.e. the chain where the MsgTransfer was committed.
MsgTimeoutOnClose(msgTransfer PacketInfo, proofUnreceived PacketProof) (RelayerMessage, error)
// Get the commitment prefix of the chain.
CommitmentPrefix() commitmenttypes.MerklePrefix
// [End] Packet flow IBC message assembly
// [Begin] Connection handshake IBC message assembly
// ConnectionHandshakeProof queries for proof of an initialized connection handshake.
ConnectionHandshakeProof(ctx context.Context, msgOpenInit ConnectionInfo, height uint64) (ConnectionProof, error)
// ConnectionProof queries for proof of an acked handshake.
ConnectionProof(ctx context.Context, msgOpenAck ConnectionInfo, height uint64) (ConnectionProof, error)
// MsgConnectionOpenInit takes connection info and assembles a MsgConnectionOpenInit message
// ready to write to the chain. The connection proof is not needed here, but it needs
// the same signature as the other connection message assembly methods.
MsgConnectionOpenInit(info ConnectionInfo, proof ConnectionProof) (RelayerMessage, error)
// MsgConnectionOpenTry takes connection info along with the proof that the connection has been initialized
// on the counterparty chain, and assembles a MsgConnectionOpenTry message ready to write to the chain.
MsgConnectionOpenTry(msgOpenInit ConnectionInfo, proof ConnectionProof) (RelayerMessage, error)
// MsgConnectionOpenAck takes connection info along with the proof that the connection try has occurred
// on the counterparty chain, and assembles a MsgConnectionOpenAck message ready to write to the chain.
MsgConnectionOpenAck(msgOpenTry ConnectionInfo, proof ConnectionProof) (RelayerMessage, error)
// MsgConnectionOpenConfirm takes connection info along with the proof that the connection ack has occurred
// on the counterparty chain, and assembles a MsgConnectionOpenConfirm message ready to write to the chain.
MsgConnectionOpenConfirm(msgOpenAck ConnectionInfo, proof ConnectionProof) (RelayerMessage, error)
// [End] Connection handshake IBC message assembly
// [Begin] Channel handshake IBC message assembly
// ChannelProof queries for proof of a channel state.
ChannelProof(ctx context.Context, msg ChannelInfo, height uint64) (ChannelProof, error)
// MsgChannelOpenInit takes channel info and assembles a MsgChannelOpenInit message
// ready to write to the chain. The channel proof is not needed here, but it needs
// the same signature as the other channel message assembly methods.
MsgChannelOpenInit(info ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// MsgChannelOpenTry takes channel info along with the proof that the channel has been initialized
// on the counterparty chain, and assembles a MsgChannelOpenTry message ready to write to the chain.
MsgChannelOpenTry(msgOpenInit ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// MsgChannelOpenAck takes channel info along with the proof that the channel try has occurred
// on the counterparty chain, and assembles a MsgChannelOpenAck message ready to write to the chain.
MsgChannelOpenAck(msgOpenTry ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// MsgChannelOpenConfirm takes connection info along with the proof that the channel ack has occurred
// on the counterparty chain, and assembles a MsgChannelOpenConfirm message ready to write to the chain.
MsgChannelOpenConfirm(msgOpenAck ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// MsgChannelCloseInit takes channel info and assembles a MsgChannelCloseInit message
// ready to write to the chain. The channel proof is not needed here, but it needs
// the same signature as the other channel message assembly methods.
MsgChannelCloseInit(info ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// MsgChannelCloseConfirm takes connection info along with the proof that the channel close has occurred
// on the counterparty chain, and assembles a MsgChannelCloseConfirm message ready to write to the chain.
MsgChannelCloseConfirm(msgCloseInit ChannelInfo, proof ChannelProof) (RelayerMessage, error)
// [End] Channel handshake IBC message assembly
// [Begin] Client IBC message assembly
// MsgUpdateClientHeader takes the latest chain header, in addition to the latest client trusted header
// and assembles a new header for updating the light client on the counterparty chain.
MsgUpdateClientHeader(latestHeader IBCHeader, trustedHeight clienttypes.Height, trustedHeader IBCHeader) (ibcexported.ClientMessage, error)
// MsgUpdateClient takes an update client header to prove trust for the previous
// consensus height and the new height, and assembles a MsgUpdateClient message
// formatted for this chain.
MsgUpdateClient(clientID string, counterpartyHeader ibcexported.ClientMessage) (RelayerMessage, error)
// [End] Client IBC message assembly
// [Begin] Client ICQ message assembly
// QueryICQWithProof performs an ABCI query and includes the required proofOps.
QueryICQWithProof(ctx context.Context, msgType string, request []byte, height uint64) (ICQProof, error)
// MsgSubmitQueryResponse takes the counterparty chain ID, the ICQ query ID, and the query result proof,
// then assembles a MsgSubmitQueryResponse message formatted for sending to this chain.
MsgSubmitQueryResponse(chainID string, queryID ClientICQQueryID, proof ICQProof) (RelayerMessage, error)
// [End] Client ICQ message assembly
// Query heavy relay methods. Only used for flushing old packets.
RelayPacketFromSequence(ctx context.Context, src ChainProvider, srch, dsth, seq uint64, srcChanID, srcPortID string, order chantypes.Order) (RelayerMessage, RelayerMessage, error)
AcknowledgementFromSequence(ctx context.Context, dst ChainProvider, dsth, seq uint64, dstChanID, dstPortID, srcChanID, srcPortID string) (RelayerMessage, error)
SendMessage(ctx context.Context, msg RelayerMessage, memo string) (*RelayerTxResponse, bool, error)
SendMessages(ctx context.Context, msgs []RelayerMessage, memo string) (*RelayerTxResponse, bool, error)
SendMessagesToMempool(
ctx context.Context,
msgs []RelayerMessage,
memo string,
asyncCtx context.Context,
asyncCallbacks []func(*RelayerTxResponse, error),
) error
MsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr string) (RelayerMessage, error)
ChainName() string
ChainId() string
Type() string
ProviderConfig() ProviderConfig
Key() string
Address() (string, error)
Timeout() string
TrustingPeriod(ctx context.Context, overrideUnbondingPeriod time.Duration, percentage int64) (time.Duration, error)
WaitForNBlocks(ctx context.Context, n int64) error
Sprint(toPrint proto.Message) (string, error)
SetRpcAddr(rpcAddr string) error
}
// Do we need intermediate types? i.e. can we use the SDK types for both substrate and cosmos?
type QueryProvider interface {
// chain
BlockTime(ctx context.Context, height int64) (time.Time, error)
QueryTx(ctx context.Context, hashHex string) (*RelayerTxResponse, error)
QueryTxs(ctx context.Context, page, limit int, events []string) ([]*RelayerTxResponse, error)
QueryLatestHeight(ctx context.Context) (int64, error)
// QueryIBCHeader returns the IBC compatible block header at a specific height.
QueryIBCHeader(ctx context.Context, h int64) (IBCHeader, error)
// query packet info for sequence
QuerySendPacket(ctx context.Context, srcChanID, srcPortID string, sequence uint64) (PacketInfo, error)
QueryRecvPacket(ctx context.Context, dstChanID, dstPortID string, sequence uint64) (PacketInfo, error)
// bank
QueryBalance(ctx context.Context, keyName string) (sdk.Coins, error)
QueryBalanceWithAddress(ctx context.Context, addr string) (sdk.Coins, error)
// staking
QueryUnbondingPeriod(context.Context) (time.Duration, error)
// ics 02 - client
QueryClientState(ctx context.Context, height int64, clientid string) (ibcexported.ClientState, error)
QueryClientStateResponse(ctx context.Context, height int64, srcClientId string) (*clienttypes.QueryClientStateResponse, error)
QueryClientConsensusState(ctx context.Context, chainHeight int64, clientid string, clientHeight ibcexported.Height) (*clienttypes.QueryConsensusStateResponse, error)
QueryUpgradedClient(ctx context.Context, height int64) (*clienttypes.QueryClientStateResponse, error)
QueryUpgradedConsState(ctx context.Context, height int64) (*clienttypes.QueryConsensusStateResponse, error)
QueryConsensusState(ctx context.Context, height int64) (ibcexported.ConsensusState, int64, error)
QueryClients(ctx context.Context) (clienttypes.IdentifiedClientStates, error)
// ics 03 - connection
QueryConnection(ctx context.Context, height int64, connectionid string) (*conntypes.QueryConnectionResponse, error)
QueryConnections(ctx context.Context) (conns []*conntypes.IdentifiedConnection, err error)
QueryConnectionsUsingClient(ctx context.Context, height int64, clientid string) (*conntypes.QueryConnectionsResponse, error)
GenerateConnHandshakeProof(ctx context.Context, height int64, clientId, connId string) (clientState ibcexported.ClientState,
clientStateProof []byte, consensusProof []byte, connectionProof []byte,
connectionProofHeight ibcexported.Height, err error)
// ics 04 - channel
QueryChannel(ctx context.Context, height int64, channelid, portid string) (chanRes *chantypes.QueryChannelResponse, err error)
QueryChannelClient(ctx context.Context, height int64, channelid, portid string) (*clienttypes.IdentifiedClientState, error)
QueryConnectionChannels(ctx context.Context, height int64, connectionid string) ([]*chantypes.IdentifiedChannel, error)
QueryChannels(ctx context.Context) ([]*chantypes.IdentifiedChannel, error)
QueryPacketCommitments(ctx context.Context, height uint64, channelid, portid string) (commitments *chantypes.QueryPacketCommitmentsResponse, err error)
QueryPacketAcknowledgements(ctx context.Context, height uint64, channelid, portid string) (acknowledgements []*chantypes.PacketState, err error)
QueryUnreceivedPackets(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error)
QueryUnreceivedAcknowledgements(ctx context.Context, height uint64, channelid, portid string, seqs []uint64) ([]uint64, error)
QueryNextSeqRecv(ctx context.Context, height int64, channelid, portid string) (recvRes *chantypes.QueryNextSequenceReceiveResponse, err error)
QueryNextSeqAck(ctx context.Context, height int64, channelid, portid string) (recvRes *chantypes.QueryNextSequenceReceiveResponse, err error)
QueryPacketCommitment(ctx context.Context, height int64, channelid, portid string, seq uint64) (comRes *chantypes.QueryPacketCommitmentResponse, err error)
QueryPacketAcknowledgement(ctx context.Context, height int64, channelid, portid string, seq uint64) (ackRes *chantypes.QueryPacketAcknowledgementResponse, err error)
QueryPacketReceipt(ctx context.Context, height int64, channelid, portid string, seq uint64) (recRes *chantypes.QueryPacketReceiptResponse, err error)
// ics 20 - transfer
QueryDenomTrace(ctx context.Context, denom string) (*transfertypes.DenomTrace, error)
QueryDenomTraces(ctx context.Context, offset, limit uint64, height int64) ([]transfertypes.DenomTrace, error)
}
type RelayPacket interface {
Msg(src ChainProvider, srcPortId, srcChanId, dstPortId, dstChanId string) (RelayerMessage, error)
Data() []byte
Seq() uint64
Timeout() clienttypes.Height
TimeoutStamp() uint64
}
// KeyOutput contains mnemonic and address of key
type KeyOutput struct {
Mnemonic string `json:"mnemonic" yaml:"mnemonic"`
Address string `json:"address" yaml:"address"`
}
// TimeoutHeightError is used during packet validation to inform the PathProcessor
// that the current chain height has exceeded the packet height timeout so that
// a MsgTimeout can be assembled for the counterparty chain.
type TimeoutHeightError struct {
latestHeight uint64
timeoutHeight uint64
}
func (t *TimeoutHeightError) Error() string {
return fmt.Sprintf("latest height %d is greater than expiration height: %d", t.latestHeight, t.timeoutHeight)
}
func NewTimeoutHeightError(latestHeight, timeoutHeight uint64) *TimeoutHeightError {
return &TimeoutHeightError{latestHeight, timeoutHeight}
}
// TimeoutTimestampError is used during packet validation to inform the PathProcessor
// that current block timestamp has exceeded the packet timestamp timeout so that
// a MsgTimeout can be assembled for the counterparty chain.
type TimeoutTimestampError struct {
latestTimestamp uint64
timeoutTimestamp uint64
}
func (t *TimeoutTimestampError) Error() string {
return fmt.Sprintf("latest block timestamp %d is greater than expiration timestamp: %d", t.latestTimestamp, t.timeoutTimestamp)
}
func NewTimeoutTimestampError(latestTimestamp, timeoutTimestamp uint64) *TimeoutTimestampError {
return &TimeoutTimestampError{latestTimestamp, timeoutTimestamp}
}
type TimeoutOnCloseError struct {
msg string
}
func (t *TimeoutOnCloseError) Error() string {
return fmt.Sprintf("packet timeout on close error: %s", t.msg)
}
func NewTimeoutOnCloseError(msg string) *TimeoutOnCloseError {
return &TimeoutOnCloseError{msg}
}
type TendermintIBCHeader struct {
SignedHeader *types.SignedHeader
ValidatorSet *types.ValidatorSet
TrustedValidators *types.ValidatorSet
TrustedHeight clienttypes.Height
}
func (h TendermintIBCHeader) Height() uint64 {
return uint64(h.SignedHeader.Height)
}
func (h TendermintIBCHeader) ConsensusState() ibcexported.ConsensusState {
return &tendermint.ConsensusState{
Timestamp: h.SignedHeader.Time,
Root: commitmenttypes.NewMerkleRoot(h.SignedHeader.AppHash),
NextValidatorsHash: h.SignedHeader.NextValidatorsHash,
}
}
func (h TendermintIBCHeader) NextValidatorsHash() []byte {
return h.SignedHeader.NextValidatorsHash
}
func (h TendermintIBCHeader) TMHeader() (*tendermint.Header, error) {
valSet, err := h.ValidatorSet.ToProto()
if err != nil {
return nil, err
}
trustedVals, err := h.TrustedValidators.ToProto()
if err != nil {
return nil, err
}
return &tendermint.Header{
SignedHeader: h.SignedHeader.ToProto(),
ValidatorSet: valSet,
TrustedHeight: h.TrustedHeight,
TrustedValidators: trustedVals,
}, nil
}
type ExtensionOption struct {
Type string `json:"type"`
Value string `json:"value"`
}