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

fix: export command #3450

Merged
merged 25 commits into from
May 14, 2024
Merged

fix: export command #3450

merged 25 commits into from
May 14, 2024

Conversation

rootulp
Copy link
Collaborator

@rootulp rootulp commented May 9, 2024

Closes #3392
Opens #3472

Fixes a few bugs:

  1. Previously all modules had ExportGenesis invoked on them even if they weren't supported by the current app version. Now we only call ExportGenesis for the modules that are supported by the current app version
  2. The export command wasn't updated to account for the changes in feat!: use versioned keys for dynamically adding and remove commit stores #3320 which force us to mount stores after app.New() based on the current app version
  3. The minfee module couldn't be exported b/c it didn't register a key table in ExportGenesis

Testing

I could export an app on app version 1 and 2. See output

@rootulp rootulp self-assigned this May 9, 2024
@rootulp
Copy link
Collaborator Author

rootulp commented May 9, 2024

Why is the Info command reseting baseapp.AppVersion from 2 -> 1?!

app/export.go Outdated
Comment on lines 22 to 23
app.InitializeAppVersion(ctx)
app.mountKeysAndInit(app.AppVersion())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is important because without this, we couldn't call export on the app because it wasn't fully initialized. A recent PR made it so that the app needs to have it's app version initialized + key stores mounted after app.New is invoked.

