Revert "Merge PR #2217: Governance BFT Time"
This reverts commit94b86f85c1
, reversing changes made to2a4edcca48
.
This commit is contained in:
parent
e0713404d7
commit
72e9664ce1
|
@ -28,8 +28,7 @@ BREAKING CHANGES
|
||||||
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator operator type has now changed to `sdk.ValAddress`
|
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator operator type has now changed to `sdk.ValAddress`
|
||||||
* A new bech32 prefix has been introduced for Tendermint signing keys and
|
* A new bech32 prefix has been introduced for Tendermint signing keys and
|
||||||
addresses, `cosmosconspub` and `cosmoscons` respectively.
|
addresses, `cosmosconspub` and `cosmoscons` respectively.
|
||||||
* [x/gov] \#2195 Made governance use BFT Time instead of Block Heights for deposit and voting periods.
|
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
* [core] [\#1807](https://github.com/cosmos/cosmos-sdk/issues/1807) Switch from use of rational to decimal
|
* [core] [\#1807](https://github.com/cosmos/cosmos-sdk/issues/1807) Switch from use of rational to decimal
|
||||||
* [types] [\#1901](https://github.com/cosmos/cosmos-sdk/issues/1901) Validator interface's GetOwner() renamed to GetOperator()
|
* [types] [\#1901](https://github.com/cosmos/cosmos-sdk/issues/1901) Validator interface's GetOwner() renamed to GetOperator()
|
||||||
|
|
|
@ -13,13 +13,13 @@ has to be created and the previous one rendered inactive.
|
||||||
```go
|
```go
|
||||||
type DepositProcedure struct {
|
type DepositProcedure struct {
|
||||||
MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period.
|
MinDeposit sdk.Coins // Minimum deposit for a proposal to enter voting period.
|
||||||
MaxDepositPeriod time.Time // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
|
MaxDepositPeriod int64 // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```go
|
```go
|
||||||
type VotingProcedure struct {
|
type VotingProcedure struct {
|
||||||
VotingPeriod time.Time // Length of the voting period. Initial value: 2 weeks
|
VotingPeriod int64 // Length of the voting period. Initial value: 2 weeks
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ type TallyingProcedure struct {
|
||||||
Threshold sdk.Dec // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
|
Threshold sdk.Dec // Minimum propotion of Yes votes for proposal to pass. Initial value: 0.5
|
||||||
Veto sdk.Dec // Minimum proportion of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
|
Veto sdk.Dec // Minimum proportion of Veto votes to Total votes ratio for proposal to be vetoed. Initial value: 1/3
|
||||||
GovernancePenalty sdk.Dec // Penalty if validator does not vote
|
GovernancePenalty sdk.Dec // Penalty if validator does not vote
|
||||||
GracePeriod time.Time // If validator entered validator set in this period of blocks before vote ended, governance penalty does not apply
|
GracePeriod int64 // If validator entered validator set in this period of blocks before vote ended, governance penalty does not apply
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -97,10 +97,10 @@ type Proposal struct {
|
||||||
Type ProposalType // Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
|
Type ProposalType // Type of proposal. Initial set {PlainTextProposal, SoftwareUpgradeProposal}
|
||||||
TotalDeposit sdk.Coins // Current deposit on this proposal. Initial value is set at InitialDeposit
|
TotalDeposit sdk.Coins // Current deposit on this proposal. Initial value is set at InitialDeposit
|
||||||
Deposits []Deposit // List of deposits on the proposal
|
Deposits []Deposit // List of deposits on the proposal
|
||||||
SubmitTime time.Time // Time of the block where TxGovSubmitProposal was included
|
SubmitBlock int64 // Height of the block where TxGovSubmitProposal was included
|
||||||
Submitter sdk.Address // Address of the submitter
|
Submitter sdk.Address // Address of the submitter
|
||||||
|
|
||||||
VotingStartTime time.Time // Time of the block where MinDeposit was reached. time.Time{} if MinDeposit is not reached
|
VotingStartBlock int64 // Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached
|
||||||
CurrentStatus ProposalStatus // Current status of the proposal
|
CurrentStatus ProposalStatus // Current status of the proposal
|
||||||
|
|
||||||
YesVotes sdk.Dec
|
YesVotes sdk.Dec
|
||||||
|
@ -137,7 +137,7 @@ For pseudocode purposes, here are the two function we will use to read or write
|
||||||
* `ProposalProcessingQueue`: A queue `queue[proposalID]` containing all the
|
* `ProposalProcessingQueue`: A queue `queue[proposalID]` containing all the
|
||||||
`ProposalIDs` of proposals that reached `MinDeposit`. Each round, the oldest
|
`ProposalIDs` of proposals that reached `MinDeposit`. Each round, the oldest
|
||||||
element of `ProposalProcessingQueue` is checked during `BeginBlock` to see if
|
element of `ProposalProcessingQueue` is checked during `BeginBlock` to see if
|
||||||
`CurrentTime == VotingStartTime + activeProcedure.VotingPeriod`. If it is,
|
`CurrentBlock == VotingStartBlock + activeProcedure.VotingPeriod`. If it is,
|
||||||
then the application tallies the votes, compute the votes of each validator and checks if every validator in the valdiator set have voted
|
then the application tallies the votes, compute the votes of each validator and checks if every validator in the valdiator set have voted
|
||||||
and, if not, applies `GovernancePenalty`. If the proposal is accepted, deposits are refunded.
|
and, if not, applies `GovernancePenalty`. If the proposal is accepted, deposits are refunded.
|
||||||
After that proposal is ejected from `ProposalProcessingQueue` and the next element of the queue is evaluated.
|
After that proposal is ejected from `ProposalProcessingQueue` and the next element of the queue is evaluated.
|
||||||
|
@ -159,7 +159,7 @@ And the pseudocode for the `ProposalProcessingQueue`:
|
||||||
proposal = load(Governance, <proposalID|'proposal'>) // proposal is a const key
|
proposal = load(Governance, <proposalID|'proposal'>) // proposal is a const key
|
||||||
votingProcedure = load(GlobalParams, 'VotingProcedure')
|
votingProcedure = load(GlobalParams, 'VotingProcedure')
|
||||||
|
|
||||||
if (CurrentTime == proposal.VotingStartTime + votingProcedure.VotingPeriod && proposal.CurrentStatus == ProposalStatusActive)
|
if (CurrentBlock == proposal.VotingStartBlock + votingProcedure.VotingPeriod && proposal.CurrentStatus == ProposalStatusActive)
|
||||||
|
|
||||||
// End of voting period, tally
|
// End of voting period, tally
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ And the pseudocode for the `ProposalProcessingQueue`:
|
||||||
|
|
||||||
// Slash validators that did not vote, or update tally if they voted
|
// Slash validators that did not vote, or update tally if they voted
|
||||||
for each validator in validators
|
for each validator in validators
|
||||||
if (validator.bondTime < CurrentTime - tallyingProcedure.GracePeriod)
|
if (validator.bondHeight < CurrentBlock - tallyingProcedure.GracePeriod)
|
||||||
// only slash if validator entered validator set before grace period
|
// only slash if validator entered validator set before grace period
|
||||||
if (!tmpValMap(validator).HasVoted)
|
if (!tmpValMap(validator).HasVoted)
|
||||||
slash validator by tallyingProcedure.GovernancePenalty
|
slash validator by tallyingProcedure.GovernancePenalty
|
||||||
|
|
|
@ -2,7 +2,6 @@ package gov
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
@ -29,18 +28,12 @@ func TestTickExpiredDepositPeriod(t *testing.T) {
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(10)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(250)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -66,10 +59,7 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(10)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(2) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
@ -78,20 +68,14 @@ func TestTickMultipleExpiredDepositPeriod(t *testing.T) {
|
||||||
res = govHandler(ctx, newProposalMsg2)
|
res = govHandler(ctx, newProposalMsg2)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(205)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(time.Duration(-1) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(215)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(5) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.True(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -121,10 +105,7 @@ func TestTickPassedDepositPeriod(t *testing.T) {
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(10)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.InactiveProposalQueuePeek(ctx))
|
||||||
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
require.False(t, shouldPopInactiveProposalQueue(ctx, keeper))
|
||||||
|
@ -165,20 +146,14 @@ func TestTickPassedVotingPeriod(t *testing.T) {
|
||||||
var proposalID int64
|
var proposalID int64
|
||||||
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(10)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
newDepositMsg := NewMsgDeposit(addrs[1], proposalID, sdk.Coins{sdk.NewInt64Coin("steak", 5)})
|
||||||
res = govHandler(ctx, newDepositMsg)
|
res = govHandler(ctx, newDepositMsg)
|
||||||
require.True(t, res.IsOK())
|
require.True(t, res.IsOK())
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(215)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.True(t, shouldPopActiveProposalQueue(ctx, keeper))
|
require.True(t, shouldPopActiveProposalQueue(ctx, keeper))
|
||||||
depositsIterator := keeper.GetDeposits(ctx, proposalID)
|
depositsIterator := keeper.GetDeposits(ctx, proposalID)
|
||||||
require.True(t, depositsIterator.Valid())
|
require.True(t, depositsIterator.Valid())
|
||||||
|
@ -222,10 +197,7 @@ func TestSlashing(t *testing.T) {
|
||||||
var proposalID int64
|
var proposalID int64
|
||||||
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
keeper.cdc.UnmarshalBinaryBare(res.Data, &proposalID)
|
||||||
|
|
||||||
newHeader := ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(10)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(time.Duration(1) * time.Second)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
||||||
|
|
||||||
newVoteMsg := NewMsgVote(addrs[0], proposalID, OptionYes)
|
newVoteMsg := NewMsgVote(addrs[0], proposalID, OptionYes)
|
||||||
|
@ -234,10 +206,7 @@ func TestSlashing(t *testing.T) {
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
|
||||||
newHeader = ctx.BlockHeader()
|
ctx = ctx.WithBlockHeight(215)
|
||||||
newHeader.Time = ctx.BlockHeader().Time.Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod).Add(keeper.GetDepositProcedure(ctx).MaxDepositPeriod)
|
|
||||||
ctx = ctx.WithBlockHeader(newHeader)
|
|
||||||
|
|
||||||
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
require.Equal(t, StatusVotingPeriod, keeper.GetProposal(ctx, proposalID).GetStatus())
|
||||||
|
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package gov
|
package gov
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,10 +27,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: time.Duration(172800) * time.Second,
|
MaxDepositPeriod: 200,
|
||||||
},
|
},
|
||||||
VotingProcedure: VotingProcedure{
|
VotingProcedure: VotingProcedure{
|
||||||
VotingPeriod: time.Duration(172800) * time.Second,
|
VotingPeriod: 200,
|
||||||
},
|
},
|
||||||
TallyingProcedure: TallyingProcedure{
|
TallyingProcedure: TallyingProcedure{
|
||||||
Threshold: sdk.NewDecWithPrec(5, 1),
|
Threshold: sdk.NewDecWithPrec(5, 1),
|
||||||
|
|
|
@ -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)
|
||||||
|
|
||||||
proposalStartTime := activeProposal.GetVotingStartTime()
|
proposalStartBlock := activeProposal.GetVotingStartBlock()
|
||||||
votingPeriod := keeper.GetVotingProcedure(ctx).VotingPeriod
|
votingPeriod := keeper.GetVotingProcedure(ctx).VotingPeriod
|
||||||
if ctx.BlockHeader().Time.Before(proposalStartTime.Add(votingPeriod)) {
|
if ctx.BlockHeight() < proposalStartBlock+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.BlockHeader().Time.Before(peekProposal.GetSubmitTime().Add(depositProcedure.MaxDepositPeriod)) {
|
} else if ctx.BlockHeight() >= peekProposal.GetSubmitBlock()+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.BlockHeader().Time.Before(peekProposal.GetVotingStartTime().Add(votingProcedure.VotingPeriod)) {
|
} else if ctx.BlockHeight() >= peekProposal.GetVotingStartBlock()+votingProcedure.VotingPeriod {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -66,14 +66,15 @@ 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{},
|
||||||
SubmitTime: ctx.BlockHeader().Time,
|
SubmitBlock: ctx.BlockHeight(),
|
||||||
|
VotingStartBlock: -1, // TODO: Make Time
|
||||||
}
|
}
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
keeper.InactiveProposalQueuePush(ctx, proposal)
|
keeper.InactiveProposalQueuePush(ctx, proposal)
|
||||||
|
@ -199,7 +200,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.SetVotingStartTime(ctx.BlockHeader().Time)
|
proposal.SetVotingStartBlock(ctx.BlockHeight())
|
||||||
proposal.SetStatus(StatusVotingPeriod)
|
proposal.SetStatus(StatusVotingPeriod)
|
||||||
keeper.SetProposal(ctx, proposal)
|
keeper.SetProposal(ctx, proposal)
|
||||||
keeper.ActiveProposalQueuePush(ctx, proposal)
|
keeper.ActiveProposalQueuePush(ctx, proposal)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package gov
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
@ -46,12 +45,12 @@ func TestActivateVotingPeriod(t *testing.T) {
|
||||||
|
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
|
|
||||||
require.True(t, proposal.GetVotingStartTime().Equal(time.Time{}))
|
require.Equal(t, int64(-1), proposal.GetVotingStartBlock())
|
||||||
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||||
|
|
||||||
keeper.activateVotingPeriod(ctx, proposal)
|
keeper.activateVotingPeriod(ctx, proposal)
|
||||||
|
|
||||||
require.True(t, proposal.GetVotingStartTime().Equal(ctx.BlockHeader().Time))
|
require.Equal(t, proposal.GetVotingStartBlock(), ctx.BlockHeight())
|
||||||
require.Equal(t, proposal.GetProposalID(), keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
require.Equal(t, proposal.GetProposalID(), keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +77,7 @@ func TestDeposits(t *testing.T) {
|
||||||
// Check no deposits at beginning
|
// Check no deposits at beginning
|
||||||
deposit, found := keeper.GetDeposit(ctx, proposalID, addrs[1])
|
deposit, found := keeper.GetDeposit(ctx, proposalID, addrs[1])
|
||||||
require.False(t, found)
|
require.False(t, found)
|
||||||
require.True(t, keeper.GetProposal(ctx, proposalID).GetVotingStartTime().Equal(time.Time{}))
|
require.Equal(t, keeper.GetProposal(ctx, proposalID).GetVotingStartBlock(), int64(-1))
|
||||||
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
require.Nil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||||
|
|
||||||
// Check first deposit
|
// Check first deposit
|
||||||
|
@ -115,7 +114,7 @@ func TestDeposits(t *testing.T) {
|
||||||
require.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1]))
|
require.Equal(t, addr1Initial.Minus(fourSteak), keeper.ck.GetCoins(ctx, addrs[1]))
|
||||||
|
|
||||||
// Check that proposal moved to voting period
|
// Check that proposal moved to voting period
|
||||||
require.True(t, keeper.GetProposal(ctx, proposalID).GetVotingStartTime().Equal(ctx.BlockHeader().Time))
|
require.Equal(t, ctx.BlockHeight(), keeper.GetProposal(ctx, proposalID).GetVotingStartBlock())
|
||||||
require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx))
|
require.NotNil(t, keeper.ActiveProposalQueuePeek(ctx))
|
||||||
require.Equal(t, proposalID, keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
require.Equal(t, proposalID, keeper.ActiveProposalQueuePeek(ctx).GetProposalID())
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
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 time.Duration `json:"max_deposit_period"` // Maximum period for Atom holders to deposit on a proposal. Initial value: 2 months
|
MaxDepositPeriod int64 `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
|
||||||
|
@ -21,5 +19,5 @@ type TallyingProcedure struct {
|
||||||
|
|
||||||
// Procedure around Voting in governance
|
// Procedure around Voting in governance
|
||||||
type VotingProcedure struct {
|
type VotingProcedure struct {
|
||||||
VotingPeriod time.Duration `json:"voting_period"` // Length of the voting period.
|
VotingPeriod int64 `json:"voting_period"` // Length of the voting period.
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package gov
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
@ -31,14 +30,14 @@ type Proposal interface {
|
||||||
GetTallyResult() TallyResult
|
GetTallyResult() TallyResult
|
||||||
SetTallyResult(TallyResult)
|
SetTallyResult(TallyResult)
|
||||||
|
|
||||||
GetSubmitTime() time.Time
|
GetSubmitBlock() int64
|
||||||
SetSubmitTime(time.Time)
|
SetSubmitBlock(int64)
|
||||||
|
|
||||||
GetTotalDeposit() sdk.Coins
|
GetTotalDeposit() sdk.Coins
|
||||||
SetTotalDeposit(sdk.Coins)
|
SetTotalDeposit(sdk.Coins)
|
||||||
|
|
||||||
GetVotingStartTime() time.Time
|
GetVotingStartBlock() int64
|
||||||
SetVotingStartTime(time.Time)
|
SetVotingStartBlock(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if two proposals are equal
|
// checks if two proposals are equal
|
||||||
|
@ -49,9 +48,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.GetSubmitTime().Equal(proposalB.GetSubmitTime()) &&
|
proposalA.GetSubmitBlock() == proposalB.GetSubmitBlock() &&
|
||||||
proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit()) &&
|
proposalA.GetTotalDeposit().IsEqual(proposalB.GetTotalDeposit()) &&
|
||||||
proposalA.GetVotingStartTime().Equal(proposalB.GetVotingStartTime()) {
|
proposalA.GetVotingStartBlock() == proposalB.GetVotingStartBlock() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -68,10 +67,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
|
||||||
|
|
||||||
SubmitTime time.Time `json:"submit_block"` // Height of the block where TxGovSubmitProposal was included
|
SubmitBlock int64 `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
|
||||||
|
|
||||||
VotingStartTime time.Time `json:"voting_start_block"` // Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached
|
VotingStartBlock int64 `json:"voting_start_block"` // Height of the block where MinDeposit was reached. -1 if MinDeposit is not reached
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements Proposal Interface
|
// Implements Proposal Interface
|
||||||
|
@ -90,13 +89,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) GetSubmitTime() time.Time { return tp.SubmitTime }
|
func (tp TextProposal) GetSubmitBlock() int64 { return tp.SubmitBlock }
|
||||||
func (tp *TextProposal) SetSubmitTime(submitTime time.Time) { tp.SubmitTime = submitTime }
|
func (tp *TextProposal) SetSubmitBlock(submitBlock int64) { tp.SubmitBlock = submitBlock }
|
||||||
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) GetVotingStartTime() time.Time { return tp.VotingStartTime }
|
func (tp TextProposal) GetVotingStartBlock() int64 { return tp.VotingStartBlock }
|
||||||
func (tp *TextProposal) SetVotingStartTime(votingStartTime time.Time) {
|
func (tp *TextProposal) SetVotingStartBlock(votingStartBlock int64) {
|
||||||
tp.VotingStartTime = votingStartTime
|
tp.VotingStartBlock = votingStartBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------
|
//-----------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue