Skip to content

Commit 18c7fd5

Browse files
author
francois branciard
committed
improve STAKE_BONUS_RATIO STAKE_BONUS_MIN_THRESHOLD usage
1 parent 8fed212 commit 18c7fd5

File tree

3 files changed

+133
-76
lines changed

3 files changed

+133
-76
lines changed

contracts/IexecHub.sol

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ contract IexecHub
2626
address public tokenAddress;
2727

2828
uint256 public constant STAKE_BONUS_RATIO = 10;
29+
uint256 public constant STAKE_BONUS_MIN_THRESHOLD = 1000;
30+
31+
uint256 public constant SCORE_UNITARY_SLASH = 50;
2932

3033
/**
3134
* Slaves contracts
@@ -367,14 +370,8 @@ contract IexecHub
367370
uint256 locked;
368371
(,locked) = checkBalance(this);
369372
if(locked > 0){
370-
if(locked <= 10){
371-
require(seize(this, locked));
372-
require(reward(workerpoolOwner, locked));
373-
}
374-
else{
375-
require(seize(this, locked.percentage(STAKE_BONUS_RATIO)));
376-
require(reward(workerpoolOwner, locked.percentage(STAKE_BONUS_RATIO)));
377-
}
373+
require(seize(this, locked.min(locked.percentage(STAKE_BONUS_RATIO).max(STAKE_BONUS_MIN_THRESHOLD))));
374+
require(reward(workerpoolOwner,locked.min(locked.percentage(STAKE_BONUS_RATIO).max(STAKE_BONUS_MIN_THRESHOLD))));
378375
}
379376

380377
emit WorkOrderCompleted(_woid, workorder.m_workerpool());
@@ -519,7 +516,7 @@ contract IexecHub
519516
if (_reputation)
520517
{
521518
m_contributionHistory.failled = m_contributionHistory.failled.add(1);
522-
m_scores[_worker] = m_scores[_worker].sub(m_scores[_worker].min(50));
519+
m_scores[_worker] = m_scores[_worker].sub(m_scores[_worker].min(SCORE_UNITARY_SLASH));
523520
emit FaultyContribution(_woid, _worker);
524521
}
525522
return true;

contracts/SafeMathOZ.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ library SafeMathOZ
4040
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
4141
return c;
4242
}
43-
/* not used
43+
4444
function max(uint256 a, uint256 b) internal pure returns (uint256)
4545
{
4646
return a >= b ? a : b;
4747
}
48-
*/
48+
4949
function min(uint256 a, uint256 b) internal pure returns (uint256)
5050
{
5151
return a < b ? a : b;

0 commit comments

Comments
 (0)