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

#193 Enable governance module #278

Merged
merged 1 commit into from
Feb 28, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 18 additions & 5 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand Down Expand Up @@ -69,6 +70,7 @@ type CyberdApp struct {
stakingKeeper staking.Keeper
slashingKeeper slashing.Keeper
distrKeeper distr.Keeper
govKeeper gov.Keeper
paramsKeeper params.Keeper
accBandwidthKeeper bw.Keeper

Expand Down Expand Up @@ -147,6 +149,13 @@ func NewCyberdApp(
app.bankKeeper, stakingKeeper, app.feeCollectionKeeper,
distr.DefaultCodespace,
)

app.govKeeper = gov.NewKeeper(
app.cdc, dbKeys.gov,
app.paramsKeeper, app.paramsKeeper.Subspace(gov.DefaultParamspace), app.bankKeeper, &stakingKeeper,
gov.DefaultCodespace,
)

app.minter = mint.NewMinter(
app.feeCollectionKeeper, stakingKeeper,
app.paramsKeeper.Subspace(mint.DefaultParamspace),
Expand Down Expand Up @@ -179,18 +188,20 @@ func NewCyberdApp(
AddRoute(bank.RouterKey, bank.NewHandler(app.bankKeeper)).
AddRoute(staking.RouterKey, staking.NewHandler(app.stakingKeeper)).
AddRoute(distr.RouterKey, distr.NewHandler(app.distrKeeper)).
AddRoute(slashing.RouterKey, slashing.NewHandler(app.slashingKeeper))
AddRoute(slashing.RouterKey, slashing.NewHandler(app.slashingKeeper)).
AddRoute(gov.RouterKey, gov.NewHandler(app.govKeeper))

app.QueryRouter().
AddRoute(distr.QuerierRoute, distr.NewQuerier(app.distrKeeper)).
AddRoute(gov.QuerierRoute, gov.NewQuerier(app.govKeeper)).
AddRoute(slashing.QuerierRoute, slashing.NewQuerier(app.slashingKeeper, app.cdc)).
AddRoute(staking.QuerierRoute, staking.NewQuerier(app.stakingKeeper, app.cdc))

// mount the multistore and load the latest state
app.MountStores(
dbKeys.main, dbKeys.acc, dbKeys.cidNum, dbKeys.cidNumReverse, dbKeys.links, dbKeys.rank, dbKeys.stake,
dbKeys.slashing, dbKeys.params, dbKeys.distr, dbKeys.fees, dbKeys.accBandwidth, dbKeys.blockBandwidth,
dbKeys.tDistr, dbKeys.tParams, dbKeys.tStake,
dbKeys.slashing, dbKeys.gov, dbKeys.params, dbKeys.distr, dbKeys.fees, dbKeys.accBandwidth,
dbKeys.blockBandwidth, dbKeys.tDistr, dbKeys.tParams, dbKeys.tStake,
)

app.SetInitChainer(app.initChainer)
Expand Down Expand Up @@ -268,6 +279,7 @@ func (app *CyberdApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) ab
ctx, app.slashingKeeper, genesisState.SlashingData,
genesisState.StakingData.Validators.ToSDKValidators(),
)
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
mint.InitGenesis(ctx, app.minter, genesisState.MintData)
bandwidth.InitGenesis(ctx, app.bandwidthMeter, app.accBandwidthKeeper, genesisState.GetAddresses())

Expand Down Expand Up @@ -466,7 +478,8 @@ func (app *CyberdApp) EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock) abci.R
app.latestBlockHeight = ctx.BlockHeight()
app.mainKeeper.StoreLatestBlockNumber(ctx, uint64(ctx.BlockHeight()))

validatorUpdates, tags := staking.EndBlocker(ctx, app.stakingKeeper)
tags := gov.EndBlocker(ctx, app.govKeeper)
validatorUpdates, stakingTags := staking.EndBlocker(ctx, app.stakingKeeper)
app.stakingIndex.EndBlocker(ctx)

bandwidth.EndBlocker(ctx, app.bandwidthMeter)
Expand All @@ -476,7 +489,7 @@ func (app *CyberdApp) EndBlocker(ctx sdk.Context, _ abci.RequestEndBlock) abci.R

return abci.ResponseEndBlock{
ValidatorUpdates: validatorUpdates,
Tags: tags,
Tags: append(tags, stakingTags...),
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cybercongress/cyberd/x/link"
Expand Down Expand Up @@ -35,7 +36,8 @@ func (app *CyberdApp) ExportAppStateAndValidators() (appState json.RawMessage, v
staking.ExportGenesis(ctx, app.stakingKeeper),
mint.ExportGenesis(ctx, app.minter),
distr.ExportGenesis(ctx, app.distrKeeper),
slashing.ExportGenesis(ctx, app.slashingKeeper),
gov.GenesisState{},
slashing.GenesisState{},
)
appState, err = codec.MarshalJSONIndent(app.cdc, genState)
if err != nil {
Expand Down
24 changes: 23 additions & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/cosmos/cosmos-sdk/x/staking/types"
Expand All @@ -25,6 +26,7 @@ type GenesisState struct {
MintData mint.GenesisState `json:"mint"`
StakingData staking.GenesisState `json:"staking"`
SlashingData slashing.GenesisState `json:"slashing"`
GovData gov.GenesisState `json:"gov"`
GenTxs []json.RawMessage `json:"gentxs"`
}

Expand All @@ -39,7 +41,7 @@ func (gs *GenesisState) GetAddresses() []sdk.AccAddress {
func NewGenesisState(
accounts []GenesisAccount, authData auth.GenesisState,
stakingData staking.GenesisState, mintData mint.GenesisState,
distrData distr.GenesisState,
distrData distr.GenesisState, govData gov.GenesisState,
slashingData slashing.GenesisState,
) GenesisState {

Expand All @@ -50,6 +52,7 @@ func NewGenesisState(
MintData: mintData,
DistrData: distrData,
SlashingData: slashingData,
GovData: govData,
}
}

Expand Down Expand Up @@ -123,6 +126,22 @@ func NewDefaultGenesisState() GenesisState {
WithdrawAddrEnabled: true,
PreviousProposer: nil,
},
GovData: gov.GenesisState{
StartingProposalID: 1,
DepositParams: gov.DepositParams{
MinDeposit: sdk.Coins{coin.NewCybCoin(500 * coin.Giga)}, //top 50 of current network
MaxDepositPeriod: gov.DefaultPeriod,
},
VotingParams: gov.VotingParams{
VotingPeriod: gov.DefaultPeriod,
},
TallyParams: gov.TallyParams{
Quorum: sdk.NewDecWithPrec(334, 3),
Threshold: sdk.NewDecWithPrec(5, 1),
Veto: sdk.NewDecWithPrec(334, 3),
GovernancePenalty: sdk.NewDecWithPrec(1, 2),
},
},
GenTxs: []json.RawMessage{},
}
}
Expand Down Expand Up @@ -194,6 +213,9 @@ func validateGenesisState(genesisState GenesisState) (err error) {
if err := distr.ValidateGenesis(genesisState.DistrData); err != nil {
return err
}
if err := gov.ValidateGenesis(genesisState.GovData); err != nil {
return err
}

return staking.ValidateGenesis(genesisState.StakingData)
}
Expand Down
3 changes: 3 additions & 0 deletions app/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/params"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand All @@ -22,6 +23,7 @@ type CyberdAppDbKeys struct {
tStake *sdk.TransientStoreKey
distr *sdk.KVStoreKey
tDistr *sdk.TransientStoreKey
gov *sdk.KVStoreKey
slashing *sdk.KVStoreKey
fees *sdk.KVStoreKey
params *sdk.KVStoreKey
Expand All @@ -40,6 +42,7 @@ func NewCyberdAppDbKeys() CyberdAppDbKeys {
fees: sdk.NewKVStoreKey(auth.FeeStoreKey),
distr: sdk.NewKVStoreKey(distr.StoreKey),
tDistr: sdk.NewTransientStoreKey(distr.TStoreKey),
gov: sdk.NewKVStoreKey(gov.StoreKey),
slashing: sdk.NewKVStoreKey(slashing.StoreKey),
params: sdk.NewKVStoreKey(params.StoreKey),
tParams: sdk.NewTransientStoreKey(params.TStoreKey),
Expand Down
2 changes: 2 additions & 0 deletions app/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/slashing"
"github.com/cosmos/cosmos-sdk/x/staking"
Expand All @@ -25,6 +26,7 @@ func MakeCodec() *codec.Codec {
auth.RegisterCodec(cdc)
staking.RegisterCodec(cdc)
slashing.RegisterCodec(cdc)
gov.RegisterCodec(cdc)
link.RegisterCodec(cdc)

cdc.Seal()
Expand Down
4 changes: 2 additions & 2 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ func txCmd(cdc *amino.Codec, mc []sdk.ModuleClients) *cobra.Command {
client.LineBreak,
authcmd.GetSignCommand(cdc),
authcmd.GetMultiSignCommand(cdc),
authcmd.GetBroadcastCommand(cdc),
authcmd.GetEncodeCommand(cdc),
tx.GetBroadcastCommand(cdc),
tx.GetEncodeCommand(cdc),
client.LineBreak,
)

Expand Down
2 changes: 1 addition & 1 deletion client/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *HttpCyberdClient) BroadcastTx(msgs []sdk.Msg) error {
}

if result.Code != 0 {
return errors.New(string(result.Log))
return errors.New(string(result.Logs.String()))
}
newBuilder := c.txBuilder.WithSequence(c.txBuilder.Sequence() + 1)
c.txBuilder = &newBuilder
Expand Down
4 changes: 2 additions & 2 deletions daemon/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func collectStdTxs(cdc *codec.Codec, moniker string, genTxsDir string, genDoc tm

msg := msgs[0].(staking.MsgCreateValidator)
// validate delegator and validator addresses and funds against the accounts in the state
delAddr := msg.DelegatorAddr.String()
valAddr := sdk.AccAddress(msg.ValidatorAddr).String()
delAddr := msg.DelegatorAddress.String()
valAddr := sdk.AccAddress(msg.ValidatorAddress).String()

delAcc, delOk := addrMap[delAddr]
_, valOk := addrMap[valAddr]
Expand Down
10 changes: 9 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ require (
github.com/ZondaX/hid-go v0.0.0-20180905224704-48b08affede2 // indirect
github.com/bartekn/go-bip39 v0.0.0-20171116152956-a05967ea095d // indirect
github.com/bgentry/speakeasy v0.1.0 // indirect
github.com/cosmos/cosmos-sdk v0.32.0
github.com/cosmos/cosmos-sdk v0.33.0-0.20190227001305-3804d0dbb44d
github.com/cosmos/go-bip39 v0.0.0-20180618194314-52158e4697b8 // indirect
github.com/ethereum/go-ethereum v1.8.20
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/protobuf v1.3.0 // indirect
github.com/gorilla/context v1.1.1 // indirect
github.com/gorilla/mux v1.6.2 // indirect
github.com/hleb-albau/ethereum-pubkey-collector v0.1.1-0.20190225072122-8f45df369725
github.com/ipfs/go-cid v0.9.0
github.com/kr/pretty v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.3 // indirect
github.com/multiformats/go-multibase v0.0.0-20190219024939-f25b77813c0a // indirect
github.com/multiformats/go-multihash v0.0.1 // indirect
github.com/pkg/errors v0.8.0
github.com/rakyll/statik v0.1.5 // indirect
github.com/spf13/afero v1.2.1 // indirect
github.com/spf13/cobra v0.0.3
github.com/spf13/viper v1.0.0
github.com/stretchr/testify v1.2.2
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tendermint/btcd v0.0.0-20180816174608-e5840949ff4f
github.com/tendermint/go-amino v0.14.1
github.com/tendermint/tendermint v0.30.1
github.com/whyrusleeping/base32 v0.0.0-20170828182744-c30ac30633cc // indirect
github.com/zondax/ledger-cosmos-go v0.1.0 // indirect
golang.org/x/net v0.0.0-20190227022144-312bce6e941f // indirect
google.golang.org/grpc v1.19.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)

replace golang.org/x/crypto => github.com/tendermint/crypto v0.0.0-20180820045704-3764759f34a5
Loading