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

Modify ExportCmd to export genesis with bech32_prefix #402

Closed
wants to merge 12 commits into from

Conversation

anhductn2001
Copy link
Contributor

@anhductn2001 anhductn2001 commented Apr 26, 2024

PR Standards

Since Exported type of Cosmos-SDK default return format is GenesisDoc which does not include the bech32_prefix field, we need to modify it to allow bech32_prefix to be exported every time we export genesis

Opening a pull request should be able to meet the following requirements


Closes #XXX

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow-up issues.

For Author:

  • Targeted PR against correct branch
  • included the correct type prefix in the PR title
  • Linked to Github issue with discussion and accepted design
  • Targets only one github issue
  • Wrote unit and integration tests
  • All CI checks have passed
  • Added relevant godoc comments

For Reviewer:

  • confirmed the correct type prefix in the PR title
  • Reviewers assigned
  • confirmed all author checklist items have been addressed

After reviewer approval:

  • In case targets main branch, PR should be squashed and merged.
  • In case PR targets a release branch, PR should be rebased.

@anhductn2001 anhductn2001 requested a review from a team as a code owner April 26, 2024 06:51
@danwt
Copy link
Contributor

danwt commented Apr 26, 2024

Is there an issue?

@danwt
Copy link
Contributor

danwt commented Apr 26, 2024

linter fails btw

@anhductn2001
Copy link
Contributor Author

yea, it relate to: dymensionxyz/rollapp-evm#178

Copy link
Contributor

@danwt danwt left a comment

Choose a reason for hiding this comment

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

I'm kind of missing the TLDR here
what is the problem being solved?

server/commands.go Outdated Show resolved Hide resolved
@@ -19,7 +20,7 @@ import (
)

// add Rollapp commands
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong docstr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was a previous comment, but I'll add some comments to it

server/export.go Outdated
"os"
"strconv"

rdk_genutiltypes "github.com/dymensionxyz/dymension-rdk/x/genutil/types"
Copy link
Contributor

Choose a reason for hiding this comment

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

no snake

Comment on lines 23 to 24
func AddRollappCommands(rootCmd *cobra.Command, defaultNodeHome string, appCreator types.AppCreator, appExport rdk_types.AppExporter, addStartFlags types.ModuleInitFlags) {
dymintCmd := &cobra.Command{
Copy link
Contributor

Choose a reason for hiding this comment

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

does this have usages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

server/export.go Outdated
Comment on lines 50 to 65
if _, err := fmt.Fprintln(os.Stderr, "WARNING: App exporter not defined. Returning genesis file."); err != nil {
return err
}

genesis, err := os.ReadFile(config.GenesisFile())
if err != nil {
return err
}

fmt.Println(string(genesis))
return nil
}

genDoc, err := rdk_genutiltypes.GenesisDocFromFile(config.GenesisFile())
if err != nil {
fmt.Println("Failed to read genesis doc from file", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

why sometimes stderr, sometimes stdout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's just a function taken from cosmos-sdk with a little change


exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper)
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("error exporting state: %v", err)
return fmt.Errorf("exporting state: %v", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we shouldn't change it


exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper)
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("error exporting state: %v", err)
return fmt.Errorf("exporting state: %w", err)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we shouldn't change it

server/export.go Outdated
Comment on lines 92 to 94
consensus_param := doc["consensus_params"].(map[string]interface{})
block := consensus_param["block"].(map[string]interface{})
time_iota_ms, _ := strconv.ParseInt(block["time_iota_ms"].(string), 10, 64)
Copy link
Contributor

Choose a reason for hiding this comment

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

no snake

Need to check OK for type assertion?

// the expected types and could result in type assertion errors. It is recommend
// to either use the cast package or perform manual conversion for safety.
AppOptions interface {
Get(string) interface{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Get(string) interface{}
Get(string) any

// for the application.
//
// NOTE: The pubkey input is this machines pubkey.
func GenesisStateFromGenFile(genFile string) (genesisState map[string]json.RawMessage, genDoc map[string]interface{}, 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.

if you do concrete type assertions without checking ok on the genesisState, can we have a concrete type instead?

@anhductn2001
Copy link
Contributor Author

I have updated description of this PR.

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.

5 participants