Skip to content

Commit

Permalink
resolve merge conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
mpoke committed Aug 28, 2024
2 parents 2a7aa76 + a9b39dd commit 2cf18a8
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 157 deletions.
5 changes: 5 additions & 0 deletions proto/interchain_security/ccv/provider/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,11 @@ message Chain {
repeated string allowlist = 7;
// Corresponds to a list of provider consensus addresses of validators that CANNOT validate the consumer chain.
repeated string denylist = 8;
// Corresponds to the minimal amount of (provider chain) stake required to validate on the consumer chain.
uint64 min_stake = 9;
// Corresponds to whether inactive validators are allowed to validate the consumer chain.
bool allow_inactive_vals = 10;

}

message QueryValidatorConsumerAddrRequest {
Expand Down
57 changes: 57 additions & 0 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,63 @@ which is done in `getChainState`.
Typically, this is ultimately done, like actions, by issuing commands to the chain binary
inside the docker container. See how this is done e.g. for `getBalance`.

## Defining extra validators

In `config.go`, you can define extra validators that are not part of the default test configuration, for example
for tests that need more than 3 validators.

To create a configuration for a new validator, it suffices to add a new `ValidatorConfig`. For example, this is the validator config for alice:

```
ValidatorID("alice"): {
Mnemonic: "pave immune ethics wrap gain ceiling always holiday employ earth tumble real ice engage false unable carbon equal fresh sick tattoo nature pupil nuclear",
DelAddress: "cosmos19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddwhu7lm",
DelAddressOnConsumer: "consumer19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddtz33vu",
ValoperAddress: "cosmosvaloper19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddtrgtng",
ValoperAddressOnConsumer: "consumervaloper19pe9pg5dv9k5fzgzmsrgnw9rl9asf7ddy6jwzg",
ValconsAddress: "cosmosvalcons1qmq08eruchr5sf5s3rwz7djpr5a25f7xw4mceq",
ValconsAddressOnConsumer: "consumervalcons1qmq08eruchr5sf5s3rwz7djpr5a25f7xpvpagq",
PrivValidatorKey: `{"address":"06C0F3E47CC5C748269088DC2F36411D3AAA27C6","pub_key":{"type":"tendermint/PubKeyEd25519","value":"RrclQz9bIhkIy/gfL485g3PYMeiIku4qeo495787X10="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"uX+ZpDMg89a6gtqs/+MQpCTSqlkZ0nJQJOhLlCJvwvdGtyVDP1siGQjL+B8vjzmDc9gx6IiS7ip6jj3nvztfXQ=="}}`,
NodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"fjw4/DAhyRPnwKgXns5SV7QfswRSXMWJpHS7TyULDmJ8ofUc5poQP8dgr8bZRbCV5RV8cPqDq3FPdqwpmUbmdA=="}}`,
IpSuffix: "4",
// consumer chain assigned key
ConsumerMnemonic: "exile install vapor thing little toss immune notable lounge december final easy strike title end program interest quote cloth forget forward job october twenty",
ConsumerDelAddress: "consumer1eeeggku6dzk3mv7wph3zq035rhtd890sh9rl32",
ConsumerDelAddressOnProvider: "cosmos1eeeggku6dzk3mv7wph3zq035rhtd890sjswszd",
ConsumerValoperAddress: "consumervaloper1eeeggku6dzk3mv7wph3zq035rhtd890scaqql7",
ConsumerValoperAddressOnProvider: "cosmosvaloper1eeeggku6dzk3mv7wph3zq035rhtd890shy69w7",
ConsumerValconsAddress: "consumervalcons1muys5jyqk4xd27e208nym85kn0t4zjcfk9q5ce",
ConsumerValconsAddressOnProvider: "cosmosvalcons1muys5jyqk4xd27e208nym85kn0t4zjcfeu63fe",
ConsumerValPubKey: `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"ujY14AgopV907IYgPAk/5x8c9267S4fQf89nyeCPTes="}`,
ConsumerPrivValidatorKey: `{"address":"DF090A4880B54CD57B2A79E64D9E969BD7514B09","pub_key":{"type":"tendermint/PubKeyEd25519","value":"ujY14AgopV907IYgPAk/5x8c9267S4fQf89nyeCPTes="},"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"TRJgf7lkTjs/sj43pyweEOanyV7H7fhnVivOi0A4yjW6NjXgCCilX3TshiA8CT/nHxz3brtLh9B/z2fJ4I9N6w=="}}`,
ConsumerNodeKey: `{"priv_key":{"type":"tendermint/PrivKeyEd25519","value":"F966RL9pi20aXRzEBe4D0xRQJtZt696Xxz44XUON52cFc83FMn1WXJbP6arvA2JPyn2LA3DLKCFHSgALrCGXGA=="}}`,
UseConsumerKey: false,
},
```

Here is a short guide for generating this config for a new validator:
```
# Commands
interchain-security-pd init bob --home ./bob
cat ./bob/config/priv_validator_key.json # gets you the private key
interchain-security-pd tendermint show-address --home ./bob # returns valcons
interchain-security-pd keys add bob --keyring-backend test --home ./bob --output json # gives mnemonic, account address
interchain-security-pd keys show bob --keyring-backend test --bech=val --home ./bob --output json # returns valoper address
cat ./bob/config/node_key.json # returns the node key
```

Fill these values into the `ValidatorConfig` struct in `config.go`.
To get the values for the consumer chain, you can simply run the command in question using the
`interchain-security-cd` binary.
For example,
```
interchain-security-cd tendermint show-address --home ./bob
```
will return the validator consensus address on the consumer chain.

One important note is that the `IPSuffix` field should be unique for each validator.

## Traces

It is possible to dump the test cases (in the form of actions+state checks)
Expand Down
15 changes: 11 additions & 4 deletions tests/e2e/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ func (tr Chain) submitConsumerAdditionProposal(
"validator_set_cap": %d,
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn"
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"allow_inactive_vals": %t,
"min_stake": "%d"
}
],
"metadata": "ipfs://CID",
Expand Down Expand Up @@ -327,6 +329,8 @@ func (tr Chain) submitConsumerAdditionProposal(
action.ValidatorSetCap,
action.Allowlist,
action.Denylist,
action.AllowInactiveVals,
action.MinStake,
action.Deposit)

//#nosec G204 -- bypass unsafe quoting warning (no production code)
Expand Down Expand Up @@ -587,13 +591,14 @@ type SubmitConsumerModificationProposalAction struct {
ValidatorSetCap uint32
Allowlist []string
Denylist []string
AllowInactiveVals bool
MinStake uint64
}

func (tr Chain) submitConsumerModificationProposal(
action SubmitConsumerModificationProposalAction,
verbose bool,
) {

template := `
{
Expand All @@ -609,8 +614,8 @@ func (tr Chain) submitConsumerModificationProposal(
"allowlist": %s,
"denylist": %s,
"authority": "cosmos10d07y265gmmuvt4z0w9aw880jnsr700j6zn9kn",
"min_stake": "0",
"allow_inactive_vals": false
"min_stake": %d,
"allow_inactive_vals": %t
}
],
"metadata": "ipfs://CID",
Expand All @@ -629,6 +634,8 @@ func (tr Chain) submitConsumerModificationProposal(
action.Allowlist,
action.Denylist,
action.Deposit,
action.MinStake,
action.AllowInactiveVals,
)

