Skip to content

Commit

Permalink
test short key
Browse files Browse the repository at this point in the history
  • Loading branch information
codchen committed Jun 9, 2023
1 parent 0bd4589 commit 43491c4
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 27 deletions.
72 changes: 48 additions & 24 deletions aclmapping/staking/mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ func MsgDelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context, ms

// Before Unbond Distribution Hook
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},
{
AccessType: sdkacltypes.AccessType_READ,
Expand Down Expand Up @@ -293,9 +299,12 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,

// Before Unbond Distribution Hook
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},
{
AccessType: sdkacltypes.AccessType_READ,
Expand Down Expand Up @@ -353,9 +362,12 @@ func MsgUndelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Context,
},

{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(validatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, validatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},

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

// Before Unbond Distribution Hook
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, srcValidatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},
{
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_READ,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, dstValidatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},

{
Expand Down Expand Up @@ -582,14 +600,20 @@ func MsgBeginRedelegateDependencyGenerator(keeper aclkeeper.Keeper, ctx sdk.Cont
},

{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(srcValidatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, srcValidatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},
{
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(dstValidatorAddr, delegateAddr)),
AccessType: sdkacltypes.AccessType_WRITE,
ResourceType: sdkacltypes.ResourceType_KV_DISTRIBUTION_DELEGATOR_STARTING_INFO,
IdentifierTemplate: hex.EncodeToString(distributiontypes.GetDelegatorStartingInfoKey(
keeper.StakingKeeper.GetValidatorID(ctx, dstValidatorAddr),
keeper.AccountKeeper.GetAccount(ctx, delegateAddr).GetAccountNumber(),
)),
},

// Update the delegator and validator account balances
Expand Down
26 changes: 26 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,32 @@ func New(
// this line is used by starport scaffolding # stargate/app/initGenesis
)

app.mm.SetOrderMigrations(
upgradetypes.ModuleName,
paramstypes.ModuleName,
capabilitytypes.ModuleName,
authtypes.ModuleName,
banktypes.ModuleName,
stakingtypes.ModuleName,
distrtypes.ModuleName,
slashingtypes.ModuleName,
govtypes.ModuleName,
minttypes.ModuleName,
vestingtypes.ModuleName,
crisistypes.ModuleName,
ibchost.ModuleName,
dexmoduletypes.ModuleName,
genutiltypes.ModuleName,
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
feegrant.ModuleName,
oracletypes.ModuleName,
tokenfactorytypes.ModuleName,
epochmoduletypes.ModuleName,
wasm.ModuleName,
acltypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
Expand Down
132 changes: 132 additions & 0 deletions cmd/seid/cmd/migrate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package cmd

import (
"context"
"fmt"
"io"
"os"
"path/filepath"

"github.com/cosmos/cosmos-sdk/client"
clientconfig "github.com/cosmos/cosmos-sdk/client/config"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/server/config"
"github.com/cosmos/cosmos-sdk/server/types"
sdk "github.com/cosmos/cosmos-sdk/types"
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
"github.com/sei-protocol/sei-chain/app"
"github.com/spf13/cobra"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/cli"
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"
)

func MigrateCmd(appCreator types.AppCreator, defaultNodeHome string) *cobra.Command {
cmd := &cobra.Command{
Use: "migrate_oneoff",
Short: "",
Long: "",
PreRunE: func(cmd *cobra.Command, _ []string) error {
serverCtx := server.GetServerContextFromCmd(cmd)

// Bind flags to the Context's Viper so the app construction can set
// options accordingly.
serverCtx.Viper.BindPFlags(cmd.Flags())

_, err := server.GetPruningOptionsFromFlags(serverCtx.Viper)
return err
},
RunE: func(cmd *cobra.Command, _ []string) error {
serverCtx := server.GetServerContextFromCmd(cmd)
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
clientCtx, err = clientconfig.ReadFromClientConfig(clientCtx)
if err != nil {
return err
}

chainID := clientCtx.ChainID
flagChainID, _ := cmd.Flags().GetString(server.FlagChainID)
if flagChainID != "" {
if flagChainID != chainID {
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))
}
chainID = flagChainID
}

serverCtx.Viper.Set(flags.FlagChainID, chainID)

genesisFile, _ := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
if genesisFile.ChainID != clientCtx.ChainID {
panic(fmt.Sprintf("genesis file chain-id=%s does not equal config.toml chain-id=%s", genesisFile.ChainID, clientCtx.ChainID))
}

cfg := serverCtx.Config
home := cfg.RootDir

traceWriterFile := serverCtx.Viper.GetString("trace-store")
db, err := openDB(home)
if err != nil {
return err
}

traceWriter, err := openTraceWriter(traceWriterFile)
if err != nil {
return err
}

config, err := config.GetConfig(serverCtx.Viper)
if err != nil {
return err
}

if err := config.ValidateBasic(serverCtx.Config); err != nil {
serverCtx.Logger.Error("WARNING: The minimum-gas-prices config in app.toml is set to the empty string. " +
"This defaults to 0 in the current version, but will error in the next version " +
"(SDK v0.45). Please explicitly put the desired minimum-gas-prices in your app.toml.")
}
a := appCreator(serverCtx.Logger, db, traceWriter, serverCtx.Config, serverCtx.Viper)
seiApp := a.(*app.App)
seiApp.FinalizeBlock(context.Background(), &abci.RequestFinalizeBlock{})
stakingMigrator := stakingkeeper.NewMigrator(seiApp.StakingKeeper)
authMigrator := authkeeper.NewMigrator(seiApp.AccountKeeper, seiApp.GRPCQueryRouter())
distMigrator := distributionkeeper.NewMigrator(seiApp.DistrKeeper)
stakingMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
fmt.Println("migrated staking")
authMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
fmt.Println("migrated auth")
distMigrator.Migrate2to3(seiApp.GetContextForDeliverTx([]byte{}))
fmt.Println("migrated distribution")
_, err = seiApp.Commit(context.Background())
if err != nil {
panic(err)
}
return nil
},
}
cmd.Flags().String(cli.HomeFlag, defaultNodeHome, "node's home directory")
cmd.Flags().String(server.FlagChainID, "", "Chain ID")
return cmd
}

