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: Added bank module's total supply feature #2939

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
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
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ IMPROVEMENTS
* SDK
- [x/mock/simulation] [\#2720] major cleanup, introduction of helper objects, reorganization
- \#2821 Codespaces are now strings
- \#1277 Complete bank module specification
- [types] #2776 Improve safety of `Coin` and `Coins` types. Various functions
and methods will panic when a negative amount is discovered.
- #2815 Gas unit fields changed from `int64` to `uint64`.
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type GaiaApp struct {
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
tkeyStake *sdk.TransientStoreKey
keySlashing *sdk.KVStoreKey
Expand Down Expand Up @@ -80,6 +81,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyBank: sdk.NewKVStoreKey("bank"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keyMint: sdk.NewKVStoreKey("mint"),
Expand All @@ -100,7 +102,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
)

// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(
app.cdc,
app.keyFeeCollection,
Expand Down Expand Up @@ -158,7 +160,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
AddRoute("stake", stake.NewQuerier(app.stakeKeeper, app.cdc))

// initialize BaseApp
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyStake, app.keyMint, app.keyDistr,
app.MountStoresIAVL(app.keyMain, app.keyAccount, app.keyBank, app.keyStake, app.keyMint, app.keyDistr,
app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams)
app.SetInitChainer(app.initChainer)
app.SetBeginBlocker(app.BeginBlocker)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (app *GaiaApp) runtimeInvariants() []simulation.Invariant {
return []simulation.Invariant{
banksim.NonnegativeBalanceInvariant(app.accountKeeper),
distrsim.ValAccumInvariants(app.distrKeeper, app.stakeKeeper),
stakesim.SupplyInvariants(app.bankKeeper, app.stakeKeeper,
stakesim.BondedAmountInvariants(app.bankKeeper, app.stakeKeeper,
app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
stakesim.PositivePowerInvariant(app.stakeKeeper),
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type GaiaApp struct {
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
tkeyStake *sdk.TransientStoreKey
keySlashing *sdk.KVStoreKey
Expand Down Expand Up @@ -158,6 +159,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyBank: sdk.NewKVStoreKey("bank"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
Expand All @@ -173,7 +175,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
)

// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), stake.DefaultCodespace)
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), slashing.DefaultCodespace)
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type BasecoinApp struct {

// keys to access the multistore
keyMain *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey

Expand All @@ -62,6 +63,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
cdc: cdc,
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...),
keyMain: sdk.NewKVStoreKey("main"),
keyBank: sdk.NewKVStoreKey("bank"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
}
Expand All @@ -74,7 +76,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
return &types.AppAccount{}
},
)
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, ibc.DefaultCodespace)

// register message routes
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type DemocoinApp struct {
// keys to access the substores
capKeyMainStore *sdk.KVStoreKey
capKeyAccountStore *sdk.KVStoreKey
capKeyBankStore *sdk.KVStoreKey
capKeyPowStore *sdk.KVStoreKey
capKeyIBCStore *sdk.KVStoreKey
capKeyStakingStore *sdk.KVStoreKey
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
cdc: cdc,
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
capKeyBankStore: sdk.NewKVStoreKey("bank"),
capKeyPowStore: sdk.NewKVStoreKey("pow"),
capKeyIBCStore: sdk.NewKVStoreKey("ibc"),
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
Expand All @@ -82,7 +84,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
)

// Add handlers.
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.capKeyBankStore)
app.coolKeeper = cool.NewKeeper(app.capKeyMainStore, app.bankKeeper, cool.DefaultCodespace)
app.powKeeper = pow.NewKeeper(app.capKeyPowStore, pow.NewConfig("pow", int64(1)), app.bankKeeper, pow.DefaultCodespace)
app.ibcMapper = ibc.NewMapper(app.cdc, app.capKeyIBCStore, ibc.DefaultCodespace)
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/democoin/x/cool/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func getMockApp(t *testing.T) *mock.App {

RegisterCodec(mapp.Cdc)
keyCool := sdk.NewKVStoreKey("cool")
bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper)
keyBank := sdk.NewKVStoreKey("bank")
bankKeeper := bank.NewBaseKeeper(mapp.Cdc, mapp.AccountKeeper, keyBank)
keeper := NewKeeper(keyCool, bankKeeper, DefaultCodespace)
mapp.Router().AddRoute("cool", NewHandler(keeper))

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/cool/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCoolKeeper(t *testing.T) {

am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
ck := bank.NewBaseKeeper(am)
ck := bank.NewBaseKeeper(cdc, am, capKey)
keeper := NewKeeper(capKey, ck, DefaultCodespace)

err := InitGenesis(ctx, keeper, Genesis{"icy"})
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/democoin/x/pow/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func getMockApp(t *testing.T) *mock.App {

RegisterCodec(mapp.Cdc)
keyPOW := sdk.NewKVStoreKey("pow")
bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper)
keyBank := sdk.NewKVStoreKey("bank")
bankKeeper := bank.NewBaseKeeper(mapp.Cdc, mapp.AccountKeeper, keyBank)
config := Config{"pow", 1}
keeper := NewKeeper(keyPOW, config, bankKeeper, DefaultCodespace)
mapp.Router().AddRoute("pow", keeper.Handler)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/pow/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPowHandler(t *testing.T) {
am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
config := NewConfig("pow", int64(1))
ck := bank.NewBaseKeeper(am)
ck := bank.NewBaseKeeper(cdc, am, sdk.NewKVStoreKey("bank"))
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)

handler := keeper.Handler
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/pow/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPowKeeperGetSet(t *testing.T) {
am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
config := NewConfig("pow", int64(1))
ck := bank.NewBaseKeeper(am)
ck := bank.NewBaseKeeper(cdc, am, sdk.NewKVStoreKey("bank"))
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)

err := InitGenesis(ctx, keeper, Genesis{uint64(1), uint64(0)})
Expand Down
14 changes: 8 additions & 6 deletions docs/examples/democoin/x/simplestake/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
)

func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey, *sdk.KVStoreKey) {
db := dbm.NewMemDB()
authKey := sdk.NewKVStoreKey("authkey")
bankKey := sdk.NewKVStoreKey("bankkey")
capKey := sdk.NewKVStoreKey("capkey")
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db)
ms.LoadLatestVersion()
return ms, authKey, capKey
return ms, authKey, bankKey, capKey
}

