Skip to content

Commit

Permalink
fix: BootstrapState use custom genesis doc provider (backport: cometb…
Browse files Browse the repository at this point in the history
…ft#2791) (cometbft#2793)

The cosmos-sdk 0.50 genesis doc marshalling not being compatible with
the cometbft default one (see
cosmos/cosmos-sdk#18477), so we need to
support custom genesis doc provider in this public API as well, it's
called by the `bootstrap-state` command in cosmos-sdk.

<!--

Please add a reference to the issue that this PR addresses and indicate
which
files are most critical to review. If it fully addresses a particular
issue,
please include "Closes #XXX" (where "XXX" is the issue number).

If this PR is non-trivial/large/complex, please ensure that you have
either
created an issue that the team's had a chance to respond to, or had some
discussion with the team prior to submitting substantial pull requests.
The team
can be reached via GitHub Discussions or the Cosmos Network Discord
server in
the #cometbft channel. GitHub Discussions is preferred over Discord as
it
allows us to keep track of conversations topically.
https://github.com/cometbft/cometbft/discussions

If the work in this PR is not aligned with the team's current
priorities, please
be advised that it may take some time before it is merged - especially
if it has
not yet been discussed with the team.

See the project board for the team's current priorities:
https://github.com/orgs/cometbft/projects/1

-->

---

#### PR checklist

- [ ] Tests written/updated
- [ ] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments
- [ ] Title follows the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec

Co-authored-by: Anton Kaliaev <[email protected]>
  • Loading branch information
yihuang and melekes committed Apr 12, 2024
1 parent e5cf488 commit 1f67e39
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,16 @@ func StateProvider(stateProvider statesync.StateProvider) Option {
// store are empty at the time the function is called.
//
// If the block store is not empty, the function returns an error.
func BootstrapState(ctx context.Context, config *cfg.Config, dbProvider cfg.DBProvider, height uint64, appHash []byte) (err error) {
func BootstrapState(ctx context.Context, config *cfg.Config, dbProvider cfg.DBProvider, height uint64, appHash []byte) error {
return BootstrapStateWithGenProvider(ctx, config, dbProvider, DefaultGenesisDocProviderFunc(config), height, appHash)
}

// BootstrapStateWithGenProvider synchronizes the stores with the application after state sync
// has been performed offline. It is expected that the block store and state
// store are empty at the time the function is called.
//
// If the block store is not empty, the function returns an error.
func BootstrapStateWithGenProvider(ctx context.Context, config *cfg.Config, dbProvider cfg.DBProvider, genProvider GenesisDocProvider, height uint64, appHash []byte) (err error) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
if ctx == nil {
ctx = context.Background()
Expand Down Expand Up @@ -193,7 +202,7 @@ func BootstrapState(ctx context.Context, config *cfg.Config, dbProvider cfg.DBPr
return fmt.Errorf("state not empty, trying to initialize non empty state")
}

genState, _, err := LoadStateFromDBOrGenesisDocProvider(stateDB, DefaultGenesisDocProviderFunc(config))
genState, _, err := LoadStateFromDBOrGenesisDocProvider(stateDB, genProvider)
if err != nil {
return err
}
Expand Down

0 comments on commit 1f67e39

Please sign in to comment.