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

R4R [Staging PR 1/3]: module generalization #4208

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fc3343b
first commit
rigelrozanski Apr 3, 2019
2ed7ec3
gaia cleanup
rigelrozanski Apr 4, 2019
fa8d51b
...
rigelrozanski Apr 4, 2019
78beb8b
Merge 'origin/develop' and working on module manager
rigelrozanski Apr 4, 2019
f3c84d2
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 8, 2019
31e268a
staking multihooks
rigelrozanski Apr 8, 2019
f04fd65
missing module function return args
rigelrozanski Apr 8, 2019
b9fea80
bank module name constant
rigelrozanski Apr 8, 2019
53096ec
working, module interface for x/
rigelrozanski Apr 9, 2019
f89b67b
got this thing compiling
rigelrozanski Apr 9, 2019
fc2c20a
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 9, 2019
f026bec
make test compiles and passes
rigelrozanski Apr 9, 2019
45d82f9
remove expanded simulation invariants
rigelrozanski Apr 9, 2019
3f4d0cf
genesis issue
rigelrozanski Apr 10, 2019
050317d
continued
rigelrozanski Apr 10, 2019
69a543e
continued
rigelrozanski Apr 10, 2019
95236c4
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 10, 2019
03328ee
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 10, 2019
9031e9d
register crisis routes thought mm
rigelrozanski Apr 10, 2019
480c10e
begin blocker to mm
rigelrozanski Apr 10, 2019
ef5ec28
end blocker to mm
rigelrozanski Apr 10, 2019
3c681a6
empty routes not initialized
rigelrozanski Apr 10, 2019
4ad51d2
move gaia initChainer sanity check to baseapp
rigelrozanski Apr 10, 2019
3620b2e
remove codecs from module manager
rigelrozanski Apr 10, 2019
62342b2
reorging genesis stuff
rigelrozanski Apr 10, 2019
6ce6260
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 15, 2019
c8c3a08
module manager passed by reference/bugfixes from working last commit
rigelrozanski Apr 15, 2019
cd4d68f
move invariant checks from gaia to crisis
rigelrozanski Apr 15, 2019
2d95c57
typo
rigelrozanski Apr 15, 2019
631298e
MultiStakingHooks from types to x/staking/types
rigelrozanski Apr 17, 2019
a2cd3dc
default module manager order of operations from input modules
rigelrozanski Apr 17, 2019
022498e
typo
rigelrozanski Apr 17, 2019
092aab3
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 22, 2019
7977e7e
Merge remote-tracking branch 'origin/develop' into rigel/genesis-gene…
rigelrozanski Apr 26, 2019
87ed491
comment improvement
rigelrozanski Apr 26, 2019
13840bd
Merge branch 'origin/master' into rigel/genesis-generalization
rigelrozanski Apr 29, 2019
8008e48
bez staging PR 1 comments
rigelrozanski May 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"reflect"
"runtime/debug"
"sort"
"strings"

