-
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
v2 genesis #20076
v2 genesis #20076
Changes from all commits
50a2333
481d327
f971ee6
f547b91
326345d
db09b12
1f98e32
b4452e1
b7ab61e
46992b5
41cf76b
b468294
aac84e3
12a52c9
ab6d7aa
fe760b7
8a404fd
c725900
8933045
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
package app | ||
|
||
var RuntimeIdentity = []byte("runtime") | ||
var ConsensusIdentity = []byte("consensus") | ||
var ( | ||
RuntimeIdentity = []byte("runtime") | ||
ConsensusIdentity = []byte("consensus") | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
sdkmodule "github.com/cosmos/cosmos-sdk/types/module" | ||
"github.com/cosmos/cosmos-sdk/x/genutil/types" | ||
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. To remove this dependency a genesis themed extension interface in |
||
) | ||
|
||
type MM struct { | ||
|
@@ -140,13 +141,58 @@ | |
return nil | ||
} | ||
|
||
// ExportGenesis performs export genesis functionality for modules | ||
func (m *MM) ExportGenesis(ctx context.Context, modulesToExport ...string) (map[string]json.RawMessage, error) { | ||
if len(modulesToExport) == 0 { | ||
modulesToExport = m.config.ExportGenesis | ||
} | ||
// InitGenesisJSON performs init genesis functionality for modules from genesis data in JSON format | ||
func (m *MM) InitGenesisJSON(ctx context.Context, genesisData map[string]json.RawMessage, txHandler func(json.RawMessage) error) error { | ||
m.logger.Info("initializing blockchain state from genesis.json", "order", m.config.InitGenesis) | ||
var seenValUpdates bool | ||
for _, moduleName := range m.config.InitGenesis { | ||
if genesisData[moduleName] == nil { | ||
continue | ||
} | ||
|
||
mod := m.modules[moduleName] | ||
|
||
// skip genutil as it's a special module that handles gentxs | ||
// TODO: should this be an empty extension interface on genutil for server v2? | ||
if moduleName == "genutil" { | ||
var genesisState types.GenesisState | ||
err := m.cdc.UnmarshalJSON(genesisData[moduleName], &genesisState) | ||
if err != nil { | ||
return fmt.Errorf("failed to unmarshal %s genesis state: %w", moduleName, err) | ||
} | ||
for _, jsonTx := range genesisState.GenTxs { | ||
txHandler(jsonTx) | ||
|
||
} | ||
continue | ||
} | ||
|
||
return m.ExportGenesisForModules(ctx, modulesToExport...) | ||
// we might get an adapted module, a native core API module or a legacy module | ||
if _, ok := mod.(appmodule.HasGenesisAuto); ok { | ||
panic(fmt.Sprintf("module %s isn't server/v2 compatible", moduleName)) | ||
} else if module, ok := mod.(appmodulev2.HasGenesis); ok { | ||
m.logger.Debug("running initialization for module", "module", moduleName) | ||
if err := module.InitGenesis(ctx, genesisData[moduleName]); err != nil { | ||
return err | ||
} | ||
} else if module, ok := mod.(appmodulev2.HasABCIGenesis); ok { | ||
m.logger.Debug("running initialization for module", "module", moduleName) | ||
moduleValUpdates, err := module.InitGenesis(ctx, genesisData[moduleName]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// use these validator updates if provided, the module manager assumes | ||
// only one module will update the validator set | ||
if len(moduleValUpdates) > 0 { | ||
if seenValUpdates { | ||
return errors.New("validator InitGenesis updates already set by a previous module") | ||
} else { | ||
seenValUpdates = true | ||
} | ||
} | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// ExportGenesisForModules performs export genesis functionality for modules | ||
|
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.
For usage see: https://github.com/cosmos/cosmos-sdk/blob/kocu/genesis-v2/x/distribution/keeper/abci.go#L27
I think this can be resolved with #19602 which adds a message to retrieve
CometInfo
from the RouterService, or optionally including a keeper.