mirror of https://github.com/nucypher/nucypher.git
Renamed `downtime` to `pastDowntime` in the MinersEscrow contract
parent
c75cd0e330
commit
86e5df2585
|
@ -64,7 +64,7 @@ contract MinersEscrow is Issuer {
|
||||||
uint16 confirmedPeriod2;
|
uint16 confirmedPeriod2;
|
||||||
// downtime
|
// downtime
|
||||||
uint16 lastActivePeriod;
|
uint16 lastActivePeriod;
|
||||||
Downtime[] downtime;
|
Downtime[] pastDowntime;
|
||||||
StakeInfo[] stakes;
|
StakeInfo[] stakes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ contract MinersEscrow is Issuer {
|
||||||
|
|
||||||
// miner was inactive for several periods
|
// miner was inactive for several periods
|
||||||
if (_lastActivePeriod < currentPeriod) {
|
if (_lastActivePeriod < currentPeriod) {
|
||||||
info.downtime.push(Downtime(_lastActivePeriod + 1, currentPeriod));
|
info.pastDowntime.push(Downtime(_lastActivePeriod + 1, currentPeriod));
|
||||||
}
|
}
|
||||||
emit ActivityConfirmed(_miner, nextPeriod, _lockedValue);
|
emit ActivityConfirmed(_miner, nextPeriod, _lockedValue);
|
||||||
}
|
}
|
||||||
|
@ -681,21 +681,21 @@ contract MinersEscrow is Issuer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Return the length of the downtime array
|
* @notice Return the length of the array of past downtime
|
||||||
**/
|
**/
|
||||||
function getDowntimeLength(address _miner) public view returns (uint256) {
|
function getPastDowntimeLength(address _miner) public view returns (uint256) {
|
||||||
return minerInfo[_miner].downtime.length;
|
return minerInfo[_miner].pastDowntime.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Return the information about downtime
|
* @notice Return the information about past downtime
|
||||||
**/
|
**/
|
||||||
function getDowntime(address _miner, uint256 _index)
|
function getPastDowntime(address _miner, uint256 _index)
|
||||||
// TODO change to structure when ABIEncoderV2 is released
|
// TODO change to structure when ABIEncoderV2 is released
|
||||||
// public view returns (Downtime)
|
// public view returns (Downtime)
|
||||||
public view returns (uint16 startPeriod, uint16 endPeriod)
|
public view returns (uint16 startPeriod, uint16 endPeriod)
|
||||||
{
|
{
|
||||||
Downtime storage downtime = minerInfo[_miner].downtime[_index];
|
Downtime storage downtime = minerInfo[_miner].pastDowntime[_index];
|
||||||
startPeriod = downtime.startPeriod;
|
startPeriod = downtime.startPeriod;
|
||||||
endPeriod = downtime.endPeriod;
|
endPeriod = downtime.endPeriod;
|
||||||
}
|
}
|
||||||
|
@ -728,11 +728,11 @@ contract MinersEscrow is Issuer {
|
||||||
/**
|
/**
|
||||||
* @dev Get Downtime structure by delegatecall
|
* @dev Get Downtime structure by delegatecall
|
||||||
**/
|
**/
|
||||||
function delegateGetDowntime(address _target, address _miner, uint256 _index)
|
function delegateGetPastDowntime(address _target, address _miner, uint256 _index)
|
||||||
internal returns (Downtime memory result)
|
internal returns (Downtime memory result)
|
||||||
{
|
{
|
||||||
bytes32 memoryAddress = delegateGetData(
|
bytes32 memoryAddress = delegateGetData(
|
||||||
_target, "getDowntime(address,uint256)", 2, bytes32(_miner), bytes32(_index));
|
_target, "getPastDowntime(address,uint256)", 2, bytes32(_miner), bytes32(_index));
|
||||||
assembly {
|
assembly {
|
||||||
result := memoryAddress
|
result := memoryAddress
|
||||||
}
|
}
|
||||||
|
@ -764,10 +764,11 @@ contract MinersEscrow is Issuer {
|
||||||
infoToCheck.confirmedPeriod2 == info.confirmedPeriod2 &&
|
infoToCheck.confirmedPeriod2 == info.confirmedPeriod2 &&
|
||||||
infoToCheck.lastActivePeriod == info.lastActivePeriod);
|
infoToCheck.lastActivePeriod == info.lastActivePeriod);
|
||||||
|
|
||||||
require(uint256(delegateGet(_testTarget, "getDowntimeLength(address)", miner)) == info.downtime.length);
|
require(uint256(delegateGet(_testTarget, "getPastDowntimeLength(address)", miner)) ==
|
||||||
for (i = 0; i < info.downtime.length && i < MAX_CHECKED_VALUES; i++) {
|
info.pastDowntime.length);
|
||||||
Downtime storage downtime = info.downtime[i];
|
for (i = 0; i < info.pastDowntime.length && i < MAX_CHECKED_VALUES; i++) {
|
||||||
Downtime memory downtimeToCheck = delegateGetDowntime(_testTarget, minerAddress, i);
|
Downtime storage downtime = info.pastDowntime[i];
|
||||||
|
Downtime memory downtimeToCheck = delegateGetPastDowntime(_testTarget, minerAddress, i);
|
||||||
require(downtimeToCheck.startPeriod == downtime.startPeriod &&
|
require(downtimeToCheck.startPeriod == downtime.startPeriod &&
|
||||||
downtimeToCheck.endPeriod == downtime.endPeriod);
|
downtimeToCheck.endPeriod == downtime.endPeriod);
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,7 +176,7 @@ contract PolicyManager is Upgradeable {
|
||||||
nodeInfo.rewardDelta[policy.startPeriod] = nodeInfo.rewardDelta[policy.startPeriod]
|
nodeInfo.rewardDelta[policy.startPeriod] = nodeInfo.rewardDelta[policy.startPeriod]
|
||||||
.add(startReward);
|
.add(startReward);
|
||||||
nodeInfo.rewardDelta[endPeriod] = nodeInfo.rewardDelta[endPeriod].sub(policy.rewardRate);
|
nodeInfo.rewardDelta[endPeriod] = nodeInfo.rewardDelta[endPeriod].sub(policy.rewardRate);
|
||||||
policy.arrangements.push(ArrangementInfo(node, escrow.getDowntimeLength(node), 0));
|
policy.arrangements.push(ArrangementInfo(node, escrow.getPastDowntimeLength(node), 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit PolicyCreated(_policyId, msg.sender);
|
emit PolicyCreated(_policyId, msg.sender);
|
||||||
|
@ -231,13 +231,13 @@ contract PolicyManager is Upgradeable {
|
||||||
uint16 maxPeriod = AdditionalMath.min16(getCurrentPeriod(), _policy.lastPeriod);
|
uint16 maxPeriod = AdditionalMath.min16(getCurrentPeriod(), _policy.lastPeriod);
|
||||||
uint16 minPeriod = AdditionalMath.max16(_policy.startPeriod, _arrangement.lastRefundedPeriod);
|
uint16 minPeriod = AdditionalMath.max16(_policy.startPeriod, _arrangement.lastRefundedPeriod);
|
||||||
uint16 downtimePeriods = 0;
|
uint16 downtimePeriods = 0;
|
||||||
uint256 length = escrow.getDowntimeLength(_arrangement.node);
|
uint256 length = escrow.getPastDowntimeLength(_arrangement.node);
|
||||||
for (indexOfDowntimePeriods = _arrangement.indexOfDowntimePeriods;
|
for (indexOfDowntimePeriods = _arrangement.indexOfDowntimePeriods;
|
||||||
indexOfDowntimePeriods < length;
|
indexOfDowntimePeriods < length;
|
||||||
indexOfDowntimePeriods++)
|
indexOfDowntimePeriods++)
|
||||||
{
|
{
|
||||||
(uint16 startPeriod, uint16 endPeriod) =
|
(uint16 startPeriod, uint16 endPeriod) =
|
||||||
escrow.getDowntime(_arrangement.node, indexOfDowntimePeriods);
|
escrow.getPastDowntime(_arrangement.node, indexOfDowntimePeriods);
|
||||||
if (startPeriod > maxPeriod) {
|
if (startPeriod > maxPeriod) {
|
||||||
break;
|
break;
|
||||||
} else if (endPeriod < minPeriod) {
|
} else if (endPeriod < minPeriod) {
|
||||||
|
@ -264,7 +264,8 @@ contract PolicyManager is Upgradeable {
|
||||||
if (lastActivePeriod < _policy.startPeriod - 1) {
|
if (lastActivePeriod < _policy.startPeriod - 1) {
|
||||||
refundValue = _policy.firstPartialReward;
|
refundValue = _policy.firstPartialReward;
|
||||||
} else if (_arrangement.indexOfDowntimePeriods < length) {
|
} else if (_arrangement.indexOfDowntimePeriods < length) {
|
||||||
(startPeriod, endPeriod) = escrow.getDowntime(_arrangement.node, _arrangement.indexOfDowntimePeriods);
|
(startPeriod, endPeriod) = escrow.getPastDowntime(
|
||||||
|
_arrangement.node, _arrangement.indexOfDowntimePeriods);
|
||||||
if (_policy.startPeriod > startPeriod && _policy.startPeriod - 1 <= endPeriod) {
|
if (_policy.startPeriod > startPeriod && _policy.startPeriod - 1 <= endPeriod) {
|
||||||
refundValue = _policy.firstPartialReward;
|
refundValue = _policy.firstPartialReward;
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,14 +105,14 @@ contract MinersEscrowForPolicyMock {
|
||||||
/**
|
/**
|
||||||
* @notice Emulate getDowntimeLength
|
* @notice Emulate getDowntimeLength
|
||||||
**/
|
**/
|
||||||
function getDowntimeLength(address) public view returns (uint256) {
|
function getPastDowntimeLength(address) public view returns (uint256) {
|
||||||
return downtime.length;
|
return downtime.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notice Emulate getDowntime
|
* @notice Emulate getDowntime
|
||||||
**/
|
**/
|
||||||
function getDowntime(address, uint256 _index)
|
function getPastDowntime(address, uint256 _index)
|
||||||
public view returns (uint16 startPeriod, uint16 endPeriod)
|
public view returns (uint16 startPeriod, uint16 endPeriod)
|
||||||
{
|
{
|
||||||
Downtime storage data = downtime[_index];
|
Downtime storage data = downtime[_index];
|
||||||
|
|
|
@ -66,12 +66,12 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
assert period == policy_manager.functions.getPeriod(ursula1, 0).call()
|
assert period == policy_manager.functions.getPeriod(ursula1, 0).call()
|
||||||
assert period == policy_manager.functions.getPeriod(ursula2, 0).call()
|
assert period == policy_manager.functions.getPeriod(ursula2, 0).call()
|
||||||
# Check downtime parameters
|
# Check downtime parameters
|
||||||
assert 1 == escrow.functions.getDowntimeLength(ursula1).call()
|
assert 1 == escrow.functions.getPastDowntimeLength(ursula1).call()
|
||||||
downtime = escrow.functions.getDowntime(ursula1, 0).call()
|
downtime = escrow.functions.getPastDowntime(ursula1, 0).call()
|
||||||
assert 1 == downtime[0]
|
assert 1 == downtime[0]
|
||||||
assert period == downtime[1]
|
assert period == downtime[1]
|
||||||
assert 1 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 1 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
downtime = escrow.functions.getDowntime(ursula2, 0).call()
|
downtime = escrow.functions.getPastDowntime(ursula2, 0).call()
|
||||||
assert 1 == downtime[0]
|
assert 1 == downtime[0]
|
||||||
assert period == downtime[1]
|
assert period == downtime[1]
|
||||||
assert period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
assert period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||||
|
@ -91,7 +91,7 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||||
|
|
||||||
testerchain.wait_for_receipt(tx)
|
testerchain.wait_for_receipt(tx)
|
||||||
assert 1 == escrow.functions.getDowntimeLength(ursula1).call()
|
assert 1 == escrow.functions.getPastDowntimeLength(ursula1).call()
|
||||||
|
|
||||||
# Checks that no error from repeated method call
|
# Checks that no error from repeated method call
|
||||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||||
|
@ -110,8 +110,8 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
assert 1046 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
assert 1046 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||||
assert 525 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
assert 525 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||||
# Check that downtime value has not changed
|
# Check that downtime value has not changed
|
||||||
assert 1 == escrow.functions.getDowntimeLength(ursula1).call()
|
assert 1 == escrow.functions.getPastDowntimeLength(ursula1).call()
|
||||||
assert 1 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 1 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
assert period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
assert period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||||
assert period - 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
assert period - 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
testerchain.wait_for_receipt(tx)
|
testerchain.wait_for_receipt(tx)
|
||||||
|
|
||||||
assert period + 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
assert period + 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||||
assert 2 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 2 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
downtime = escrow.functions.getDowntime(ursula2, 1).call()
|
downtime = escrow.functions.getPastDowntime(ursula2, 1).call()
|
||||||
assert period - 1 == downtime[0]
|
assert period - 1 == downtime[0]
|
||||||
assert period == downtime[1]
|
assert period == downtime[1]
|
||||||
|
|
||||||
|
@ -221,8 +221,8 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula2})
|
tx = escrow.functions.lock(500, 2).transact({'from': ursula2})
|
||||||
testerchain.wait_for_receipt(tx)
|
testerchain.wait_for_receipt(tx)
|
||||||
|
|
||||||
assert 3 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 3 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
downtime = escrow.functions.getDowntime(ursula2, 2).call()
|
downtime = escrow.functions.getPastDowntime(ursula2, 2).call()
|
||||||
assert period == downtime[0]
|
assert period == downtime[0]
|
||||||
assert period == downtime[1]
|
assert period == downtime[1]
|
||||||
|
|
||||||
|
@ -236,8 +236,8 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
|
|
||||||
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
assert 1152 == escrow.functions.minerInfo(ursula1).call()[VALUE_FIELD]
|
||||||
assert 1025 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
assert 1025 == escrow.functions.minerInfo(ursula2).call()[VALUE_FIELD]
|
||||||
assert 4 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 4 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
downtime = escrow.functions.getDowntime(ursula2, 3).call()
|
downtime = escrow.functions.getPastDowntime(ursula2, 3).call()
|
||||||
assert period - 3 == downtime[0]
|
assert period - 3 == downtime[0]
|
||||||
assert period == downtime[1]
|
assert period == downtime[1]
|
||||||
|
|
||||||
|
@ -255,7 +255,7 @@ def test_mining(testerchain, token, escrow_contract):
|
||||||
testerchain.time_travel(hours=1)
|
testerchain.time_travel(hours=1)
|
||||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||||
testerchain.wait_for_receipt(tx)
|
testerchain.wait_for_receipt(tx)
|
||||||
assert 4 == escrow.functions.getDowntimeLength(ursula2).call()
|
assert 4 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||||
testerchain.time_travel(hours=1)
|
testerchain.time_travel(hours=1)
|
||||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||||
testerchain.wait_for_receipt(tx)
|
testerchain.wait_for_receipt(tx)
|
||||||
|
|
|
@ -157,7 +157,7 @@ def test_pre_deposit(testerchain, token, escrow_contract):
|
||||||
period = escrow.functions.getCurrentPeriod().call()
|
period = escrow.functions.getCurrentPeriod().call()
|
||||||
assert 1 == policy_manager.functions.getPeriodsLength(owner).call()
|
assert 1 == policy_manager.functions.getPeriodsLength(owner).call()
|
||||||
assert period == policy_manager.functions.getPeriod(owner, 0).call()
|
assert period == policy_manager.functions.getPeriod(owner, 0).call()
|
||||||
assert 0 == escrow.functions.getDowntimeLength(owner).call()
|
assert 0 == escrow.functions.getPastDowntimeLength(owner).call()
|
||||||
assert 0 == escrow.functions.getLastActivePeriod(owner).call()
|
assert 0 == escrow.functions.getLastActivePeriod(owner).call()
|
||||||
|
|
||||||
# Can't pre-deposit tokens again for the same miner twice
|
# Can't pre-deposit tokens again for the same miner twice
|
||||||
|
@ -195,7 +195,7 @@ def test_pre_deposit(testerchain, token, escrow_contract):
|
||||||
assert 0 == escrow.functions.getLockedTokens(owner, 50 * (index + 1) + 1).call()
|
assert 0 == escrow.functions.getLockedTokens(owner, 50 * (index + 1) + 1).call()
|
||||||
assert 1 == policy_manager.functions.getPeriodsLength(owner).call()
|
assert 1 == policy_manager.functions.getPeriodsLength(owner).call()
|
||||||
assert period == policy_manager.functions.getPeriod(owner, 0).call()
|
assert period == policy_manager.functions.getPeriod(owner, 0).call()
|
||||||
assert 0 == escrow.functions.getDowntimeLength(owner).call()
|
assert 0 == escrow.functions.getPastDowntimeLength(owner).call()
|
||||||
assert 0 == escrow.functions.getLastActivePeriod(owner).call()
|
assert 0 == escrow.functions.getLastActivePeriod(owner).call()
|
||||||
|
|
||||||
events = deposit_log.get_all_entries()
|
events = deposit_log.get_all_entries()
|
||||||
|
|
Loading…
Reference in New Issue