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

Push code to develop #591

Merged
merged 8 commits into from
Nov 13, 2018
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
13 changes: 12 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion iparam/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 23 additions & 22 deletions modules/gov/genesis.go
Original file line number Diff line number Diff line change
@@ -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"`
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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),
},
}
}
8 changes: 4 additions & 4 deletions modules/gov/params/gov_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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),
}
}
}
Expand Down Expand Up @@ -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"))
Expand Down
32 changes: 16 additions & 16 deletions modules/gov/params/gov_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand All @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions modules/gov/tally.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion modules/gov/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion modules/upgrade/keep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
))
Expand Down
16 changes: 8 additions & 8 deletions modules/upgrade/params/upgrade_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
))
Expand All @@ -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) {
Expand All @@ -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),
))
Expand Down Expand Up @@ -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),
))
Expand Down Expand Up @@ -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),
))
Expand All @@ -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) )

Expand Down