return servertypes.ExportedApp{
AppState: appState,
Validators: validators,
Height: height,
Height: app.getExportHeight(forZeroHeight),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

[refactor] this extracts logic to a helper to make it easier to read

Comment on lines +187 to 193
moduleNamesForVersion := m.ModuleNames(version)
moduleNamesToExport := filter(m.OrderExportGenesis, func(moduleName string) bool {
// filter out modules that are not supported by this version
return slices.Contains(moduleNamesForVersion, moduleName)
})
for _, moduleName := range moduleNamesToExport {
genesisData[moduleName] = modules[moduleName].ExportGenesis(ctx, cdc)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this fixes a bug so that ExportGenesis is only invoked on the modules that are supported for the given version

Copy link
Contributor

Choose a reason for hiding this comment

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

make sense

}
require.Equal(t, want, mm.ExportGenesis(ctx, cdc, 1))
})
t.Run("export genesis with one modules at version 1, one modules at version 2", func(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

unit tests the fix

Comment on lines 256 to +272
func createAppAndExport(
logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
logger log.Logger,
db dbm.DB,
traceStore io.Writer,
height int64,
forZeroHeight bool,
jailWhiteList []string,
appOpts servertypes.AppOptions,
) (servertypes.ExportedApp, error) {
encCfg := encoding.MakeConfig(app.ModuleEncodingRegisters...) // Ideally, we would reuse the one created by NewRootCmd.
encCfg.Codec = codec.NewProtoCodec(encCfg.InterfaceRegistry)
var capp *app.App
config := encoding.MakeConfig(app.ModuleEncodingRegisters...)
celestiaApp := app.New(logger, db, traceStore, uint(1), config, 0, appOpts)
if height != -1 {
capp = app.New(logger, db, traceStore, uint(1), encCfg, 0, appOpts)

if err := capp.LoadHeight(height); err != nil {
if err := celestiaApp.LoadHeight(height); err != nil {
return servertypes.ExportedApp{}, err
}
} else {
capp = app.New(logger, db, traceStore, uint(1), encCfg, 0, appOpts)
}

return capp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
return celestiaApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

refactored for readability

go.mod Outdated
@@ -257,7 +257,7 @@ require (
)

replace (
github.com/cosmos/cosmos-sdk => github.com/celestiaorg/cosmos-sdk v1.22.0-sdk-v0.46.16
github.com/cosmos/cosmos-sdk => /Users/rootulp/git/rootulp/celestiaorg/cosmos-sdk
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

need to revert

@rootulp
Copy link
Collaborator Author

rootulp commented May 12, 2024

panic: parameter GlobalMinGasPrice not registered

goroutine 1 [running]:
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.checkType({{0x105127140, 0x14000122c20}, 0x140013b6060, {0x1050fb1e8, 0x14000122db0}, {0x1050fb210, 0x14000123110}, {0x14001b8e208, 0x6, 0x8}, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/cosmos-sdk/x/params/types/subspace.go:170 +0x174
github.com/cosmos/cosmos-sdk/x/params/types.Subspace.Get({{_, _}, _, {_, _}, {_, _}, {_, _, _}, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/cosmos-sdk/x/params/types/subspace.go:104 +0x80
github.com/celestiaorg/celestia-app/v2/x/minfee.ExportGenesis({{0x105115438, 0x106557920}, {0x105127840, 0x140010b3d80}, {{0x0, 0x0}, {0x0, 0x0}, 0x4, {0x0, ...}, ...}, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/x/minfee/genesis.go:31 +0x1e0
github.com/celestiaorg/celestia-app/v2/x/minfee.AppModule.ExportGenesis({{}, {{_, _}, _, {_, _}, {_, _}, _}}, {{0x105115438, ...}, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/x/minfee/module.go:132 +0x84
github.com/celestiaorg/celestia-app/v2/app/module.(*Manager).ExportGenesis(_, {{0x105115438, 0x106557920}, {0x105127840, 0x140010b3d80}, {{0x0, 0x0}, {0x0, 0x0}, 0x4, ...}, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/app/module/manager.go:193 +0x344
github.com/celestiaorg/celestia-app/v2/app.(*App).ExportAppStateAndValidators(0x1400079a008, 0x0, {0x106557920, 0x0, 0x0})
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/app/export.go:36 +0x334
github.com/celestiaorg/celestia-app/v2/cmd/celestia-appd/cmd.createAppAndExport({0x1051157f0, 0x1400133efc0}, {0x105127f18, 0x140013b6058}, {0x0, 0x0}, 0xffffffffffffffff, 0x0, {0x106557920, 0x0, ...}, ...)
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/cmd/celestia-appd/cmd/root.go:272 +0x158
github.com/cosmos/cosmos-sdk/server.ExportCmd.func1(0x14001346908, {0x106557920?, 0x0?, 0x0?})
	/Users/rootulp/git/rootulp/celestiaorg/cosmos-sdk/server/export.go:70 +0x3cc
github.com/spf13/cobra.(*Command).execute(0x14001346908, {0x106557920, 0x0, 0x0})
	/Users/rootulp/go/pkg/mod/github.com/spf13/[email protected]/command.go:983 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x14001283b08)
	/Users/rootulp/go/pkg/mod/github.com/spf13/[email protected]/command.go:1115 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
	/Users/rootulp/go/pkg/mod/github.com/spf13/[email protected]/command.go:1039
github.com/spf13/cobra.(*Command).ExecuteContext(...)
	/Users/rootulp/go/pkg/mod/github.com/spf13/[email protected]/command.go:1032
github.com/cosmos/cosmos-sdk/server/cmd.Execute(0x14001283b08, {0x103ee27a4, 0x8}, {0x140006f9f00, 0x1c})
	/Users/rootulp/git/rootulp/celestiaorg/cosmos-sdk/server/cmd/execute.go:36 +0x158
main.main()
	/Users/rootulp/git/rootulp/celestiaorg/celestia-app/cmd/celestia-appd/main.go:14 +0x3c

@rootulp
Copy link
Collaborator Author

rootulp commented May 12, 2024

Strange because InitGenesis is called on the minfee module when upgrading from app version 1 -> 2. The param does exist in the correct subspace:

$ celestia-appd query params subspace minfee GlobalMinGasPrice
key: GlobalMinGasPrice
subspace: minfee
value: '"0.000001000000000000"'

It looks like the export command isn't loading the correct params

@rootulp rootulp requested a review from evan-forbes May 12, 2024 23:03
@rootulp rootulp marked this pull request as ready for review May 12, 2024 23:15
@rootulp rootulp requested a review from a team as a code owner May 12, 2024 23:15
Copy link
Contributor

coderabbitai bot commented May 12, 2024

Walkthrough

Walkthrough

The recent changes aim to enhance the Celestia application by refining initialization processes, improving export functionalities, and enhancing version handling. These updates streamline code structure, enhance method clarity, and address issues related to application state exporting for increased stability and reliability.

Changes

File Pattern Change Summary
app/ante/min_fee_test.go Updated subspace assignment in the test function.
app/app.go Refactored initialization and information functions, introduced new methods for app version management.
app/export.go Adjusted ExportAppStateAndValidators to refine parameter handling and logic flow.
app/module/manager.go Enhanced ExportGenesis to filter modules based on version support.
app/module/manager_test.go Added new test scenarios for module export logic.
app/test/export_test.go Introduced tests for exporting application state and version upgrade logic.
cmd/celestia-appd/cmd/... Improved readability and simplified app creation logic in command setup.
scripts/single-node.sh Updated script configurations for debugging and version upgrade.
x/minfee/... Adjusted RegisterMinFeeParamTable function and related logic in multiple files.

Assessment against linked issues

Objective Addressed Explanation
Problem Description: celestia-appd export results in a panic due to nil pointer dereference [#3392] The changes do not explicitly address the nil pointer dereference issue causing the panic.
Expected Behavior: Command executes without runtime errors or panics [#3392] The resolution of runtime errors or panics is not explicitly mentioned in the recent changes.
Root Cause Analysis: Identify bug or inconsistency in state handling logic [#3392] While enhancements are made, the specific resolution of bugs or inconsistencies is not detailed.
Resolution: Fix the root cause to ensure correct function on the main branch [#3392] The changes aim to improve functionality but lack explicit details on resolving the root cause.

The recent modifications enhance overall application functionality and export processes, but they do not explicitly address the nil pointer dereference issue causing panics or provide specific resolutions for identified bugs and inconsistencies. Further clarification is needed to ensure the resolution of these critical issues.


Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 825f926 and 2af0033.
Files selected for processing (1)
  • scripts/single-node.sh (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • scripts/single-node.sh

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

Note: Auto-reply has been disabled for this repository by the repository owner. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Out of diff range and nitpick comments (3)
app/app.go (3)

172-176: Clarify the deprecation note for upgradeHeightV2.

Consider expanding the comment on line 175 to explain what the "dynamically signalling scheme" will involve, or link to documentation if this change is significant.


Line range hint 508-530: Ensure robust error handling in Info.

The function uses a panic for error handling (line 512). Consider using a more graceful error handling mechanism to improve the robustness of the application. For example, you could return an error to the caller instead of panicking.

-			panic(err)
+			return abci.ResponseInfo{}, err

Line range hint 535-553: Review the panic usage in InitChain.

The use of panic (lines 539 and 541) could be replaced with more graceful error handling. Consider returning an error to the caller or handling the error within the function to improve the application's stability.

-		panic("no consensus params set")
+		return abci.ResponseInitChain{}, fmt.Errorf("no consensus params set")
-		panic("app version 0 is not accepted. Please set an app version in the genesis")
+		return abci.ResponseInitChain{}, fmt.Errorf("app version 0 is not accepted. Please set an app version in the genesis")

Comment on lines +559 to +568
// mountKeysAndInit mounts the keys for the provided app version and then
// invokes baseapp.Init().
func (app *App) mountKeysAndInit(appVersion uint64) {
app.MountKVStores(app.versionedKeys(appVersion))

// Invoke load latest version for it's side-effect of invoking baseapp.Init()
if err := app.LoadLatestVersion(); err != nil {
panic(fmt.Sprintf("loading latest version: %s", err.Error()))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure error messages are informative in mountKeysAndInit.

The error message in line 566 could be more informative. Consider including more context about the failure to help with debugging.

-		panic(fmt.Sprintf("loading latest version: %s", err.Error()))
+		panic(fmt.Sprintf("Failed to load the latest version during app initialization: %s", err.Error()))

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
// mountKeysAndInit mounts the keys for the provided app version and then
// invokes baseapp.Init().
func (app *App) mountKeysAndInit(appVersion uint64) {
app.MountKVStores(app.versionedKeys(appVersion))
// Invoke load latest version for it's side-effect of invoking baseapp.Init()
if err := app.LoadLatestVersion(); err != nil {
panic(fmt.Sprintf("loading latest version: %s", err.Error()))
}
}
// mountKeysAndInit mounts the keys for the provided app version and then
// invokes baseapp.Init().
func (app *App) mountKeysAndInit(appVersion uint64) {
app.MountKVStores(app.versionedKeys(appVersion))
// Invoke load latest version for it's side-effect of invoking baseapp.Init()
if err := app.LoadLatestVersion(); err != nil {
panic(fmt.Sprintf("Failed to load the latest version during app initialization: %s", err.Error()))
}
}

exported, err := testApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs)
require.NoError(t, err)
assert.NotNil(t, exported)
// TODO: the following assertion is commented out because the exported app does not populate consensus params.version
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Complete the test for consensus parameters version in the exported app state.

Would you like me to help complete this test case or should we track this as an issue?

Copy link
Member

@rach-id rach-id left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Left two blocking comments to understand more

app/app.go Show resolved Hide resolved
app/export.go Show resolved Hide resolved
app/test/export_test.go Show resolved Hide resolved
cmd/celestia-appd/cmd/root.go Show resolved Hide resolved
scripts/single-node.sh Outdated Show resolved Hide resolved
x/minfee/params.go Outdated Show resolved Hide resolved
@celestia-bot celestia-bot requested review from a team and ramin and removed request for a team May 13, 2024 22:24
@celestia-bot celestia-bot requested a review from a team May 13, 2024 22:24
@rootulp rootulp requested a review from rach-id May 13, 2024 22:25
Copy link
Member

@evan-forbes evan-forbes left a comment

Choose a reason for hiding this comment

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

LGTM

@rootulp rootulp merged commit 5c6a797 into celestiaorg:main May 14, 2024
33 checks passed
Copy link
Contributor

@cmwaters cmwaters left a comment

Choose a reason for hiding this comment

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

Looks good to me. Nice find

app/test/export_test.go Show resolved Hide resolved
Comment on lines +187 to 193
moduleNamesForVersion := m.ModuleNames(version)
moduleNamesToExport := filter(m.OrderExportGenesis, func(moduleName string) bool {
// filter out modules that are not supported by this version
return slices.Contains(moduleNamesForVersion, moduleName)
})
for _, moduleName := range moduleNamesToExport {
genesisData[moduleName] = modules[moduleName].ExportGenesis(ctx, cdc)
Copy link
Contributor

Choose a reason for hiding this comment

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

make sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

celestia-appd export broken on main
4 participants