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

feat(runtime/v2): store loader on simappv2 #21704

Merged
merged 57 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ebf5006
add state export
tac0turtle Jun 24, 2024
268c034
minor
tac0turtle Jun 24, 2024
babf339
Merge branch 'main' into marko/state_export
tac0turtle Jul 1, 2024
6780043
comment out export zero height
tac0turtle Jul 1, 2024
61c0343
Merge branch 'main' into marko/state_export
randygrok Jul 30, 2024
b8ac0e5
add logic for export app state and bootstrap simapp tests
randygrok Aug 6, 2024
a1b0a5f
fix bug with export genesis nil pointer
randygrok Aug 6, 2024
71d0027
some additions to continue the test
randygrok Aug 6, 2024
cadccd4
add context with value
randygrok Aug 6, 2024
7bc73f0
remove commented code
randygrok Aug 7, 2024
728313a
go mod tidy all
randygrok Aug 7, 2024
e97fda6
add version on export
randygrok Aug 7, 2024
57c9751
include export validators
randygrok Aug 8, 2024
a32d778
add validators into status
randygrok Aug 8, 2024
4bcf345
include new types mode
randygrok Aug 9, 2024
7006da5
go mod tidy all
randygrok Aug 13, 2024
91570fb
temp commit, include logic for zeroheight
randygrok Aug 13, 2024
de93866
remove zero height part
randygrok Aug 13, 2024
9fc2546
add export
randygrok Aug 13, 2024
7a1fa60
apply into simapp v2
randygrok Aug 13, 2024
6b32d53
Merge remote-tracking branch 'origin/main' into randy/export-genesis
randygrok Aug 13, 2024
db542cf
remove option to export certain modules only
randygrok Aug 13, 2024
70f1090
remove modules to export feature
randygrok Aug 13, 2024
ea0193d
remove modules to export feature part 2
randygrok Aug 13, 2024
c552beb
remove debug entry in manager
randygrok Aug 13, 2024
f67770e
delete commented code
randygrok Aug 14, 2024
2948e09
rename RunWithCtx
randygrok Aug 14, 2024
a0ffd0a
race condition not fixed yet
randygrok Aug 14, 2024
519d6b7
remove concurrent export
randygrok Aug 14, 2024
f199f06
include issue number
randygrok Aug 14, 2024
11ec8d2
fix lint
randygrok Aug 15, 2024
a634633
fix lint, last
randygrok Aug 15, 2024
e0093cf
move ExportedApp to genutil
randygrok Aug 15, 2024
5ab7c1a
Merge branch 'main' into randy/export-genesis
randygrok Aug 15, 2024
da07a4a
lint
randygrok Aug 15, 2024
264434e
Merge branch 'randy/export-genesis' of github.com-randy:cosmos/cosmos…
randygrok Aug 15, 2024
aedc7b0
remove duplicated package on import
randygrok Aug 15, 2024
8f97b21
lint
randygrok Aug 15, 2024
9156b86
linter
randygrok Aug 15, 2024
858af16
pass linter
randygrok Aug 15, 2024
a789413
remove unsafe message
randygrok Aug 15, 2024
dee4c3b
remove command
randygrok Aug 15, 2024
5051c67
review changes
randygrok Aug 15, 2024
73e839b
Revert "remove option to export certain modules only"
randygrok Aug 15, 2024
98b4397
remove comment
randygrok Aug 15, 2024
4324f42
Merge branch 'main' into randy/export-genesis
randygrok Aug 15, 2024
3ea6367
bring back viper sets
randygrok Aug 16, 2024
1874e0c
Merge branch 'randy/export-genesis' of github.com-randy:cosmos/cosmos…
randygrok Aug 16, 2024
64eb9a4
temp commit with only store changes
randygrok Sep 13, 2024
8035440
Merge remote-tracking branch 'origin/main' into feat/store-loader
randygrok Sep 13, 2024
1aeda3a
add upgrade handler
randygrok Sep 13, 2024
346e715
bring back version
randygrok Sep 13, 2024
7586ee2
move UpgradeStoreLoader to runtime mod
randygrok Sep 13, 2024
4ecf936
fix from review
randygrok Sep 13, 2024
c732286
Merge branch 'main' into feat/store-loader
randygrok Sep 13, 2024
b2082c8
add changelog
randygrok Sep 13, 2024
8c23aa5
lint upgrades
randygrok Sep 13, 2024
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
9 changes: 8 additions & 1 deletion runtime/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ type App[T transaction.Tx] struct {
// GRPCMethodsToMessageMap maps gRPC method name to a function that decodes the request
// bytes into a gogoproto.Message, which then can be passed to appmanager.
GRPCMethodsToMessageMap map[string]func() gogoproto.Message

storeLoader StoreLoader
}

