Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update GetAllValidatorsByConsumerAddr for fast find consensus key in use #1279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/e2e/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (s *TestConfig) SetRelayerConfig(useRly bool) {
}

// validateStringLiterals enforces that configs follow the constraints
// necessary to to execute the tests
// necessary to execute the tests
//
// Note: Network interfaces (name of virtual ethernet interfaces for ip link)
// within the container will be named as "$CHAIN_ID-$VAL_ID-out" etc.
Expand Down
26 changes: 19 additions & 7 deletions x/ccv/provider/keeper/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,28 @@ func ValidatorConsensusKeyInUse(k *Keeper, ctx sdk.Context, valAddr sdk.ValAddre
panic("could not get validator cons addr ")
}

inUse := false

for _, validatorConsumerAddrs := range k.GetAllValidatorsByConsumerAddr(ctx, nil) {
if sdk.ConsAddress(validatorConsumerAddrs.ConsumerAddr).Equals(consensusAddr) {
inUse = true
break
allConsumerChains := []string{}
consumerChains := k.GetAllConsumerChains(ctx)
for _, consumerChain := range consumerChains {
allConsumerChains = append(allConsumerChains, consumerChain.ChainId)
}
proposedChains := k.GetAllProposedConsumerChainIDs(ctx)
for _, proposedChain := range proposedChains {
allConsumerChains = append(allConsumerChains, proposedChain.ChainID)
}
pendingChainIDs := k.GetAllPendingConsumerChainIDs(ctx)
allConsumerChains = append(allConsumerChains, pendingChainIDs...)

for _, c := range allConsumerChains {
if _, exist := k.GetValidatorByConsumerAddr(
ctx,
c,
providertypes.NewConsumerConsAddress(consensusAddr)); exist {
return true
}
}

return inUse
return false
}

func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error {
Expand Down
4 changes: 4 additions & 0 deletions x/ccv/provider/keeper/hooks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestValidatorConsensusKeyInUse(t *testing.T) {
newValidator.ConsumerConsAddress(),
anotherValidator0.ProviderConsAddress(),
)
k.SetConsumerClientId(ctx, "chainid", "clientID")
},
expect: true,
},
Expand All @@ -50,10 +51,13 @@ func TestValidatorConsensusKeyInUse(t *testing.T) {
newValidator.ConsumerConsAddress(),
anotherValidator0.ProviderConsAddress(),
)
k.SetConsumerClientId(ctx, "chainid0", "clientID0")

k.SetValidatorByConsumerAddr(ctx, "chainid1",
anotherValidator1.ConsumerConsAddress(),
anotherValidator1.ProviderConsAddress(),
)
k.SetConsumerClientId(ctx, "chainid1", "clientID1")
},
expect: true,
},
Expand Down
11 changes: 11 additions & 0 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ func (k Keeper) GetAllProposedConsumerChainIDs(ctx sdk.Context) []types.Proposed
return proposedChains
}

// GetAllPendingConsumerChainIDs gets pending consumer chains have not reach spawn time
func (k Keeper) GetAllPendingConsumerChainIDs(ctx sdk.Context) []string {
chainIDs := []string{}
props := k.GetAllPendingConsumerAdditionProps(ctx)
for _, prop := range props {
chainIDs = append(chainIDs, prop.ChainId)
}

return chainIDs
}

// GetAllConsumerChains gets all of the consumer chains, for which the provider module
// created IBC clients. Consumer chains with created clients are also referred to as registered.
//
Expand Down
Loading