Skip to content

Commit 3fe5869

Browse files
Merge PR #4159: Module/Genesis Generalization
* first commit * gaia cleanup * ... * staking multihooks * missing module function return args * bank module name constant * working, module interface for x/ * got this thing compiling * make test compiles and passes * remove expanded simulation invariants * genesis issue * continued * continued * register crisis routes thought mm * begin blocker to mm * end blocker to mm * empty routes not initialized * move gaia initChainer sanity check to baseapp * remove codecs from module manager * reorging genesis stuff * module manager passed by reference/bugfixes from working last commit int int * move invariant checks from gaia to crisis * typo * basic refactors cmd/gaia/init * working * MultiStakingHooks from types to x/staking/types int * default module manager order of operations from input modules * working * typo * add AppModuleBasic * moduleBasicManager / non-test code compiles * working attempting to get tests passing * make test passes * sim random genesis fix * export bug * ... * genutil module * genutil working * refactored - happy with non-testing code in cmd/ * ... * lint fixes * comment improvement * cli test fix * compile housing * working through compile errors * working gettin' compilin' * non-test code compiles * move testnet to its own module * reworking tests int * bez staging PR 1 comments * concise module function-of names * moved all tests from genesis_test.go to other genutil tests * genaccounts package, add genutil and genaccounts to app.go * docs for genutil genaccounts * genaccounts iterate fn * non-test code with genaccounts/ now compiles * working test compiling * debugging tests * resolved all make test compile errors * test debuggin * resolved all unit tests, introduced param module * cli-test compile fixes * staking initialization bug * code comment improvements, changelog entries * BasicGaiaApp -> ModuleBasics * highlevel explanation in types/module.go * @alexanderbez comment revisions * @fedekunze PR comments * @alexanderbez PR comments (x2) * @cwgoes comments (minor updates) * @fedekunze suggestions * panic on init with multiple validator updates from different modules * initchain panic makes validate genesis fail int * AppModuleGenesis seperation int * test * remove init panic logic in validate genesis replaced with TODO * set maxprocs to match system's GOMAXPROCS * Update circleci * Cap maxprocs in CI to 4 * @alexanderbez recent comments addressed * less blocks in twouble sims int * runsim error output flag * -e on import_export as well * error out int * Try to fix failures * runsim
1 parent f8fd50a commit 3fe5869

File tree

137 files changed

+3661
-2307
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

137 files changed

+3661
-2307
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#4159 use module pattern and module manager for initialization
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#4159 create the default module patterns and module manager

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,11 @@ test_sim_gaia_fast:
170170

171171
test_sim_gaia_import_export: runsim
172172
@echo "Running Gaia import/export simulation. This may take several minutes..."
173-
$(BINDIR)/runsim 50 5 TestGaiaImportExport
173+
$(BINDIR)/runsim -e 25 5 TestGaiaImportExport
174174

175175
test_sim_gaia_simulation_after_import: runsim
176176
@echo "Running Gaia simulation-after-import. This may take several minutes..."
177-
$(BINDIR)/runsim 50 5 TestGaiaSimulationAfterImport
177+
$(BINDIR)/runsim -e 25 5 TestGaiaSimulationAfterImport
178178

179179
test_sim_gaia_custom_genesis_multi_seed: runsim
180180
@echo "Running multi-seed custom genesis simulation..."

baseapp/baseapp.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"os"
77
"reflect"
88
"runtime/debug"
9+
"sort"
910
"strings"
1011

