Skip to content

Commit

Permalink
fix: Fix has-to-validate query (#1823)
Browse files Browse the repository at this point in the history
* Fix has-to-validate query

* Flip comparison sign for checking minPower

* Regenerate traces

* Remove unnecessary print

* Address comments
  • Loading branch information
p-offtermatt authored Apr 30, 2024
1 parent d2cedd0 commit 8b7b938
Show file tree
Hide file tree
Showing 13 changed files with 529 additions and 23 deletions.
32 changes: 32 additions & 0 deletions tests/e2e/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type ChainState struct {
ConsumerPendingPacketQueueSize *uint // Only relevant to consumer chains
RegisteredConsumerRewardDenoms *[]string
ClientsFrozenHeights *map[string]clienttypes.Height
HasToValidate *map[ValidatorID][]ChainID // only relevant to provider chain
}

type Proposal interface {
Expand Down Expand Up @@ -180,6 +181,14 @@ func (tr TestConfig) getChainState(chain ChainID, modelState ChainState) ChainSt
chainState.ClientsFrozenHeights = &chainClientsFrozenHeights
}

if modelState.HasToValidate != nil {
hasToValidate := map[ValidatorID][]ChainID{}
for validatorId := range *modelState.HasToValidate {
hasToValidate[validatorId] = tr.getHasToValidate(validatorId)
}
chainState.HasToValidate = &hasToValidate
}

if modelState.ConsumerPendingPacketQueueSize != nil {
pendingPacketQueueSize := tr.getPendingPacketQueueSize(chain)
chainState.ConsumerPendingPacketQueueSize = &pendingPacketQueueSize
Expand Down Expand Up @@ -833,6 +842,29 @@ func (tc TestConfig) getClientFrozenHeight(chain ChainID, clientID string) clien
return clienttypes.Height{RevisionHeight: uint64(revHeight), RevisionNumber: uint64(revNumber)}
}

func (tr TestConfig) getHasToValidate(
validatorId ValidatorID,
) []ChainID {
//#nosec G204 -- Bypass linter warning for spawning subprocess with cmd arguments.
bz, err := exec.Command("docker", "exec", tr.containerConfig.InstanceName, tr.chainConfigs[ChainID("provi")].BinaryName,
"query", "provider", "has-to-validate",
tr.validatorConfigs[validatorId].ValconsAddress,
`--node`, tr.getQueryNode(ChainID("provi")),
`-o`, `json`,
).CombinedOutput()
if err != nil {
log.Fatal(err, "\n", string(bz))
}

arr := gjson.Get(string(bz), "consumer_chain_ids").Array()
chains := []ChainID{}
for _, c := range arr {
chains = append(chains, ChainID(c.String()))
}

return chains
}

func (tc TestConfig) getTrustedHeight(
chain ChainID,
clientID string,
Expand Down
134 changes: 130 additions & 4 deletions tests/e2e/steps_partial_set_security.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func stepsOptInChain() []Step {
Status: "PROPOSAL_STATUS_VOTING_PERIOD",
},
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {},
ValidatorID("bob"): {},
ValidatorID("carol"): {},
},
},
},
},
Expand All @@ -56,14 +61,30 @@ func stepsOptInChain() []Step {
Chain: ChainID("consu"),
Validator: ValidatorID("alice"),
},
State: State{},
State: State{
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {}, // chain is not running yet
ValidatorID("bob"): {},
ValidatorID("carol"): {},
},
},
},
},
{
Action: OptInAction{
Chain: ChainID("consu"),
Validator: ValidatorID("bob"),
},
State: State{},
State: State{
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {},
ValidatorID("bob"): {},
ValidatorID("carol"): {},
},
},
},
},
{
Action: VoteGovProposalAction{
Expand Down Expand Up @@ -149,6 +170,13 @@ func stepsOptInChain() []Step {
ValidatorID("carol"): 0,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand Down Expand Up @@ -179,6 +207,13 @@ func stepsOptInChain() []Step {
ValidatorID("carol"): 300,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand Down Expand Up @@ -213,6 +248,13 @@ func stepsOptInChain() []Step {
ValidatorID("carol"): 300,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand All @@ -229,6 +271,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 0,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"}, // but has to validate is true because bob opted in on the provider
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand Down Expand Up @@ -271,6 +318,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand All @@ -290,6 +342,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"}, // but alice still is in the consumer valset so has to validate
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand All @@ -309,6 +366,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
ChainID("consu"): ChainState{
ValPowers: &map[ValidatorID]uint{
Expand All @@ -334,6 +396,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
// still 0 power on the consumer
ChainID("consu"): ChainState{
Expand Down Expand Up @@ -385,6 +452,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand All @@ -404,6 +476,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand All @@ -430,6 +507,11 @@ func stepsOptInChain() []Step {
ValidatorID("bob"): 200,
ValidatorID("carol"): 300,
},
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
Expand Down Expand Up @@ -582,6 +664,13 @@ func stepsTopNChain() []Step {
ValidatorID("carol"): 500,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand Down Expand Up @@ -616,7 +705,15 @@ func stepsTopNChain() []Step {
Validator: ValidatorID("bob"),
ExpectError: true,
},
State: State{},
State: State{
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
// opting out "bob" or "carol" does not work because they belong to the Top N validators
Expand All @@ -634,6 +731,13 @@ func stepsTopNChain() []Step {
ValidatorID("carol"): 500,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand All @@ -659,6 +763,13 @@ func stepsTopNChain() []Step {
ValidatorID("carol"): 500,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {}, // alice has opted out and the epoch is over, so definitely does not have to validate anymore
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
// opt alice back in
Expand All @@ -667,7 +778,15 @@ func stepsTopNChain() []Step {
Chain: ChainID("consu"),
Validator: ValidatorID("alice"),
},
State: State{},
State: State{
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"}, // alice has to validate again
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Action: RelayPacketsAction{
Expand All @@ -685,6 +804,13 @@ func stepsTopNChain() []Step {
ValidatorID("carol"): 500,
},
},
ChainID("provi"): ChainState{
HasToValidate: &map[ValidatorID][]ChainID{
ValidatorID("alice"): {"consu"},
ValidatorID("bob"): {"consu"},
ValidatorID("carol"): {"consu"},
},
},
},
},
{
Expand Down
Loading

0 comments on commit 8b7b938

Please sign in to comment.