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

chore: move gov migrations to right folder #14788

Merged
merged 2 commits into from
Jan 25, 2023
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
6 changes: 2 additions & 4 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ This allows you to remove the replace directive `replace github.com/gogo/protobu

Please use the `ghcr.io/cosmos/proto-builder` image (version >= `0.11.5`) for generating protobuf files.

See which buf commit for `cosmos/cosmos-sdk` to pin in your `buf.yaml` file [here](./proto/README.md)
See which buf commit for `cosmos/cosmos-sdk` to pin in your `buf.yaml` file [here](./proto/README.md).

#### `{accepts,implements}_interface` proto annotations

Expand Down Expand Up @@ -231,9 +231,7 @@ modified to set the new parameter to the desired value.

##### New Proposal.Proposer field

The `Proposal` proto has been updated with proposer field. For proposal state migraton developers can call `v4.AddProposerAddressToProposal` in their upgrade handler to update all existing proposal and make them compatible and this migration is optional.

> This migration is optional, if chain wants to cancel previous proposals which are active (deposit or voting period) they can do this proposals state migration.
The `Proposal` proto has been updated with proposer field. For proposal state migraton developers can call `v4.AddProposerAddressToProposal` in their upgrade handler to update all existing proposal and make them compatible and **this migration is optional**.

```go
import (
Expand Down
51 changes: 51 additions & 0 deletions x/gov/migrations/v4/store.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package v4

import (
"fmt"
"sort"

"cosmossdk.io/store/prefix"
storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/gov/exported"
v1 "github.com/cosmos/cosmos-sdk/x/gov/migrations/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types"
govv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
)

Expand Down Expand Up @@ -78,3 +82,50 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, legacySubspace

return migrateParams(ctx, storeKey, legacySubspace, cdc)
}

// AddProposerAddressToProposal will add proposer to proposal and set to the store. This function is optional.
func AddProposerAddressToProposal(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.BinaryCodec, proposals map[uint64]string) error {
proposalIDs := make([]uint64, 0, len(proposals))

for proposalID := range proposals {
proposalIDs = append(proposalIDs, proposalID)
}

// sort the proposalIDs
sort.Slice(proposalIDs, func(i, j int) bool { return proposalIDs[i] < proposalIDs[j] })

store := ctx.KVStore(storeKey)

for _, proposalID := range proposalIDs {
if len(proposals[proposalID]) == 0 {
return fmt.Errorf("found missing proposer for proposal ID: %d", proposalID)
}

if _, err := sdk.AccAddressFromBech32(proposals[proposalID]); err != nil {
return fmt.Errorf("invalid proposer address : %s", proposals[proposalID])
}

bz := store.Get(types.ProposalKey(proposalID))
var proposal govv1.Proposal
if err := cdc.Unmarshal(bz, &proposal); err != nil {
panic(err)
}

// Check if proposal is active
if proposal.Status != govv1.ProposalStatus_PROPOSAL_STATUS_VOTING_PERIOD &&
proposal.Status != govv1.ProposalStatus_PROPOSAL_STATUS_DEPOSIT_PERIOD {
return fmt.Errorf("invalid proposal : %s, proposal not active", proposals[proposalID])
}

proposal.Proposer = proposals[proposalID]

// set the new proposal with proposer
bz, err := cdc.Marshal(&proposal)
if err != nil {
panic(err)
}
store.Set(types.ProposalKey(proposal.Id), bz)
}

return nil
}
62 changes: 0 additions & 62 deletions x/gov/migrations/v5/store.go

This file was deleted.