func openDB(rootDir string) (dbm.DB, error) {
dataDir := filepath.Join(rootDir, "data")
return sdk.NewLevelDB("application", dataDir)
}

func openTraceWriter(traceWriterFile string) (w io.Writer, err error) {
if traceWriterFile == "" {
return
}
return os.OpenFile(
traceWriterFile,
os.O_WRONLY|os.O_APPEND|os.O_CREATE,
0666,
)
}
1 change: 1 addition & 0 deletions cmd/seid/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func initRootCmd(
config.Cmd(),
pruning.PruningCmd(newApp),
CompactCmd(app.DefaultNodeHome),
MigrateCmd(newApp, app.DefaultNodeHome),
)

tracingProviderOpts, err := tracing.GetTracerProviderOptions(tracing.DefaultTracingURL)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ require (
replace (
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.0.2
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.43
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.2.43-short-key
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.4
github.com/cosmos/ibc-go/v3 => github.com/sei-protocol/sei-ibc-go/v3 v3.1.0
github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1072,8 +1072,8 @@ github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod
github.com/securego/gosec/v2 v2.11.0 h1:+PDkpzR41OI2jrw1q6AdXZCbsNGNGT7pQjal0H0cArI=
github.com/securego/gosec/v2 v2.11.0/go.mod h1:SX8bptShuG8reGC0XS09+a4H2BoWSJi+fscA+Pulbpo=
github.com/segmentio/fasthash v1.0.3/go.mod h1:waKX8l2N8yckOgmSsXJi7x1ZfdKZ4x7KRMzBtS3oedY=
github.com/sei-protocol/sei-cosmos v0.2.43 h1:WZJJZrzPScXzbNdCYwFfca09fLV1jAEIzEcQuaIhKEY=
github.com/sei-protocol/sei-cosmos v0.2.43/go.mod h1:LSR2ut3T6Sv24d8TkXSh9hQ8fskdpI6PNUjY3NQ3pcA=
github.com/sei-protocol/sei-cosmos v0.2.43-short-key h1:ICzjpuy8h5opqAqs+7C5edsWqhtPyShNb5RwcX9ik5M=
github.com/sei-protocol/sei-cosmos v0.2.43-short-key/go.mod h1:LSR2ut3T6Sv24d8TkXSh9hQ8fskdpI6PNUjY3NQ3pcA=
github.com/sei-protocol/sei-iavl v0.1.4 h1:lT5doPDTBq/UlbofQbM5iS01FbTSJttmA22+d0PJj5o=
github.com/sei-protocol/sei-iavl v0.1.4/go.mod h1:7PfkEVT5dcoQE+s/9KWdoXJ8VVVP1QpYYPLdxlkSXFk=
github.com/sei-protocol/sei-ibc-go/v3 v3.1.0 h1:rFHk2R/3vbG9iNr7cYtVclW/UyEDSRFjNVPz60zZswU=
Expand Down

0 comments on commit 43491c4

Please sign in to comment.