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

Introduce min ballot duration in VotingToManageEmissionFunds contract #207

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
14 changes: 8 additions & 6 deletions contracts/VotingToManageEmissionFunds.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ contract VotingToManageEmissionFunds is VotingTo {
address _receiver,
string _memo
) public onlyValidVotingKey(msg.sender) {
require(_startTime > 0 && _endTime > 0);
uint256 currentTime = getTime();
require(_endTime > _startTime && _startTime > currentTime);
uint256 releaseTimeSnapshot = emissionReleaseTime();
uint256 releaseTime = refreshEmissionReleaseTime();
require(currentTime >= releaseTime);
Expand Down Expand Up @@ -159,20 +157,20 @@ contract VotingToManageEmissionFunds is VotingTo {
uint256 _emissionReleaseTime, // unix timestamp
uint256 _emissionReleaseThreshold, // seconds
uint256 _distributionThreshold, // seconds
uint256 _minBallotDuration, // seconds
address _emissionFunds
) public onlyOwner {
require(!initDisabled());
require(_emissionReleaseTime > getTime());
require(_emissionReleaseThreshold > 0);
require(_distributionThreshold > ballotCancelingThreshold());
require(_emissionReleaseThreshold > _distributionThreshold);
require(_minBallotDuration < _distributionThreshold);
require(_emissionFunds != address(0));
_init(_minBallotDuration);
_setNoActiveBallotExists(true);
_setEmissionReleaseTime(_emissionReleaseTime);
addressStorage[EMISSION_FUNDS] = _emissionFunds;
uintStorage[EMISSION_RELEASE_THRESHOLD] = _emissionReleaseThreshold;
uintStorage[DISTRIBUTION_THRESHOLD] = _distributionThreshold;
boolStorage[INIT_DISABLED] = true;
}

function noActiveBallotExists() public view returns(bool) {
Expand Down Expand Up @@ -215,7 +213,11 @@ contract VotingToManageEmissionFunds is VotingTo {
IProxyStorage(proxyStorage()).getPoaConsensus()
).getCurrentValidatorsLengthWithoutMoC();

if (getTotalVoters(_id) >= validatorsLength && !_withinCancelingThreshold(_id)) {
if (
getTotalVoters(_id) >= validatorsLength &&
!_withinCancelingThreshold(_id) &&
getTime().sub(_getStartTime(_id)) > minBallotDuration()
) {
_finalize(_id);
}
}
Expand Down
27 changes: 26 additions & 1 deletion contracts/abstracts/VotingTo.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract VotingTo is EternalStorage, EnumBallotTypes, EnumThresholdTypes {

bytes32 internal constant OWNER = keccak256("owner");
bytes32 internal constant INIT_DISABLED = keccak256("initDisabled");
bytes32 internal constant MIN_BALLOT_DURATION = keccak256("minBallotDuration");
bytes32 internal constant NEXT_BALLOT_ID = keccak256("nextBallotId");
bytes32 internal constant PROXY_STORAGE = keccak256("proxyStorage");

Expand Down Expand Up @@ -56,6 +57,15 @@ contract VotingTo is EternalStorage, EnumBallotTypes, EnumThresholdTypes {
_;
}

modifier onlyValidTime(uint256 _startTime, uint256 _endTime) {
require(_startTime > 0 && _endTime > 0);
require(_endTime > _startTime && _startTime > getTime());
uint256 diffTime = _endTime.sub(_startTime);
require(diffTime > minBallotDuration());
require(diffTime <= maxBallotDuration());
_;
}

function areOldMiningKeysVoted(uint256 _id, address _miningKey)
public
view
Expand Down Expand Up @@ -131,14 +141,29 @@ contract VotingTo is EternalStorage, EnumBallotTypes, EnumThresholdTypes {
return addressStorage[PROXY_STORAGE];
}

function maxBallotDuration() public pure returns(uint256) {
return 14 days;
}

function minBallotDuration() public view returns(uint256) {
return uintStorage[MIN_BALLOT_DURATION];
}

function _init(uint256 _minBallotDuration) internal onlyOwner {
require(!initDisabled());
require(_minBallotDuration < maxBallotDuration());
uintStorage[MIN_BALLOT_DURATION] = _minBallotDuration;
boolStorage[INIT_DISABLED] = true;
}

function _createBallot(
uint256 _ballotType,
uint256 _startTime,
uint256 _endTime,
string _memo,
uint256 _quorumState,
address _creatorMiningKey
) internal returns(uint256) {
) internal onlyValidTime(_startTime, _endTime) returns(uint256) {
require(initDisabled());
uint256 ballotId = nextBallotId();
_setNextBallotId(ballotId.add(1));
Expand Down
24 changes: 1 addition & 23 deletions contracts/abstracts/VotingToChange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import "./VotingTo.sol";
contract VotingToChange is VotingTo {
bytes32 internal constant ACTIVE_BALLOTS = keccak256("activeBallots");
bytes32 internal constant MIGRATE_DISABLED = keccak256("migrateDisabled");
bytes32 internal constant MIN_BALLOT_DURATION = keccak256("minBallotDuration");

bytes32 internal constant INDEX = "index";
bytes32 internal constant FINALIZE_CALLED = "finalizeCalled";
Expand All @@ -19,15 +18,6 @@ contract VotingToChange is VotingTo {
enum QuorumStates {Invalid, InProgress, Accepted, Rejected}
enum ActionChoice {Invalid, Accept, Reject}

modifier onlyValidTime(uint256 _startTime, uint256 _endTime) {
require(_startTime > 0 && _endTime > 0);
require(_endTime > _startTime && _startTime > getTime());
uint256 diffTime = _endTime.sub(_startTime);
require(diffTime > minBallotDuration());
require(diffTime <= maxBallotDuration());
_;
}

function activeBallots(uint256 _index) public view returns(uint256) {
return uintArrayStorage[ACTIVE_BALLOTS][_index];
}
Expand All @@ -49,10 +39,6 @@ contract VotingToChange is VotingTo {
return uintStorage[keccak256(abi.encode(VOTING_STATE, _id, INDEX))];
}

function maxBallotDuration() public pure returns(uint256) {
return 14 days;
}

function migrateBasicAll(address _prevVotingToChange) public onlyOwner {
require(_prevVotingToChange != address(0));
require(initDisabled());
Expand Down Expand Up @@ -92,10 +78,6 @@ contract VotingToChange is VotingTo {
return boolStorage[MIGRATE_DISABLED];
}

function minBallotDuration() public view returns(uint256) {
return uintStorage[MIN_BALLOT_DURATION];
}

function validatorActiveBallots(address _miningKey) public view returns(uint256) {
return uintStorage[
keccak256(abi.encode(VALIDATOR_ACTIVE_BALLOTS, _miningKey))
Expand Down Expand Up @@ -171,7 +153,6 @@ contract VotingToChange is VotingTo {
)
internal
onlyValidVotingKey(msg.sender)
onlyValidTime(_startTime, _endTime)
returns(uint256)
{
require(migrateDisabled());
Expand Down Expand Up @@ -259,11 +240,8 @@ contract VotingToChange is VotingTo {
}

function _init(uint256 _minBallotDuration) internal onlyOwner {
require(!initDisabled());
require(!migrateDisabled());
require(_minBallotDuration < maxBallotDuration());
uintStorage[MIN_BALLOT_DURATION] = _minBallotDuration;
boolStorage[INIT_DISABLED] = true;
super._init(_minBallotDuration);
}

function _setIndex(uint256 _ballotId, uint256 _value) internal {
Expand Down
1 change: 1 addition & 0 deletions migrations/2_deploy_contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ module.exports = function(deployer, network, accounts) {
demoMode ? moment.utc().add(10, 'minutes').unix() : moment.utc().add(3, 'months').unix(),
demoMode ? 3600 : 7776000, // emissionReleaseThreshold: 1 hour for demo, 3 months for production
demoMode ? 1500 : 604800, // distributionThreshold: 25 minutes for demo, 7 days for production
minBallotDuration,
emissionFunds.address
);

Expand Down
Loading