Skip to content

Commit

Permalink
Merge branch 'main' into marius/894-preccv
Browse files Browse the repository at this point in the history
  • Loading branch information
stana-miric committed Dec 23, 2024
2 parents 72e4064 + 67b0fbd commit 4e034e1
Show file tree
Hide file tree
Showing 25 changed files with 353 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
./build_deploy.sh
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4.6.9
uses: JamesIves/github-pages-deploy-action@v4.7.2
with:
branch: gh-pages
folder: ~/output
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@4f58ea79222b3b9dc2c8bbdd6debcef730109a75 #v6.9.0
uses: docker/build-push-action@48aba3b46d1b1fec4febb7c5d0c644b249a11355 #v6.10.0
with:
context: .
file: ./Dockerfile
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
**/go.sum
**/Makefile
Makefile
- uses: actions/cache@v4.1.2
- uses: actions/cache@v4.2.0
with:
path: |
~/.cache/go-build
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/adrs/adr-022-fault-resolutions.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Additional states are added to the `provider` modules:
```

```protobuf
messsage {
message {
// timestamp recording the last time a validator opted in to the consumer chain
google.protobuf.Timestamp join_time = 1;
// timestamp recording the last time a validator opted out of the consumer chain
Expand Down
12 changes: 8 additions & 4 deletions docs/docs/build/modules/02-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -2886,11 +2886,13 @@ grpcurl -plaintext -d '{"consumer_id": "0"}' localhost:9090 interchain_security.
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
"jail_duration":"9223372036.854775807s",
"tombstone": true
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
"jail_duration":"600s",
"tombstone": false
}
},
"clientId": "07-tendermint-28"
Expand Down Expand Up @@ -3596,11 +3598,13 @@ Output:
"infraction_parameters":{
"double_sign":{
"slash_fraction":"0.050000000000000000",
"jail_duration":"9223372036.854775807s"
"jail_duration":"9223372036.854775807s",
"tombstone": true
},
"downtime":{
"slash_fraction":"0.000000000000000000",
"jail_duration":"600s"
"jail_duration":"600s",
"tombstone": false
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require (
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.26.0 // indirect
google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094 // indirect
google.golang.org/grpc v1.68.0
google.golang.org/grpc v1.68.1
google.golang.org/protobuf v1.35.2
gopkg.in/yaml.v2 v2.4.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1659,8 +1659,8 @@ google.golang.org/grpc v1.48.0/go.mod h1:vN9eftEi1UMyUsIF80+uQXhHjbXYbm0uXoFCACu
google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.50.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.50.1/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI=
google.golang.org/grpc v1.68.0 h1:aHQeeJbo8zAkAa3pRzrVjZlbz6uSfeOXlJNQM0RAbz0=
google.golang.org/grpc v1.68.0/go.mod h1:fmSPC5AsjSBCK54MyHRx48kpOti1/jRfOlwEWywNjWA=
google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0=
google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw=
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
2 changes: 2 additions & 0 deletions proto/interchain_security/ccv/provider/v1/provider.proto
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,6 @@ message SlashJailParameters {
// for permanent jailing use 9223372036854775807 which is the largest value a time.Duration can hold (approximately 292 years)
google.protobuf.Duration jail_duration = 2
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
// Indicates whether the validator should be tombstoned when slashed
bool tombstone = 3;
}
6 changes: 4 additions & 2 deletions scripts/test_doc/test_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
|----------|-------------------|
[TestDemocracyRewardsDistribution](../../tests/integration/democracy.go#L77) | TestDemocracyRewardsDistribution checks that rewards to democracy representatives, community pool, and provider redistribution account are done correctly.<details><summary>Details</summary>* Set up a democracy consumer chain.<br>* Create a new block.<br>* Check that rewards to democracy representatives, community pool, and provider redistribution account are distributed in the right proportions.</details> |
[TestDemocracyMsgUpdateParams](../../tests/integration/democracy.go#L187) | TestDemocracyMsgUpdateParams checks that the consumer parameters can be updated through a governance proposal.<details><summary>Details</summary>* Set up a democracy consumer chain.<br>* Submit a proposal containing changes to the consumer module parameters.<br>* Check that the proposal is executed, and the parameters are updated.</details> |
[TestDemocracyValidatorUnjail](../../tests/integration/democracy.go#L243) | TestDemocracyValidatorUnjail checks that the consumer validator can be unjailed when there is a standalone staking keeper available.<details><summary>Details</summary>* Set up a democracy consumer chain.<br>* Jail a validator.<br>* Check that the validator is jailed.<br>* Unjail the validator.<br>* Check that the validator is unjailed.</details> |
</details>

# [distribution.go](../../tests/integration/distribution.go)
Expand Down Expand Up @@ -84,7 +85,7 @@
|----------|-------------------|
[TestRelayAndApplyDowntimePacket](../../tests/integration/slashing.go#L50) | TestRelayAndApplyDowntimePacket tests that downtime slash packets can be properly relayed from consumer to provider, handled by provider, with a VSC and jailing eventually effective on consumer and provider.<details><summary>Details</summary>* Set up CCV channels and retrieve consumer validators.<br>* Select a validator and create its consensus address.<br>* Retrieve the provider consensus address that corresponds to the consumer consensus address of the validator.<br>* The validator's current state is also retrieved, including its token balance,<br>* Set validator's signing information is to ensure it will be jailed for downtime.<br>* Create the slashing packet and send it from the consumer chain to the provider chain with a specified timeout.<br>* Receive the packet and verify that the validator was removed from the provider validator set.<br>* Relay VSC packets from the provider chain to each consumer chain and verify that the consumer chains correctly process these packets.<br>* Check the validator's balance and status on the provider chain to ensure it was jailed correctly but not slashed,<br>and its unjailing time is updated.<br>* Reset the outstanding downtime flag on the consumer chain, and ensure that the consumer<br>chain acknowledges receipt of the packet from the provider chain.<br><br>Note: This method does not test the actual slash packet sending logic for downtime<br>and double-signing, see TestValidatorDowntime and TestValidatorDoubleSigning for<br>those types of tests.</details> |
[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> |
[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> |
[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 the 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> |
[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> |
[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> |
[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> |
Expand Down Expand Up @@ -127,7 +128,8 @@

| Function | Short Description |
|----------|-------------------|
[TestUndelegationCompletion](../../tests/integration/unbonding.go#L16) | TestUndelegationCompletion tests that undelegations complete after the unbonding period elapses on the provider, regardless of the consumer's state<details><summary>Details</summary>* Set up CCV channel.<br>* Perform initial delegation of tokens followed by a partial undelegation (1/4 of the tokens).<br>* Verify that the staking unbonding operation is created as expected.<br>* Increment provider block height.<br>* Check that the unbonding operation has been completed.<br>* Verify that the token balances are correctly updated and the expected amount of tokens has been returned to the account.</details> |
[TestUndelegationCompletion](../../tests/integration/unbonding.go#L17) | TestUndelegationCompletion tests that undelegations complete after the unbonding period elapses on the provider, regardless of the consumer's state<details><summary>Details</summary>* Set up CCV channel.<br>* Perform initial delegation of tokens followed by a partial undelegation (1/4 of the tokens).<br>* Verify that the staking unbonding operation is created as expected.<br>* Increment provider block height.<br>* Check that the unbonding operation has been completed.<br>* Verify that the token balances are correctly updated and the expected amount of tokens has been returned to the account.</details> |
[TestConsumerUnjailNoOp](../../tests/integration/unbonding.go#L50) | TestConsumerUnjailNoOp check that consumerKeeper can call .Unjail() without error. This operation must only be available in case the app also implements a "standalone" staking keeper. |
</details>

# [valset_update.go](../../tests/integration/valset_update.go)
Expand Down
46 changes: 46 additions & 0 deletions tests/integration/democracy.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,52 @@ func (s *ConsumerDemocracyTestSuite) TestDemocracyMsgUpdateParams() {
s.Assert().Equal(votersOldBalances, getAccountsBalances(s.consumerCtx(), bankKeeper, bondDenom, votingAccounts))
}

// TestDemocracyValidatorUnjail checks that the consumer validator can be unjailed when there is a standalone staking keeper available.
// @Long Description@
// * Set up a democracy consumer chain.
// * Jail a validator.
// * Check that the validator is jailed.
// * Unjail the validator.
// * Check that the validator is unjailed.
func (s *ConsumerDemocracyTestSuite) TestDemocracyValidatorUnjail() {
stakingKeeper := s.consumerApp.GetTestStakingKeeper()
consumerKeeper := s.consumerApp.GetConsumerKeeper()

validators, err := stakingKeeper.GetAllValidators(s.consumerCtx())
s.Require().NoError(err)

// setting up pre-conditions
// validator[0] is expected to be jailed
expectJailed := validators[0]
consAddr, err := expectJailed.GetConsAddr()
s.Require().NoError(err)
stakingKeeper.GetValidatorSet().Jail(s.consumerCtx(), consAddr)

s.consumerChain.NextBlock()

validators, err = stakingKeeper.GetAllValidators(s.consumerCtx())
s.Require().NoError(err)
for _, validator := range validators {
if validator.OperatorAddress == expectJailed.OperatorAddress {
s.Require().True(validator.IsJailed())
} else {
s.Require().False(validator.IsJailed())
}
}

// confirm unjail will not error and properly unjail
// in case of a consumer chain without standalone staking the call is a no-op
err = consumerKeeper.Unjail(s.consumerCtx(), consAddr)
s.Require().NoError(err)
s.consumerChain.NextBlock()

validators, err = stakingKeeper.GetAllValidators(s.consumerCtx())
s.Require().NoError(err)
for _, validator := range validators {
s.Require().False(validator.IsJailed())
}
}

func submitProposalWithDepositAndVote(govKeeper govkeeper.Keeper, ctx sdk.Context, msgs []sdk.Msg,
accounts []ibctesting.SenderAccount, proposer sdk.AccAddress, depositAmount sdk.Coins,
) error {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (s *CCVTestSuite) TestSlashPacketAcknowledgement() {
// TestHandleSlashPacketDowntime tests the handling of a downtime related slash packet, with integration tests.
// @Long Description@
// * Retrieve a validator from provider chain's validators and checks if it's bonded.
// * Set tThe signing information for the validator.
// * Set the signing information for the validator.
// * The provider processes the downtime slashing packet from the consumer.
// * Check that the validator has been jailed as a result of the downtime slashing packet being processed.
// * Verify that the validator’s signing information is updated and that the jailing duration is set correctly.
Expand Down
13 changes: 13 additions & 0 deletions tests/integration/unbonding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package integration

import (
"cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// TestUndelegationCompletion tests that undelegations complete after
Expand Down Expand Up @@ -43,3 +44,15 @@ func (s *CCVTestSuite) TestUndelegationCompletion() {
"unexpected initial balance after unbonding; test: %s",
)
}

// TestConsumerUnjailNoOp check that consumerKeeper can call .Unjail() without error.
// This operation must only be available in case the app also implements a "standalone" staking keeper.
func (s *CCVTestSuite) TestConsumerUnjailNoOp() {
consumerKeeper := s.consumerApp.GetConsumerKeeper()

if s.consumerApp.GetStakingKeeper() == nil {
// this is a no-op
err := consumerKeeper.Unjail(s.consumerCtx(), sdk.ConsAddress([]byte{0x01, 0x02, 0x03}))
s.Require().NoError(err)
}
}
8 changes: 4 additions & 4 deletions tests/interchain/provider_single_val_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (s *SingleValidatorProviderSuite) TestProviderValidatorOptInWithKeyAssignme
s.Require().Equal(1, len(optInVals.ValidatorsProviderAddresses))
s.Require().Equal(valProviderAddress, optInVals.ValidatorsProviderAddresses[0])

// assgin custom consumer consensus key
// assign custom consumer consensus key
s.Require().NoError(s.Provider.AssignKey(s.GetContext(), consumerChain.ConsumerID, 0, valConsumerKey))
consumerKeyAddr, err := s.Provider.ValidatorConsumerAddress(s.GetContext(), consumerChain.ConsumerID, valProviderAddress)
s.Require().NoError(err)
Expand Down Expand Up @@ -249,7 +249,7 @@ func (s *SingleValidatorProviderSuite) TestProviderUpdateConsumer() {
s.Require().NoError(s.Provider.OptIn(s.GetContext(), consumerChain.ConsumerID, 0))
s.Require().Equal(providertypes.CONSUMER_PHASE_REGISTERED.String(), consumerChain.Phase)

// updated consumer with the minimum params (metadata) - regeistered phase
// updated consumer with the minimum params (metadata) - registered phase
upgradeMsg := &providertypes.MsgUpdateConsumer{
Owner: testAcc,
ConsumerId: consumerChain.ConsumerID,
Expand Down Expand Up @@ -601,7 +601,7 @@ func (s *SingleValidatorProviderSuite) TestProviderOwnerChecks() {
s.Require().Error(err)
s.Require().Contains(err.Error(), "expected gov account")

// update owner using msg submited by the current owner
// update owner using msg submitted by the current owner
s.Require().NoError(s.Provider.UpdateConsumer(s.GetContext(), upgradeMsg, testAccKey2))

// update to top N using proposal
Expand Down Expand Up @@ -652,7 +652,7 @@ func (s *SingleValidatorProviderSuite) TestInfractionParameters() {
s.Require().NoError(testutil.WaitForBlocks(s.GetContext(), 1, s.Provider))
consumerChain, err = s.Provider.GetConsumerChain(s.GetContext(), consumerId)
s.Require().NoError(err)
// chain is in pre-launched phase, params are updated immediatelly
// chain is in pre-launched phase, params are updated immediately
s.Require().Equal(infractionParamsTemplate(), convertJsonToInfractionParameters(consumerChain.InfractionParams))

// Confirm that a chain can be created with custom infraction parameters set only for double sign
Expand Down
8 changes: 8 additions & 0 deletions testutil/integration/debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func TestDemocracyMsgUpdateParams(t *testing.T) {
runConsumerDemocracyTestByName(t, "TestDemocracyMsgUpdateParams")
}

func TestDemocracyUnjail(t *testing.T) {
runConsumerDemocracyTestByName(t, "TestDemocracyValidatorUnjail")
}

//
// Distribution tests
//
Expand Down Expand Up @@ -193,6 +197,10 @@ func TestUndelegationCompletion(t *testing.T) {
runCCVTestByName(t, "TestUndelegationCompletion")
}

func TestConsumerUnjailNoOp(t *testing.T) {
runCCVTestByName(t, "TestConsumerUnjailNoOp")
}

//
// Val set update tests
//
Expand Down
2 changes: 2 additions & 0 deletions testutil/keeper/unit_test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,12 @@ func GetTestInfractionParameters() providertypes.InfractionParameters {
DoubleSign: &providertypes.SlashJailParameters{
JailDuration: 1200 * time.Second,
SlashFraction: math.LegacyNewDecWithPrec(5, 1), // 0.5
Tombstone: true,
},
Downtime: &providertypes.SlashJailParameters{
JailDuration: 600 * time.Second,
SlashFraction: math.LegacyNewDec(0),
Tombstone: false,
},
}
}
Expand Down
Loading

0 comments on commit 4e034e1

Please sign in to comment.