Skip to content

Commit

Permalink
update key
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaru Wang committed Sep 15, 2023
1 parent 690c61c commit 658b5f5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 31 deletions.
56 changes: 30 additions & 26 deletions x/ccv/provider/keeper/gov_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ func (gh GovHooks) AfterProposalSubmission(ctx sdk.Context, proposalID uint64) {
}
msgs := p.GetMessages()

var msgLegacyContent v1.MsgExecLegacyContent
err := proto.Unmarshal(msgs[0].Value, &msgLegacyContent)
if err != nil {
panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err))
}
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 proposal is not ConsumerAdditionProposal, return
var consadditionProp types.ConsumerAdditionProposal
if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consadditionProp); err != nil {
return
}
// if the proposal is not ConsumerAdditionProposal, return
var consAdditionProp types.ConsumerAdditionProposal
if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil {
return
}

if consadditionProp.ProposalType() == types.ProposalTypeConsumerAddition {
gh.k.SetChainsInProposal(ctx, consadditionProp.ChainId, proposalID)
if consAdditionProp.ProposalType() == types.ProposalTypeConsumerAddition {
gh.k.SetChainsInProposal(ctx, consAdditionProp.ChainId, proposalID)
}
}
}

Expand All @@ -64,22 +66,24 @@ func (gh GovHooks) AfterProposalVotingPeriodEnded(ctx sdk.Context, proposalID ui
}
msgs := p.GetMessages()

var msgLegacyContent v1.MsgExecLegacyContent
err := proto.Unmarshal(msgs[0].Value, &msgLegacyContent)
if err != nil {
panic(fmt.Errorf("failed to unmarshal proposal content in gov hook: %w", err))
}
var consadditionProp types.ConsumerAdditionProposal
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 {
return
}
if consadditionProp.ProposalType() != types.ProposalTypeConsumerAddition {
return
}
// if the proposal is not ConsumerAdditionProposal, return
if err := proto.Unmarshal(msgLegacyContent.Content.Value, &consAdditionProp); err != nil {
return
}
if consAdditionProp.ProposalType() != types.ProposalTypeConsumerAddition {
return
}

gh.k.DeleteChainsInProposal(ctx, consadditionProp.ChainId)
gh.k.DeleteChainsInProposal(ctx, consAdditionProp.ChainId, proposalID)
}
}

func (gh GovHooks) AfterProposalDeposit(ctx sdk.Context, proposalID uint64, depositorAddr sdk.AccAddress) {}

Check failure on line 89 in x/ccv/provider/keeper/gov_hook.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/interchain-security) --custom-order (gci)
Expand Down
6 changes: 3 additions & 3 deletions x/ccv/provider/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ func (k Keeper) DeleteChainToChannel(ctx sdk.Context, chainID string) {
// does not end.
func (k Keeper) SetChainsInProposal(ctx sdk.Context, chainID string, proposalID uint64) {
store := ctx.KVStore(k.storeKey)
store.Set(types.ChainInProposalKey(chainID), sdk.Uint64ToBigEndian(proposalID))
store.Set(types.ChainInProposalKey(chainID, proposalID), []byte(chainID))
}

// DeleteChainsInProposal deletes the consumer chainID from store
// which is in gov consumerAddition proposal
func (k Keeper) DeleteChainsInProposal(ctx sdk.Context, chainID string) {
func (k Keeper) DeleteChainsInProposal(ctx sdk.Context, chainID string, proposalID uint64) {
store := ctx.KVStore(k.storeKey)
store.Delete(types.ChainInProposalKey(chainID))
store.Delete(types.ChainInProposalKey(chainID, proposalID))
}

// GetAllChainsInProposal get consumer chainId in gov consumerAddition proposal before
Expand Down
8 changes: 6 additions & 2 deletions x/ccv/provider/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,12 @@ func ChainIdWithLenKey(prefix byte, chainID string) []byte {
}

// ChainInProposalKey returns the consumer chainId in consumerAddition gov proposal submitted before voting finishes
func ChainInProposalKey(chainID string) []byte {
return append([]byte{ChainInProposalByteKey}, []byte(chainID)...)
func ChainInProposalKey(chainID string, proposalID uint64) []byte {
return ccvtypes.AppendMany(
[]byte{ChainInProposalByteKey},
[]byte(chainID),
sdk.Uint64ToBigEndian(proposalID),
)

Check failure on line 425 in x/ccv/provider/types/keys.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gci`-ed with --skip-generated -s standard -s default -s blank -s dot -s prefix(cosmossdk.io) -s prefix(github.com/cosmos/cosmos-sdk) -s prefix(github.com/cometbft/cometbft) -s prefix(github.com/cosmos/interchain-security) --custom-order (gci)
}

// ParseChainIdAndTsKey returns the chain ID and time for a ChainIdAndTs key
Expand Down

0 comments on commit 658b5f5

Please sign in to comment.