This commit is contained in:
Sunny Aggarwal 2018-08-31 22:10:05 -07:00 committed by Sunny Aggarwal
parent d214952450
commit 3a62c83873
5 changed files with 36 additions and 32 deletions

View File

@ -1,6 +1,8 @@
package gov package gov
import ( import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
@ -27,10 +29,10 @@ func DefaultGenesisState() GenesisState {
StartingProposalID: 1, StartingProposalID: 1,
DepositProcedure: DepositProcedure{ DepositProcedure: DepositProcedure{
MinDeposit: sdk.Coins{sdk.NewInt64Coin("steak", 10)}, MinDeposit: sdk.Coins{sdk.NewInt64Coin("steak", 10)},
MaxDepositPeriod: 200, MaxDepositPeriod: time.Duration(172800) * time.Second,
}, },
VotingProcedure: VotingProcedure{ VotingProcedure: VotingProcedure{
VotingPeriod: 200, VotingPeriod: time.Duration(172800) * time.Second,
}, },
TallyingProcedure: TallyingProcedure{ TallyingProcedure: TallyingProcedure{
Threshold: sdk.NewDecWithPrec(5, 1), Threshold: sdk.NewDecWithPrec(5, 1),

View File

@ -122,9 +122,9 @@ func EndBlocker(ctx sdk.Context, keeper Keeper) (resTags sdk.Tags) {
for shouldPopActiveProposalQueue(ctx, keeper) { for shouldPopActiveProposalQueue(ctx, keeper) {
activeProposal := keeper.ActiveProposalQueuePop(ctx) activeProposal := keeper.ActiveProposalQueuePop(ctx)
proposalStartBlock := activeProposal.GetVotingStartBlock() proposalStartTime := activeProposal.GetVotingStartTime()
votingPeriod := keeper.GetVotingProcedure(ctx).VotingPeriod votingPeriod := keeper.GetVotingProcedure(ctx).VotingPeriod
if ctx.BlockHeight() < proposalStartBlock+votingPeriod { if ctx.BlockHeader().Time.Before(proposalStartTime.Add(votingPeriod)) {
continue continue
} }
@ -172,7 +172,7 @@ func shouldPopInactiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
return false return false
} else if peekProposal.GetStatus() != StatusDepositPeriod { } else if peekProposal.GetStatus() != StatusDepositPeriod {
return true return true
} else if ctx.BlockHeight() >= peekProposal.GetSubmitBlock()+depositProcedure.MaxDepositPeriod { } else if !ctx.BlockHeader().Time.Before(peekProposal.GetSubmitTime().Add(depositProcedure.MaxDepositPeriod)) {
return true return true
} }
return false return false
@ -184,7 +184,7 @@ func shouldPopActiveProposalQueue(ctx sdk.Context, keeper Keeper) bool {
if peekProposal == nil { if peekProposal == nil {
return false return false
} else if ctx.BlockHeight() >= peekProposal.GetVotingStartBlock()+votingProcedure.VotingPeriod { } else if !ctx.BlockHeader().Time.Before(peekProposal.GetVotingStartTime().Add(votingProcedure.VotingPeriod)) {
return true return true
} }
return false return false

View File

@ -66,15 +66,14 @@ func (keeper Keeper) NewTextProposal(ctx sdk.Context, title string, description
return nil return nil
} }
var proposal Proposal = &TextProposal{ var proposal Proposal = &TextProposal{
ProposalID: proposalID, ProposalID: proposalID,
Title: title, Title: title,
Description: description, Description: description,
ProposalType: proposalType, ProposalType: proposalType,
Status: StatusDepositPeriod, Status: StatusDepositPeriod,
TallyResult: EmptyTallyResult(), TallyResult: EmptyTallyResult(),
TotalDeposit: sdk.Coins{}, TotalDeposit: sdk.Coins{},
SubmitBlock: ctx.BlockHeight(), SubmitTime: ctx.BlockHeader().Time,
VotingStartBlock: -1, // TODO: Make Time
} }
keeper.SetProposal(ctx, proposal) keeper.SetProposal(ctx, proposal)
keeper.InactiveProposalQueuePush(ctx, proposal) keeper.InactiveProposalQueuePush(ctx, proposal)
@ -200,7 +199,7 @@ func (keeper Keeper) peekCurrentProposalID(ctx sdk.Context) (proposalID int64, e
} }
func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) { func (keeper Keeper) activateVotingPeriod(ctx sdk.Context, proposal Proposal) {
proposal.SetVotingStartBlock(ctx.BlockHeight()) proposal.SetVotingStartTime(ctx.BlockHeader().Time)
proposal.SetStatus(StatusVotingPeriod) proposal.SetStatus(StatusVotingPeriod)
keeper.SetProposal(ctx, proposal) keeper.SetProposal(ctx, proposal)
keeper.ActiveProposalQueuePush(ctx, proposal) keeper.ActiveProposalQueuePush(ctx, proposal)

View File

@ -1,13 +1,15 @@
package gov package gov
import ( import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
) )
// Procedure around Deposits for governance // Procedure around Deposits for governance
type DepositProcedure struct { type DepositProcedure struct {
MinDeposit sdk.Coins `json:"min_deposit"` // Minimum deposit for a proposal to enter voting period. MinDeposit sdk.Coins `json:"min_deposit"` // Minimum deposit for a proposal to enter voting period.
MaxDepositPeriod int64 `json:"max_deposit_period"` // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months MaxDepositPeriod time.Duration `json:"max_deposit_period"` // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
} }
// Procedure around Tallying votes in governance // Procedure around Tallying votes in governance
@ -19,5 +21,5 @@ type TallyingProcedure struct {
// Procedure around Voting in governance // Procedure around Voting in governance
type VotingProcedure struct { type VotingProcedure struct {
VotingPeriod int64 `json:"voting_period"` // Length of the voting period. VotingPeriod time.Duration `json:"voting_period"` // Length of the voting period.
} }

View File

@ -3,6 +3,7 @@ package gov
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"time"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -30,14 +31,14 @@ type Proposal interface {
GetTallyResult() TallyResult GetTallyResult() TallyResult
SetTallyResult(TallyResult) SetTallyResult(TallyResult)
GetSubmitBlock() int64 GetSubmitTime() time.Time
SetSubmitBlock(int64) SetSubmitTime(time.Time)
GetTotalDeposit() sdk.Coins GetTotalDeposit() sdk.Coins
SetTotalDeposit(sdk.Coins) SetTotalDeposit(sdk.Coins)
GetVotingStartBlock() int64 GetVotingStartTime() time.Time
SetVotingStartBlock(int64) SetVotingStartTime(time.Time)
} }
// checks if two proposals are equal // checks if two proposals are equal
@ -48,9 +49,9 @@ func ProposalEqual(proposalA Proposal, proposalB Proposal) bool {
proposalA.GetProposalType() == proposalB.GetProposalType() && proposalA.GetProposalType() == proposalB.GetProposalType() &&
proposalA.GetStatus() == proposalB.GetStatus() && proposalA.GetStatus() == proposalB.GetStatus() &&
proposalA.GetTallyResult().Equals(proposalB.GetTallyResult()) && proposalA.GetTallyResult().Equals(proposalB.GetTallyResult()) &&
proposalA.GetSubmitBlock() == proposalB.GetSubmitBlock() && proposalA.GetSubmitTime().Equal(proposalB.GetSubmitTime()) &&
proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit()) && proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit()) &&
proposalA.GetVotingStartBlock() == proposalB.GetVotingStartBlock() { proposalA.GetVotingStartTime().Equal(proposalB.GetVotingStartTime()) {
return true return true
} }
return false return false
@ -67,10 +68,10 @@ type TextProposal struct {
Status ProposalStatus `json:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected} Status ProposalStatus `json:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected}
TallyResult TallyResult `json:"tally_result"` // Result of Tallys TallyResult TallyResult `json:"tally_result"` // Result of Tallys
SubmitBlock int64 `json:"submit_block"` // Height of the block where TxGovSubmitProposal was included SubmitTime time.Time `json:"submit_block"` // Height of the block where TxGovSubmitProposal was included
TotalDeposit sdk.Coins `json:"total_deposit"` // Current deposit on this proposal. Initial value is set at InitialDeposit TotalDeposit sdk.Coins `json:"total_deposit"` // Current deposit on this proposal. Initial value is set at InitialDeposit
VotingStartBlock int64 `json:"voting_start_block"` // Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached VotingStartTime time.Time `json:"voting_start_block"` // Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached
} }
// Implements Proposal Interface // Implements Proposal Interface
@ -89,13 +90,13 @@ func (tp TextProposal) GetStatus() ProposalStatus { return tp.S
func (tp *TextProposal) SetStatus(status ProposalStatus) { tp.Status = status } func (tp *TextProposal) SetStatus(status ProposalStatus) { tp.Status = status }
func (tp TextProposal) GetTallyResult() TallyResult { return tp.TallyResult } func (tp TextProposal) GetTallyResult() TallyResult { return tp.TallyResult }
func (tp *TextProposal) SetTallyResult(tallyResult TallyResult) { tp.TallyResult = tallyResult } func (tp *TextProposal) SetTallyResult(tallyResult TallyResult) { tp.TallyResult = tallyResult }
func (tp TextProposal) GetSubmitBlock() int64 { return tp.SubmitBlock } func (tp TextProposal) GetSubmitTime() time.Time { return tp.SubmitTime }
func (tp *TextProposal) SetSubmitBlock(submitBlock int64) { tp.SubmitBlock = submitBlock } func (tp *TextProposal) SetSubmitTime(submitTime time.Time) { tp.SubmitTime = submitTime }
func (tp TextProposal) GetTotalDeposit() sdk.Coins { return tp.TotalDeposit } func (tp TextProposal) GetTotalDeposit() sdk.Coins { return tp.TotalDeposit }
func (tp *TextProposal) SetTotalDeposit(totalDeposit sdk.Coins) { tp.TotalDeposit = totalDeposit } func (tp *TextProposal) SetTotalDeposit(totalDeposit sdk.Coins) { tp.TotalDeposit = totalDeposit }
func (tp TextProposal) GetVotingStartBlock() int64 { return tp.VotingStartBlock } func (tp TextProposal) GetVotingStartTime() time.Time { return tp.VotingStartTime }
func (tp *TextProposal) SetVotingStartBlock(votingStartBlock int64) { func (tp *TextProposal) SetVotingStartTime(votingStartTime time.Time) {
tp.VotingStartBlock = votingStartBlock tp.VotingStartTime = votingStartTime
} }
//----------------------------------------------------------- //-----------------------------------------------------------