diff --git a/Makefile b/Makefile index 11d253862..b1b68b708 100644 --- a/Makefile +++ b/Makefile @@ -125,7 +125,18 @@ test_sim_iris_slow: testnet_start: @if ! [ -f build/iris ]; then $(MAKE) build_linux ; fi - @if ! [ -f build/nodecluster/node0/iris/config/genesis.json ]; then ./build/iris testnet --v 4 --output-dir build/nodecluster --chain-id irishub-test --starting-ip-address 192.168.10.2 ; fi + @if ! [ -f build/nodecluster/node0/iris/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/home ubuntu:16.04 /home/iris testnet --v 4 --output-dir /home/nodecluster --chain-id irishub-test --starting-ip-address 192.168.10.2 ; fi + @echo "To install jq command, please refer to this page: https://stedolan.github.io/jq/download/" + @jq '.app_state.accounts+= [{"address": "faa1ljemm0yznz58qxxs8xyak7fashcfxf5lssn6jm", "coins": [{ "denom":"iris-atto","amount": "1000000000000000000000000"}], "sequence_number": "0", "account_number": "0"}]' build/nodecluster/node0/iris/config/genesis.json > build/genesis_temp.json + @jq '.app_state.stake.pool.loose_tokens="1000600000000000000000000.0000000000"' build/genesis_temp.json > build/genesis_temp1.json + @sudo cp build/genesis_temp1.json build/nodecluster/node0/iris/config/genesis.json + @sudo cp build/genesis_temp1.json build/nodecluster/node1/iris/config/genesis.json + @sudo cp build/genesis_temp1.json build/nodecluster/node2/iris/config/genesis.json + @sudo cp build/genesis_temp1.json build/nodecluster/node3/iris/config/genesis.json + @rm build/genesis_temp.json build/genesis_temp1.json + @echo "Faucet address: faa1ljemm0yznz58qxxs8xyak7fashcfxf5lssn6jm" + @echo "Faucet coin amount: 1000000iris" + @echo "Faucet key seed: tube lonely pause spring gym veteran know want grid tired taxi such same mesh charge orient bracket ozone concert once good quick dry boss" docker-compose up -d testnet_stop: diff --git a/iparam/errors.go b/iparam/errors.go index 2f6ee4350..5ed92aca7 100644 --- a/iparam/errors.go +++ b/iparam/errors.go @@ -14,7 +14,7 @@ const ( CodeInvalidVotingPeriod sdk.CodeType = 105 CodeInvalidVotingProcedure sdk.CodeType = 106 CodeInvalidThreshold sdk.CodeType = 107 - CodeInvalidGovernancePenalty sdk.CodeType = 108 + CodeInvalidParticipation sdk.CodeType = 108 CodeInvalidVeto sdk.CodeType = 109 CodeInvalidTallyingProcedure sdk.CodeType = 110 CodeInvalidKey sdk.CodeType = 111 diff --git a/modules/gov/genesis.go b/modules/gov/genesis.go index c42962335..9e1ec53dd 100644 --- a/modules/gov/genesis.go +++ b/modules/gov/genesis.go @@ -1,30 +1,30 @@ - package gov import ( + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/irisnet/irishub/iparam" "github.com/irisnet/irishub/modules/gov/params" - "fmt" "github.com/irisnet/irishub/types" "time" - "github.com/irisnet/irishub/iparam" ) // GenesisState - all gov state that must be provided at genesis type GenesisState struct { - StartingProposalID uint64 `json:"starting_proposalID"` - Deposits []DepositWithMetadata `json:"deposits"` - Votes []VoteWithMetadata `json:"votes"` - Proposals []Proposal `json:"proposals"` - DepositProcedure govparams.DepositProcedure `json:"deposit_period"` - VotingProcedure govparams.VotingProcedure `json:"voting_period"` - TallyingProcedure govparams.TallyingProcedure `json:"tallying_procedure"` + StartingProposalID uint64 `json:"starting_proposalID"` + Deposits []DepositWithMetadata `json:"deposits"` + Votes []VoteWithMetadata `json:"votes"` + Proposals []Proposal `json:"proposals"` + DepositProcedure govparams.DepositProcedure `json:"deposit_period"` + VotingProcedure govparams.VotingProcedure `json:"voting_period"` + TallyingProcedure govparams.TallyingProcedure `json:"tallying_procedure"` } type DepositWithMetadata struct { ProposalID uint64 `json:"proposal_id"` Deposit Deposit `json:"deposit"` } + // VoteWithMetadata (just for genesis) type VoteWithMetadata struct { ProposalID uint64 `json:"proposal_id"` @@ -101,9 +101,10 @@ func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { TallyingProcedure: tallyingProcedure, } } + // get raw genesis raw message for testing func DefaultGenesisState() GenesisState { - Denom := "iris" + Denom := "iris" IrisCt := types.NewDefaultCoinType(Denom) minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 1000, Denom)) if err != nil { @@ -119,16 +120,16 @@ func DefaultGenesisState() GenesisState { VotingPeriod: time.Duration(172800) * time.Second, }, TallyingProcedure: govparams.TallyingProcedure{ - Threshold: sdk.NewDecWithPrec(5, 1), - Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Threshold: sdk.NewDecWithPrec(5, 1), + Veto: sdk.NewDecWithPrec(334, 3), + Participation: sdk.NewDecWithPrec(667, 3), }, } } // get raw genesis raw message for testing func DefaultGenesisStateForCliTest() GenesisState { - Denom := "iris" + Denom := "iris" IrisCt := types.NewDefaultCoinType(Denom) minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 10, Denom)) if err != nil { @@ -144,16 +145,16 @@ func DefaultGenesisStateForCliTest() GenesisState { VotingPeriod: time.Duration(60) * time.Second, }, TallyingProcedure: govparams.TallyingProcedure{ - Threshold: sdk.NewDecWithPrec(5, 1), - Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Threshold: sdk.NewDecWithPrec(5, 1), + Veto: sdk.NewDecWithPrec(334, 3), + Participation: sdk.NewDecWithPrec(667, 3), }, } } // get raw genesis raw message for testing func DefaultGenesisStateForLCDTest() GenesisState { - Denom := "iris" + Denom := "iris" IrisCt := types.NewDefaultCoinType(Denom) minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 10, Denom)) if err != nil { @@ -169,9 +170,9 @@ func DefaultGenesisStateForLCDTest() GenesisState { VotingPeriod: time.Duration(172800) * time.Second, }, TallyingProcedure: govparams.TallyingProcedure{ - Threshold: sdk.NewDecWithPrec(5, 1), - Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Threshold: sdk.NewDecWithPrec(5, 1), + Veto: sdk.NewDecWithPrec(334, 3), + Participation: sdk.NewDecWithPrec(667, 3), }, } } diff --git a/modules/gov/params/gov_params.go b/modules/gov/params/gov_params.go index 02e960f28..f662169d1 100644 --- a/modules/gov/params/gov_params.go +++ b/modules/gov/params/gov_params.go @@ -213,7 +213,7 @@ var _ iparam.GovParameter = (*TallyingProcedureParam)(nil) type TallyingProcedure struct { Threshold sdk.Dec `json:"threshold"` // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5 Veto sdk.Dec `json:"veto"` // Minimum value of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3 - GovernancePenalty sdk.Dec `json:"governance_penalty"` // Penalty if validator does not vote + Participation sdk.Dec `json:"participation"` // } type TallyingProcedureParam struct { @@ -233,7 +233,7 @@ func (param *TallyingProcedureParam) InitGenesis(genesisState interface{}) { param.Value = TallyingProcedure{ Threshold: sdk.NewDecWithPrec(5, 1), Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Participation: sdk.NewDecWithPrec(667, 3), } } } @@ -288,8 +288,8 @@ func (param *TallyingProcedureParam) Valid(jsonStr string) sdk.Error { if param.Value.Threshold.LTE(sdk.ZeroDec()) || param.Value.Threshold.GTE(sdk.NewDec(1)) { return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidThreshold, fmt.Sprintf("Invalid Threshold ( "+param.Value.Threshold.String()+" ) should be between 0 and 1")) } - if param.Value.GovernancePenalty.LTE(sdk.ZeroDec()) || param.Value.GovernancePenalty.GTE(sdk.NewDec(1)) { - return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidGovernancePenalty, fmt.Sprintf("Invalid Penalty ( "+param.Value.GovernancePenalty.String()+" ) should be between 0 and 1")) + if param.Value.Participation.LTE(sdk.ZeroDec()) || param.Value.Participation.GTE(sdk.NewDec(1)) { + return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidParticipation, fmt.Sprintf("Invalid participation ( "+param.Value.Participation.String()+" ) should be between 0 and 1")) } if param.Value.Veto.LTE(sdk.ZeroDec()) || param.Value.Veto.GTE(sdk.NewDec(1)) { return sdk.NewError(iparam.DefaultCodespace, iparam.CodeInvalidVeto, fmt.Sprintf("Invalid Veto ( "+param.Value.Veto.String()+" ) should be between 0 and 1")) diff --git a/modules/gov/params/gov_params_test.go b/modules/gov/params/gov_params_test.go index 6f6ae87d5..ba3f72a10 100644 --- a/modules/gov/params/gov_params_test.go +++ b/modules/gov/params/gov_params_test.go @@ -2,12 +2,12 @@ package govparams import ( "fmt" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/x/params" - "github.com/irisnet/irishub/types" "github.com/irisnet/irishub/iparam" + "github.com/irisnet/irishub/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" dbm "github.com/tendermint/tendermint/libs/db" @@ -39,8 +39,8 @@ func TestInitGenesisParameter(t *testing.T) { skey, tkeyParams, ) - Denom := "iris" - IrisCt := types.NewDefaultCoinType(Denom) + Denom := "iris" + IrisCt := types.NewDefaultCoinType(Denom) minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 10, Denom)) require.NoError(t, err) @@ -83,8 +83,8 @@ func TestRegisterParamMapping(t *testing.T) { skey, tkeyParams, ) - Denom := "iris" - IrisCt := types.NewDefaultCoinType(Denom) + Denom := "iris" + IrisCt := types.NewDefaultCoinType(Denom) minDeposit, err := IrisCt.ConvertToMinCoin(fmt.Sprintf("%d%s", 10, Denom)) require.NoError(t, err) @@ -261,15 +261,15 @@ func TestTallyingProcedureParam(t *testing.T) { ) p1 := TallyingProcedure{ - Threshold: sdk.NewDecWithPrec(5, 1), - Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Threshold: sdk.NewDecWithPrec(5, 1), + Veto: sdk.NewDecWithPrec(334, 3), + Participation: sdk.NewDecWithPrec(667, 3), } p2 := TallyingProcedure{ - Threshold: sdk.NewDecWithPrec(5, 1), - Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(2, 2), + Threshold: sdk.NewDecWithPrec(5, 1), + Veto: sdk.NewDecWithPrec(334, 3), + Participation: sdk.NewDecWithPrec(2, 2), } subspace := paramKeeper.Subspace("Gov").WithTypeTable( @@ -285,17 +285,17 @@ func TestTallyingProcedureParam(t *testing.T) { TallyingProcedureParameter.InitGenesis(nil) require.Equal(t, p1, TallyingProcedureParameter.Value) - require.Equal(t, "{\"threshold\":\"0.5000000000\",\"veto\":\"0.3340000000\",\"governance_penalty\":\"0.0100000000\"}", TallyingProcedureParameter.ToJson("")) + require.Equal(t, "{\"threshold\":\"0.5000000000\",\"veto\":\"0.3340000000\",\"participation\":\"0.6670000000\"}", TallyingProcedureParameter.ToJson("")) - TallyingProcedureParameter.Update(ctx, "{\"threshold\":\"0.5\",\"veto\":\"0.3340000000\",\"governance_penalty\":\"0.0200000000\"}") + TallyingProcedureParameter.Update(ctx, "{\"threshold\":\"0.5\",\"veto\":\"0.3340000000\",\"participation\":\"0.0200000000\"}") require.NotEqual(t, p1, TallyingProcedureParameter.Value) require.Equal(t, p2, TallyingProcedureParameter.Value) - result := TallyingProcedureParameter.Valid("{\"threshold\":\"1/1\",\"veto\":\"1/3\",\"governance_penalty\":\"1/100\"}") + result := TallyingProcedureParameter.Valid("{\"threshold\":\"1/1\",\"veto\":\"1/3\",\"participation\":\"1/100\"}") require.Error(t, result) - result = TallyingProcedureParameter.Valid("{\"threshold\":\"abcd\",\"veto\":\"1/3\",\"governance_penalty\":\"1/100\"}") + result = TallyingProcedureParameter.Valid("{\"threshold\":\"abcd\",\"veto\":\"1/3\",\"participation\":\"1/100\"}") require.Error(t, result) TallyingProcedureParameter.InitGenesis(p2) diff --git a/modules/gov/tally.go b/modules/gov/tally.go index a8d1ce264..e63fe025a 100644 --- a/modules/gov/tally.go +++ b/modules/gov/tally.go @@ -105,6 +105,12 @@ func tally(ctx sdk.Context, keeper Keeper, proposal Proposal) (passes bool, tall if results[OptionNoWithVeto].Quo(totalVotingPower).GT(tallyingProcedure.Veto) { return false, tallyResults } + //////////////////// iris begin /////////////////////////// + //if more than 1/3 of voters abstain, proposal fails + if totalVotingPower.Sub(results[OptionAbstain]).Quo(totalVotingPower).LTE(tallyingProcedure.Participation){ + return false, tallyResults + } + //////////////////// iris end /////////////////////////// // If more than 1/2 of non-abstaining voters vote Yes, proposal passes if results[OptionYes].Quo(totalVotingPower.Sub(results[OptionAbstain])).GT(tallyingProcedure.Threshold) { return true, tallyResults diff --git a/modules/gov/test_common.go b/modules/gov/test_common.go index a7340ec88..31757cd78 100644 --- a/modules/gov/test_common.go +++ b/modules/gov/test_common.go @@ -88,7 +88,7 @@ func getInitChainer(mapp *mock.App, keeper Keeper, stakeKeeper stake.Keeper) sdk TallyingProcedure: govparams.TallyingProcedure{ Threshold: sdk.NewDecWithPrec(5, 1), Veto: sdk.NewDecWithPrec(334, 3), - GovernancePenalty: sdk.NewDecWithPrec(1, 2), + Participation: sdk.NewDecWithPrec(667, 3), }, }) return abci.ResponseInitChain{ diff --git a/modules/upgrade/keep_test.go b/modules/upgrade/keep_test.go index fde61f022..0d70b5cd2 100644 --- a/modules/upgrade/keep_test.go +++ b/modules/upgrade/keep_test.go @@ -185,7 +185,7 @@ func TestKeeper_InitGenesis_commidID(t *testing.T) { fmt.Println(keeper.GetKVStoreKeylist(ctx)) subspace := paramKeeper.Subspace("Sig").WithTypeTable(params.NewTypeTable( - upgradeparams.CurrentUpgradeProposalIdParameter.GetStoreKey(), int64((0)), + upgradeparams.CurrentUpgradeProposalIdParameter.GetStoreKey(), uint64((0)), upgradeparams.ProposalAcceptHeightParameter.GetStoreKey(), int64(0), upgradeparams.SwitchPeriodParameter.GetStoreKey(), int64(0), )) diff --git a/modules/upgrade/params/upgrade_params_test.go b/modules/upgrade/params/upgrade_params_test.go index 6eb7f142d..3f11995c4 100644 --- a/modules/upgrade/params/upgrade_params_test.go +++ b/modules/upgrade/params/upgrade_params_test.go @@ -37,7 +37,7 @@ func TestCurrentUpgradeProposalIdParameter(t *testing.T) { ) subspace := paramKeeper.Subspace("Sig").WithTypeTable(params.NewTypeTable( - CurrentUpgradeProposalIdParameter.GetStoreKey(), int64((0)), + CurrentUpgradeProposalIdParameter.GetStoreKey(), uint64((0)), ProposalAcceptHeightParameter.GetStoreKey(), int64(0), SwitchPeriodParameter.GetStoreKey(), int64(0), )) @@ -47,16 +47,16 @@ func TestCurrentUpgradeProposalIdParameter(t *testing.T) { require.Equal(t, find, false) CurrentUpgradeProposalIdParameter.InitGenesis(nil) - require.Equal(t, int64(-1), CurrentUpgradeProposalIdParameter.Value) + require.Equal(t, uint64(0), CurrentUpgradeProposalIdParameter.Value) CurrentUpgradeProposalIdParameter.LoadValue(ctx) - require.Equal(t, int64(-1), CurrentUpgradeProposalIdParameter.Value) + require.Equal(t, uint64(0), CurrentUpgradeProposalIdParameter.Value) CurrentUpgradeProposalIdParameter.Value = 3 CurrentUpgradeProposalIdParameter.SaveValue(ctx) CurrentUpgradeProposalIdParameter.LoadValue(ctx) - require.Equal(t, int64(3), CurrentUpgradeProposalIdParameter.Value) + require.Equal(t, uint64(3), CurrentUpgradeProposalIdParameter.Value) } func TestProposalAcceptHeightParameter(t *testing.T) { @@ -72,7 +72,7 @@ func TestProposalAcceptHeightParameter(t *testing.T) { ) subspace := paramKeeper.Subspace("Sig").WithTypeTable(params.NewTypeTable( - CurrentUpgradeProposalIdParameter.GetStoreKey(), int64((0)), + CurrentUpgradeProposalIdParameter.GetStoreKey(), uint64((0)), ProposalAcceptHeightParameter.GetStoreKey(), int64(0), SwitchPeriodParameter.GetStoreKey(), int64(0), )) @@ -107,7 +107,7 @@ func TestSwitchPeriodParameter(t *testing.T) { ) subspace := paramKeeper.Subspace("Sig").WithTypeTable(params.NewTypeTable( - CurrentUpgradeProposalIdParameter.GetStoreKey(), int64((0)), + CurrentUpgradeProposalIdParameter.GetStoreKey(), uint64((0)), ProposalAcceptHeightParameter.GetStoreKey(), int64(0), SwitchPeriodParameter.GetStoreKey(), int64(0), )) @@ -142,7 +142,7 @@ func TestUpgradeParameterSetAndGet(t *testing.T) { ) subspace := paramKeeper.Subspace("Sig").WithTypeTable(params.NewTypeTable( - CurrentUpgradeProposalIdParameter.GetStoreKey(), int64((0)), + CurrentUpgradeProposalIdParameter.GetStoreKey(), uint64((0)), ProposalAcceptHeightParameter.GetStoreKey(), int64(0), SwitchPeriodParameter.GetStoreKey(), int64(0), )) @@ -160,7 +160,7 @@ func TestUpgradeParameterSetAndGet(t *testing.T) { require.Equal(t, find, false) SetCurrentUpgradeProposalId(ctx,5) - require.Equal(t,int64(5),GetCurrentUpgradeProposalId(ctx)) + require.Equal(t,uint64(5),GetCurrentUpgradeProposalId(ctx)) SetProposalAcceptHeight(ctx,100) require.Equal(t, int64(100),GetProposalAcceptHeight(ctx) )