func TestKeeperGetSet(t *testing.T) {
ms, authKey, capKey := setupMultiStore()
ms, authKey, bankKey, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)

accountKeeper := auth.NewAccountKeeper(cdc, authKey, auth.ProtoBaseAccount)
stakeKeeper := NewKeeper(capKey, bank.NewBaseKeeper(accountKeeper), DefaultCodespace)
stakeKeeper := NewKeeper(capKey, bank.NewBaseKeeper(cdc, accountKeeper, bankKey), DefaultCodespace)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
addr := sdk.AccAddress([]byte("some-address"))

Expand All @@ -59,14 +61,14 @@ func TestKeeperGetSet(t *testing.T) {
}

func TestBonding(t *testing.T) {
ms, authKey, capKey := setupMultiStore()
ms, authKey, bankKey, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)

ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())

accountKeeper := auth.NewAccountKeeper(cdc, authKey, auth.ProtoBaseAccount)
bankKeeper := bank.NewBaseKeeper(accountKeeper)
bankKeeper := bank.NewBaseKeeper(cdc, accountKeeper, bankKey)
stakeKeeper := NewKeeper(capKey, bankKeeper, DefaultCodespace)
addr := sdk.AccAddress([]byte("some-address"))
privKey := ed25519.GenPrivKey()
Expand Down
26 changes: 26 additions & 0 deletions docs/spec/bank/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Bank module specification

## Abstract

This document specifies the bank module of the Cosmos SDK.

The bank module is responsible for handling multi-asset coin transfers between
accounts and tracking special-case pseudo-transfers which must work differently
with particular kinds of accounts (notably delegating/undelegating for vesting
accounts). It exposes several interfaces with varying capabilities for secure
interaction with other modules which must alter user balances.

This module will be used in the Cosmos Hub.

## Contents

1. **[State](state.md)**
1. **[Keepers](keepers.md)**
1. [Common Types](keepers.md#common-types)
1. [Input](keepers.md#input)
1. [Output](keepers.md#output)
1. [BaseKeeper](keepers.md#basekeeper)
1. [SendKeeper](keepers.md#sendkeeper)
1. [ViewKeeper](keepers.md#viewkeeper)
1. **[Transactions](transactions.md)**
1. [MsgSend](transactions.md#msgsend)
25 changes: 0 additions & 25 deletions docs/spec/bank/WIP_keeper.md

This file was deleted.

Loading