Skip to content

Commit aadfb10

Browse files
insumitygithub-actions
and
github-actions
authored
fix!: some cleaning up (#2346)
* init commit * Update testing documentation * took into account comments * readded slash acks --------- Co-authored-by: github-actions <[email protected]>
1 parent b5a3ae1 commit aadfb10

File tree

4 files changed

+53
-19
lines changed

4 files changed

+53
-19
lines changed

scripts/test_doc/test_documentation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
[TestSlashPacketAcknowledgement](../../tests/integration/slashing.go#L185) | TestSlashPacketAcknowledgement tests the handling of a slash packet acknowledgement.<details><summary>Details</summary>* Set up a provider and consumer chain, with channel initialization between them performed.<br>* Send a slash packet with randomized fields from the consumer to the provider.<br>* The provider processes the packet</details> |
8888
[TestHandleSlashPacketDowntime](../../tests/integration/slashing.go#L236) | TestHandleSlashPacketDowntime tests the handling of a downtime related slash packet, with integration tests.<details><summary>Details</summary>* Retrieve a validator from provider chain's validators and checks if it's bonded.<br>* Set tThe signing information for the validator.<br>* The provider processes the downtime slashing packet from the consumer.<br>* Check that the validator has been jailed as a result of the downtime slashing packet being processed.<br>* Verify that the validator’s signing information is updated and that the jailing duration is set correctly.<br><br>Note that only downtime slash packets are processed by HandleSlashPacket.</details> |
8989
[TestOnRecvSlashPacketErrors](../../tests/integration/slashing.go#L283) | TestOnRecvSlashPacketErrors tests errors for the OnRecvSlashPacket method in an integration testing setting.<details><summary>Details</summary>* Set up all CCV channels and expect panic if the channel is not established via dest channel of packet.<br>* After the correct channelID is added to the packet, a panic shouldn't occur anymore.<br>* Create an instance of SlashPacketData and then verify correct processing and error handling<br>for slashing packets received by the provider chain.<br>TODO: Move to unit tests.</details> |
90-
[TestValidatorDowntime](../../tests/integration/slashing.go#L401) | TestValidatorDowntime tests if a slash packet is sent and if the outstanding slashing flag is switched when a validator has downtime on the slashing module.<details><summary>Details</summary>* Set up all CCV channel and send an empty VSC packet, then retrieve the address of a validator.<br>* Validator signs blocks for the duration of the signedBlocksWindow and a slash packet is constructed to be sent and committed.<br>* Simulate the validator missing blocks and then verify that the validator is jailed and the jailed time is correctly updated.<br>* Ensure that the missed block counters are reset.<br>* Check that there is a pending slash packet in the queue, and then send the pending packets.<br>* Check if slash record is created and verify that the consumer queue still contains the packet since no<br>acknowledgment has been received from the provider.<br>* Verify that the slash packet was sent and check that the outstanding slashing flag prevents the jailed validator to keep missing block.</details> |
91-
[TestQueueAndSendSlashPacket](../../tests/integration/slashing.go#L522) | TestQueueAndSendSlashPacket tests the integration of QueueSlashPacket with SendPackets. In normal operation slash packets are queued in BeginBlock and sent in EndBlock.<details><summary>Details</summary>* Set up all CCV channels and then queue slash packets for both downtime and double-signing infractions.<br>* Check that the correct number of slash requests are stored in the queue, including duplicates for downtime infractions.<br>* Prepare the CCV channel for sending actual slash packets.<br>* Send the slash packets and check that the outstanding downtime flags are correctly set for validators that were slashed<br>for downtime infractions.<br>* Ensure that the pending data packets queue is empty.<br>TODO: Move to unit tests.</details> |
92-
[TestCISBeforeCCVEstablished](../../tests/integration/slashing.go#L607) | TestCISBeforeCCVEstablished tests that the consumer chain doesn't panic or have any undesired behavior when a slash packet is queued before the CCV channel is established. Then once the CCV channel is established, the slash packet should be sent soon after.<details><summary>Details</summary>* Check that no pending packets exist and that there's no slash record found.<br>* Triggers a slashing event which queues a slash packet.<br>* The slash packet should be queued but not sent, and it should stay like that until the CCV channel is established and the packet is sent.<br>*Verify that a slashing record now exists, indicating that the slashing packet has been successfully sent.</details> |
90+
[TestValidatorDowntime](../../tests/integration/slashing.go#L412) | TestValidatorDowntime tests if a slash packet is sent and if the outstanding slashing flag is switched when a validator has downtime on the slashing module.<details><summary>Details</summary>* Set up all CCV channel and send an empty VSC packet, then retrieve the address of a validator.<br>* Validator signs blocks for the duration of the signedBlocksWindow and a slash packet is constructed to be sent and committed.<br>* Simulate the validator missing blocks and then verify that the validator is jailed and the jailed time is correctly updated.<br>* Ensure that the missed block counters are reset.<br>* Check that there is a pending slash packet in the queue, and then send the pending packets.<br>* Check if slash record is created and verify that the consumer queue still contains the packet since no<br>acknowledgment has been received from the provider.<br>* Verify that the slash packet was sent and check that the outstanding slashing flag prevents the jailed validator to keep missing block.</details> |
91+
[TestQueueAndSendSlashPacket](../../tests/integration/slashing.go#L533) | TestQueueAndSendSlashPacket tests the integration of QueueSlashPacket with SendPackets. In normal operation slash packets are queued in BeginBlock and sent in EndBlock.<details><summary>Details</summary>* Set up all CCV channels and then queue slash packets for both downtime and double-signing infractions.<br>* Check that the correct number of slash requests are stored in the queue, including duplicates for downtime infractions.<br>* Prepare the CCV channel for sending actual slash packets.<br>* Send the slash packets and check that the outstanding downtime flags are correctly set for validators that were slashed<br>for downtime infractions.<br>* Ensure that the pending data packets queue is empty.<br>TODO: Move to unit tests.</details> |
92+
[TestCISBeforeCCVEstablished](../../tests/integration/slashing.go#L618) | TestCISBeforeCCVEstablished tests that the consumer chain doesn't panic or have any undesired behavior when a slash packet is queued before the CCV channel is established. Then once the CCV channel is established, the slash packet should be sent soon after.<details><summary>Details</summary>* Check that no pending packets exist and that there's no slash record found.<br>* Triggers a slashing event which queues a slash packet.<br>* The slash packet should be queued but not sent, and it should stay like that until the CCV channel is established and the packet is sent.<br>*Verify that a slashing record now exists, indicating that the slashing packet has been successfully sent.</details> |
9393
</details>
9494

9595
# [stop_consumer.go](../../tests/integration/stop_consumer.go)

tests/integration/slashing.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,27 @@ func (suite *CCVTestSuite) TestOnRecvSlashPacketErrors() {
356356

357357
// Expect the packet to bounce if the slash meter is negative
358358
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
359-
// Only reaches the bouncing code if it fails in the check that chain is launched and the validator is not a consumer validator,
360-
// so we set the chain as stopped.
361-
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_STOPPED)
359+
// Only reaches the bouncing code if it fails in the check that chain is not launched and in the check that
360+
// the validator is not a consumer validator.
361+
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_LAUNCHED)
362+
err = providerKeeper.SetConsumerValidator(ctx, firstBundle.ConsumerId, providertypes.ConsensusValidator{
363+
ProviderConsAddr: validAddress,
364+
})
362365
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)
363366
suite.Require().NoError(err)
364367
suite.Require().Equal(ccv.SlashPacketBouncedResult, ackResult, "expected bounced result")
365368

366-
// Expect packet not to bounce if the chain is launched
369+
// Expect packet not to bounce if the chain is stopped
370+
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
371+
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_STOPPED)
372+
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)
373+
suite.Require().NoError(err)
374+
suite.Require().Equal(ccv.SlashPacketHandledResult, ackResult, "expected successful ack")
375+
376+
// Expect packet not to bounce if the chain is launched but the validator is not a consumer validator
367377
providerKeeper.SetSlashMeter(ctx, math.NewInt(-1))
368378
providerKeeper.SetConsumerPhase(suite.providerCtx(), firstBundle.ConsumerId, providertypes.CONSUMER_PHASE_LAUNCHED)
379+
providerKeeper.DeleteConsumerValidator(ctx, firstBundle.ConsumerId, providertypes.NewProviderConsAddress(sdk.ConsAddress(validAddress)))
369380
ackResult, err = providerKeeper.OnRecvSlashPacket(ctx, packet, *slashPacketData)
370381
suite.Require().Equal(ccv.SlashPacketHandledResult, ackResult, "expected successful ack")
371382

x/ccv/provider/keeper/relay.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,10 +343,27 @@ func (k Keeper) OnRecvSlashPacket(
343343
return ccv.V1Result, nil
344344
}
345345

346-
// Check that chain is launched and the validator belongs to the consumer chain valset
347-
if k.GetConsumerPhase(ctx, consumerId) == providertypes.CONSUMER_PHASE_LAUNCHED && !k.IsConsumerValidator(ctx, consumerId, providerConsAddr) {
348-
k.Logger(ctx).Error("cannot jail validator %s that does not belong to consumer %s valset",
349-
providerConsAddr.String(), consumerId)
346+
// check that the chain is launched
347+
if k.GetConsumerPhase(ctx, consumerId) != providertypes.CONSUMER_PHASE_LAUNCHED {
348+
k.Logger(ctx).Info("cannot jail validator on a chain that is not currently launched",
349+
"consumerId", consumerId,
350+
"phase", k.GetConsumerPhase(ctx, consumerId),
351+
"provider cons addr", providerConsAddr.String(),
352+
)
353+
354+
// drop packet but return a slash ack
355+
k.AppendSlashAck(ctx, consumerId, consumerConsAddr.String())
356+
357+
return ccv.SlashPacketHandledResult, nil
358+
}
359+
360+
// check that the validator belongs to the consumer chain valset
361+
if !k.IsConsumerValidator(ctx, consumerId, providerConsAddr) {
362+
k.Logger(ctx).Error("cannot jail validator that does not belong on the consumer valset",
363+
"consumerId", consumerId,
364+
"provider cons addr", providerConsAddr.String(),
365+
)
366+
350367
// drop packet but return a slash ack so that the consumer can send another slash packet
351368
k.AppendSlashAck(ctx, consumerId, consumerConsAddr.String())
352369

x/ccv/provider/keeper/relay_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ func TestOnRecvDowntimeSlashPacket(t *testing.T) {
152152
providerKeeper.SetParams(ctx, providertypes.DefaultParams())
153153

154154
// Set channel to chain (faking multiple established channels)
155-
providerKeeper.SetChannelToConsumerId(ctx, "channel-1", "chain-1")
156-
providerKeeper.SetChannelToConsumerId(ctx, "channel-2", "chain-2")
155+
consumerId0 := "0"
156+
channelId0 := "channel-0"
157+
consumerId1 := "1"
158+
channelId1 := "channel-1"
159+
providerKeeper.SetChannelToConsumerId(ctx, channelId0, consumerId0)
160+
providerKeeper.SetChannelToConsumerId(ctx, channelId1, consumerId1)
161+
providerKeeper.SetConsumerPhase(ctx, consumerId0, providertypes.CONSUMER_PHASE_LAUNCHED)
162+
providerKeeper.SetConsumerPhase(ctx, consumerId1, providertypes.CONSUMER_PHASE_LAUNCHED)
157163

158164
// Generate a new slash packet data instance with double sign infraction type
159165
packetData := testkeeper.GetNewSlashPacketData()
@@ -163,33 +169,33 @@ func TestOnRecvDowntimeSlashPacket(t *testing.T) {
163169
providerKeeper.SetValsetUpdateBlockHeight(ctx, packetData.ValsetUpdateId, uint64(15))
164170

165171
// Set consumer validator
166-
err := providerKeeper.SetConsumerValidator(ctx, "chain-1", providertypes.ConsensusValidator{
172+
err := providerKeeper.SetConsumerValidator(ctx, consumerId0, providertypes.ConsensusValidator{
167173
ProviderConsAddr: packetData.Validator.Address,
168174
})
169175
require.NoError(t, err)
170176

171177
// Set slash meter to negative value and assert a bounce ack is returned
172178
providerKeeper.SetSlashMeter(ctx, math.NewInt(-5))
173-
ackResult, err := executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData)
179+
ackResult, err := executeOnRecvSlashPacket(t, &providerKeeper, ctx, channelId0, 1, packetData)
174180
require.Equal(t, ccv.SlashPacketBouncedResult, ackResult)
175181
require.NoError(t, err)
176182

177183
// Set consumer validator
178-
err = providerKeeper.SetConsumerValidator(ctx, "chain-2", providertypes.ConsensusValidator{
184+
err = providerKeeper.SetConsumerValidator(ctx, consumerId1, providertypes.ConsensusValidator{
179185
ProviderConsAddr: packetData.Validator.Address,
180186
})
181187
require.NoError(t, err)
182188

183189
// Also bounced for chain-2
184-
ackResult, err = executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-2", 2, packetData)
190+
ackResult, err = executeOnRecvSlashPacket(t, &providerKeeper, ctx, channelId1, 2, packetData)
185191
require.Equal(t, ccv.SlashPacketBouncedResult, ackResult)
186192
require.NoError(t, err)
187193

188194
// Now set slash meter to positive value and assert slash packet handled result is returned
189195
providerKeeper.SetSlashMeter(ctx, math.NewInt(5))
190196

191197
// Set the consumer validator
192-
err = providerKeeper.SetConsumerValidator(ctx, "chain-1", providertypes.ConsensusValidator{ProviderConsAddr: packetData.Validator.Address})
198+
err = providerKeeper.SetConsumerValidator(ctx, consumerId0, providertypes.ConsensusValidator{ProviderConsAddr: packetData.Validator.Address})
193199
require.NoError(t, err)
194200

195201
// Mock call to GetEffectiveValPower, so that it returns 2.
@@ -213,7 +219,7 @@ func TestOnRecvDowntimeSlashPacket(t *testing.T) {
213219
gomock.InOrder(calls...)
214220

215221
// Execute on recv and confirm slash packet handled result is returned
216-
ackResult, err = executeOnRecvSlashPacket(t, &providerKeeper, ctx, "channel-1", 1, packetData)
222+
ackResult, err = executeOnRecvSlashPacket(t, &providerKeeper, ctx, channelId0, 1, packetData)
217223
require.Equal(t, ccv.SlashPacketHandledResult, ackResult)
218224
require.NoError(t, err)
219225

0 commit comments

Comments
 (0)