Skip to content

Commit

Permalink
Fix flush on ordered channels (cosmos#1150)
Browse files Browse the repository at this point in the history
* Fix flush on ordered channels

* Queue all packets at nextseqrecv or above
  • Loading branch information
agouin authored Mar 27, 2023
1 parent f29a2c7 commit dcc6060
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions relayer/processor/path_processor_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1089,15 +1089,51 @@ func queuePendingRecvAndAcks(
return nil
}

unrecv, err := dst.chainProvider.QueryUnreceivedPackets(ctx, dst.latestBlock.Height, k.CounterpartyChannelID, k.CounterpartyPortID, seqs)
dstChan, dstPort := k.CounterpartyChannelID, k.CounterpartyPortID

unrecv, err := dst.chainProvider.QueryUnreceivedPackets(ctx, dst.latestBlock.Height, dstChan, dstPort, seqs)
if err != nil {
return err
}

dstHeight := int64(dst.latestBlock.Height)

if len(unrecv) > 0 {
src.log.Debug("Will flush MsgRecvPacket", zap.String("channel", k.ChannelID), zap.String("port", k.PortID), zap.Uint64s("sequences", unrecv))
channel, err := dst.chainProvider.QueryChannel(ctx, dstHeight, dstChan, dstPort)
if err != nil {
return err
}

if channel.Channel.Ordering == chantypes.ORDERED {
nextSeqRecv, err := dst.chainProvider.QueryNextSeqRecv(ctx, dstHeight, dstChan, dstPort)
if err != nil {
return err
}

var newUnrecv []uint64

for _, seq := range unrecv {
if seq >= nextSeqRecv.NextSequenceReceive {
newUnrecv = append(newUnrecv, seq)
break
}
}

unrecv = newUnrecv
}
}

if len(unrecv) > 0 {
src.log.Debug("Will flush MsgRecvPacket",
zap.String("channel", k.ChannelID),
zap.String("port", k.PortID),
zap.Uint64s("sequences", unrecv),
)
} else {
src.log.Debug("No MsgRecvPacket to flush", zap.String("channel", k.ChannelID), zap.String("port", k.PortID))
src.log.Debug("No MsgRecvPacket to flush",
zap.String("channel", k.ChannelID),
zap.String("port", k.PortID),
)
}

for _, seq := range unrecv {
Expand Down

0 comments on commit dcc6060

Please sign in to comment.