// #nosec G204 -- bypass unsafe quoting warning (no production code)
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/steps_multi_consumer_downtime.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package main

// stepsDowntime tests validator jailing and slashing.
// stepsMultiConsumerDowntimeFromConsumer tests validator jailing and slashing.
// No slashing should occur for downtime slash initiated from the consumer chain
// validators will simply be jailed in those cases
// If an infraction is committed on the provider chain then the validator will be slashed
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/expired_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
ccv "github.com/cosmos/interchain-security/v5/x/ccv/types"
)

// TestVSCPacketSendWithExpiredClient tests queueing of VSCPackets when the consumer client is expired.
// TestVSCPacketSendExpiredClient tests queueing of VSCPackets when the consumer client is expired.
// While the consumer client is expired (or inactive for some reason) all packets will be queued and
// and cleared once the consumer client is established.
func (s *CCVTestSuite) TestVSCPacketSendExpiredClient() {
Expand Down Expand Up @@ -203,7 +203,7 @@ func expireClient(s *CCVTestSuite, clientTo ChainType) {
checkClientExpired(s, clientTo, true)
}

// checkClientIsExpired checks whether the client to `clientTo` is expired
// checkClientExpired checks whether the client to `clientTo` is expired
func checkClientExpired(s *CCVTestSuite, clientTo ChainType, expectedExpired bool) {
var hostEndpoint *ibctesting.Endpoint
var hostChain *ibctesting.TestChain
Expand Down
13 changes: 12 additions & 1 deletion x/ccv/provider/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func (k Keeper) QueryConsumerChains(goCtx context.Context, req *types.QueryConsu

// GetConsumerChain returns a Chain data structure with all the necessary fields
func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chain, error) {
chainID, err := k.GetConsumerChainId(ctx, consumerId)
if err != nil {
return types.Chain{}, fmt.Errorf("cannot find chainID for consumer (%s)", consumerId)
}

clientID, found := k.GetConsumerClientId(ctx, consumerId)
if !found {
return types.Chain{}, fmt.Errorf("cannot find clientID for consumer (%s)", consumerId)
Expand Down Expand Up @@ -95,15 +100,21 @@ func (k Keeper) GetConsumerChain(ctx sdk.Context, consumerId string) (types.Chai
strDenylist[i] = addr.String()
}

allowInactiveVals := k.AllowsInactiveValidators(ctx, consumerId)

minStake := k.GetMinStake(ctx, consumerId)

return types.Chain{
ChainId: consumerId,
ChainId: chainID,
ClientId: clientID,
Top_N: topN,
MinPowerInTop_N: minPowerInTopN,
ValidatorSetCap: validatorSetCap,
ValidatorsPowerCap: validatorsPowerCap,
Allowlist: strAllowlist,
Denylist: strDenylist,
AllowInactiveVals: allowInactiveVals,
MinStake: minStake,
}, nil
}

Expand Down
32 changes: 24 additions & 8 deletions x/ccv/provider/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,8 @@ func TestGetConsumerChain(t *testing.T) {
pk, ctx, ctrl, mocks := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

consumerIDs := []string{"1", "23", "345", "6789"}

chainIDs := []string{"chain-1", "chain-2", "chain-3", "chain-4"}

// mock the validator set
Expand Down Expand Up @@ -423,22 +425,34 @@ func TestGetConsumerChain(t *testing.T) {
{},
}

allowInactiveVals := []bool{true, false, true, false}

minStakes := []math.Int{
math.NewInt(0),
math.NewInt(100),
math.NewInt(200),
math.NewInt(300),
}

expectedGetAllOrder := []types.Chain{}
for i, chainID := range chainIDs {
clientID := fmt.Sprintf("client-%d", len(chainIDs)-i)
for i, consumerID := range consumerIDs {
pk.SetConsumerChainId(ctx, consumerID, chainIDs[i])
clientID := fmt.Sprintf("client-%d", len(consumerID)-i)
topN := topNs[i]
pk.SetConsumerClientId(ctx, chainID, clientID)
pk.SetConsumerPowerShapingParameters(ctx, chainID, types.PowerShapingParameters{
pk.SetConsumerClientId(ctx, consumerID, clientID)
pk.SetConsumerPowerShapingParameters(ctx, consumerID, types.PowerShapingParameters{
Top_N: topN,
ValidatorSetCap: validatorSetCaps[i],
ValidatorsPowerCap: validatorPowerCaps[i],
AllowInactiveVals: allowInactiveVals[i],
MinStake: minStakes[i].Uint64(),
})
pk.SetMinimumPowerInTopN(ctx, chainID, expectedMinPowerInTopNs[i])
pk.SetMinimumPowerInTopN(ctx, consumerID, expectedMinPowerInTopNs[i])
for _, addr := range allowlists[i] {
pk.SetAllowlist(ctx, chainID, addr)
pk.SetAllowlist(ctx, consumerID, addr)
}
for _, addr := range denylists[i] {
pk.SetDenylist(ctx, chainID, addr)
pk.SetDenylist(ctx, consumerID, addr)
}
strAllowlist := make([]string, len(allowlists[i]))
for j, addr := range allowlists[i] {
Expand All @@ -452,14 +466,16 @@ func TestGetConsumerChain(t *testing.T) {

expectedGetAllOrder = append(expectedGetAllOrder,
types.Chain{
ChainId: chainID,
ChainId: chainIDs[i],
ClientId: clientID,
Top_N: topN,
MinPowerInTop_N: expectedMinPowerInTopNs[i],
ValidatorSetCap: validatorSetCaps[i],
ValidatorsPowerCap: validatorPowerCaps[i],
Allowlist: strAllowlist,
Denylist: strDenylist,
AllowInactiveVals: allowInactiveVals[i],
MinStake: minStakes[i].Uint64(),
})
}

Expand Down
4 changes: 0 additions & 4 deletions x/ccv/provider/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,10 @@ func (h Hooks) BeforeTokenizeShareRecordRemoved(_ context.Context, _ uint64) err
// gov hooks
//

// AfterProposalSubmission - call hook if registered
// If an update consumer message exists in the proposal, a record is created that maps the proposal id to the consumer id
func (h Hooks) AfterProposalSubmission(goCtx context.Context, proposalId uint64) error {
return nil
}

// AfterProposalVotingPeriodEnded - call hook if registered
// After proposal voting ends, the consumer to proposal id record in store is deleted.
func (h Hooks) AfterProposalVotingPeriodEnded(goCtx context.Context, proposalId uint64) error {
return nil
}
Expand Down
Loading

0 comments on commit 2cf18a8

Please sign in to comment.