-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: store proposed chainID before voting finishes (#1289)
* feat: store chain in proposal * add govHook * delete GetChainsInProposal * check proposal type * update key * feat: add query proposed chainIDs * feat: set govhook * feat: parse key * refactor: names * feat: add list proposed consumer chains * test: add e2e test * add e2e test * update comments * update ProposeConsumerChains in e2e test * remove wait for block * docs: update changelog * fix: lint * add TestParseProposedConsumerChainKey * refactor gov hook * Update proto/interchain_security/ccv/provider/v1/query.proto Co-authored-by: MSalopek <[email protected]> * update proto * add test for set kv * refactor key to be prefix_proposalID * formatting * update e2e test * format * Update x/ccv/provider/keeper/gov_hook.go Co-authored-by: Shawn <[email protected]> * Update x/ccv/provider/keeper/keeper.go Co-authored-by: Shawn <[email protected]> * Update x/ccv/provider/keeper/keeper.go Co-authored-by: Shawn <[email protected]> * fix e2e test * fix gosec * remove type url check * test: add unit test * lint * fix lint * fix err --------- Co-authored-by: MSalopek <[email protected]> Co-authored-by: Shawn <[email protected]>
- Loading branch information
1 parent
3cbf9c8
commit 67ec715
Showing
15 changed files
with
1,086 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/gogoproto/proto" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" | ||
sdkgov "github.com/cosmos/cosmos-sdk/x/gov/types" | ||
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
|
||
"github.com/cosmos/interchain-security/v3/x/ccv/provider/types" | ||
) | ||
|
||
type GovHooks struct { | ||
gk *govkeeper.Keeper | ||
k *Keeper | ||
} | ||
|
||
// Implements GovHooks interface | ||
// GovHooks exist in cosmos-sdk/x/gov/keeper/hooks.go of v0.45.16-lsm-ics and on | ||
var _ sdkgov.GovHooks = GovHooks{} | ||
|
||
func (k *Keeper) GovHooks(gk *govkeeper.Keeper) GovHooks { | ||
return GovHooks{ | ||
gk: gk, | ||
k: k, | ||
} | ||
} | ||
|
||
// AfterProposalSubmission - call hook if registered | ||
// After consumerAddition proposal submission, the consumer chainID is stored | ||
func (gh GovHooks) AfterProposalSubmission(ctx sdk.Context, proposalID uint64) { | ||
p, ok := gh.gk.GetProposal(ctx, proposalID) | ||
if !ok { | ||
panic(fmt.Errorf("failed to get proposal %d in gov hook", proposalID)) | ||
} | ||
msgs := p.GetMessages() | ||
|
||
for _, msg := range msgs { | ||
var msgLegacyContent v1.MsgExecLegacyContent | ||
err := proto.Unmarshal(msg.Value, &msgLegacyContent) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err)) | ||
} | ||
|
||
// if the consumer addition proposal cannot be unmarshaled, continue | ||
var consAdditionProp types.ConsumerAdditionProposal | ||
if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil { | ||
continue | ||
} | ||
|
||
if consAdditionProp.ProposalType() == types.ProposalTypeConsumerAddition { | ||
gh.k.SetProposedConsumerChain(ctx, consAdditionProp.ChainId, proposalID) | ||
} | ||
} | ||
} | ||
|
||
// AfterProposalVotingPeriodEnded - call hook if registered | ||
// After proposal voting ends, the consumer chainID in store is deleted. | ||
// When a proposal passes, this chainID will be available in providerKeeper.GetAllPendingConsumerAdditionProps | ||
// or providerKeeper.GetAllConsumerChains(ctx). | ||
func (gh GovHooks) AfterProposalVotingPeriodEnded(ctx sdk.Context, proposalID uint64) { | ||
p, ok := gh.gk.GetProposal(ctx, proposalID) | ||
if !ok { | ||
panic(fmt.Errorf("failed to get proposal %d in gov hook", proposalID)) | ||
} | ||
msgs := p.GetMessages() | ||
|
||
for _, msg := range msgs { | ||
var msgLegacyContent v1.MsgExecLegacyContent | ||
err := proto.Unmarshal(msg.Value, &msgLegacyContent) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err)) | ||
} | ||
|
||
var consAdditionProp types.ConsumerAdditionProposal | ||
// if the proposal is not ConsumerAdditionProposal, return | ||
if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil { | ||
continue | ||
} | ||
|
||
if consAdditionProp.ProposalType() == types.ProposalTypeConsumerAddition { | ||
gh.k.DeleteProposedConsumerChainInStore(ctx, proposalID) | ||
} | ||
} | ||
} | ||
|
||
func (gh GovHooks) AfterProposalDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) { | ||
} | ||
func (gh GovHooks) AfterProposalVote(ctx sdk.Context, proposalID uint64, voterAddr sdk.AccAddress) {} | ||
func (gh GovHooks) AfterProposalFailedMinDeposit(ctx sdk.Context, proposalID uint64) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.