Skip to content

Commit 43491c4

Browse files
committed
test short key
1 parent 0bd4589 commit 43491c4

File tree

6 files changed

+210
-27
lines changed

6 files changed

+210
-27
lines changed

aclmapping/staking/mappings.go

+48-24
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,20 @@ func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, ms
6969

7070
// Before Unbond Distribution Hook
7171
{
72-
AccessType: sdkacltypes.AccessType_READ,
73-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
74-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
72+
AccessType: sdkacltypes.AccessType_READ,
73+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
74+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
75+
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
76+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
77+
)),
7578
},
7679
{
77-
AccessType: sdkacltypes.AccessType_WRITE,
78-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
79-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
80+
AccessType: sdkacltypes.AccessType_WRITE,
81+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
82+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
83+
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
84+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
85+
)),
8086
},
8187
{
8288
AccessType: sdkacltypes.AccessType_READ,
@@ -293,9 +299,12 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,
293299

294300
// Before Unbond Distribution Hook
295301
{
296-
AccessType: sdkacltypes.AccessType_READ,
297-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
298-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
302+
AccessType: sdkacltypes.AccessType_READ,
303+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
304+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
305+
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
306+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
307+
)),
299308
},
300309
{
301310
AccessType: sdkacltypes.AccessType_READ,
@@ -353,9 +362,12 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,
353362
},
354363

355364
{
356-
AccessType: sdkacltypes.AccessType_WRITE,
357-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
358-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
365+
AccessType: sdkacltypes.AccessType_WRITE,
366+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
367+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
368+
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
369+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
370+
)),
359371
},
360372

361373
// Update the delegator and validator account balances
@@ -484,14 +496,20 @@ func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Cont
484496

485497
// Before Unbond Distribution Hook
486498
{
487-
AccessType: sdkacltypes.AccessType_READ,
488-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
489-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)),
499+
AccessType: sdkacltypes.AccessType_READ,
500+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
501+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
502+
keeper.StakingKeeper.GetValidatorID(ctx, srcValidatorAddr),
503+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
504+
)),
490505
},
491506
{
492-
AccessType: sdkacltypes.AccessType_READ,
493-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
494-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)),
507+
AccessType: sdkacltypes.AccessType_READ,
508+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
509+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
510+
keeper.StakingKeeper.GetValidatorID(ctx, dstValidatorAddr),
511+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
512+
)),
495513
},
496514

497515
{
@@ -582,14 +600,20 @@ func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Cont
582600
},
583601

584602
{
585-
AccessType: sdkacltypes.AccessType_WRITE,
586-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
587-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)),
603+
AccessType: sdkacltypes.AccessType_WRITE,
604+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
605+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
606+
keeper.StakingKeeper.GetValidatorID(ctx, srcValidatorAddr),
607+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
608+
)),
588609
},
589610
{
590-
AccessType: sdkacltypes.AccessType_WRITE,
591-
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
592-
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)),
611+
AccessType: sdkacltypes.AccessType_WRITE,
612+
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
613+
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
614+
keeper.StakingKeeper.GetValidatorID(ctx, dstValidatorAddr),
615+
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
616+
)),
593617
},
594618

595619
// Update the delegator and validator account balances

app/app.go

+26
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,32 @@ func New(
721721
// this line is used by starport scaffolding # stargate/app/initGenesis
722722
)
723723

724+
app.mm.SetOrderMigrations(
725+
upgradetypes.ModuleName,
726+
paramstypes.ModuleName,
727+
capabilitytypes.ModuleName,
728+
authtypes.ModuleName,
729+
banktypes.ModuleName,
730+
stakingtypes.ModuleName,
731+
distrtypes.ModuleName,
732+
slashingtypes.ModuleName,
733+
govtypes.ModuleName,
734+
minttypes.ModuleName,
735+
vestingtypes.ModuleName,
736+
crisistypes.ModuleName,
737+
ibchost.ModuleName,
738+
dexmoduletypes.ModuleName,
739+
genutiltypes.ModuleName,
740+
evidencetypes.ModuleName,
741+
ibctransfertypes.ModuleName,
742+
feegrant.ModuleName,
743+
oracletypes.ModuleName,
744+
tokenfactorytypes.ModuleName,
745+
epochmoduletypes.ModuleName,
746+
wasm.ModuleName,
747+
acltypes.ModuleName,
748+
)
749+
724750
app.mm.RegisterInvariants(&app.CrisisKeeper)
725751
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
726752
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())