// Name returns the app name.
Expand All @@ -68,9 +70,14 @@ func (a *App[T]) DefaultGenesis() map[string]json.RawMessage {
return a.moduleManager.DefaultGenesis()
}

// SetStoreLoader sets the store loader.
func (a *App[T]) SetStoreLoader(loader StoreLoader) {
a.storeLoader = loader
}

// LoadLatest loads the latest version.
func (a *App[T]) LoadLatest() error {
return a.db.LoadLatestVersion()
return a.storeLoader(a.db)
}

// LoadHeight loads a particular height
Expand Down
1 change: 1 addition & 0 deletions runtime/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func ProvideAppBuilder[T transaction.Tx](
msgRouterBuilder: msgRouterBuilder,
queryRouterBuilder: stf.NewMsgRouterBuilder(), // TODO dedicated query router
GRPCMethodsToMessageMap: map[string]func() proto.Message{},
storeLoader: DefaultStoreLoader,
}
appBuilder := &AppBuilder[T]{app: app}

Expand Down
31 changes: 31 additions & 0 deletions runtime/v2/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package runtime

import (
"fmt"

"cosmossdk.io/core/store"
"cosmossdk.io/server/v2/stf"
storev2 "cosmossdk.io/store/v2"
Expand Down Expand Up @@ -55,3 +57,32 @@ type Store interface {
// LastCommitID returns the latest commit ID
LastCommitID() (proof.CommitID, error)
}

// StoreLoader allows for custom loading of the store, this is useful when upgrading the store from a previous version
type StoreLoader func(store Store) error

// DefaultStoreLoader just calls LoadLatestVersion on the store
func DefaultStoreLoader(store Store) error {
return store.LoadLatestVersion()
}

func V2UpgradeStoreLoader(upgradeHeight int64, storeUpgrades *store.StoreUpgrades) StoreLoader {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a go doc?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that it is in runtime/v2, no need to prepend it by V2 imho.
For consistency, shall we place the other one from x/upgrade in runtime?
And just alias it back in x/upgrade for not introducing breaking changes?

Additionally, can we add a :tip: in x/upgrade docs mentioning for server/v2 this helper is in runtime/v2

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

return func(store Store) error {
latestVersion, err := store.GetLatestVersion()
if err != nil {
return err
}

if uint64(upgradeHeight) == latestVersion+1 {
if len(storeUpgrades.Deleted) > 0 || len(storeUpgrades.Added) > 0 {
if upgrader, ok := store.(storev2.UpgradeableStore); ok {
return upgrader.LoadVersionAndUpgrade(latestVersion, storeUpgrades)
}

return fmt.Errorf("store does not support upgrades")
}
}

return DefaultStoreLoader(store)
}
}
2 changes: 2 additions & 0 deletions simapp/v2/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/viper"
"github.com/stretchr/testify/require"

app2 "cosmossdk.io/core/app"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

"cosmossdk.io/core/comet"
context2 "cosmossdk.io/core/context"
"cosmossdk.io/core/server"
Expand All @@ -21,6 +22,7 @@ import (
serverv2 "cosmossdk.io/server/v2"
comettypes "cosmossdk.io/server/v2/cometbft/types"
"cosmossdk.io/store/v2/db"
authtypes "cosmossdk.io/x/auth/types"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably from some of my tests, will remove

banktypes "cosmossdk.io/x/bank/types"

"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down
5 changes: 2 additions & 3 deletions simapp/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package simapp

import (
"context"
"cosmossdk.io/runtime/v2"

"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
Expand Down Expand Up @@ -44,8 +45,6 @@ func (app *SimApp[T]) RegisterUpgradeHandlers() {
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}

// configure store loader that checks if version == upgradeHeight and applies store upgrades
_ = storeUpgrades
// app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
app.SetStoreLoader(runtime.V2UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
}
Loading