From 7060c455531a19e4aa0bd4662b9f94dbdb149559 Mon Sep 17 00:00:00 2001 From: Yaru Wang Date: Fri, 8 Sep 2023 12:40:15 +0200 Subject: [PATCH 1/3] update GetAllValidatorsByConsumerAddr --- x/ccv/provider/keeper/hooks.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/x/ccv/provider/keeper/hooks.go b/x/ccv/provider/keeper/hooks.go index 35c9b96301..11168cc738 100644 --- a/x/ccv/provider/keeper/hooks.go +++ b/x/ccv/provider/keeper/hooks.go @@ -98,16 +98,17 @@ 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 + consumerChains := k.GetAllConsumerChains(ctx) + for _, consumerChain := range consumerChains { + if _, exist := k.GetValidatorByConsumerAddr( + ctx, + consumerChain.ChainId, + providertypes.NewConsumerConsAddress(consensusAddr)); exist { + return true } } - return inUse + return false } func (h Hooks) AfterValidatorCreated(ctx sdk.Context, valAddr sdk.ValAddress) error { From 90d98a45513d760d833ae5a478d7315f36f3f01c Mon Sep 17 00:00:00 2001 From: Yaru Wang Date: Fri, 8 Sep 2023 13:21:46 +0200 Subject: [PATCH 2/3] fix test --- x/ccv/provider/keeper/hooks_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x/ccv/provider/keeper/hooks_test.go b/x/ccv/provider/keeper/hooks_test.go index 83dbfe9622..14720bd970 100644 --- a/x/ccv/provider/keeper/hooks_test.go +++ b/x/ccv/provider/keeper/hooks_test.go @@ -38,6 +38,7 @@ func TestValidatorConsensusKeyInUse(t *testing.T) { newValidator.ConsumerConsAddress(), anotherValidator0.ProviderConsAddress(), ) + k.SetConsumerClientId(ctx, "chainid", "clientID") }, expect: true, }, @@ -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, }, From 70b5f0d0ae7656f2c6b52c547a30e441ef9c8481 Mon Sep 17 00:00:00 2001 From: Yaru Wang Date: Mon, 2 Oct 2023 17:56:29 +0200 Subject: [PATCH 3/3] update ValidatorConsensusKeyInUse --- tests/e2e/config.go | 2 +- x/ccv/provider/keeper/hooks.go | 13 ++++++++++++- x/ccv/provider/keeper/keeper.go | 11 +++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tests/e2e/config.go b/tests/e2e/config.go index f58af0de65..bbd2278d75 100644 --- a/tests/e2e/config.go +++ b/tests/e2e/config.go @@ -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. diff --git a/x/ccv/provider/keeper/hooks.go b/x/ccv/provider/keeper/hooks.go index 11168cc738..56c8d1e094 100644 --- a/x/ccv/provider/keeper/hooks.go +++ b/x/ccv/provider/keeper/hooks.go @@ -98,11 +98,22 @@ func ValidatorConsensusKeyInUse(k *Keeper, ctx sdk.Context, valAddr sdk.ValAddre panic("could not get validator cons addr ") } + 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, - consumerChain.ChainId, + c, providertypes.NewConsumerConsAddress(consensusAddr)); exist { return true } diff --git a/x/ccv/provider/keeper/keeper.go b/x/ccv/provider/keeper/keeper.go index ba2b6f47fe..562e4903fa 100644 --- a/x/ccv/provider/keeper/keeper.go +++ b/x/ccv/provider/keeper/keeper.go @@ -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. //