"errors"
Expand Down Expand Up @@ -48,8 +49,8 @@ type BaseApp struct {
name string // application name from abci.Info
db dbm.DB // common DB backend
cms sdk.CommitMultiStore // Main (uncached) state
router Router // handle any kind of message
queryRouter QueryRouter // router for redirecting query calls
router sdk.Router // handle any kind of message
queryRouter sdk.QueryRouter // router for redirecting query calls
txDecoder sdk.TxDecoder // unmarshal []byte into sdk.Tx

// set upon LoadVersion or LoadLatestVersion.
Expand Down Expand Up @@ -239,7 +240,7 @@ func (app *BaseApp) setHaltHeight(height uint64) {
}

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

// QueryRouter returns the QueryRouter of a BaseApp.
func (app *BaseApp) QueryRouter() QueryRouter { return app.queryRouter }
func (app *BaseApp) QueryRouter() sdk.QueryRouter { return app.queryRouter }

// Seal seals a BaseApp. It prohibits any further modifications to a BaseApp.
func (app *BaseApp) Seal() { app.sealed = true }
Expand Down Expand Up @@ -361,6 +362,22 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC

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

// sanity check
if len(req.Validators) > 0 {
if len(req.Validators) != len(res.Validators) {
panic(fmt.Errorf(
"len(RequestInitChain.Validators) != len(validators) (%d != %d)",
len(req.Validators), len(res.Validators)))
}
sort.Sort(abci.ValidatorUpdates(req.Validators))
sort.Sort(abci.ValidatorUpdates(res.Validators))
for i, val := range res.Validators {
if !val.Equal(req.Validators[i]) {
panic(fmt.Errorf("validators[%d] != req.Validators[%d] ", i, i))
}
}
}

// NOTE: We don't commit, but BeginBlock for block 1 starts from this
// deliverState.
return
Expand Down
10 changes: 3 additions & 7 deletions baseapp/queryrouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// QueryRouter provides queryables for each query path.
type QueryRouter interface {
AddRoute(r string, h sdk.Querier) (rtr QueryRouter)
Route(path string) (h sdk.Querier)
}

type queryRouter struct {
routes map[string]sdk.Querier
}

var _ sdk.QueryRouter = NewQueryRouter()

// NewQueryRouter returns a reference to a new queryRouter.
//
// TODO: Either make the function private or make return type (queryRouter) public.
Expand All @@ -27,7 +23,7 @@ func NewQueryRouter() *queryRouter { // nolint: golint

// AddRoute adds a query path to the router with a given Querier. It will panic
// if a duplicate route is given. The route must be alphanumeric.
func (qrt *queryRouter) AddRoute(path string, q sdk.Querier) QueryRouter {
func (qrt *queryRouter) AddRoute(path string, q sdk.Querier) sdk.QueryRouter {
if !isAlphaNumeric(path) {
panic("route expressions can only contain alphanumeric characters")
}
Expand Down
10 changes: 3 additions & 7 deletions baseapp/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

// Router provides handlers for each transaction type.
type Router interface {
AddRoute(r string, h sdk.Handler) (rtr Router)
Route(path string) (h sdk.Handler)
}

type router struct {
routes map[string]sdk.Handler
}

var _ sdk.Router = NewRouter()

// NewRouter returns a reference to a new router.
//
// TODO: Either make the function private or make return type (router) public.
Expand All @@ -27,7 +23,7 @@ func NewRouter() *router { // nolint: golint

// AddRoute adds a route path to the router with a given handler. The route must
// be alphanumeric.
func (rtr *router) AddRoute(path string, h sdk.Handler) Router {
func (rtr *router) AddRoute(path string, h sdk.Handler) sdk.Router {
if !isAlphaNumeric(path) {
panic("route expressions can only contain alphanumeric characters")
}
Expand Down
8 changes: 4 additions & 4 deletions client/lcd/lcd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func TestCoinMultiSendGenerateOnly(t *testing.T) {
var stdTx auth.StdTx
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &stdTx))
require.Equal(t, len(stdTx.Msgs), 1)
require.Equal(t, stdTx.GetMsgs()[0].Route(), "bank")
require.Equal(t, stdTx.GetMsgs()[0].Route(), bank.RouterKey)
require.Equal(t, stdTx.GetMsgs()[0].GetSigners(), []sdk.AccAddress{addr})
require.Equal(t, 0, len(stdTx.Signatures))
require.Equal(t, memo, stdTx.Memo)
Expand Down Expand Up @@ -269,7 +269,7 @@ func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
var tx auth.StdTx
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &tx))
require.Equal(t, len(tx.Msgs), 1)
require.Equal(t, tx.Msgs[0].Route(), "bank")
require.Equal(t, tx.Msgs[0].Route(), bank.RouterKey)
require.Equal(t, tx.Msgs[0].GetSigners(), []sdk.AccAddress{addr})
require.Equal(t, 0, len(tx.Signatures))
require.Equal(t, memo, tx.Memo)
Expand Down Expand Up @@ -389,8 +389,8 @@ func TestPoolParamsQuery(t *testing.T) {
tokens := sdk.TokensFromTendermintPower(100)
freeTokens := sdk.TokensFromTendermintPower(50)
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(tokens)
initialPool.BondedTokens = initialPool.BondedTokens.Add(tokens) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeTokens) // freeTokensPerAcc = 50 on GaiaAppGenState
initialPool.BondedTokens = initialPool.BondedTokens.Add(tokens) // Delegate tx on GaiaAppGenState
initialPool.NotBondedTokens = initialPool.NotBondedTokens.Add(freeTokens)

require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)

Expand Down
Loading