Skip to content

Commit

Permalink
perf: Faster state export (backport #14332) (#14355)
Browse files Browse the repository at this point in the history
Co-authored-by: Reece Williams <31943163+Reecepbcups@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
  • Loading branch information
3 people authored Dec 19, 2022
1 parent ee8890c commit 58896f1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (types) [#14332](https://github.com/cosmos/cosmos-sdk/issues/14332) Reduce state export time by 50%.
* (types) [#14163](https://github.com/cosmos/cosmos-sdk/pull/14163) Refactor `(coins Coins) Validate()` to avoid unnecessary map.
* [#13881](https://github.com/cosmos/cosmos-sdk/pull/13881) Optimize iteration on nested cached KV stores and other operations in general.

Expand Down
11 changes: 7 additions & 4 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ test-integration:
test-integration-cov:
go test ./integration/... -timeout 30m -coverpkg=../... -coverprofile=integration-profile.out -covermode=atomic

test-e2e:
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e'
test-e2e: test-e2e-server
go test ./e2e/... -mod=readonly -timeout 30m -tags='e2e'

test-e2e-cov:
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' -coverpkg=../... -coverprofile=e2e-profile.out -covermode=atomic
test-e2e-cov: test-e2e-server
go test ./e2e/... -mod=readonly -timeout 30m -race -tags='e2e' -coverpkg=../... -coverprofile=e2e-profile.out -covermode=atomic

test-e2e-server:
go test ./e2e/server -mod=readonly -timeout 30m -tags='e2e' -coverpkg=../... -coverprofile=e2e-server-profile.out -covermode=atomic
4 changes: 2 additions & 2 deletions tests/e2e/server/export_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build e2e
// +build e2e
//go:build !race
// +build !race

package server_test

Expand Down
25 changes: 16 additions & 9 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,27 +383,34 @@ func (m *Manager) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) map[string
// ExportGenesisForModules performs export genesis functionality for modules
func (m *Manager) ExportGenesisForModules(ctx sdk.Context, cdc codec.JSONCodec, modulesToExport []string) map[string]json.RawMessage {
genesisData := make(map[string]json.RawMessage)
if len(modulesToExport) == 0 {
for _, moduleName := range m.OrderExportGenesis {
if module, ok := m.Modules[moduleName].(HasGenesis); ok {
genesisData[moduleName] = module.ExportGenesis(ctx, cdc)
}
}

return genesisData
if len(modulesToExport) == 0 {
modulesToExport = m.OrderExportGenesis
}

// verify modules exists in app, so that we don't panic in the middle of an export
if err := m.checkModulesExists(modulesToExport); err != nil {
panic(err)
}

for _, moduleName := range modulesToExport {
channels := make([]chan json.RawMessage, len(modulesToExport))
modulesWithGenesis := make([]string, 0, len(modulesToExport))

for i, moduleName := range modulesToExport {
if module, ok := m.Modules[moduleName].(HasGenesis); ok {
genesisData[moduleName] = module.ExportGenesis(ctx, cdc)
channels[i] = make(chan json.RawMessage)
modulesWithGenesis = append(modulesWithGenesis, moduleName)

go func(module HasGenesis, ch chan json.RawMessage) {
ch <- module.ExportGenesis(ctx, cdc)
}(module, channels[i])
}
}

for i, moduleName := range modulesWithGenesis {
genesisData[moduleName] = <-channels[i]
}

return genesisData
}

Expand Down

0 comments on commit 58896f1

Please sign in to comment.