cmd/seid/cmd/migrate.go

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package cmd
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"io"
7+
"os"
8+
"path/filepath"
9+
10+
"github.com/cosmos/cosmos-sdk/client"
11+
clientconfig "github.com/cosmos/cosmos-sdk/client/config"
12+
"github.com/cosmos/cosmos-sdk/client/flags"
13+
"github.com/cosmos/cosmos-sdk/server"
14+
"github.com/cosmos/cosmos-sdk/server/config"
15+
"github.com/cosmos/cosmos-sdk/server/types"
16+
sdk "github.com/cosmos/cosmos-sdk/types"
17+
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
18+
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
19+
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
20+
"github.com/sei-protocol/sei-chain/app"
21+
"github.com/spf13/cobra"
22+
abci "github.com/tendermint/tendermint/abci/types"
23+
"github.com/tendermint/tendermint/libs/cli"
24+
tmtypes "github.com/tendermint/tendermint/types"
25+
dbm "github.com/tendermint/tm-db"
26+
)
27+
28+
func MigrateCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
29+
cmd := &cobra.Command{
30+
Use: "migrate_oneoff",
31+
Short: "",
32+
Long: "",
33+
PreRunE: func(cmd *cobra.Command, _ []string) error {
34+
serverCtx := server.GetServerContextFromCmd(cmd)
35+
36+
// Bind flags to the Context's Viper so the app construction can set
37+
// options accordingly.
38+
serverCtx.Viper.BindPFlags(cmd.Flags())
39+
40+
_, err := server.GetPruningOptionsFromFlags(serverCtx.Viper)
41+
return err
42+
},
43+
RunE: func(cmd *cobra.Command, _ []string) error {
44+
serverCtx := server.GetServerContextFromCmd(cmd)
45+
clientCtx, err := client.GetClientQueryContext(cmd)
46+
if err != nil {
47+
return err
48+
}
49+
clientCtx, err = clientconfig.ReadFromClientConfig(clientCtx)
50+
if err != nil {
51+
return err
52+
}
53+
54+
chainID := clientCtx.ChainID
55+
flagChainID, _ := cmd.Flags().GetString(server.FlagChainID)
56+
if flagChainID != "" {
57+
if flagChainID != chainID {
58+
panic(fmt.Sprintf("chain-id mismatch: %s vs %s. The chain-id passed in is different from the value in ~/.sei/config/client.toml \n", flagChainID, chainID))
59+
}
60+
chainID = flagChainID
61+
}
62+
63+
serverCtx.Viper.Set(flags.FlagChainID, chainID)
64+
65+
genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
66+
if genesisFile.ChainID != clientCtx.ChainID {
67+
panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID))
68+
}
69+
70+
cfg := serverCtx.Config
71+
home := cfg.RootDir
72+
73+
traceWriterFile := serverCtx.Viper.GetString("trace-store")
74+
db, err := openDB(home)
75+
if err != nil {
76+
return err
77+
}
78+
79+
traceWriter, err := openTraceWriter(traceWriterFile)
80+
if err != nil {
81+
return err
82+
}
83+
84+
config, err := config.GetConfig(serverCtx.Viper)
85+
if err != nil {
86+
return err
87+
}
88+
89+
if err := config.ValidateBasic(serverCtx.Config); err != nil {
90+
serverCtx.Logger.Error("WARNING: The minimum-gas-prices config in app.toml is set to the empty string. " +
91+
"This defaults to 0 in the current version, but will error in the next version " +
92+
"(SDK v0.45). Please explicitly put the desired minimum-gas-prices in your app.toml.")
93+
}
94+
a := appCreator(serverCtx.Logger, db, traceWriter, serverCtx.Config, serverCtx.Viper)
95+
seiApp := a.(*app.App)
96+
seiApp.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{})
97+
stakingMigrator := stakingkeeper.NewMigrator(seiApp.StakingKeeper)
98+
authMigrator := authkeeper.NewMigrator(seiApp.AccountKeeper, seiApp.GRPCQueryRouter())
99+
distMigrator := distributionkeeper.NewMigrator(seiApp.DistrKeeper)
100+
stakingMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
101+
fmt.Println("migrated staking")
102+
authMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
103+
fmt.Println("migrated auth")
104+
distMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
105+
fmt.Println("migrated distribution")
106+
_, err = seiApp.Commit(context.Background())
107+
if err != nil {
108+
panic(err)
109+
}
110+
return nil
111+
},
112+
}
113+
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
114+
cmd.Flags().String(server.FlagChainID, "", "Chain ID")
115+
return cmd
116+
}
117+
118+
func openDB(rootDir string) (dbm.DB, error) {
119+
dataDir := filepath.Join(rootDir, "data")
120+
return sdk.NewLevelDB("application", dataDir)
121+
}
122+
123+
func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
124+
if traceWriterFile == "" {
125+
return
126+
}
127+
return os.OpenFile(
128+
traceWriterFile,
129+
os.O_WRONLY|os.O_APPEND|os.O_CREATE,
130+
0666,
131+
)
132+
}

cmd/seid/cmd/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func initRootCmd(
137137
config.Cmd(),
138138
pruning.PruningCmd(newApp),
139139
CompactCmd(app.DefaultNodeHome),
140+
MigrateCmd(newApp, app.DefaultNodeHome),
140141
)
141142

142143
tracingProviderOpts, err := tracing.GetTracerProviderOptions(tracing.DefaultTracingURL)

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ require (
272272
replace (
273273
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.0.2
274274
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
275-
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.43
275+
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.43-short-key
276276
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.4
277277
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.1.0
278278
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod
10721072
github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI=
10731073
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
10741074
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
1075-
github.com/sei-protocol/sei-cosmos v0.2.43 h1:WZJJZrzPScXzbNdCYwFfca09fLV1jAEIzEcQuaIhKEY=
1076-
github.com/sei-protocol/sei-cosmos v0.2.43/go.mod h1:LSR2ut3T6Sv24d8TkXSh9hQ8fskdpI6PNUjY3NQ3pcA=
1075+
github.com/sei-protocol/sei-cosmos v0.2.43-short-key h1:ICzjpuy8h5opqAqs+7C5edsWqhtPyShNb5RwcX9ik5M=
1076+
github.com/sei-protocol/sei-cosmos v0.2.43-short-key/go.mod h1:LSR2ut3T6Sv24d8TkXSh9hQ8fskdpI6PNUjY3NQ3pcA=
10771077
github.com/sei-protocol/sei-iavl v0.1.4 h1:lT5doPDTBq/UlbofQbM5iS01FbTSJttmA22+d0PJj5o=
10781078
github.com/sei-protocol/sei-iavl v0.1.4/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
10791079
github.com/sei-protocol/sei-ibc-go/v3 v3.1.0 h1:rFHk2R/3vbG9iNr7cYtVclW/UyEDSRFjNVPz60zZswU=

0 commit comments

Comments
 (0)