Add simple miner slashing algorithm, add error messages to DioneDispute.sol
This commit is contained in:
parent
21e50dd13a
commit
8ead31a45e
@ -15,6 +15,7 @@ contract DioneDispute {
|
|||||||
bool disputeResult; // true - dispute had basis, false - dispute was false
|
bool disputeResult; // true - dispute had basis, false - dispute was false
|
||||||
address miner; // the miner against whom the dispute
|
address miner; // the miner against whom the dispute
|
||||||
address disputeInitiator; // the miner who started the dispute
|
address disputeInitiator; // the miner who started the dispute
|
||||||
|
uint256 timestamp; // dispute creation timestamp
|
||||||
mapping(address => bool) voted; // map of miners who vote for/against
|
mapping(address => bool) voted; // map of miners who vote for/against
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,6 +30,7 @@ contract DioneDispute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function beginDispute(address miner, uint256 requestID) public {
|
function beginDispute(address miner, uint256 requestID) public {
|
||||||
|
require(!disputes[dhash], "dispute already exists");
|
||||||
bytes32 dhash = keccak256(miner, requestID, now);
|
bytes32 dhash = keccak256(miner, requestID, now);
|
||||||
Dispute dispute = Dispute(
|
Dispute dispute = Dispute(
|
||||||
{
|
{
|
||||||
@ -37,6 +39,7 @@ contract DioneDispute {
|
|||||||
finished: false,
|
finished: false,
|
||||||
disputeResult: true,
|
disputeResult: true,
|
||||||
miner: miner,
|
miner: miner,
|
||||||
|
timesyamp: now,
|
||||||
disputeInitiator: msg.sender,
|
disputeInitiator: msg.sender,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -47,10 +50,10 @@ contract DioneDispute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function vote(bytes32 dhash, bool voteStatus) public {
|
function vote(bytes32 dhash, bool voteStatus) public {
|
||||||
require(disputes[dhash]);
|
require(disputes[dhash], "dispute doesn't exist");
|
||||||
Dispute storage dispute = disputes[dhash];
|
Dispute storage dispute = disputes[dhash];
|
||||||
require(dispute.finished == false);
|
require(dispute.finished == false, "dispute already finished");
|
||||||
require(dioneStaking.isMiner(msg.sender));
|
require(dioneStaking.isMiner(msg.sender), "caller isn't dione miner");
|
||||||
int256 stake = dioneStaking.minerStake(msg.sender);
|
int256 stake = dioneStaking.minerStake(msg.sender);
|
||||||
if (voteStatus) {
|
if (voteStatus) {
|
||||||
dispute.sum.sub(stake);
|
dispute.sum.sub(stake);
|
||||||
@ -63,16 +66,21 @@ contract DioneDispute {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function finishDispute(bytes32 dhash) public {
|
function finishDispute(bytes32 dhash) public {
|
||||||
require(disputes[dhash]);
|
require(disputes[dhash], "dispute doesn't exist");
|
||||||
Dispute storage dispute = disputes[dhash];
|
Dispute storage dispute = disputes[dhash];
|
||||||
require(dispute.finished == false);
|
require((now - dispute[dhash].timestamp) >= 2 hours, "vote window must be two hours");
|
||||||
require(dispute.disputeInitiator == msg.sender);
|
require(dispute.finished == false, "dispute already finished");
|
||||||
|
require(dispute.disputeInitiator == msg.sender, "only dispute initiator can call this function");
|
||||||
if (dispute.sum < 0) {
|
if (dispute.sum < 0) {
|
||||||
dispute.disputeResult = false;
|
dispute.disputeResult = false;
|
||||||
} else {
|
} else {
|
||||||
dispute.disputeResult = true;
|
dispute.disputeResult = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dioneStaking.slashMiner(dispute.miner);
|
||||||
|
|
||||||
|
dispute.finished = true;
|
||||||
|
|
||||||
emit DisputeFinished(dhash, dispute.disputeResult);
|
emit DisputeFinished(dhash, dispute.disputeResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
DioneToken public dione;
|
DioneToken public dione;
|
||||||
// Aggregator contract address.
|
// Aggregator contract address.
|
||||||
address public aggregatorAddr;
|
address public aggregatorAddr;
|
||||||
|
// Dispute contract address.
|
||||||
|
address public disputeContractAddr;
|
||||||
// Miner rewards in DIONE tokens.
|
// Miner rewards in DIONE tokens.
|
||||||
uint256 public minerReward;
|
uint256 public minerReward;
|
||||||
// The block number when DIONE mining starts.
|
// The block number when DIONE mining starts.
|
||||||
@ -45,6 +47,11 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
_;
|
_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
modifier onlyDispute(address addr) {
|
||||||
|
require(addr == disputeContractAddr, "Exception: caller is not the dispute contract");
|
||||||
|
_;
|
||||||
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
DioneToken _dione,
|
DioneToken _dione,
|
||||||
uint256 _minerReward,
|
uint256 _minerReward,
|
||||||
@ -132,4 +139,13 @@ contract DioneStaking is Ownable, ReentrancyGuard {
|
|||||||
function setAggregator(address _aggregatorAddr) public onlyOwner {
|
function setAggregator(address _aggregatorAddr) public onlyOwner {
|
||||||
aggregatorAddr = _aggregatorAddr;
|
aggregatorAddr = _aggregatorAddr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function slashMiner(address miner, address[] receipentMiners) public onlyDispute {
|
||||||
|
uint256 share = minerInfo[miner].amount.div(receipentMiners.length);
|
||||||
|
|
||||||
|
for (var i = 0; i < receipentMiners.length; i++) {
|
||||||
|
minerInfo[miner].amount.sub(share);
|
||||||
|
minerInfo[receipentMiners[i]].amount += share;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user