-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
fix: Fix v0.45->v0.46 migration #12028
Changes from 6 commits
f7f181b
543fe08
11a48e4
9884ac5
fbb5bab
3146574
8a8b57b
73dfe79
55ae6b7
881179a
d8b5f0c
f9e46fb
26eebaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,14 @@ package server | |
// DONTCOVER | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
cfg "github.com/tendermint/tendermint/config" | ||
pvm "github.com/tendermint/tendermint/privval" | ||
"github.com/tendermint/tendermint/scripts/keymigrate" | ||
"github.com/tendermint/tendermint/scripts/scmigrate" | ||
tversion "github.com/tendermint/tendermint/version" | ||
"sigs.k8s.io/yaml" | ||
|
||
|
@@ -123,3 +127,67 @@ func VersionCmd() *cobra.Command { | |
}, | ||
} | ||
} | ||
|
||
// MakeKeyMigrateCommand is ported from tendermint's key-migrate command, but | ||
// uses the SDK's own server.Context. | ||
// ref: https://github.com/tendermint/tendermint/blob/master/UPGRADING.md#database-key-format-changes | ||
func MakeKeyMigrateCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "key-migrate", | ||
Short: "Run TendermintDatabase key migration", | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx, cancel := context.WithCancel(cmd.Context()) | ||
defer cancel() | ||
|
||
serverCtx := GetServerContextFromCmd(cmd) | ||
config := serverCtx.Config | ||
|
||
contexts := []string{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm shocked we have to actually write any substantial code here. I would've presumed Tendermint would've exposed a command that'll do all of this for us? In any case, does Tendermint not expose the contexts we want to migrate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TM exposes: But it needs additional flags to get the DB dir right. In this PR, we use the same code, but with I couldn't think of less code re-use, best I could do was to mention this was copy-pasted from tendermint - like other commands in that file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Such an easy problem to solve if the TM command just had a function that the command called instead. Sigh... |
||
// this is ordered to put the | ||
// (presumably) biggest/most important | ||
// subsets first. | ||
"blockstore", | ||
"state", | ||
"peerstore", | ||
"tx_index", | ||
"evidence", | ||
"light", | ||
} | ||
|
||
for idx, dbctx := range contexts { | ||
serverCtx.Logger.Info("beginning a key migration", | ||
"dbctx", dbctx, | ||
"num", idx+1, | ||
"total", len(contexts), | ||
) | ||
|
||
db, err := cfg.DefaultDBProvider(&cfg.DBContext{ | ||
ID: dbctx, | ||
Config: config, | ||
}) | ||
|
||
if err != nil { | ||
return fmt.Errorf("constructing database handle: %w", err) | ||
} | ||
|
||
if err = keymigrate.Migrate(ctx, db); err != nil { | ||
return fmt.Errorf("running migration for context %q: %w", | ||
dbctx, err) | ||
} | ||
|
||
if dbctx == "blockstore" { | ||
if err := scmigrate.Migrate(ctx, db); err != nil { | ||
return fmt.Errorf("running seen commit migration: %w", err) | ||
|
||
} | ||
} | ||
} | ||
|
||
serverCtx.Logger.Info("completed database migration successfully") | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -321,9 +321,6 @@ func NewSimApp( | |
// set the governance module account as the authority for conducting upgrades | ||
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) | ||
|
||
// RegisterUpgradeHandlers is used for registering any on-chain upgrades | ||
app.RegisterUpgradeHandlers() | ||
|
||
app.NFTKeeper = nftkeeper.NewKeeper(keys[nftkeeper.StoreKey], appCodec, app.AccountKeeper, app.BankKeeper) | ||
|
||
// create evidence keeper with router | ||
|
@@ -408,6 +405,10 @@ func NewSimApp( | |
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) | ||
app.mm.RegisterServices(app.configurator) | ||
|
||
// RegisterUpgradeHandlers is used for registering any on-chain upgrades. | ||
// Make sure it's called after `app.mm` and `app.configurator` are set. | ||
app.RegisterUpgradeHandlers() | ||
Comment on lines
+393
to
+395
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel this should be communicated in the release notes too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Release notes imo are brief & high-level (see proposed defs in #11587). How about int he UPGRADING.md document? |
||
|
||
// add test gRPC service for testing gRPC queries in isolation | ||
testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import ( | |
"github.com/cosmos/cosmos-sdk/x/staking/types" | ||
) | ||
|
||
// MigrateStore performs in-place store migrations from v0.43/v0.44 to v0.45. | ||
// MigrateStore performs in-place store migrations from v0.43/v0.44/v0.45 to v0.46. | ||
// The migration includes: | ||
// | ||
// - Setting the MinCommissionRate param in the paramstore | ||
|
@@ -19,6 +19,10 @@ func MigrateStore(ctx sdk.Context, storeKey storetypes.StoreKey, cdc codec.Binar | |
} | ||
|
||
func migrateParamsStore(ctx sdk.Context, paramstore paramtypes.Subspace) { | ||
paramstore.WithKeyTable(types.ParamKeyTable()) | ||
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) | ||
if paramstore.HasKeyTable() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. encountered the same bug as in #9484, so applied the same fix |
||
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) | ||
} else { | ||
paramstore.WithKeyTable(types.ParamKeyTable()) | ||
paramstore.Set(ctx, types.KeyMinCommissionRate, types.DefaultMinCommissionRate) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@facundomedica In the upgrade handler, no. See the original issue, we need to run the key migration before starting tendermint, so way before the upgrade handler is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative solution, the SDK's
start
command is a combination of TM'skey-migrate
+start
.key-migrate
is idempotent, so it can be run multiple times.However, if we decide to show logs, as we do in this PR and as it's done in tendermint, then those logs will be shown on each startup:
Any opinions on separate
key-migrate
andstart
commands VS onestart
command which runskey-migrate
under the hood?