From c2cb5291584974d80ba432539440cb10320eb3a7 Mon Sep 17 00:00:00 2001 From: Yaru Wang Date: Thu, 21 Sep 2023 17:15:56 +0200 Subject: [PATCH] refactor gov hook --- x/ccv/provider/keeper/gov_hook.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/x/ccv/provider/keeper/gov_hook.go b/x/ccv/provider/keeper/gov_hook.go index dcb02683b3..d8e73586d6 100644 --- a/x/ccv/provider/keeper/gov_hook.go +++ b/x/ccv/provider/keeper/gov_hook.go @@ -45,10 +45,14 @@ func (gh GovHooks) AfterProposalSubmission(ctx sdk.Context, proposalID uint64) { panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err)) } - // if the proposal is not ConsumerAdditionProposal, return + // if the proposal is not ConsumerAdditionProposal, continue + if msgLegacyContent.Content.TypeUrl != "/interchain_security.ccv.provider.v1.ConsumerAdditionProposal" { + continue + } + // if the proposal is not ConsumerAdditionProposal, continue var consAdditionProp types.ConsumerAdditionProposal if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil { - return + continue } if consAdditionProp.ProposalType() == types.ProposalTypeConsumerAddition { @@ -74,17 +78,20 @@ func (gh GovHooks) AfterProposalVotingPeriodEnded(ctx sdk.Context, proposalID ui if err != nil { panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err)) } - var consAdditionProp types.ConsumerAdditionProposal + if msgLegacyContent.Content.TypeUrl != "/interchain_security.ccv.provider.v1.ConsumerAdditionProposal" { + continue + } + var consAdditionProp types.ConsumerAdditionProposal // if the proposal is not ConsumerAdditionProposal, return if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil { - return + continue } - if consAdditionProp.ProposalType() != types.ProposalTypeConsumerAddition { - return + + if consAdditionProp.ProposalType() == types.ProposalTypeConsumerAddition { + gh.k.DeleteChainsInProposal(ctx, consAdditionProp.ChainId, proposalID) } - gh.k.DeleteChainsInProposal(ctx, consAdditionProp.ChainId, proposalID) } }