Skip to content

Commit

Permalink
vsc matured handled res
Browse files Browse the repository at this point in the history
  • Loading branch information
shaspitz committed Jul 14, 2023
1 parent bc853b3 commit 0e1df65
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 2 additions & 0 deletions x/ccv/consumer/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ func (k Keeper) OnAcknowledgementPacket(ctx sdk.Context, packet channeltypes.Pac
case ccv.SlashPacketBouncedResult[0]:
k.UpdateSlashRecordOnBounce(ctx)
// Note slash is still at head of queue and will now be retried after appropriate delay period.
case ccv.VSCMaturedPacketHandledResult[0]:
// VSC matured are deleted upon sending, nothing to do here.
default:
k.Logger(ctx).Error("recv invalid result ack; expected 1, 2, or 3", "channel", packet.SourceChannel, "ack", res)
}
Expand Down
11 changes: 7 additions & 4 deletions x/ccv/consumer/keeper/relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,17 @@ func TestOnAcknowledgementPacketResult(t *testing.T) {
require.Len(t, consumerKeeper.GetPendingPackets(ctx), 2)
require.Equal(t, types.SlashPacket, consumerKeeper.GetPendingPackets(ctx)[0].Type)

// No-op result shouldn't do anything
// v1 result should delete slash record and head of pending packets. Vsc matured remains
ack := channeltypes.NewResultAcknowledgement(types.V1Result)
err := consumerKeeper.OnAcknowledgementPacket(ctx, packet, ack)
require.Nil(t, err)
_, found = consumerKeeper.GetSlashRecord(ctx)
require.True(t, found)
require.Len(t, consumerKeeper.GetPendingPackets(ctx), 2)
require.Equal(t, types.SlashPacket, consumerKeeper.GetPendingPackets(ctx)[0].Type)
require.False(t, found)
require.Len(t, consumerKeeper.GetPendingPackets(ctx), 1)
require.Equal(t, types.VscMaturedPacket, consumerKeeper.GetPendingPackets(ctx)[0].Type)

// refresh state
setupSlashBeforeVscMatured(ctx, &consumerKeeper)

// Slash packet handled result should delete slash record and head of pending packets
ack = channeltypes.NewResultAcknowledgement(types.SlashPacketHandledResult)
Expand Down
4 changes: 3 additions & 1 deletion x/ccv/types/ccv.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,15 @@ var ( // slice types can't be const

// The result ack that has historically been sent from the provider.
// A provider with v1 throttling sends these acks for both slash and vsc matured packets.
// A provider with v2 throttling sends this ack for vsc matured packets only.
V1Result = PacketAckResult([]byte{byte(1)})
// Slash packet handled result ack, sent by a throttling v2 provider to indicate that a slash packet was handled.
SlashPacketHandledResult = PacketAckResult([]byte{byte(2)})
// Slash packet bounced result ack, sent by a throttling v2 provider to indicate that a slash packet was NOT handled
// and should eventually be retried.
SlashPacketBouncedResult = PacketAckResult([]byte{byte(3)})
// VSC matured packet handled result ack, sent by a throttling v2 provider
// to indicate that a vsc matured packet was handled.
VSCMaturedPacketHandledResult = PacketAckResult([]byte{byte(4)})
)

// An exported wrapper around the auto generated isConsumerPacketData_Data interface, only for
Expand Down

0 comments on commit 0e1df65

Please sign in to comment.