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

release/v0.3.41 -> master #632

Merged
merged 4 commits into from
Jan 15, 2024
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
3 changes: 1 addition & 2 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
Features:

- Add default denom on AllTokenAliases response
- Update default_parameters type from bool to uint64 on codec metadata
- Add flag for filtering only required modules for migration #630
2 changes: 1 addition & 1 deletion types/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package types
const (
// we set page iteration limit for safety
PageIterationLimit = 512
SekaiVersion = "v0.3.40"
SekaiVersion = "v0.3.41"
CosmosVersion = "v0.47.6"
)
291 changes: 155 additions & 136 deletions x/genutil/client/cli/upgrade_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cli
import (
"encoding/json"
"fmt"
"strings"

"github.com/KiraCore/sekai/x/genutil"
v01228govtypes "github.com/KiraCore/sekai/x/gov/legacy/v01228"
Expand All @@ -22,6 +23,7 @@ import (

const (
FlagJsonMinimize = "json-minimize"
FlagModulesOnly = "modules-only"
)

func upgradedPlan(plan *v03123upgradetypes.PlanV03123) *upgradetypes.Plan {
Expand Down Expand Up @@ -89,165 +91,181 @@ $ %s new-genesis-from-exported exported-genesis.json new-genesis.json
return errors.Wrap(err, "failed to unmarshal genesis state")
}

if err = mbm.ValidateGenesis(cdc, txEncCfg, genesisState); err != nil {
return errors.Wrap(err, "failed to validate genesis state")
modulesCombined, err := cmd.Flags().GetString(FlagModulesOnly)
if err != nil {
return err
}

upgradeGenesisV03123 := v03123upgradetypes.GenesisStateV03123{}
err = cdc.UnmarshalJSON(genesisState[upgradetypes.ModuleName], &upgradeGenesisV03123)
if err == nil { // which means old upgrade genesis
upgradeGenesis := upgradetypes.GenesisState{
Version: "v0.3.1.24",
CurrentPlan: upgradedPlan(upgradeGenesisV03123.CurrentPlan),
NextPlan: upgradedPlan(upgradeGenesisV03123.NextPlan),
if modulesCombined != "" {
newGenesis := mbm.DefaultGenesis(cdc)
modules := strings.Split(modulesCombined, ",")
for _, module := range modules {
moduleGenesis, ok := genesisState[module]
if !ok {
return errors.New("invalid module")
}
newGenesis[module] = moduleGenesis
}
genesisState[upgradetypes.ModuleName] = cdc.MustMarshalJSON(&upgradeGenesis)
genesisState = newGenesis
} else {
fmt.Println("error exists v0.3.1.23 upgrade genesis parsing", err)
}
if err = mbm.ValidateGenesis(cdc, txEncCfg, genesisState); err != nil {
return errors.Wrap(err, "failed to validate genesis state")
}

upgradeGenesis := upgradetypes.GenesisState{}
cdc.MustUnmarshalJSON(genesisState[upgradetypes.ModuleName], &upgradeGenesis)
oldVersion := upgradeGenesis.Version
if upgradeGenesis.Version == "" {
upgradeGenesis.Version = "v0.1.22.11"
fmt.Println("upgraded the upgrade module genesis to v0.1.22.11")
}
upgradeGenesisV03123 := v03123upgradetypes.GenesisStateV03123{}
err = cdc.UnmarshalJSON(genesisState[upgradetypes.ModuleName], &upgradeGenesisV03123)
if err == nil { // which means old upgrade genesis
upgradeGenesis := upgradetypes.GenesisState{
Version: "v0.3.1.24",
CurrentPlan: upgradedPlan(upgradeGenesisV03123.CurrentPlan),
NextPlan: upgradedPlan(upgradeGenesisV03123.NextPlan),
}
genesisState[upgradetypes.ModuleName] = cdc.MustMarshalJSON(&upgradeGenesis)
} else {
fmt.Println("error exists v0.3.1.23 upgrade genesis parsing", err)
}

if upgradeGenesis.NextPlan == nil {
return fmt.Errorf("next plan is not available")
}
upgradeGenesis := upgradetypes.GenesisState{}
cdc.MustUnmarshalJSON(genesisState[upgradetypes.ModuleName], &upgradeGenesis)
oldVersion := upgradeGenesis.Version
if upgradeGenesis.Version == "" {
upgradeGenesis.Version = "v0.1.22.11"
fmt.Println("upgraded the upgrade module genesis to v0.1.22.11")
}

if genDoc.ChainID != upgradeGenesis.NextPlan.OldChainId {
return fmt.Errorf("next plan has different oldchain id, current chain_id=%s, next_plan.old_chain_id=%s", genDoc.ChainID, upgradeGenesis.NextPlan.OldChainId)
}
if upgradeGenesis.NextPlan == nil {
return fmt.Errorf("next plan is not available")
}

genDoc.ChainID = upgradeGenesis.NextPlan.NewChainId
upgradeGenesis.CurrentPlan = upgradeGenesis.NextPlan
upgradeGenesis.NextPlan = nil
if genDoc.ChainID != upgradeGenesis.NextPlan.OldChainId {
return fmt.Errorf("next plan has different oldchain id, current chain_id=%s, next_plan.old_chain_id=%s", genDoc.ChainID, upgradeGenesis.NextPlan.OldChainId)
}

genesisState[upgradetypes.ModuleName] = cdc.MustMarshalJSON(&upgradeGenesis)
genDoc.ChainID = upgradeGenesis.NextPlan.NewChainId
upgradeGenesis.CurrentPlan = upgradeGenesis.NextPlan
upgradeGenesis.NextPlan = nil

govGenesisV01228 := v01228govtypes.GenesisStateV01228{}
err = cdc.UnmarshalJSON(genesisState[govtypes.ModuleName], &govGenesisV01228)
genesisState[upgradetypes.ModuleName] = cdc.MustMarshalJSON(&upgradeGenesis)

// we are referencing oldPlan.name to determine upgrade genesis or not
if err == nil && oldVersion == "" { // it means v0.1.22.8 gov genesis
govGenesis := govtypes.GenesisState{
StartingProposalId: govGenesisV01228.StartingProposalId,
NextRoleId: govtypes.DefaultGenesis().NextRoleId,
Roles: govtypes.DefaultGenesis().Roles,
RolePermissions: govGenesisV01228.Permissions,
NetworkActors: govGenesisV01228.NetworkActors,
NetworkProperties: &govtypes.NetworkProperties{
MinTxFee: govGenesisV01228.NetworkProperties.MinTxFee,
MaxTxFee: govGenesisV01228.NetworkProperties.MaxTxFee,
VoteQuorum: govGenesisV01228.NetworkProperties.VoteQuorum,
MinimumProposalEndTime: govGenesisV01228.NetworkProperties.ProposalEndTime,
ProposalEnactmentTime: govGenesisV01228.NetworkProperties.ProposalEnactmentTime,
MinProposalEndBlocks: govGenesisV01228.NetworkProperties.MinProposalEndBlocks,
MinProposalEnactmentBlocks: govGenesisV01228.NetworkProperties.MinProposalEnactmentBlocks,
EnableForeignFeePayments: govGenesisV01228.NetworkProperties.EnableForeignFeePayments,
MischanceRankDecreaseAmount: govGenesisV01228.NetworkProperties.MischanceRankDecreaseAmount,
MaxMischance: govGenesisV01228.NetworkProperties.MaxMischance,
MischanceConfidence: govGenesisV01228.NetworkProperties.MischanceConfidence,
InactiveRankDecreasePercent: sdk.NewDecWithPrec(int64(govGenesisV01228.NetworkProperties.InactiveRankDecreasePercent), 2),
MinValidators: govGenesisV01228.NetworkProperties.MinValidators,
PoorNetworkMaxBankSend: govGenesisV01228.NetworkProperties.PoorNetworkMaxBankSend,
UnjailMaxTime: govGenesisV01228.NetworkProperties.JailMaxTime,
EnableTokenWhitelist: govGenesisV01228.NetworkProperties.EnableTokenWhitelist,
EnableTokenBlacklist: govGenesisV01228.NetworkProperties.EnableTokenBlacklist,
MinIdentityApprovalTip: govGenesisV01228.NetworkProperties.MinIdentityApprovalTip,
UniqueIdentityKeys: govGenesisV01228.NetworkProperties.UniqueIdentityKeys,
UbiHardcap: 6000_000,
ValidatorsFeeShare: sdk.NewDecWithPrec(50, 2), // 50%
InflationRate: sdk.NewDecWithPrec(18, 2), // 18%
InflationPeriod: 31557600, // 1 year
UnstakingPeriod: 2629800, // 1 month
MaxDelegators: 100,
MinDelegationPushout: 10,
SlashingPeriod: 3600,
MaxJailedPercentage: sdk.NewDecWithPrec(25, 2),
MaxSlashingPercentage: sdk.NewDecWithPrec(1, 2),
MinCustodyReward: 200,
MaxCustodyTxSize: 8192,
MaxCustodyBufferSize: 10,
AbstentionRankDecreaseAmount: 1,
MaxAbstention: 2,
MinCollectiveBond: 100_000, // in KEX
MinCollectiveBondingTime: 86400, // in seconds
MaxCollectiveOutputs: 10,
MinCollectiveClaimPeriod: 14400, // 4hrs
ValidatorRecoveryBond: 300000, // 300k KEX
MaxAnnualInflation: sdk.NewDecWithPrec(35, 2),
MaxProposalTitleSize: 128,
MaxProposalDescriptionSize: 1024,
MaxProposalPollOptionSize: 64,
MaxProposalPollOptionCount: 128,
MinDappBond: 1000000,
MaxDappBond: 10000000,
DappBondDuration: 604800,
DappVerifierBond: sdk.NewDecWithPrec(1, 3), //0.1%
DappAutoDenounceTime: 60, // 60s
DappMischanceRankDecreaseAmount: 1,
DappMaxMischance: 10,
DappInactiveRankDecreasePercent: 10,
DappPoolSlippageDefault: sdk.NewDecWithPrec(1, 1), // 10%
MintingFtFee: 100_000_000_000_000,
MintingNftFee: 100_000_000_000_000,
VetoThreshold: sdk.NewDecWithPrec(3340, 2), //33.40%
AutocompoundIntervalNumBlocks: 17280,
},
ExecutionFees: govGenesisV01228.ExecutionFees,
PoorNetworkMessages: govGenesisV01228.PoorNetworkMessages,
Proposals: []govtypes.Proposal{}, // govGenesisV01228.Proposals,
Votes: []govtypes.Vote{}, // govGenesisV01228.Votes,
DataRegistry: govGenesisV01228.DataRegistry,
IdentityRecords: govGenesisV01228.IdentityRecords,
LastIdentityRecordId: govGenesisV01228.LastIdentityRecordId,
IdRecordsVerifyRequests: govGenesisV01228.IdRecordsVerifyRequests,
LastIdRecordVerifyRequestId: govGenesisV01228.LastIdRecordVerifyRequestId,
ProposalDurations: make(map[string]uint64),
}
govGenesisV01228 := v01228govtypes.GenesisStateV01228{}
err = cdc.UnmarshalJSON(genesisState[govtypes.ModuleName], &govGenesisV01228)

genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenesis)
} else {
fmt.Println("GovGenesis01228 unmarshal test: ", err)
fmt.Println("Skipping governance module upgrade since it is not v0.1.22.8 genesis")
}
// we are referencing oldPlan.name to determine upgrade genesis or not
if err == nil && oldVersion == "" { // it means v0.1.22.8 gov genesis
govGenesis := govtypes.GenesisState{
StartingProposalId: govGenesisV01228.StartingProposalId,
NextRoleId: govtypes.DefaultGenesis().NextRoleId,
Roles: govtypes.DefaultGenesis().Roles,
RolePermissions: govGenesisV01228.Permissions,
NetworkActors: govGenesisV01228.NetworkActors,
NetworkProperties: &govtypes.NetworkProperties{
MinTxFee: govGenesisV01228.NetworkProperties.MinTxFee,
MaxTxFee: govGenesisV01228.NetworkProperties.MaxTxFee,
VoteQuorum: govGenesisV01228.NetworkProperties.VoteQuorum,
MinimumProposalEndTime: govGenesisV01228.NetworkProperties.ProposalEndTime,
ProposalEnactmentTime: govGenesisV01228.NetworkProperties.ProposalEnactmentTime,
MinProposalEndBlocks: govGenesisV01228.NetworkProperties.MinProposalEndBlocks,
MinProposalEnactmentBlocks: govGenesisV01228.NetworkProperties.MinProposalEnactmentBlocks,
EnableForeignFeePayments: govGenesisV01228.NetworkProperties.EnableForeignFeePayments,
MischanceRankDecreaseAmount: govGenesisV01228.NetworkProperties.MischanceRankDecreaseAmount,
MaxMischance: govGenesisV01228.NetworkProperties.MaxMischance,
MischanceConfidence: govGenesisV01228.NetworkProperties.MischanceConfidence,
InactiveRankDecreasePercent: sdk.NewDecWithPrec(int64(govGenesisV01228.NetworkProperties.InactiveRankDecreasePercent), 2),
MinValidators: govGenesisV01228.NetworkProperties.MinValidators,
PoorNetworkMaxBankSend: govGenesisV01228.NetworkProperties.PoorNetworkMaxBankSend,
UnjailMaxTime: govGenesisV01228.NetworkProperties.JailMaxTime,
EnableTokenWhitelist: govGenesisV01228.NetworkProperties.EnableTokenWhitelist,
EnableTokenBlacklist: govGenesisV01228.NetworkProperties.EnableTokenBlacklist,
MinIdentityApprovalTip: govGenesisV01228.NetworkProperties.MinIdentityApprovalTip,
UniqueIdentityKeys: govGenesisV01228.NetworkProperties.UniqueIdentityKeys,
UbiHardcap: 6000_000,
ValidatorsFeeShare: sdk.NewDecWithPrec(50, 2), // 50%
InflationRate: sdk.NewDecWithPrec(18, 2), // 18%
InflationPeriod: 31557600, // 1 year
UnstakingPeriod: 2629800, // 1 month
MaxDelegators: 100,
MinDelegationPushout: 10,
SlashingPeriod: 3600,
MaxJailedPercentage: sdk.NewDecWithPrec(25, 2),
MaxSlashingPercentage: sdk.NewDecWithPrec(1, 2),
MinCustodyReward: 200,
MaxCustodyTxSize: 8192,
MaxCustodyBufferSize: 10,
AbstentionRankDecreaseAmount: 1,
MaxAbstention: 2,
MinCollectiveBond: 100_000, // in KEX
MinCollectiveBondingTime: 86400, // in seconds
MaxCollectiveOutputs: 10,
MinCollectiveClaimPeriod: 14400, // 4hrs
ValidatorRecoveryBond: 300000, // 300k KEX
MaxAnnualInflation: sdk.NewDecWithPrec(35, 2),
MaxProposalTitleSize: 128,
MaxProposalDescriptionSize: 1024,
MaxProposalPollOptionSize: 64,
MaxProposalPollOptionCount: 128,
MinDappBond: 1000000,
MaxDappBond: 10000000,
DappBondDuration: 604800,
DappVerifierBond: sdk.NewDecWithPrec(1, 3), //0.1%
DappAutoDenounceTime: 60, // 60s
DappMischanceRankDecreaseAmount: 1,
DappMaxMischance: 10,
DappInactiveRankDecreasePercent: 10,
DappPoolSlippageDefault: sdk.NewDecWithPrec(1, 1), // 10%
MintingFtFee: 100_000_000_000_000,
MintingNftFee: 100_000_000_000_000,
VetoThreshold: sdk.NewDecWithPrec(3340, 2), //33.40%
AutocompoundIntervalNumBlocks: 17280,
},
ExecutionFees: govGenesisV01228.ExecutionFees,
PoorNetworkMessages: govGenesisV01228.PoorNetworkMessages,
Proposals: []govtypes.Proposal{}, // govGenesisV01228.Proposals,
Votes: []govtypes.Vote{}, // govGenesisV01228.Votes,
DataRegistry: govGenesisV01228.DataRegistry,
IdentityRecords: govGenesisV01228.IdentityRecords,
LastIdentityRecordId: govGenesisV01228.LastIdentityRecordId,
IdRecordsVerifyRequests: govGenesisV01228.IdRecordsVerifyRequests,
LastIdRecordVerifyRequestId: govGenesisV01228.LastIdRecordVerifyRequestId,
ProposalDurations: make(map[string]uint64),
}

// upgrade gov genesis for more role permissions
govGenesis := govtypes.GenesisState{}
err = cdc.UnmarshalJSON(genesisState[govtypes.ModuleName], &govGenesis)
if err == nil {
govGenesis.RolePermissions[govtypes.RoleSudo] = govtypes.DefaultGenesis().RolePermissions[govtypes.RoleSudo]
genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenesis)
} else {
fmt.Println("parse error for latest gov genesis", err)
fmt.Println("trying to parse v03123 gov genesis for following error on genesis parsing")
govGenesisV03123 := make(map[string]interface{})
err = json.Unmarshal(genesisState[govtypes.ModuleName], &govGenesisV03123)
if err != nil {
panic(err)
genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenesis)
} else {
fmt.Println("GovGenesis01228 unmarshal test: ", err)
fmt.Println("Skipping governance module upgrade since it is not v0.1.22.8 genesis")
}
govGenesisV03123["proposals"] = []govtypes.Proposal{}
govGenesisV03123["votes"] = []govtypes.Vote{}
bz, err := json.Marshal(&govGenesisV03123)
if err != nil {
panic(err)

// upgrade gov genesis for more role permissions
govGenesis := govtypes.GenesisState{}
err = cdc.UnmarshalJSON(genesisState[govtypes.ModuleName], &govGenesis)
if err == nil {
govGenesis.RolePermissions[govtypes.RoleSudo] = govtypes.DefaultGenesis().RolePermissions[govtypes.RoleSudo]
genesisState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenesis)
} else {
fmt.Println("parse error for latest gov genesis", err)
fmt.Println("trying to parse v03123 gov genesis for following error on genesis parsing")
govGenesisV03123 := make(map[string]interface{})
err = json.Unmarshal(genesisState[govtypes.ModuleName], &govGenesisV03123)
if err != nil {
panic(err)
}
govGenesisV03123["proposals"] = []govtypes.Proposal{}
govGenesisV03123["votes"] = []govtypes.Vote{}
bz, err := json.Marshal(&govGenesisV03123)
if err != nil {
panic(err)
}
genesisState[govtypes.ModuleName] = bz
}
genesisState[govtypes.ModuleName] = bz
}

appState, err := json.MarshalIndent(genesisState, "", " ")
if err != nil {
return errors.Wrap(err, "Failed to marshall default genesis state")
return errors.Wrap(err, "Failed to marshal default genesis state")
}

genDoc.AppState = appState

if jsonMinimize, _ := cmd.Flags().GetBool(FlagJsonMinimize); jsonMinimize {

genDocBytes, err := tmjson.Marshal(genDoc)
if err != nil {
return err
Expand All @@ -262,6 +280,7 @@ $ %s new-genesis-from-exported exported-genesis.json new-genesis.json
},
}
cmd.Flags().Bool(FlagJsonMinimize, true, "flag to export genesis in minimized version")
cmd.Flags().String(FlagModulesOnly, "", "flag to derive only specific modules - one of followings auth,bank,customstaking,customslashing,evidence,consensus,params,upgrade,recovery,customgov,spending,distributor,basket,ubi,tokens,custody,multistaking,collectives,layer2")

return cmd
}
Loading