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!: use versioned keys for dynamically adding and remove commit stores #3320

Merged
merged 14 commits into from
Apr 17, 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
462 changes: 143 additions & 319 deletions app/app.go

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ func TestNew(t *testing.T) {
logger := log.NewNopLogger()
db := tmdb.NewMemDB()
traceStore := &NoopWriter{}
loadLatest := true
invCheckPeriod := uint(1)
encodingConfig := encoding.MakeConfig(app.ModuleEncodingRegisters...)
upgradeHeight := int64(0)
appOptions := NoopAppOptions{}

got := app.New(logger, db, traceStore, loadLatest, invCheckPeriod, encodingConfig, upgradeHeight, appOptions)
got := app.New(logger, db, traceStore, invCheckPeriod, encodingConfig, upgradeHeight, appOptions)

t.Run("initializes ICAHostKeeper", func(t *testing.T) {
assert.NotNil(t, got.ICAHostKeeper)
Expand Down
31 changes: 28 additions & 3 deletions app/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,6 @@ func (m *Manager) assertNoForgottenModules(setOrderFnName string, moduleNames []
// MigrationHandler is the migration function that each module registers.
type MigrationHandler func(sdk.Context) error

// VersionMap is a map of moduleName -> version
type VersionMap map[string]uint64

// RunMigrations performs in-place store migrations for all modules. This
// function MUST be called when the state machine changes appVersion
func (m Manager) RunMigrations(ctx sdk.Context, cfg sdkmodule.Configurator, fromVersion, toVersion uint64) error {
Expand Down Expand Up @@ -335,6 +332,22 @@ func (m *Manager) EndBlock(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
}
}

// GetVersionMap gets consensus version from all modules
func (m *Manager) GetVersionMap(version uint64) sdkmodule.VersionMap {
vermap := make(sdkmodule.VersionMap)
if version > m.lastVersion || version < m.firstVersion {
return vermap
}

for _, v := range m.versionedModules[version] {
version := v.ConsensusVersion()
name := v.Name()
vermap[name] = version
}

return vermap
}

// ModuleNames returns list of all module names, without any particular order.
func (m *Manager) ModuleNames(version uint64) []string {
modules, ok := m.versionedModules[version]
Expand All @@ -351,6 +364,7 @@ func (m *Manager) ModuleNames(version uint64) []string {
return ms
}

// SupportedVersions returns all the supported versions for the module manager
func (m *Manager) SupportedVersions() []uint64 {
output := make([]uint64, 0, m.lastVersion-m.firstVersion+1)
for version := m.firstVersion; version <= m.lastVersion; version++ {
Expand Down Expand Up @@ -385,6 +399,17 @@ func (m *Manager) checkUpgradeSchedule() error {
return nil
}

// assertMatchingModules performs a sanity check that the basic module manager
// contains all the same modules present in the module manager
func (m *Manager) AssertMatchingModules(basicModuleManager sdkmodule.BasicManager) error {
for _, module := range m.allModules {
if _, exists := basicModuleManager[module.Name()]; !exists {
return fmt.Errorf("module %s not found in basic module manager", module.Name())
}
}
return nil
}

// DefaultMigrationsOrder returns a default migrations order: ascending alphabetical by module name,
// except x/auth which will run last, see:
// https://github.com/cosmos/cosmos-sdk/issues/10591
Expand Down
Loading
Loading