Skip to content

Commit

Permalink
perf: Faster state export (#14332)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reecepbcups authored Dec 19, 2022
1 parent be8c5a0 commit de6ef1e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
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 de6ef1e

Please sign in to comment.