1112
"errors"
@@ -47,8 +48,8 @@ type BaseApp struct {
4748
name string // application name from abci.Info
4849
db dbm.DB // common DB backend
4950
cms sdk.CommitMultiStore // Main (uncached) state
50-
router Router // handle any kind of message
51-
queryRouter QueryRouter // router for redirecting query calls
51+
router sdk.Router // handle any kind of message
52+
queryRouter sdk.QueryRouter // router for redirecting query calls
5253
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx
5354

5455
// set upon LoadVersion or LoadLatestVersion.
@@ -246,7 +247,7 @@ func (app *BaseApp) setHaltHeight(height uint64) {
246247
}
247248

248249
// Router returns the router of the BaseApp.
249-
func (app *BaseApp) Router() Router {
250+
func (app *BaseApp) Router() sdk.Router {
250251
if app.sealed {
251252
// We cannot return a router when the app is sealed because we can't have
252253
// any routes modified which would cause unexpected routing behavior.
@@ -256,7 +257,7 @@ func (app *BaseApp) Router() Router {
256257
}
257258

258259
// QueryRouter returns the QueryRouter of a BaseApp.
259-
func (app *BaseApp) QueryRouter() QueryRouter { return app.queryRouter }
260+
func (app *BaseApp) QueryRouter() sdk.QueryRouter { return app.queryRouter }
260261

261262
// Seal seals a BaseApp. It prohibits any further modifications to a BaseApp.
262263
func (app *BaseApp) Seal() { app.sealed = true }
@@ -368,6 +369,22 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
368369

369370
res = app.initChainer(app.deliverState.ctx, req)
370371

372+
// sanity check
373+
if len(req.Validators) > 0 {
374+
if len(req.Validators) != len(res.Validators) {
375+
panic(fmt.Errorf(
376+
"len(RequestInitChain.Validators) != len(validators) (%d != %d)",
377+
len(req.Validators), len(res.Validators)))
378+
}
379+
sort.Sort(abci.ValidatorUpdates(req.Validators))
380+
sort.Sort(abci.ValidatorUpdates(res.Validators))
381+
for i, val := range res.Validators {
382+
if !val.Equal(req.Validators[i]) {
383+
panic(fmt.Errorf("validators[%d] != req.Validators[%d] ", i, i))
384+
}
385+
}
386+
}
387+
371388
// NOTE: We don't commit, but BeginBlock for block 1 starts from this
372389
// deliverState.
373390
return

baseapp/queryrouter.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77
)
88

9-
// QueryRouter provides queryables for each query path.
10-
type QueryRouter interface {
11-
AddRoute(r string, h sdk.Querier) (rtr QueryRouter)
12-
Route(path string) (h sdk.Querier)
13-
}
14-
159
type queryRouter struct {
1610
routes map[string]sdk.Querier
1711
}
1812

13+
var _ sdk.QueryRouter = NewQueryRouter()
14+
1915
// NewQueryRouter returns a reference to a new queryRouter.
2016
//
2117
// TODO: Either make the function private or make return type (queryRouter) public.
@@ -27,7 +23,7 @@ func NewQueryRouter() *queryRouter { // nolint: golint
2723

2824
// AddRoute adds a query path to the router with a given Querier. It will panic
2925
// if a duplicate route is given. The route must be alphanumeric.
30-
func (qrt *queryRouter) AddRoute(path string, q sdk.Querier) QueryRouter {
26+
func (qrt *queryRouter) AddRoute(path string, q sdk.Querier) sdk.QueryRouter {
3127
if !isAlphaNumeric(path) {
3228
panic("route expressions can only contain alphanumeric characters")
3329
}

baseapp/router.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77
)
88

9-
// Router provides handlers for each transaction type.
10-
type Router interface {
11-
AddRoute(r string, h sdk.Handler) (rtr Router)
12-
Route(path string) (h sdk.Handler)
13-
}
14-
159
type router struct {
1610
routes map[string]sdk.Handler
1711
}
1812

13+
var _ sdk.Router = NewRouter()
14+
1915
// NewRouter returns a reference to a new router.
2016
//
2117
// TODO: Either make the function private or make return type (router) public.
@@ -27,7 +23,7 @@ func NewRouter() *router { // nolint: golint
2723

2824
// AddRoute adds a route path to the router with a given handler. The route must
2925
// be alphanumeric.
30-
func (rtr *router) AddRoute(path string, h sdk.Handler) Router {
26+
func (rtr *router) AddRoute(path string, h sdk.Handler) sdk.Router {
3127
if !isAlphaNumeric(path) {
3228
panic("route expressions can only contain alphanumeric characters")
3329
}

0 commit comments

Comments
 (0)