mirror of https://github.com/nucypher/nucypher.git
StakingEscrow: confirmActivity -> commitToNextPeriod, lastActivePeriod -> lastCommittedPeriod
parent
28e41c4a21
commit
4a0b79b2ca
|
@ -24,8 +24,8 @@
|
|||
- "staker address: {{status_data.json.staker_address}}"
|
||||
- "worker address: {{status_data.json.worker_address}}"
|
||||
- "rest url: https://{{status_data.json.rest_url}}"
|
||||
- "missing_confirmations: {{status_data.json.missing_confirmations}}"
|
||||
- "last active period: {{status_data.json.last_active_period}}"
|
||||
- "missing commitments: {{status_data.json.missing_commitments}}"
|
||||
- "last committed period: {{status_data.json.last_committed_period}}"
|
||||
- "balances:"
|
||||
- " ETH: {{status_data.json.balances.eth}}"
|
||||
- " NU: {{status_data.json.balances.nu}}"
|
|
@ -89,7 +89,7 @@ The parameters are:
|
|||
* The periods for locking (which are serialized into an array of bytes)
|
||||
|
||||
When staking tokens, the staker sets the number of periods the tokens will be locked, which must be no less than some minimal locking time (30 periods).
|
||||
In order to unlock tokens, the staker must be active during the time of locking (and confirm activity each period).
|
||||
In order to unlock tokens, the staker must be active during the time of locking (and make a commitment each period).
|
||||
Each stake is represented by the amount of tokens locked, and the stake's duration in periods.
|
||||
The staker can add a new stake using ``StakingEscrow.deposit(uint256, uint16)`` or ``StakingEscrow.lock(uint256, uint16)`` methods.
|
||||
The staker can split stake into two parts: one with the same duration and another with an extended duration.
|
||||
|
@ -100,23 +100,23 @@ When calculating locked tokens using the ``StakingEscrow.getLockedTokens(address
|
|||
The Staker Bonds to a Worker ("Ursula")
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The staker must specify a worker who will confirm the activity and sign on behalf of this staker by calling the ``StakingEscrow.setWorker(address)`` method.
|
||||
The staker must specify a worker who will make a commitment and sign on behalf of this staker by calling the ``StakingEscrow.setWorker(address)`` method.
|
||||
Changing a worker is allowed no more than once within ``StakingEscrow.minWorkerPeriods()``.
|
||||
Only the worker can confirm activity.
|
||||
Only the worker can make a commitment.
|
||||
|
||||
Ursula Confirms Activity
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Ursula Makes a Commitment
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
In order to confirm activity every period, workers call ``StakingEscrow.confirmActivity()`` wherein activities for the next period are registered.
|
||||
The staker gets a reward for every confirmed period.
|
||||
In order to make a commitment to the next period, workers call ``StakingEscrow.commitToNextPeriod()`` wherein activities for the next period are registered.
|
||||
The staker gets a reward for every commitment period.
|
||||
|
||||
Ursula Generates Staking Rewards
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
After the period of activity has passed, the staker may call ``StakingEscrow.mint()`` method which computes and transfers tokens to the staker's account.
|
||||
Also note that calls to ``StakingEscrow.confirmActivity()`` are included the ``StakingEscrow.mint()`` method.
|
||||
Also note that calls to ``StakingEscrow.commitToNextPeriod()`` are included the ``StakingEscrow.mint()`` method.
|
||||
|
||||
The reward value depends on the fraction of locked tokens for the period (only those who confirmed activity are accounted for).
|
||||
The reward value depends on the fraction of locked tokens for the period (only those who made a commitment are accounted for).
|
||||
Also, the reward depends on the number of periods during which the tokens will be locked: if the tokens will be locked for half a year, the coefficient is 1.5.
|
||||
The minimum coefficient is 1 (when tokens will get unlocked in the next period), and the maximum is 2 (when the time is 1 year or more).
|
||||
The reward is calculated separately for each stake that is active during the mining period and all rewards are summed up.
|
||||
|
|
|
@ -17,10 +17,10 @@ Each sub-stake has:
|
|||
|
||||
* **Locking duration**
|
||||
|
||||
Locking duration is defined to be the required number of times that ``confirmActivity()`` needs to be called so that the sub-stake is registered as locked for the subsequent period. For example, if a sub-stake has a *locking duration of 5 periods* it means that the sub-stake will be locked for periods: 1,2,3,4,5 because ``confirmActivity()`` would be called during periods 0,1,2,3,4 each time confirming activity for the subsequent period (1,2,3,4,5) respectively. Unless the starting period is specified, the sub-stake is considered locked for the 0th (current) period by default.
|
||||
Locking duration is defined to be the required number of times that ``commitToNextPeriod()`` needs to be called so that the sub-stake is registered as locked for the subsequent period. For example, if a sub-stake has a *locking duration of 5 periods* it means that the sub-stake will be locked for periods: 1,2,3,4,5 because ``commitToNextPeriod()`` would be called during periods 0,1,2,3,4 each time making a commitment for the subsequent period (1,2,3,4,5) respectively. Unless the starting period is specified, the sub-stake is considered locked for the 0th (current) period by default.
|
||||
|
||||
|
||||
A sub-stake remains active until it becomes unlocked, and a staker gets the reward for the last period by calling ``mint()`` or ``confirmActivity()`` once the last period is surpassed. Each staker can have no more than 30 active sub-stakes which are stored in an array. All sub-stake changes initially reuse slots of inactive sub-stakes for storage in the array, and if there are none, will instead use empty slots. Therefore, attempting to retrieve data about previous inactive sub-stakes is not guaranteed to be successful since the data could have been overwritten.
|
||||
A sub-stake remains active until it becomes unlocked, and a staker gets the reward for the last period by calling ``mint()`` or ``commitToNextPeriod()`` once the last period is surpassed. Each staker can have no more than 30 active sub-stakes which are stored in an array. All sub-stake changes initially reuse slots of inactive sub-stakes for storage in the array, and if there are none, will instead use empty slots. Therefore, attempting to retrieve data about previous inactive sub-stakes is not guaranteed to be successful since the data could have been overwritten.
|
||||
|
||||
|
||||
Operations that modify the sub-stake array
|
||||
|
@ -148,10 +148,10 @@ Flags that affect the sub-stake array
|
|||
|
||||
Re-staking
|
||||
^^^^^^^^^^
|
||||
*Used in methods* : ``confirmActivity()``, ``mint()``
|
||||
*Used in methods* : ``commitToNextPeriod()``, ``mint()``
|
||||
|
||||
When re-staking is disabled, the number of locked tokens in sub-stakes does not change by itself.
|
||||
However, when re-staking is enabled (default) then all staking rewards are re-locked as part of each relevant sub-stake (inside ``confirmActivity()`` and/or ``mint()``). Consequently, each such sub-stake has an increased locked amount (by the accrued staking reward) and the number of sub-stakes remains unchanged.
|
||||
However, when re-staking is enabled (default) then all staking rewards are re-locked as part of each relevant sub-stake (inside ``commitToNextPeriod()`` and/or ``mint()``). Consequently, each such sub-stake has an increased locked amount (by the accrued staking reward) and the number of sub-stakes remains unchanged.
|
||||
|
||||
**Example:**
|
||||
|
||||
|
@ -216,13 +216,13 @@ However, when re-staking is enabled (default) then all staking rewards are re-lo
|
|||
|
||||
Winding down
|
||||
^^^^^^^^^^^^
|
||||
*Used in methods* : ``confirmActivity()``
|
||||
*Used in methods* : ``commitToNextPeriod()``
|
||||
|
||||
An enabled "winding down" parameter means that each call to ``confirmActivity()`` (no more than once in a period) leads to a reduction of the locking duration for each sub-stake. In other words, the sub-stake will unlock after the worker calls ``confirm-activity()`` at least N times (no more than once in a period), where N is the locking duration of sub-stake. When disabled (default), the unlock date for each sub-stakes shifts forward by 1 period after each period. In other words, the duration continues to remain the same until the "winding down" parameter is enabled.
|
||||
An enabled "winding down" parameter means that each call to ``commitToNextPeriod()`` (no more than once in a period) leads to a reduction of the locking duration for each sub-stake. In other words, the sub-stake will unlock after the worker calls ``commitToNextPeriod()`` at least N times (no more than once in a period), where N is the locking duration of sub-stake. When disabled (default), the unlock date for each sub-stakes shifts forward by 1 period after each period. In other words, the duration continues to remain the same until the "winding down" parameter is enabled.
|
||||
|
||||
**Example:**
|
||||
|
||||
A staker has few sub-stakes, worker calls ``сonfirmActivity()`` each period:
|
||||
A staker has few sub-stakes, worker calls ``commitToNextPeriod()`` each period:
|
||||
- Current period:
|
||||
* 1st sub-stake = 400 tokens with locking duration of 8 periods
|
||||
* 2nd sub-stake = 100 tokens locked starting from the next period and a locking duration of 5 periods
|
||||
|
|
|
@ -142,7 +142,7 @@ Inflation Rewards (NU) and Policy Fees (ETH).
|
|||
Q: How are Policy Fees (ETH) determined?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
The fee is calculated with Confirm Activity taking into account the number of policies Ursula is enforcing.
|
||||
The fee is calculated with Commit to Next Period taking into account the number of policies Ursula is enforcing.
|
||||
|
||||
Q: How many Ursulas per period collect Inflation rewards (NU)?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -260,7 +260,7 @@ Note that a minimum of two periods must elapse before rewards will be delivered
|
|||
are in Period 5 when you start staking:
|
||||
|
||||
- Period 5: You deposit stake and initiate a worker
|
||||
- Period 5: Your worker calls ``confirmActivity()`` in order to receive work for the next period
|
||||
- Period 5: Your worker calls ``commitToNextPeriod()`` in order to receive work for the next period
|
||||
- Period 6: Your worker successfully performs the work
|
||||
- Period 7: Your worker receives rewards for the work completed in the previous period
|
||||
|
||||
|
@ -318,13 +318,13 @@ See :ref:`node-providers`.
|
|||
Q: Why is my node is labelled as "*Idle*" in the status monitor?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Your node is `Idle` because it has never confirmed activity. Likely, your worker address does not have any
|
||||
Your node is `Idle` because it has never made a commitment. Likely, your worker address does not have any
|
||||
ETH to use for transaction gas.
|
||||
|
||||
Q: The status of my node on the status monitor seems incorrect?
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Check when last your node confirmed activity by running::
|
||||
Check when last your node made a commitment by running::
|
||||
|
||||
nucypher status stakers
|
||||
> --provider <your_geth_provider>
|
||||
|
|
|
@ -1183,9 +1183,9 @@ class Staker(NucypherTokenActor):
|
|||
return receipt
|
||||
|
||||
@property
|
||||
def missing_confirmations(self) -> int:
|
||||
def missing_commitments(self) -> int:
|
||||
staker_address = self.checksum_address
|
||||
missing = self.staking_agent.get_missing_confirmations(checksum_address=staker_address)
|
||||
missing = self.staking_agent.get_missing_commitments(checksum_address=staker_address)
|
||||
return missing
|
||||
|
||||
@only_me
|
||||
|
@ -1341,21 +1341,21 @@ class Worker(NucypherTokenActor):
|
|||
return nu_balance
|
||||
|
||||
@property
|
||||
def last_active_period(self) -> int:
|
||||
period = self.staking_agent.get_last_active_period(staker_address=self.checksum_address)
|
||||
def last_committed_period(self) -> int:
|
||||
period = self.staking_agent.get_last_committed_period(staker_address=self.checksum_address)
|
||||
return period
|
||||
|
||||
@only_me
|
||||
@save_receipt
|
||||
def confirm_activity(self) -> dict:
|
||||
"""For each period that the worker confirms activity, the staker is rewarded"""
|
||||
receipt = self.staking_agent.confirm_activity(worker_address=self.__worker_address)
|
||||
def commit_to_next_period(self) -> dict:
|
||||
"""For each period that the worker makes a commitment, the staker is rewarded"""
|
||||
receipt = self.staking_agent.commit_to_next_period(worker_address=self.__worker_address)
|
||||
return receipt
|
||||
|
||||
@property
|
||||
def missing_confirmations(self) -> int:
|
||||
def missing_commitments(self) -> int:
|
||||
staker_address = self.checksum_address
|
||||
missing = self.staking_agent.get_missing_confirmations(checksum_address=staker_address)
|
||||
missing = self.staking_agent.get_missing_commitments(checksum_address=staker_address)
|
||||
return missing
|
||||
|
||||
|
||||
|
|
|
@ -256,10 +256,10 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
return stakers
|
||||
|
||||
def partition_stakers_by_activity(self) -> Tuple[List[str], List[str], List[str]]:
|
||||
"""Returns three lists of stakers depending on how they confirmed activity:
|
||||
The first list contains stakers that already confirmed next period.
|
||||
The second, stakers that confirmed for current period but haven't confirmed next yet.
|
||||
The third contains stakers that have missed activity confirmation before current period"""
|
||||
"""Returns three lists of stakers depending on how they made a commitments:
|
||||
The first list contains stakers that already committed to next period.
|
||||
The second, stakers that committed to current period but haven't committed to next yet.
|
||||
The third contains stakers that have missed commitments before current period"""
|
||||
|
||||
num_stakers = self.get_staker_population()
|
||||
current_period = self.get_current_period()
|
||||
|
@ -267,10 +267,10 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
active_stakers, pending_stakers, missing_stakers = [], [], []
|
||||
for i in range(num_stakers):
|
||||
staker = self.contract.functions.stakers(i).call()
|
||||
last_active_period = self.get_last_active_period(staker)
|
||||
if last_active_period == current_period + 1:
|
||||
last_committed_period = self.get_last_committed_period(staker)
|
||||
if last_committed_period == current_period + 1:
|
||||
active_stakers.append(staker)
|
||||
elif last_active_period == current_period:
|
||||
elif last_committed_period == current_period:
|
||||
pending_stakers.append(staker)
|
||||
else:
|
||||
missing_stakers.append(staker)
|
||||
|
@ -278,7 +278,7 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
return active_stakers, pending_stakers, missing_stakers
|
||||
|
||||
def get_all_active_stakers(self, periods: int, pagination_size: int = None) -> Tuple[int, List[str]]:
|
||||
"""Only stakers which confirmed the current period (in the previous period) are used."""
|
||||
"""Only stakers which committed to the current period (in the previous period) are used."""
|
||||
if not periods > 0:
|
||||
raise ValueError("Period must be > 0")
|
||||
|
||||
|
@ -318,18 +318,18 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
def get_global_locked_tokens(self, at_period: int = None) -> int:
|
||||
"""
|
||||
Gets the number of locked tokens for *all* stakers that have
|
||||
confirmed activity for the specified period.
|
||||
made a commitment to the specified period.
|
||||
|
||||
`at_period` values can be any valid period number past, present, or future:
|
||||
|
||||
PAST - Calling this function with an `at_period` value in the past will return the number
|
||||
of locked tokens whose worker activity was confirmed for that past period.
|
||||
of locked tokens whose worker commitment was made to that past period.
|
||||
|
||||
PRESENT - This is the default value, when no `at_period` value is provided.
|
||||
|
||||
FUTURE - Calling this function with an `at_period` value greater than
|
||||
the current period + 1 (next period), will result in a zero return value
|
||||
because activity cannot be confirmed beyond the next period.
|
||||
because commitment cannot be made beyond the next period.
|
||||
|
||||
Returns an amount of NuNits.
|
||||
"""
|
||||
|
@ -450,8 +450,8 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
return receipt
|
||||
|
||||
@validate_checksum_address
|
||||
def get_last_active_period(self, staker_address: str) -> int:
|
||||
period = self.contract.functions.getLastActivePeriod(staker_address).call()
|
||||
def get_last_committed_period(self, staker_address: str) -> int:
|
||||
period = self.contract.functions.getLastCommittedPeriod(staker_address).call()
|
||||
return int(period)
|
||||
|
||||
@validate_checksum_address
|
||||
|
@ -475,11 +475,11 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
return self.set_worker(staker_address=staker_address, worker_address=NULL_ADDRESS)
|
||||
|
||||
@validate_checksum_address
|
||||
def confirm_activity(self, worker_address: str):
|
||||
def commit_to_next_period(self, worker_address: str):
|
||||
"""
|
||||
For each period that the worker confirms activity, the staker is rewarded.
|
||||
For each period that the worker makes a commitment, the staker is rewarded.
|
||||
"""
|
||||
contract_function = self.contract.functions.confirmActivity()
|
||||
contract_function = self.contract.functions.commitToNextPeriod()
|
||||
receipt = self.blockchain.send_transaction(contract_function=contract_function, sender_address=worker_address)
|
||||
return receipt
|
||||
|
||||
|
@ -570,7 +570,7 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
def set_winding_down(self, staker_address: str, value: bool) -> dict:
|
||||
"""
|
||||
Enable wind down for stake.
|
||||
If set to True, then stakes duration will decrease in each period with `confirmActivity()`.
|
||||
If set to True, then stakes duration will decrease in each period with `commitToNextPeriod()`.
|
||||
"""
|
||||
contract_function = self.contract.functions.setWindDown(value)
|
||||
receipt = self.blockchain.send_transaction(contract_function=contract_function,
|
||||
|
@ -664,7 +664,7 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
|
||||
In this case, Stakers 0, 1, 3 and 5 will be selected.
|
||||
|
||||
Only stakers which confirmed the current period (in the previous period) are used.
|
||||
Only stakers which made a commitment to the current period (in the previous period) are used.
|
||||
"""
|
||||
|
||||
system_random = random.SystemRandom()
|
||||
|
@ -708,19 +708,19 @@ class StakingEscrowAgent(EthereumContractAgent):
|
|||
return total_completed_work
|
||||
|
||||
@validate_checksum_address
|
||||
def get_missing_confirmations(self, checksum_address: str) -> int:
|
||||
def get_missing_commitments(self, checksum_address: str) -> int:
|
||||
# TODO: Move this up one layer, since it utilizes a combination of contract API methods.
|
||||
last_confirmed_period = self.get_last_active_period(checksum_address)
|
||||
last_committed_period = self.get_last_committed_period(checksum_address)
|
||||
current_period = self.get_current_period()
|
||||
missing_confirmations = current_period - last_confirmed_period
|
||||
if missing_confirmations in (0, -1):
|
||||
missing_commitments = current_period - last_committed_period
|
||||
if missing_commitments in (0, -1):
|
||||
result = 0
|
||||
elif last_confirmed_period == 0: # never confirmed
|
||||
elif last_committed_period == 0: # never committed
|
||||
stakes = list(self.get_all_stakes(staker_address=checksum_address))
|
||||
initial_staking_period = min(stakes, key=lambda s: s[0])[0]
|
||||
result = current_period - initial_staking_period
|
||||
else:
|
||||
result = missing_confirmations
|
||||
result = missing_commitments
|
||||
return result
|
||||
|
||||
@property
|
||||
|
@ -1025,7 +1025,7 @@ class PreallocationEscrowAgent(EthereumContractAgent):
|
|||
def set_winding_down(self, value: bool) -> dict:
|
||||
"""
|
||||
Enable wind down for stake.
|
||||
If set to True, then stakes duration will be decreasing in each period with `confirmActivity()`.
|
||||
If set to True, then stakes duration will be decreasing in each period with `commitToNextPeriod()`.
|
||||
"""
|
||||
contract_function = self.__interface_agent.functions.setWindDown(value)
|
||||
receipt = self.blockchain.send_transaction(contract_function=contract_function,
|
||||
|
|
|
@ -385,11 +385,11 @@ contract PolicyManager is Upgradeable {
|
|||
}
|
||||
}
|
||||
|
||||
uint16 lastActivePeriod = escrow.getLastActivePeriod(_arrangement.node);
|
||||
if (indexOfDowntimePeriods == length && lastActivePeriod < maxPeriod) {
|
||||
uint16 lastCommittedPeriod = escrow.getLastCommittedPeriod(_arrangement.node);
|
||||
if (indexOfDowntimePeriods == length && lastCommittedPeriod < maxPeriod) {
|
||||
// Overflow protection removed:
|
||||
// lastActivePeriod < maxPeriod and minPeriod <= maxPeriod + 1
|
||||
downtimePeriods += maxPeriod - AdditionalMath.max16(minPeriod - 1, lastActivePeriod);
|
||||
// lastCommittedPeriod < maxPeriod and minPeriod <= maxPeriod + 1
|
||||
downtimePeriods += maxPeriod - AdditionalMath.max16(minPeriod - 1, lastCommittedPeriod);
|
||||
}
|
||||
|
||||
refundValue = _policy.feeRate * downtimePeriods;
|
||||
|
|
|
@ -58,7 +58,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
);
|
||||
event Prolonged(address indexed staker, uint256 value, uint16 lastPeriod, uint16 periods);
|
||||
event Withdrawn(address indexed staker, uint256 value);
|
||||
event ActivityConfirmed(address indexed staker, uint16 indexed period, uint256 value);
|
||||
event CommitmentMade(address indexed staker, uint16 indexed period, uint256 value);
|
||||
event Minted(address indexed staker, uint16 indexed period, uint256 value);
|
||||
event Slashed(address indexed staker, uint256 penalty, address indexed investigator, uint256 reward);
|
||||
event ReStakeSet(address indexed staker, bool reStake);
|
||||
|
@ -83,14 +83,14 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
struct StakerInfo {
|
||||
uint256 value;
|
||||
/*
|
||||
* Stores periods that are confirmed but not yet rewarded.
|
||||
* Stores periods that are committed but not yet rewarded.
|
||||
* In order to optimize storage, only two values are used instead of an array.
|
||||
* confirmActivity() method invokes mint() method so there can only be two confirmed
|
||||
* commitToNextPeriod() method invokes mint() method so there can only be two committed
|
||||
* periods that are not yet rewarded: the current and the next periods.
|
||||
*/
|
||||
uint16 currentConfirmedPeriod;
|
||||
uint16 nextConfirmedPeriod;
|
||||
uint16 lastActivePeriod; // last confirmed active period
|
||||
uint16 currentCommittedPeriod;
|
||||
uint16 nextCommittedPeriod;
|
||||
uint16 lastCommittedPeriod;
|
||||
uint16 lockReStakeUntilPeriod;
|
||||
uint256 completedWork;
|
||||
uint16 workerStartPeriod; // period when worker was set
|
||||
|
@ -280,8 +280,8 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
function getStartPeriod(StakerInfo storage _info, uint16 _currentPeriod)
|
||||
internal view returns (uint16)
|
||||
{
|
||||
// if the next period (after current) is confirmed
|
||||
if (_info.flags.bitSet(WIND_DOWN_INDEX) && _info.nextConfirmedPeriod > _currentPeriod) {
|
||||
// if the next period (after current) is committed
|
||||
if (_info.flags.bitSet(WIND_DOWN_INDEX) && _info.nextCommittedPeriod > _currentPeriod) {
|
||||
return _currentPeriod + 1;
|
||||
}
|
||||
return _currentPeriod;
|
||||
|
@ -322,7 +322,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
|
||||
/**
|
||||
* @notice Get the value of locked tokens for a staker in a specified period
|
||||
* @dev Information may be incorrect for rewarded or unconfirmed surpassed period
|
||||
* @dev Information may be incorrect for rewarded or not committed surpassed period
|
||||
* @param _info Staker structure
|
||||
* @param _currentPeriod Current period
|
||||
* @param _period Next period
|
||||
|
@ -358,7 +358,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
|
||||
/**
|
||||
* @notice Get the value of locked tokens for a staker in a previous period
|
||||
* @dev Information may be incorrect for rewarded or unconfirmed surpassed period
|
||||
* @dev Information may be incorrect for rewarded or not committed surpassed period
|
||||
* @param _staker Staker
|
||||
* @param _periods Amount of periods that will be subtracted from the current period
|
||||
*/
|
||||
|
@ -372,12 +372,12 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
}
|
||||
|
||||
/**
|
||||
* @notice Get the last active staker's period
|
||||
* @notice Get the last committed staker's period
|
||||
* @param _staker Staker
|
||||
*/
|
||||
function getLastActivePeriod(address _staker) public view returns (uint16) {
|
||||
function getLastCommittedPeriod(address _staker) public view returns (uint16) {
|
||||
StakerInfo storage info = stakerInfo[_staker];
|
||||
return info.nextConfirmedPeriod != 0 ? info.nextConfirmedPeriod : info.lastActivePeriod;
|
||||
return info.nextCommittedPeriod != 0 ? info.nextCommittedPeriod : info.lastCommittedPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -410,8 +410,8 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
for (uint256 i = _startIndex; i < endIndex; i++) {
|
||||
address staker = stakers[i];
|
||||
StakerInfo storage info = stakerInfo[staker];
|
||||
if (info.currentConfirmedPeriod != currentPeriod &&
|
||||
info.nextConfirmedPeriod != currentPeriod) {
|
||||
if (info.currentCommittedPeriod != currentPeriod &&
|
||||
info.nextCommittedPeriod != currentPeriod) {
|
||||
continue;
|
||||
}
|
||||
uint256 lockedTokens = getLockedTokens(info, currentPeriod, nextPeriod);
|
||||
|
@ -543,7 +543,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
|
||||
/**
|
||||
* @notice Set `windDown` parameter.
|
||||
* If true then stakes duration will be decreasing in each period with `confirmActivity()`
|
||||
* If true then stakes duration will be decreasing in each period with `commitToNextPeriod()`
|
||||
* @param _windDown Value for parameter
|
||||
*/
|
||||
function setWindDown(bool _windDown) external onlyStaker {
|
||||
|
@ -557,8 +557,8 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
uint16 nextPeriod = currentPeriod + 1;
|
||||
emit WindDownSet(msg.sender, _windDown);
|
||||
|
||||
// duration adjustment if next period is confirmed
|
||||
if (info.nextConfirmedPeriod != nextPeriod) {
|
||||
// duration adjustment if next period is committed
|
||||
if (info.nextCommittedPeriod != nextPeriod) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -787,15 +787,15 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
require(requestedLockedTokens <= info.value && requestedLockedTokens <= maxAllowableLockedTokens);
|
||||
|
||||
uint16 duration = _periods;
|
||||
// next period is confirmed
|
||||
if (info.nextConfirmedPeriod == nextPeriod) {
|
||||
// if winding down is enabled and next period is confirmed
|
||||
// next period is committed
|
||||
if (info.nextCommittedPeriod == nextPeriod) {
|
||||
// if winding down is enabled and next period is committed
|
||||
// then sub-stakes duration were decreased
|
||||
if (info.flags.bitSet(WIND_DOWN_INDEX)) {
|
||||
duration -= 1;
|
||||
}
|
||||
lockedPerPeriod[nextPeriod] += _value;
|
||||
emit ActivityConfirmed(_staker, nextPeriod, _value);
|
||||
emit CommitmentMade(_staker, nextPeriod, _value);
|
||||
}
|
||||
saveSubStake(info, nextPeriod, 0, duration, _value);
|
||||
|
||||
|
@ -823,10 +823,10 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
for (uint256 i = 0; i < _info.subStakes.length; i++) {
|
||||
SubStakeInfo storage subStake = _info.subStakes[i];
|
||||
if (subStake.lastPeriod != 0 &&
|
||||
(_info.currentConfirmedPeriod == 0 ||
|
||||
subStake.lastPeriod < _info.currentConfirmedPeriod) &&
|
||||
(_info.nextConfirmedPeriod == 0 ||
|
||||
subStake.lastPeriod < _info.nextConfirmedPeriod))
|
||||
(_info.currentCommittedPeriod == 0 ||
|
||||
subStake.lastPeriod < _info.currentCommittedPeriod) &&
|
||||
(_info.nextCommittedPeriod == 0 ||
|
||||
subStake.lastPeriod < _info.nextCommittedPeriod))
|
||||
{
|
||||
subStake.firstPeriod = _firstPeriod;
|
||||
subStake.lastPeriod = _lastPeriod;
|
||||
|
@ -878,7 +878,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
require(lastPeriod > currentPeriod, "The sub stake must active at least in the next period");
|
||||
|
||||
subStake.periods = subStake.periods.add16(_periods);
|
||||
// if the sub stake ends in the next confirmed period then reset the `lastPeriod` field
|
||||
// if the sub stake ends in the next committed period then reset the `lastPeriod` field
|
||||
if (lastPeriod == startPeriod) {
|
||||
subStake.lastPeriod = 0;
|
||||
}
|
||||
|
@ -909,21 +909,21 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
}
|
||||
|
||||
/**
|
||||
* @notice Confirm activity for the next period and mint for the previous period
|
||||
* @notice Make a commitment to the next period and mint for the previous period
|
||||
*/
|
||||
function confirmActivity() external isInitialized {
|
||||
function commitToNextPeriod() external isInitialized {
|
||||
address staker = stakerFromWorker[msg.sender];
|
||||
StakerInfo storage info = stakerInfo[staker];
|
||||
require(info.value > 0, "Staker must have a stake to confirm activity");
|
||||
require(msg.sender == tx.origin, "Only worker with real address can confirm activity");
|
||||
require(info.value > 0, "Staker must have a stake to make a commitment");
|
||||
require(msg.sender == tx.origin, "Only worker with real address can make a commitment");
|
||||
|
||||
uint16 lastActivePeriod = getLastActivePeriod(staker);
|
||||
uint16 lastCommittedPeriod = getLastCommittedPeriod(staker);
|
||||
mint(staker);
|
||||
uint16 currentPeriod = getCurrentPeriod();
|
||||
uint16 nextPeriod = currentPeriod + 1;
|
||||
|
||||
// the period has already been confirmed
|
||||
if (info.nextConfirmedPeriod == nextPeriod) {
|
||||
// the period has already been committed
|
||||
if (info.nextCommittedPeriod == nextPeriod) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -931,17 +931,17 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
require(lockedTokens > 0);
|
||||
lockedPerPeriod[nextPeriod] += lockedTokens;
|
||||
|
||||
info.currentConfirmedPeriod = info.nextConfirmedPeriod;
|
||||
info.nextConfirmedPeriod = nextPeriod;
|
||||
info.currentCommittedPeriod = info.nextCommittedPeriod;
|
||||
info.nextCommittedPeriod = nextPeriod;
|
||||
|
||||
decreaseSubStakesDuration(info, nextPeriod);
|
||||
|
||||
// staker was inactive for several periods
|
||||
if (lastActivePeriod < currentPeriod) {
|
||||
info.pastDowntime.push(Downtime(lastActivePeriod + 1, currentPeriod));
|
||||
if (lastCommittedPeriod < currentPeriod) {
|
||||
info.pastDowntime.push(Downtime(lastCommittedPeriod + 1, currentPeriod));
|
||||
}
|
||||
policyManager.setDefaultFeeDelta(staker, nextPeriod);
|
||||
emit ActivityConfirmed(staker, nextPeriod, lockedTokens);
|
||||
emit CommitmentMade(staker, nextPeriod, lockedTokens);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -964,22 +964,22 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
}
|
||||
|
||||
/**
|
||||
* @notice Mint tokens for previous periods if staker locked their tokens and confirmed activity
|
||||
* @notice Mint tokens for previous periods if staker locked their tokens and made a commitment
|
||||
*/
|
||||
function mint() external onlyStaker {
|
||||
// save last active period to the storage if both periods will be empty after minting
|
||||
// because we won't be able to calculate last active period
|
||||
// see getLastActivePeriod(address)
|
||||
// save last committed period to the storage if both periods will be empty after minting
|
||||
// because we won't be able to calculate last committed period
|
||||
// see getLastCommittedPeriod(address)
|
||||
StakerInfo storage info = stakerInfo[msg.sender];
|
||||
uint16 previousPeriod = getCurrentPeriod() - 1;
|
||||
if (info.nextConfirmedPeriod <= previousPeriod && info.nextConfirmedPeriod != 0) {
|
||||
info.lastActivePeriod = info.nextConfirmedPeriod;
|
||||
if (info.nextCommittedPeriod <= previousPeriod && info.nextCommittedPeriod != 0) {
|
||||
info.lastCommittedPeriod = info.nextCommittedPeriod;
|
||||
}
|
||||
mint(msg.sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notice Mint tokens for previous periods if staker locked their tokens and confirmed activity
|
||||
* @notice Mint tokens for previous periods if staker locked their tokens and made a commitment
|
||||
* @param _staker Staker
|
||||
*/
|
||||
function mint(address _staker) internal {
|
||||
|
@ -987,26 +987,26 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
uint16 previousPeriod = currentPeriod - 1;
|
||||
StakerInfo storage info = stakerInfo[_staker];
|
||||
|
||||
if (info.nextConfirmedPeriod == 0 ||
|
||||
info.currentConfirmedPeriod == 0 &&
|
||||
info.nextConfirmedPeriod > previousPeriod ||
|
||||
info.currentConfirmedPeriod > previousPeriod) {
|
||||
if (info.nextCommittedPeriod == 0 ||
|
||||
info.currentCommittedPeriod == 0 &&
|
||||
info.nextCommittedPeriod > previousPeriod ||
|
||||
info.currentCommittedPeriod > previousPeriod) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16 startPeriod = getStartPeriod(info, currentPeriod);
|
||||
uint256 reward = 0;
|
||||
bool reStake = !info.flags.bitSet(RE_STAKE_DISABLED_INDEX);
|
||||
if (info.currentConfirmedPeriod != 0) {
|
||||
reward = mint(_staker, info, info.currentConfirmedPeriod, currentPeriod, startPeriod, reStake);
|
||||
info.currentConfirmedPeriod = 0;
|
||||
if (info.currentCommittedPeriod != 0) {
|
||||
reward = mint(_staker, info, info.currentCommittedPeriod, currentPeriod, startPeriod, reStake);
|
||||
info.currentCommittedPeriod = 0;
|
||||
if (reStake) {
|
||||
lockedPerPeriod[info.nextConfirmedPeriod] += reward;
|
||||
lockedPerPeriod[info.nextCommittedPeriod] += reward;
|
||||
}
|
||||
}
|
||||
if (info.nextConfirmedPeriod <= previousPeriod) {
|
||||
reward += mint(_staker, info, info.nextConfirmedPeriod, currentPeriod, startPeriod, reStake);
|
||||
info.nextConfirmedPeriod = 0;
|
||||
if (info.nextCommittedPeriod <= previousPeriod) {
|
||||
reward += mint(_staker, info, info.nextCommittedPeriod, currentPeriod, startPeriod, reStake);
|
||||
info.nextCommittedPeriod = 0;
|
||||
}
|
||||
|
||||
info.value += reward;
|
||||
|
@ -1221,15 +1221,15 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
_penalty -= shortestSubStake.lockedValue;
|
||||
appliedPenalty = shortestSubStake.lockedValue;
|
||||
}
|
||||
if (_info.currentConfirmedPeriod >= _decreasePeriod &&
|
||||
_info.currentConfirmedPeriod <= minSubStakeLastPeriod)
|
||||
if (_info.currentCommittedPeriod >= _decreasePeriod &&
|
||||
_info.currentCommittedPeriod <= minSubStakeLastPeriod)
|
||||
{
|
||||
lockedPerPeriod[_info.currentConfirmedPeriod] -= appliedPenalty;
|
||||
lockedPerPeriod[_info.currentCommittedPeriod] -= appliedPenalty;
|
||||
}
|
||||
if (_info.nextConfirmedPeriod >= _decreasePeriod &&
|
||||
_info.nextConfirmedPeriod <= minSubStakeLastPeriod)
|
||||
if (_info.nextCommittedPeriod >= _decreasePeriod &&
|
||||
_info.nextCommittedPeriod <= minSubStakeLastPeriod)
|
||||
{
|
||||
lockedPerPeriod[_info.nextConfirmedPeriod] -= appliedPenalty;
|
||||
lockedPerPeriod[_info.nextCommittedPeriod] -= appliedPenalty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1278,7 +1278,7 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
|
||||
/**
|
||||
* @notice Save the old sub stake values to prevent decreasing reward for the previous period
|
||||
* @dev Saving happens only if the previous period is confirmed
|
||||
* @dev Saving happens only if the previous period is committed
|
||||
* @param _info Staker structure
|
||||
* @param _firstPeriod First period of the old sub stake
|
||||
* @param _lockedValue Locked value of the old sub stake
|
||||
|
@ -1293,13 +1293,13 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
internal
|
||||
{
|
||||
// Check that the old sub stake should be saved
|
||||
bool oldCurrentConfirmedPeriod = _info.currentConfirmedPeriod != 0 &&
|
||||
_info.currentConfirmedPeriod < _currentPeriod;
|
||||
bool oldNextConfirmedPeriod = _info.nextConfirmedPeriod != 0 &&
|
||||
_info.nextConfirmedPeriod < _currentPeriod;
|
||||
bool crossCurrentConfirmedPeriod = oldCurrentConfirmedPeriod && _info.currentConfirmedPeriod >= _firstPeriod;
|
||||
bool crossNextConfirmedPeriod = oldNextConfirmedPeriod && _info.nextConfirmedPeriod >= _firstPeriod;
|
||||
if (!crossCurrentConfirmedPeriod && !crossNextConfirmedPeriod) {
|
||||
bool oldcurrentCommittedPeriod = _info.currentCommittedPeriod != 0 &&
|
||||
_info.currentCommittedPeriod < _currentPeriod;
|
||||
bool oldnextCommittedPeriod = _info.nextCommittedPeriod != 0 &&
|
||||
_info.nextCommittedPeriod < _currentPeriod;
|
||||
bool crosscurrentCommittedPeriod = oldcurrentCommittedPeriod && _info.currentCommittedPeriod >= _firstPeriod;
|
||||
bool crossnextCommittedPeriod = oldnextCommittedPeriod && _info.nextCommittedPeriod >= _firstPeriod;
|
||||
if (!crosscurrentCommittedPeriod && !crossnextCommittedPeriod) {
|
||||
return;
|
||||
}
|
||||
// Try to find already existent proper old sub stake
|
||||
|
@ -1307,10 +1307,10 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
for (uint256 i = 0; i < _info.subStakes.length; i++) {
|
||||
SubStakeInfo storage subStake = _info.subStakes[i];
|
||||
if (subStake.lastPeriod == previousPeriod &&
|
||||
((crossCurrentConfirmedPeriod ==
|
||||
(oldCurrentConfirmedPeriod && _info.currentConfirmedPeriod >= subStake.firstPeriod)) &&
|
||||
(crossNextConfirmedPeriod ==
|
||||
(oldNextConfirmedPeriod && _info.nextConfirmedPeriod >= subStake.firstPeriod))))
|
||||
((crosscurrentCommittedPeriod ==
|
||||
(oldcurrentCommittedPeriod && _info.currentCommittedPeriod >= subStake.firstPeriod)) &&
|
||||
(crossnextCommittedPeriod ==
|
||||
(oldnextCommittedPeriod && _info.nextCommittedPeriod >= subStake.firstPeriod))))
|
||||
{
|
||||
subStake.lockedValue += uint128(_lockedValue);
|
||||
return;
|
||||
|
@ -1444,11 +1444,11 @@ contract StakingEscrow is Issuer, IERC900History {
|
|||
bytes32 staker = bytes32(uint256(stakerAddress));
|
||||
StakerInfo memory infoToCheck = delegateGetStakerInfo(_testTarget, staker);
|
||||
require(infoToCheck.value == info.value &&
|
||||
infoToCheck.currentConfirmedPeriod == info.currentConfirmedPeriod &&
|
||||
infoToCheck.nextConfirmedPeriod == info.nextConfirmedPeriod &&
|
||||
infoToCheck.currentCommittedPeriod == info.currentCommittedPeriod &&
|
||||
infoToCheck.nextCommittedPeriod == info.nextCommittedPeriod &&
|
||||
infoToCheck.flags == info.flags &&
|
||||
infoToCheck.lockReStakeUntilPeriod == info.lockReStakeUntilPeriod &&
|
||||
infoToCheck.lastActivePeriod == info.lastActivePeriod &&
|
||||
infoToCheck.lastCommittedPeriod == info.lastCommittedPeriod &&
|
||||
infoToCheck.completedWork == info.completedWork &&
|
||||
infoToCheck.worker == info.worker &&
|
||||
infoToCheck.workerStartPeriod == info.workerStartPeriod);
|
||||
|
|
|
@ -191,9 +191,9 @@ class Stake:
|
|||
|
||||
# TODO: #1502 - Move Me Brightly - Docs
|
||||
# After this period has passes, workers can go offline, if this is the only stake.
|
||||
# This is the last period that can be confirmed for this stake.
|
||||
# Meaning, It must be confirmed in the previous period,
|
||||
# and no confirmation can be performed in this period for this stake.
|
||||
# This is the last period that can be committed for this stake.
|
||||
# Meaning, It must be committed in the previous period,
|
||||
# and no commitment can be made in this period for this stake.
|
||||
self.final_locked_period = final_locked_period
|
||||
|
||||
# Blockchain
|
||||
|
@ -579,25 +579,25 @@ class WorkTracker:
|
|||
# self.worker.stakes.refresh() # TODO: #1517 Track stakes for fast access to terminal period.
|
||||
|
||||
# Measure working interval
|
||||
interval = onchain_period - self.worker.last_active_period
|
||||
interval = onchain_period - self.worker.last_committed_period
|
||||
if interval < 0:
|
||||
return # No need to confirm this period. Save the gas.
|
||||
return # No need to commit to this period. Save the gas.
|
||||
if interval > 0:
|
||||
# TODO: #1516 Follow-up actions for downtime
|
||||
self.log.warn(f"MISSED CONFIRMATIONS - {interval} missed staking confirmations detected.")
|
||||
self.log.warn(f"MISSED COMMITMENTS - {interval} missed staking commitments detected.")
|
||||
|
||||
# Only perform work this round if the requirements are met
|
||||
if not self.__check_work_requirement():
|
||||
self.log.warn(f'CONFIRMATION PREVENTED (callable: "{self.__requirement.__name__}") - '
|
||||
f'There are unmet confirmation requirements.')
|
||||
self.log.warn(f'COMMIT PREVENTED (callable: "{self.__requirement.__name__}") - '
|
||||
f'There are unmet commit requirements.')
|
||||
# TODO: Follow-up actions for downtime
|
||||
return
|
||||
|
||||
# Confirm Activity
|
||||
self.log.info("Confirmed activity for period {}".format(self.current_period))
|
||||
# Make a Commitment
|
||||
self.log.info("Made a commitment to period {}".format(self.current_period))
|
||||
transacting_power = self.worker.transacting_power
|
||||
with transacting_power:
|
||||
self.worker.confirm_activity() # < --- blockchain WRITE
|
||||
self.worker.commit_to_next_period() # < --- blockchain WRITE
|
||||
|
||||
|
||||
class StakeList(UserList):
|
||||
|
|
|
@ -392,34 +392,35 @@ def config(general_config, config_options, config_file):
|
|||
config_options=config_options)
|
||||
|
||||
|
||||
@ursula.command(name='confirm-activity')
|
||||
@ursula.command(name='commit-next')
|
||||
@group_character_options
|
||||
@option_config_file
|
||||
@group_general_config
|
||||
def confirm_activity(general_config, character_options, config_file):
|
||||
# TODO make available only for debug purposes #1970
|
||||
def commit_to_next_period(general_config, character_options, config_file):
|
||||
"""
|
||||
Manually confirm-activity for the current period.
|
||||
Manually make a commitment to the next period.
|
||||
"""
|
||||
emitter = _setup_emitter(general_config, character_options.config_options.worker_address)
|
||||
_pre_launch_warnings(emitter, dev=character_options.config_options.dev, force=None)
|
||||
_, URSULA = character_options.create_character(emitter, config_file, general_config.json_ipc, load_seednodes=False)
|
||||
|
||||
confirmed_period = URSULA.staking_agent.get_current_period() + 1
|
||||
click.echo(f"Confirming activity for period {confirmed_period}", color='blue')
|
||||
receipt = URSULA.confirm_activity()
|
||||
committed_period = URSULA.staking_agent.get_current_period() + 1
|
||||
click.echo(f"Making a commitment to period {committed_period}", color='blue')
|
||||
receipt = URSULA.commit_to_next_period()
|
||||
|
||||
economics = EconomicsFactory.get_economics(registry=URSULA.registry)
|
||||
date = datetime_at_period(period=confirmed_period,
|
||||
date = datetime_at_period(period=committed_period,
|
||||
seconds_per_period=economics.seconds_per_period)
|
||||
|
||||
# TODO: Double-check dates here
|
||||
emitter.echo(f'\nActivity confirmed for period #{confirmed_period} '
|
||||
emitter.echo(f'\nCommitment was made to period #{committed_period} '
|
||||
f'(starting at {date})', bold=True, color='blue')
|
||||
painting.paint_receipt_summary(emitter=emitter,
|
||||
receipt=receipt,
|
||||
chain_name=URSULA.staking_agent.blockchain.client.chain_name)
|
||||
|
||||
# TODO: Check ActivityConfirmation event (see #1193)
|
||||
# TODO: Check CommitmentMade event (see #1193)
|
||||
|
||||
|
||||
def _setup_emitter(general_config, worker_address):
|
||||
|
|
|
@ -217,15 +217,15 @@ Provider URI ............. {blockchain.provider_uri}
|
|||
Registry ................. {registry.filepath}
|
||||
"""
|
||||
|
||||
confirmed, pending, inactive = staking_agent.partition_stakers_by_activity()
|
||||
committed, pending, inactive = staking_agent.partition_stakers_by_activity()
|
||||
|
||||
staking = f"""
|
||||
| Staking |
|
||||
Current Period ........... {staking_agent.get_current_period()}
|
||||
Actively Staked Tokens ... {NU.from_nunits(staking_agent.get_global_locked_tokens())}
|
||||
Stakers population ....... {staking_agent.get_staker_population()}
|
||||
Confirmed ............. {len(confirmed)}
|
||||
Pending confirmation .. {len(pending)}
|
||||
Committed ............. {len(committed)}
|
||||
Pending commitment .... {len(pending)}
|
||||
Inactive .............. {len(inactive)}
|
||||
|
||||
"""
|
||||
|
@ -515,14 +515,14 @@ def paint_stakes(emitter, stakeholder, paint_inactive: bool = False, staker_addr
|
|||
|
||||
fees = staker.policy_agent.get_fee_amount(staker.checksum_address)
|
||||
pretty_fees = prettify_eth_amount(fees)
|
||||
last_confirmed = staker.staking_agent.get_last_active_period(staker.checksum_address)
|
||||
missing = staker.missing_confirmations
|
||||
last_committed = staker.staking_agent.get_last_committed_period(staker.checksum_address)
|
||||
missing = staker.missing_commitments
|
||||
min_fee_rate = prettify_eth_amount(staker.min_fee_rate)
|
||||
|
||||
if missing == -1:
|
||||
missing_info = "Never Confirmed (New Stake)"
|
||||
missing_info = "Never Made a Commitment (New Stake)"
|
||||
else:
|
||||
missing_info = f'Missing {missing} confirmation{"s" if missing > 1 else ""}' if missing else f'Confirmed #{last_confirmed}'
|
||||
missing_info = f'Missing {missing} commitments{"s" if missing > 1 else ""}' if missing else f'Committed #{last_committed}'
|
||||
|
||||
staker_data = [missing_info,
|
||||
f'{"Yes" if staker.is_restaking else "No"} ({"Locked" if staker.restaking_lock_enabled else "Unlocked"})',
|
||||
|
@ -707,12 +707,12 @@ def paint_stakers(emitter, stakers: List[str], staking_agent, policy_agent) -> N
|
|||
tab = " " * len(staker)
|
||||
|
||||
owned_tokens = staking_agent.owned_tokens(staker)
|
||||
last_confirmed_period = staking_agent.get_last_active_period(staker)
|
||||
last_committed_period = staking_agent.get_last_committed_period(staker)
|
||||
worker = staking_agent.get_worker_from_staker(staker)
|
||||
is_restaking = staking_agent.is_restaking(staker)
|
||||
is_winding_down = staking_agent.is_winding_down(staker)
|
||||
|
||||
missing_confirmations = current_period - last_confirmed_period
|
||||
missing_commitments = current_period - last_committed_period
|
||||
owned_in_nu = round(NU.from_nunits(owned_tokens), 2)
|
||||
locked_tokens = round(NU.from_nunits(staking_agent.get_locked_tokens(staker)), 2)
|
||||
|
||||
|
@ -727,16 +727,16 @@ def paint_stakers(emitter, stakers: List[str], staking_agent, policy_agent) -> N
|
|||
emitter.echo(f"{tab} {'Re-staking:':10} No")
|
||||
emitter.echo(f"{tab} {'Winding down:':10} {'Yes' if is_winding_down else 'No'}")
|
||||
emitter.echo(f"{tab} {'Activity:':10} ", nl=False)
|
||||
if missing_confirmations == -1:
|
||||
emitter.echo(f"Next period confirmed (#{last_confirmed_period})", color='green')
|
||||
elif missing_confirmations == 0:
|
||||
emitter.echo(f"Current period confirmed (#{last_confirmed_period}). "
|
||||
f"Pending confirmation of next period.", color='yellow')
|
||||
elif missing_confirmations == current_period:
|
||||
emitter.echo(f"Never confirmed activity", color='red')
|
||||
if missing_commitments == -1:
|
||||
emitter.echo(f"Next period committed (#{last_committed_period})", color='green')
|
||||
elif missing_commitments == 0:
|
||||
emitter.echo(f"Current period committed (#{last_committed_period}). "
|
||||
f"Pending making a commitment to next period.", color='yellow')
|
||||
elif missing_commitments == current_period:
|
||||
emitter.echo(f"Never made a commitment", color='red')
|
||||
else:
|
||||
emitter.echo(f"Missing {missing_confirmations} confirmations "
|
||||
f"(last time for period #{last_confirmed_period})", color='red')
|
||||
emitter.echo(f"Missing {missing_commitments} commitments "
|
||||
f"(last time for period #{last_committed_period})", color='red')
|
||||
|
||||
emitter.echo(f"{tab} {'Worker:':10} ", nl=False)
|
||||
if worker == NULL_ADDRESS:
|
||||
|
@ -965,8 +965,8 @@ def paint_bidding_notice(emitter, bidder):
|
|||
- WorkLock token rewards are claimed in the form of a stake and will be locked for
|
||||
the stake duration.
|
||||
|
||||
- WorkLock ETH deposits will be available for refund at a rate of {prettify_eth_amount(bidder.worklock_agent.get_bonus_refund_rate())}
|
||||
per confirmed period. This rate may vary until {maya.MayaDT(bidder.economics.bidding_end_date).local_datetime()}.
|
||||
- WorkLock ETH deposits will be available for refund at a rate of {prettify_eth_amount(bidder.worklock_agent.get_bonus_refund_rate())}.
|
||||
This rate may vary until {maya.MayaDT(bidder.economics.bidding_end_date).local_datetime()}.
|
||||
|
||||
- Once claiming WorkLock tokens, you are obligated to maintain a networked and available
|
||||
Ursula-Worker node bonded to the staker address {bidder.checksum_address}
|
||||
|
|
|
@ -59,7 +59,8 @@ class UrsulaCommandProtocol(LineReceiver):
|
|||
# 'stakes': self.paintStakes, # TODO
|
||||
|
||||
# Blockchain Control
|
||||
'confirm_activity': self.confirm_activity,
|
||||
# TODO #1970
|
||||
'commit_next': self.commit_to_next_period,
|
||||
|
||||
# Learning Control
|
||||
'cycle_teacher': self.cycle_teacher,
|
||||
|
@ -166,11 +167,11 @@ class UrsulaCommandProtocol(LineReceiver):
|
|||
"""
|
||||
return self.ursula.stop_learning_loop()
|
||||
|
||||
def confirm_activity(self):
|
||||
def commit_to_next_period(self):
|
||||
"""
|
||||
manually confirm activity for this period
|
||||
manually make a commitment to the next period
|
||||
"""
|
||||
return self.ursula.confirm_activity()
|
||||
return self.ursula.commit_to_next_period()
|
||||
|
||||
def stop(self):
|
||||
"""
|
||||
|
|
|
@ -1386,6 +1386,6 @@ class Teacher:
|
|||
if not self.federated_only:
|
||||
payload.update({
|
||||
"balances": dict(eth=float(self.eth_balance), nu=float(self.token_balance.to_tokens())),
|
||||
"missing_confirmations": self.missing_confirmations,
|
||||
"last_active_period": self.last_active_period})
|
||||
"missing_commitments": self.missing_commitments,
|
||||
"last_committed_period": self.last_committed_period})
|
||||
return payload
|
||||
|
|
|
@ -10,7 +10,7 @@ from nucypher.blockchain.eth.agents import ContractAgency, StakingEscrowAgent
|
|||
# Metrics
|
||||
known_nodes_guage = Gauge('known_nodes', 'Number of currently known nodes')
|
||||
work_orders_guage = Gauge('work_orders', 'Number of accepted work orders')
|
||||
missing_confirmation_guage = Gauge('missing_confirmations', 'Currently missed confirmations')
|
||||
missing_commitments_guage = Gauge('missing_commitments', 'Currently missed commitments')
|
||||
learning_status = Enum('node_discovery', 'Learning loop status', states=['starting', 'running', 'stopped'])
|
||||
requests_counter = Counter('http_failures', 'HTTP Failures', ['method', 'endpoint'])
|
||||
host_info = Info('host_info', 'Description of info')
|
||||
|
@ -36,12 +36,12 @@ def collect_prometheus_metrics(ursula):
|
|||
locked = staking_agent.get_locked_tokens(staker_address=ursula.checksum_address, periods=1)
|
||||
active_stake_gauge.set(locked)
|
||||
|
||||
missing_confirmations = staking_agent.get_missing_confirmations(staker_address=ursula.checksum_address) # TODO: lol
|
||||
missing_confirmation_guage.set(missing_confirmations)
|
||||
missing_commitments = staking_agent.get_missing_commitments(staker_address=ursula.checksum_address) # TODO: lol
|
||||
missing_commitments_guage.set(missing_commitments)
|
||||
|
||||
decentralized_payload = {'provider': str(ursula.provider_uri),
|
||||
'active_stake': str(locked),
|
||||
'missing_confirmations': str(missing_confirmations)}
|
||||
'missing_commitments': str(missing_commitments)}
|
||||
|
||||
base_payload.update(decentralized_payload)
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ def make_federated_ursulas(ursula_config: UrsulaConfiguration,
|
|||
def make_decentralized_ursulas(ursula_config: UrsulaConfiguration,
|
||||
stakers_addresses: Iterable[str],
|
||||
workers_addresses: Iterable[str],
|
||||
confirm_activity: bool = False,
|
||||
commit_to_next_period: bool = False,
|
||||
**ursula_overrides) -> List[Ursula]:
|
||||
|
||||
if not MOCK_KNOWN_URSULAS_CACHE:
|
||||
|
@ -86,9 +86,9 @@ def make_decentralized_ursulas(ursula_config: UrsulaConfiguration,
|
|||
db_filepath=MOCK_URSULA_DB_FILEPATH,
|
||||
rest_port=port + 100,
|
||||
**ursula_overrides)
|
||||
if confirm_activity:
|
||||
if commit_to_next_period:
|
||||
ursula.transacting_power.activate()
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
|
||||
ursulas.append(ursula)
|
||||
# Store this Ursula in our global cache.
|
||||
|
@ -103,7 +103,7 @@ def make_ursula_for_staker(staker: Staker,
|
|||
blockchain: BlockchainInterface,
|
||||
ursula_config: UrsulaConfiguration,
|
||||
ursulas_to_learn_about: Optional[List[Ursula]] = None,
|
||||
confirm_activity: bool = False,
|
||||
commit_to_next_period: bool = False,
|
||||
**ursula_overrides) -> Ursula:
|
||||
|
||||
# Assign worker to this staker
|
||||
|
@ -113,7 +113,7 @@ def make_ursula_for_staker(staker: Staker,
|
|||
blockchain=blockchain,
|
||||
stakers_addresses=[staker.checksum_address],
|
||||
workers_addresses=[worker_address],
|
||||
confirm_activity=confirm_activity,
|
||||
commit_to_next_period=commit_to_next_period,
|
||||
**ursula_overrides).pop()
|
||||
|
||||
for ursula_to_learn_about in (ursulas_to_learn_about or []):
|
||||
|
|
|
@ -52,7 +52,7 @@ contract StakingEscrowForPolicyMock {
|
|||
uint32 public immutable secondsPerPeriod;
|
||||
|
||||
PolicyManager public policyManager;
|
||||
uint16 public lastActivePeriod;
|
||||
uint16 public lastCommittedPeriod;
|
||||
Downtime[] public downtime;
|
||||
|
||||
/**
|
||||
|
@ -70,10 +70,10 @@ contract StakingEscrowForPolicyMock {
|
|||
}
|
||||
|
||||
/**
|
||||
* @notice Set last active period
|
||||
* @notice Set last committed period
|
||||
*/
|
||||
function setLastActivePeriod(uint16 _lastActivePeriod) external {
|
||||
lastActivePeriod = _lastActivePeriod;
|
||||
function setLastCommittedPeriod(uint16 _lastCommittedPeriod) external {
|
||||
lastCommittedPeriod = _lastCommittedPeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -123,8 +123,8 @@ contract StakingEscrowForPolicyMock {
|
|||
endPeriod = data.endPeriod;
|
||||
}
|
||||
|
||||
function getLastActivePeriod(address) public view returns (uint256) {
|
||||
return lastActivePeriod;
|
||||
function getLastCommittedPeriod(address) public view returns (uint256) {
|
||||
return lastCommittedPeriod;
|
||||
}
|
||||
|
||||
function register(address _node, uint16 _period) public {
|
||||
|
|
|
@ -189,8 +189,8 @@ contract Intermediary {
|
|||
escrow.deposit(_value, _periods);
|
||||
}
|
||||
|
||||
function confirmActivity() external {
|
||||
escrow.confirmActivity();
|
||||
function commitToNextPeriod() external {
|
||||
escrow.commitToNextPeriod();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -48,16 +48,16 @@ def test_reward(testerchain, agency, token_economics, mock_transacting_power_act
|
|||
_txhash = staking_agent.set_worker(staker_address=ursula, worker_address=ursula)
|
||||
_txhash = staking_agent.set_restaking(staker_address=ursula, value=False)
|
||||
|
||||
_txhash = staking_agent.confirm_activity(worker_address=ursula)
|
||||
_txhash = staking_agent.commit_to_next_period(worker_address=ursula)
|
||||
testerchain.time_travel(periods=1)
|
||||
_txhash = staking_agent.confirm_activity(worker_address=ursula)
|
||||
_txhash = staking_agent.commit_to_next_period(worker_address=ursula)
|
||||
assert staking_agent.calculate_staking_reward(staker_address=ursula) == 0
|
||||
|
||||
# Get a reward
|
||||
switch = token_economics.first_phase_final_period()
|
||||
for i in range(1, switch + MAX_PERIODS_SECOND_PHASE):
|
||||
testerchain.time_travel(periods=1)
|
||||
_txhash = staking_agent.confirm_activity(worker_address=ursula)
|
||||
_txhash = staking_agent.commit_to_next_period(worker_address=ursula)
|
||||
contract_reward = staking_agent.calculate_staking_reward(staker_address=ursula)
|
||||
calculations_reward = token_economics.cumulative_rewards_at_period(i)
|
||||
error = abs((contract_reward - calculations_reward) / calculations_reward)
|
||||
|
|
|
@ -603,15 +603,15 @@ def test_staking(testerchain,
|
|||
tx = escrow.functions.deposit(2001, 1).transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't confirm activity before initialization
|
||||
# Can't make a commitment before initialization
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Initialize escrow
|
||||
|
@ -640,7 +640,7 @@ def test_staking(testerchain,
|
|||
testerchain.wait_for_receipt(tx)
|
||||
wind_down, _re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert wind_down
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
pytest.escrow_supply += 1000
|
||||
second_sub_stake = 1000
|
||||
|
@ -699,7 +699,7 @@ def test_policy(testerchain,
|
|||
testerchain.wait_for_receipt(tx)
|
||||
wind_down, _re_stake, _measure_work, _snapshots = escrow.functions.getFlags(preallocation_escrow_interface_1.address).call()
|
||||
assert wind_down
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
pytest.escrow_supply += 1000
|
||||
assert 1000 == escrow.functions.getAllTokens(preallocation_escrow_1.address).call()
|
||||
|
@ -727,16 +727,16 @@ def test_policy(testerchain,
|
|||
tx = preallocation_escrow_interface_1.functions.divideStake(0, 500, 6).transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Confirm activity
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# Make a commitment
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Turn on re-stake for staker1
|
||||
|
@ -748,11 +748,11 @@ def test_policy(testerchain,
|
|||
assert re_stake
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Create other policies
|
||||
|
@ -830,13 +830,13 @@ def test_policy(testerchain,
|
|||
.transact({'from': alice1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Wait, confirm activity, mint
|
||||
# Wait, make a commitment, mint
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Check work measurement
|
||||
|
@ -853,11 +853,11 @@ def test_policy(testerchain,
|
|||
.transact({'from': alice2, 'gas_price': 0})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Turn off re-stake for staker1
|
||||
|
@ -869,11 +869,11 @@ def test_policy(testerchain,
|
|||
assert not re_stake
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Withdraw fee and refund
|
||||
|
@ -1044,19 +1044,19 @@ def test_slashing(testerchain,
|
|||
ursula3_with_stamp = mock_ursula(testerchain, staker3, mocker=mocker)
|
||||
|
||||
# Slash stakers
|
||||
# Confirm activity for two periods
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# Make a commitment to two periods
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
|
@ -1265,11 +1265,11 @@ def test_withdraw(testerchain,
|
|||
|
||||
# Unlock and withdraw all tokens
|
||||
for index in range(9):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
|
|
|
@ -641,7 +641,7 @@ def test_handling_wrong_state(testerchain, deploy_contract):
|
|||
tx = escrow.functions.setDefaultFeeDelta(node1, current_period, 1).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Emulate confirm activity actions
|
||||
# Emulate making a commitments
|
||||
for i in range(1, number_of_periods + 2):
|
||||
testerchain.time_travel(hours=1)
|
||||
current_period = policy_manager.functions.getCurrentPeriod().call()
|
||||
|
@ -682,7 +682,7 @@ def test_handling_wrong_state(testerchain, deploy_contract):
|
|||
tx = policy_manager.functions.setNodeFeeDelta(node2, initial_period + 2 + number_of_periods, -50).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Emulate confirm activity actions
|
||||
# Emulate making a commitments
|
||||
for i in range(1, number_of_periods + 4):
|
||||
testerchain.time_travel(hours=1)
|
||||
current_period = policy_manager.functions.getCurrentPeriod().call()
|
||||
|
|
|
@ -73,7 +73,7 @@ def test_fee(testerchain, escrow, policy_manager):
|
|||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.register(bad_node, period).transact({'from': bad_node})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Can't set default value directly (only through confirmActivity method in the escrow contract)
|
||||
# Can't set default value directly (only through commitToNextPeriod method in the escrow contract)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = policy_manager.functions.setDefaultFeeDelta(bad_node, period).transact({'from': bad_node})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -179,7 +179,7 @@ def test_refund(testerchain, escrow, policy_manager):
|
|||
.transact({'from': policy_creator, 'value': value, 'gas_price': 0})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.setLastActivePeriod(period - 1).transact({'from': creator})
|
||||
tx = escrow.functions.setLastCommittedPeriod(period - 1).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
testerchain.time_travel(hours=8)
|
||||
|
@ -265,7 +265,7 @@ def test_refund(testerchain, escrow, policy_manager):
|
|||
# Create new policy
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
tx = escrow.functions.setLastActivePeriod(period).transact()
|
||||
tx = escrow.functions.setLastCommittedPeriod(period).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
current_timestamp = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
||||
end_timestamp = current_timestamp + (number_of_periods - 1) * one_period
|
||||
|
@ -343,7 +343,7 @@ def test_refund(testerchain, escrow, policy_manager):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.mint(period + 8, 1).transact({'from': node1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setLastActivePeriod(period + 8).transact({'from': creator})
|
||||
tx = escrow.functions.setLastCommittedPeriod(period + 8).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 100 == policy_manager.functions.nodes(node1).call()[FEE_FIELD]
|
||||
|
||||
|
@ -435,7 +435,7 @@ def test_refund(testerchain, escrow, policy_manager):
|
|||
tx = escrow.functions.mint(period + 1, 3).transact({'from': node1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
period += 3
|
||||
tx = escrow.functions.setLastActivePeriod(period).transact({'from': creator})
|
||||
tx = escrow.functions.setLastCommittedPeriod(period).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 160 == policy_manager.functions.nodes(node1).call()[FEE_FIELD]
|
||||
|
||||
|
@ -497,7 +497,7 @@ def test_refund(testerchain, escrow, policy_manager):
|
|||
creator_balance = testerchain.client.get_balance(policy_creator)
|
||||
tx = escrow.functions.pushDowntimePeriod(0, period).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setLastActivePeriod(period + 1).transact({'from': creator})
|
||||
tx = escrow.functions.setLastCommittedPeriod(period + 1).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
refund_value = (number_of_periods_4 - 1) * rate
|
||||
assert refund_value == policy_manager.functions.calculateRefundValue(policy_id_4).call({'from': policy_creator})
|
||||
|
@ -596,7 +596,7 @@ def test_reentrancy(testerchain, escrow, policy_manager, deploy_contract):
|
|||
assert 0 == len(withdraw_log.get_all_entries())
|
||||
|
||||
# Prepare for refund and check reentrancy protection
|
||||
tx = escrow.functions.setLastActivePeriod(period).transact()
|
||||
tx = escrow.functions.setLastCommittedPeriod(period).transact()
|
||||
testerchain.wait_for_receipt(tx)
|
||||
transaction = policy_manager.functions.revokePolicy(policy_id).buildTransaction({'gas': 0})
|
||||
tx = reentrancy_contract.functions.setData(2, transaction['to'], 0, transaction['data']).transact()
|
||||
|
|
|
@ -44,7 +44,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
staking_log = escrow.events.Minted.createFilter(fromBlock='latest')
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
lock_log = escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
activity_log = escrow.events.ActivityConfirmed.createFilter(fromBlock='latest')
|
||||
commitments_log = escrow.events.CommitmentMade.createFilter(fromBlock='latest')
|
||||
divides_log = escrow.events.Divided.createFilter(fromBlock='latest')
|
||||
withdraw_log = escrow.events.Withdrawn.createFilter(fromBlock='latest')
|
||||
|
||||
|
@ -60,12 +60,12 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
tx = token.functions.transfer(ursula2, 850).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't confirm and mint because no locked tokens
|
||||
# Ursula can't make a commitment and mint because no locked tokens
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula and Ursula(2) give Escrow rights to transfer
|
||||
|
@ -86,7 +86,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setWindDown(True).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.deposit(ursula2_stake, 2).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -98,7 +98,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == escrow.functions.findIndexOfPastDowntime(ursula2, 0).call()
|
||||
assert 0 == escrow.functions.findIndexOfPastDowntime(ursula2, current_period + 1).call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 0 == escrow.functions.findIndexOfPastDowntime(ursula2, 0).call()
|
||||
assert 1 == escrow.functions.findIndexOfPastDowntime(ursula2, current_period + 1).call()
|
||||
|
@ -118,8 +118,8 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
downtime = escrow.functions.getPastDowntime(ursula2, 0).call()
|
||||
assert 1 == downtime[0]
|
||||
assert current_period == downtime[1]
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(ursula1).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(ursula2).call()
|
||||
|
||||
# Ursula divides her stake
|
||||
tx = escrow.functions.divideStake(0, 500, 1).transact({'from': ursula1})
|
||||
|
@ -133,9 +133,9 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
tx = escrow.functions.unMint(1).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Only Ursula confirms next period
|
||||
# Only Ursula makes a commitment to next period
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert 1 == escrow.functions.getPastDowntimeLength(ursula1).call()
|
||||
|
@ -143,14 +143,14 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
assert current_period + 1 == policy_manager.functions.getPeriod(ursula1, 2).call()
|
||||
|
||||
# Checks that no error from repeated method call
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 3 == policy_manager.functions.getPeriodsLength(ursula1).call()
|
||||
|
||||
# Ursula and Ursula(2) mint tokens for last periods
|
||||
# And only Ursula confirm activity for next period
|
||||
# And only Ursula make a commitment to next period
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert 5 == policy_manager.functions.getPeriodsLength(ursula1).call()
|
||||
|
@ -169,8 +169,8 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
# Check that downtime value has not changed
|
||||
assert 1 == escrow.functions.getPastDowntimeLength(ursula1).call()
|
||||
assert 1 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||
assert current_period - 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(ursula1).call()
|
||||
assert current_period - 1 == escrow.functions.getLastCommittedPeriod(ursula2).call()
|
||||
|
||||
events = staking_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
|
@ -191,7 +191,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
assert current_period == policy_manager.functions.getPeriod(ursula2, 2).call()
|
||||
|
||||
# Ursula tries to mint again and doesn't receive a reward
|
||||
# There are no more confirmed periods that are ready to mint
|
||||
# There are no more committed periods that are ready to mint
|
||||
ursula1_stake += ursula1_reward
|
||||
ursula2_stake += ursula2_reward
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
|
@ -200,19 +200,19 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
events = staking_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
|
||||
# Ursula can't confirm next period because stake is unlocked in current period
|
||||
# Ursula can't make a commitment to next period because stake is unlocked in current period
|
||||
testerchain.time_travel(hours=1)
|
||||
current_supply += ursula1_reward + ursula2_reward
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# But Ursula(2) can
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert current_period - 2 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
assert current_period - 2 == escrow.functions.getLastCommittedPeriod(ursula2).call()
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(ursula2).call()
|
||||
assert 2 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||
downtime = escrow.functions.getPastDowntime(ursula2, 1).call()
|
||||
assert current_period - 1 == downtime[0]
|
||||
|
@ -222,7 +222,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# But Ursula(2) can't get reward because she did not confirm activity
|
||||
# But Ursula(2) can't get reward because she did not make a commitment
|
||||
tx = escrow.functions.mint().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
ursula1_reward = calculate_reward(500, 1000, 0) + calculate_reward(500, 1000, 1) + calculate_reward(500, 500, 0)
|
||||
|
@ -264,26 +264,26 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
assert 5 == policy_manager.functions.getPeriodsLength(ursula2).call()
|
||||
assert current_period == policy_manager.functions.getPeriod(ursula2, 3).call()
|
||||
|
||||
# Ursula(2) can't more confirm activity because stake is unlocked
|
||||
# Ursula(2) can't make a commitment because stake is unlocked
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't confirm and get reward because no locked tokens
|
||||
# Ursula can't make a commitment and get reward because no locked tokens
|
||||
tx = escrow.functions.mint().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert current_period - 2 == escrow.functions.getLastActivePeriod(ursula1).call()
|
||||
assert current_period - 2 == escrow.functions.getLastCommittedPeriod(ursula1).call()
|
||||
assert ursula1_stake == escrow.functions.getAllTokens(ursula1).call()
|
||||
# Ursula still can't confirm activity
|
||||
# Ursula still can't make a commitment
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula(2) deposits and locks more tokens
|
||||
tx = escrow.functions.deposit(250, 4).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -298,12 +298,12 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.time_travel(hours=5)
|
||||
current_supply += ursula2_reward
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert current_period - 4 == escrow.functions.getLastActivePeriod(ursula2).call()
|
||||
assert current_period - 4 == escrow.functions.getLastCommittedPeriod(ursula2).call()
|
||||
tx = token.functions.approveAndCall(escrow.address, 100, testerchain.w3.toBytes(2))\
|
||||
.transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
ursula2_stake += 100
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
ursula2_reward = calculate_reward(250, 750, 4) + calculate_reward(500, 750, 4)
|
||||
|
@ -325,13 +325,13 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
assert ursula2_reward == event_args['value']
|
||||
assert current_period - 1 == event_args['period']
|
||||
|
||||
# Ursula(2) confirms activity for remaining periods
|
||||
# Ursula(2) makes a commitment to remaining periods
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 4 == escrow.functions.getPastDowntimeLength(ursula2).call()
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula(2) withdraws all
|
||||
|
@ -352,7 +352,7 @@ def test_minting(testerchain, token, escrow_contract, token_economics):
|
|||
assert 4 == len(deposit_log.get_all_entries())
|
||||
assert 6 == len(lock_log.get_all_entries())
|
||||
assert 1 == len(divides_log.get_all_entries())
|
||||
assert 10 == len(activity_log.get_all_entries())
|
||||
assert 10 == len(commitments_log.get_all_entries())
|
||||
|
||||
# Check searching downtime index
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -402,7 +402,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setWindDown(True).transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -439,14 +439,14 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
assert investigator == event_args['investigator']
|
||||
assert 10 == event_args['reward']
|
||||
|
||||
# New deposit and confirmation of activity
|
||||
# New deposit and making a commitment
|
||||
tx = escrow.functions.deposit(100, 5).transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
current_period += 1
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 100 == escrow.functions.getAllTokens(ursula).call()
|
||||
assert 100 == escrow.functions.getLockedTokens(ursula, 0).call()
|
||||
|
@ -512,7 +512,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
# New deposit of a shorter sub stake
|
||||
tx = escrow.functions.deposit(110, 2).transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
current_period += 2
|
||||
|
@ -585,8 +585,8 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
assert investigator == event_args['investigator']
|
||||
assert 0 == event_args['reward']
|
||||
|
||||
# Confirmation of activity must handle correctly inactive sub stakes after slashing
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
# Making a commitment must handle correctly inactive sub stakes after slashing
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# New deposit
|
||||
|
@ -619,7 +619,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
|
||||
# After two periods two shortest sub stakes will be unlocked, lock again and slash after this
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
|
@ -632,7 +632,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
assert 0 == escrow.functions.lockedPerPeriod(current_period + 1).call()
|
||||
tx = escrow.functions.lock(160, 2).transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 260 == escrow.functions.getLockedTokens(ursula, 0).call()
|
||||
assert 260 == escrow.functions.getLockedTokens(ursula, 1).call()
|
||||
|
@ -700,14 +700,14 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setWindDown(True).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.deposit(100, 2).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setReStake(False).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
assert 100 == escrow.functions.getLockedTokensInPast(ursula2, 2).call()
|
||||
|
@ -749,7 +749,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
assert 0 == event_args['reward']
|
||||
|
||||
# Prepare next case: new deposit is longer than previous sub stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.deposit(100, 3).transact({'from': ursula2})
|
||||
|
@ -781,7 +781,7 @@ def test_slashing(testerchain, token, escrow_contract, token_economics, deploy_c
|
|||
assert 0 == event_args['reward']
|
||||
|
||||
# Next test: optimization does not break saving old sub stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 50 == escrow.functions.getLockedTokensInPast(ursula2, 1).call()
|
||||
|
|
|
@ -37,7 +37,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
staker2 = testerchain.client.accounts[2]
|
||||
deposit_log = escrow.events.Deposited.createFilter(fromBlock='latest')
|
||||
lock_log = escrow.events.Locked.createFilter(fromBlock='latest')
|
||||
activity_log = escrow.events.ActivityConfirmed.createFilter(fromBlock='latest')
|
||||
commitments_log = escrow.events.CommitmentMade.createFilter(fromBlock='latest')
|
||||
divides_log = escrow.events.Divided.createFilter(fromBlock='latest')
|
||||
prolong_log = escrow.events.Prolonged.createFilter(fromBlock='latest')
|
||||
withdraw_log = escrow.events.Withdrawn.createFilter(fromBlock='latest')
|
||||
|
@ -118,9 +118,9 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert staker1 == event_args['staker']
|
||||
assert event_args['windDown']
|
||||
|
||||
# Can't confirm activity before initialization
|
||||
# Can't make a commitment before initialization
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Initialize Escrow contract
|
||||
|
@ -158,26 +158,26 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert staker2 == event_args['staker']
|
||||
assert event_args['windDown']
|
||||
|
||||
# Staker and Staker(2) confirm activity
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# Staker and Staker(2) make a commitment
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(staker1).call()
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(staker2).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(staker1).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(staker2).call()
|
||||
|
||||
# No active stakers before next period
|
||||
all_locked, stakers = escrow.functions.getActiveStakers(1, 0, 0).call()
|
||||
assert 0 == all_locked
|
||||
assert 0 == len(stakers)
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 2 == len(events)
|
||||
event_args = events[0]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
assert current_period + 1 == event_args['period']
|
||||
assert 1000 == event_args['value']
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
event_args = events[1]['args']
|
||||
assert staker2 == event_args['staker']
|
||||
assert current_period + 1 == event_args['period']
|
||||
|
@ -228,13 +228,13 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert 9000 == token.functions.balanceOf(staker1).call()
|
||||
|
||||
# Staker can deposit more tokens
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert current_period + 1 == escrow.functions.getLastActivePeriod(staker1).call()
|
||||
assert current_period + 1 == escrow.functions.getLastCommittedPeriod(staker1).call()
|
||||
assert 1000 == escrow.functions.getLockedTokens(staker1, 1).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(staker1, 2).call()
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 3 == len(events)
|
||||
event_args = events[2]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
|
@ -252,7 +252,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert 0 == escrow.functions.getLockedTokens(staker1, 3).call()
|
||||
assert locked_next_period + 500 == escrow.functions.lockedPerPeriod(current_period + 1).call()
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 4 == len(events)
|
||||
event_args = events[3]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
|
@ -285,15 +285,15 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert staker1 == to_checksum_address(stakers[0][0])
|
||||
assert 500 == stakers[0][1]
|
||||
|
||||
# Confirm activity and wait 1 period, locking will be decreased because of end of one stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# Make a commitment and wait 1 period, locking will be decreased because of end of one stake
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
assert 500 == escrow.functions.getLockedTokens(staker1, 0).call()
|
||||
assert 0 == escrow.functions.getLockedTokens(staker1, 1).call()
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 5 == len(events)
|
||||
event_args = events[4]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
|
@ -320,10 +320,10 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
tx = token.functions.approveAndCall(escrow.address, 500, testerchain.w3.toBytes(2))\
|
||||
.transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 6 == len(events)
|
||||
event_args = events[5]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
|
@ -333,7 +333,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
tx = escrow.functions.lock(100, 2).transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 7 == len(events)
|
||||
event_args = events[6]['args']
|
||||
assert staker1 == event_args['staker']
|
||||
|
@ -353,7 +353,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
# Staker increases lock
|
||||
tx = escrow.functions.lock(500, 2).transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 600 == escrow.functions.getLockedTokens(staker1, 0).call()
|
||||
assert 1100 == escrow.functions.getLockedTokens(staker1, 1).call()
|
||||
|
@ -366,7 +366,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
tx = token.functions.approveAndCall(escrow.address, 500, testerchain.w3.toBytes(2))\
|
||||
.transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert 500 == escrow.functions.getLockedTokens(staker2, 0).call()
|
||||
assert 1000 == escrow.functions.getLockedTokens(staker2, 1).call()
|
||||
|
@ -401,7 +401,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert 200 == event_args['newValue']
|
||||
assert 1 == event_args['periods']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
# Check number of stakes and last stake parameters
|
||||
|
@ -468,7 +468,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
assert 1 == event_args['periods']
|
||||
|
||||
# Prolong sub stake that will end in the next period
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.prolongStake(2, 1).transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -504,12 +504,12 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
tx = escrow.functions.prolongStake(1, 2).transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Just wait and confirm activity
|
||||
# Just wait and make a commitment
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can't divide old stake because it's already unlocked
|
||||
|
@ -526,7 +526,7 @@ def test_staking(testerchain, token, escrow_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
current_period = escrow.functions.getCurrentPeriod().call()
|
||||
events = activity_log.get_all_entries()
|
||||
events = commitments_log.get_all_entries()
|
||||
assert 13 == len(events)
|
||||
event_args = events[11]['args']
|
||||
assert staker2 == event_args['staker']
|
||||
|
@ -571,7 +571,7 @@ def test_max_sub_stakes(testerchain, token, escrow_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
assert 1 == escrow.functions.getSubStakesLength(staker).call()
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
for index in range(MAX_SUB_STAKES - 1):
|
||||
|
@ -586,10 +586,10 @@ def test_max_sub_stakes(testerchain, token, escrow_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# After two periods first sub stake will be unlocked and we can lock again
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert 2900 == escrow.functions.getLockedTokens(staker, 0).call()
|
||||
|
@ -693,7 +693,7 @@ def test_allowable_locked_tokens(testerchain, token_economics, token, escrow_con
|
|||
tx = escrow.functions.setWorker(staker1).transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
for _ in range(duration):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
testerchain.time_travel(hours=2)
|
||||
|
@ -747,7 +747,7 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert policy_manager.functions.getPeriodsLength(staker).call() == 1
|
||||
assert policy_manager.functions.getPeriod(staker, 0).call() == current_period - 1
|
||||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastActivePeriod(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
|
||||
deposit_events = deposit_log.get_all_entries()
|
||||
assert len(deposit_events) == 1
|
||||
|
@ -846,7 +846,7 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert policy_manager.functions.getPeriodsLength(staker).call() == 1
|
||||
assert policy_manager.functions.getPeriod(staker, 0).call() == current_period - 1
|
||||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastActivePeriod(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
|
||||
event_args = deposit_events[index + 1]['args']
|
||||
assert event_args['staker'] == staker
|
||||
|
@ -885,7 +885,7 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert policy_manager.functions.getPeriodsLength(staker).call() == 1
|
||||
assert policy_manager.functions.getPeriod(staker, 0).call() == current_period - 1
|
||||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastActivePeriod(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 1
|
||||
|
||||
event_args = deposit_events[6]['args']
|
||||
|
@ -914,7 +914,7 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert policy_manager.functions.getPeriodsLength(staker).call() == 1
|
||||
assert policy_manager.functions.getPeriod(staker, 0).call() == current_period - 1
|
||||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastActivePeriod(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 2
|
||||
|
||||
event_args = deposit_events[7]['args']
|
||||
|
@ -958,7 +958,7 @@ def test_batch_deposit(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert policy_manager.functions.getPeriodsLength(staker).call() == 1
|
||||
assert policy_manager.functions.getPeriod(staker, 0).call() == current_period - 1
|
||||
assert escrow.functions.getPastDowntimeLength(staker).call() == 0
|
||||
assert escrow.functions.getLastActivePeriod(staker).call() == 0
|
||||
assert escrow.functions.getLastCommittedPeriod(staker).call() == 0
|
||||
assert escrow.functions.getSubStakesLength(staker).call() == 3
|
||||
|
||||
event_args = deposit_events[9]['args']
|
||||
|
|
|
@ -113,10 +113,10 @@ def test_upgrading(testerchain, token, token_economics, deploy_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.setWorker(worker).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = contract.functions.confirmActivity().transact({'from': worker})
|
||||
tx = contract.functions.commitToNextPeriod().transact({'from': worker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
tx = contract.functions.confirmActivity().transact({'from': worker})
|
||||
tx = contract.functions.commitToNextPeriod().transact({'from': worker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Can set WorkLock twice, because isTestContract == True
|
||||
|
@ -345,7 +345,7 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
assert staker == event_args['staker']
|
||||
assert period + 1 == event_args['lockUntilPeriod']
|
||||
|
||||
# Ursula deposits some tokens and confirms activity
|
||||
# Ursula deposits some tokens and makes a commitment
|
||||
tx = token.functions.transfer(staker, 10000).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': staker})
|
||||
|
@ -355,7 +355,7 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setWorker(staker).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -364,8 +364,8 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
assert sub_stake == escrow.functions.lockedPerPeriod(period).call()
|
||||
assert 0 == escrow.functions.lockedPerPeriod(period + 1).call()
|
||||
|
||||
# Confirm activity and try to mint without re-stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
# Make a commitment and try to mint without re-stake
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -410,8 +410,8 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
assert staker == event_args['staker']
|
||||
assert period + 6 == event_args['lockUntilPeriod']
|
||||
|
||||
# Confirm activity and try to mint with re-stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
# Make a commitment and try to mint with re-stake
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
period = escrow.functions.getCurrentPeriod().call()
|
||||
|
@ -448,14 +448,14 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
assert 0 == escrow.functions.lockedPerPeriod(period).call()
|
||||
|
||||
# Prepares test case:
|
||||
# two Ursula with the stake value and duration, that have both confirmed two subsequent past periods
|
||||
# two Ursula with the stake value and duration, that have both committed to two subsequent past periods
|
||||
sub_stake_1 = new_sub_stake
|
||||
sub_stake_2 = sub_stake_1 // 2
|
||||
stake = sub_stake_1 + sub_stake_2
|
||||
sub_stake_duration = escrow.functions.getSubStakeInfo(staker, 0).call()[2]
|
||||
tx = escrow.functions.deposit(sub_stake_2, sub_stake_duration).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.transfer(ursula2, stake).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -467,12 +467,12 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.setReStake(False).transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
# Checks preparation
|
||||
|
@ -510,9 +510,9 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
assert sub_stake_1 + re_stake_for_first_sub_stake == escrow.functions.getSubStakeInfo(staker, 0).call()[3]
|
||||
assert sub_stake_2 + re_stake_for_second_sub_stake == escrow.functions.getSubStakeInfo(staker, 1).call()[3]
|
||||
|
||||
# Ursula2's reward for both confirmed periods will be equal because of equal stakes for this periods
|
||||
# Ursula2's reward for both committed periods will be equal because of equal stakes for this periods
|
||||
# Also this reward will be equal to Ursula1's reward for the first period
|
||||
# Because re-stake affects only the second confirmed period
|
||||
# Because re-stake affects only the second committed period
|
||||
reward_for_first_period = ursula2_reward // 2
|
||||
# Check re-stake for global `lockedPerPeriod` values
|
||||
assert 2 * stake == escrow.functions.lockedPerPeriod(period - 2).call()
|
||||
|
@ -524,8 +524,8 @@ def test_re_stake(testerchain, token, escrow_contract):
|
|||
tx = escrow.functions.setReStake(False).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Confirm activity and try to mint without re-stake
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
# Make a commitment and try to mint without re-stake
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
|
||||
|
@ -603,9 +603,9 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert NULL_ADDRESS == escrow.functions.getWorkerFromStaker(ursula3).call()
|
||||
assert NULL_ADDRESS == escrow.functions.stakerFromWorker(ursula3).call()
|
||||
|
||||
# Ursula can't confirm activity because there is no worker by default
|
||||
# Ursula can't make a commitment because there is no worker by default
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = intermediary1.functions.confirmActivity().transact({'from': ursula1})
|
||||
tx = intermediary1.functions.commitToNextPeriod().transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula can't use another staker as worker
|
||||
|
@ -613,12 +613,12 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
tx = intermediary1.functions.setWorker(ursula3).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula set worker and now worker can confirm activity
|
||||
# Ursula set worker and now worker can make a commitments
|
||||
tx = intermediary1.functions.setWorker(worker1).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert worker1 == escrow.functions.getWorkerFromStaker(intermediary1.address).call()
|
||||
assert intermediary1.address == escrow.functions.stakerFromWorker(worker1).call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': worker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': worker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
number_of_events = 1
|
||||
|
@ -629,7 +629,7 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert worker1 == event_args['worker']
|
||||
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
|
||||
|
||||
# Only worker can confirm activity
|
||||
# Only worker can make a commitment
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = intermediary1.functions.setWorker(ursula3).transact({'from': ursula1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
@ -687,12 +687,12 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert worker2 == event_args['worker']
|
||||
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
|
||||
|
||||
# Now the previous worker can no longer confirm
|
||||
# Now the previous worker can no longer make a commitment
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = escrow.functions.confirmActivity().transact({'from': worker1})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': worker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
# Only new worker can
|
||||
tx = escrow.functions.confirmActivity().transact({'from': worker2})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': worker2})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Another staker can use a free worker
|
||||
|
@ -760,8 +760,8 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert ursula3 == event_args['worker']
|
||||
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
|
||||
|
||||
# Now Ursula can confirm activity
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula3})
|
||||
# Now Ursula can make a commitment
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula set worker again
|
||||
|
@ -779,7 +779,7 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert worker3 == event_args['worker']
|
||||
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': worker3})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': worker3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Ursula try to set contract as worker
|
||||
|
@ -795,9 +795,9 @@ def test_worker(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert intermediary3.address == event_args['worker']
|
||||
assert escrow.functions.getCurrentPeriod().call() == event_args['startPeriod']
|
||||
|
||||
# But can't confirm activity using an intermediary contract
|
||||
# But can't make a commitment using an intermediary contract
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
tx = intermediary3.functions.confirmActivity().transact({'from': ursula3})
|
||||
tx = intermediary3.functions.commitToNextPeriod().transact({'from': ursula3})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
|
||||
|
@ -832,8 +832,8 @@ def test_measure_work(testerchain, token, escrow_contract, deploy_contract):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
assert escrow.functions.getCompletedWork(ursula).call() == 0
|
||||
|
||||
# Confirm activity and mint to check that work is not measured by default
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
# Make a commitment and mint to check that work is not measured by default
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
tx = escrow.functions.mint().transact({'from': ursula})
|
||||
|
@ -852,7 +852,7 @@ def test_measure_work(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert ursula == event_args['staker']
|
||||
assert event_args['measureWork']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
tx = escrow.functions.mint().transact({'from': ursula})
|
||||
|
@ -864,7 +864,7 @@ def test_measure_work(testerchain, token, escrow_contract, deploy_contract):
|
|||
# Mint again and check work done
|
||||
stake = escrow.functions.getAllTokens(ursula).call()
|
||||
work_done = escrow.functions.getCompletedWork(ursula).call()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
tx = escrow.functions.mint().transact({'from': ursula})
|
||||
|
@ -885,7 +885,7 @@ def test_measure_work(testerchain, token, escrow_contract, deploy_contract):
|
|||
assert ursula == event_args['staker']
|
||||
assert not event_args['measureWork']
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': ursula})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': ursula})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=2)
|
||||
tx = escrow.functions.mint().transact({'from': ursula})
|
||||
|
@ -917,7 +917,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
tx = escrow.functions.setWindDown(True).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Staker deposits some tokens and confirms activity
|
||||
# Staker deposits some tokens and makes a commitment
|
||||
sub_stake = token_economics.minimum_allowed_locked
|
||||
duration = 10
|
||||
|
||||
|
@ -947,13 +947,13 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
check_last_period()
|
||||
|
||||
# Wind down is false by default, after one period duration will be the same
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
|
@ -974,13 +974,13 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
assert wind_down
|
||||
check_events(wind_down=True, length=1)
|
||||
|
||||
# Enabling wind-down will affect duration only after next confirm activity
|
||||
# Enabling wind-down will affect duration only after next making a commitment
|
||||
check_last_period()
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
duration -= 1
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
|
@ -988,7 +988,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
duration -= 1
|
||||
check_last_period()
|
||||
|
||||
# Turn off wind-down and confirm activity, duration will be the same
|
||||
# Turn off wind-down and make a commitment, duration will be the same
|
||||
wind_down, _re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
assert wind_down
|
||||
tx = escrow.functions.setWindDown(False).transact({'from': staker})
|
||||
|
@ -999,14 +999,14 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
check_events(wind_down=False, length=2)
|
||||
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
testerchain.time_travel(hours=1)
|
||||
check_last_period()
|
||||
|
||||
# Turn on wind-down and confirm activity, duration will be reduced in the next period
|
||||
# Turn on wind-down and make a commitment, duration will be reduced in the next period
|
||||
tx = escrow.functions.setWindDown(True).transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
wind_down, _re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker).call()
|
||||
|
@ -1014,7 +1014,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
check_events(wind_down=True, length=3)
|
||||
|
||||
check_last_period()
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
|
@ -1023,7 +1023,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
check_last_period()
|
||||
|
||||
# Enabling/disabling winding down doesn't change staking duration in the current period
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
|
@ -1043,7 +1043,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
for i in range(duration - 1):
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
duration = 1
|
||||
|
@ -1067,7 +1067,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
|
||||
|
@ -1099,7 +1099,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.time_travel(hours=1)
|
||||
check_last_period()
|
||||
check_first_sub_stake(1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
check_first_sub_stake(1)
|
||||
|
@ -1125,7 +1125,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
check_last_period()
|
||||
check_first_sub_stake(0)
|
||||
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
check_last_period()
|
||||
check_first_sub_stake(0)
|
||||
|
@ -1150,7 +1150,7 @@ def test_wind_down(testerchain, token, escrow_contract, token_economics):
|
|||
testerchain.wait_for_receipt(tx)
|
||||
for i in range(duration):
|
||||
testerchain.time_travel(hours=1)
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker})
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
|
||||
# Switching winding down parameter doesn't affect sub-stake which will end in the current period
|
||||
|
@ -1310,7 +1310,7 @@ def test_snapshots(testerchain, token, escrow_contract):
|
|||
assert staker1 == event_args['staker']
|
||||
assert event_args['snapshotsEnabled']
|
||||
|
||||
# Staker disables restaking, deposits some tokens and confirms activity
|
||||
# Staker disables restaking, deposits some tokens and makes a commitment
|
||||
_wind_down, re_stake, _measure_work, _snapshots = escrow.functions.getFlags(staker1).call()
|
||||
assert re_stake
|
||||
tx = escrow.functions.setReStake(False).transact({'from': staker1})
|
||||
|
@ -1372,8 +1372,8 @@ def test_snapshots(testerchain, token, escrow_contract):
|
|||
assert 0 == escrow.functions.totalStakedForAt(staker1, now - 1).call()
|
||||
assert 0 == escrow.functions.totalStakedAt(now - 1).call()
|
||||
|
||||
# First confirm activity doesn't affect balance
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# First making a commitment doesn't affect balance
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
assert expected_staker1_balance == get_staker_history_from_storage(staker1)
|
||||
assert expected_global_balance == get_global_history_from_storage()
|
||||
|
@ -1387,8 +1387,8 @@ def test_snapshots(testerchain, token, escrow_contract):
|
|||
assert expected_staker1_balance == get_staker_history_from_storage(staker1)
|
||||
assert expected_global_balance == get_global_history_from_storage()
|
||||
|
||||
# 2nd confirm activity, still no change in balance
|
||||
tx = escrow.functions.confirmActivity().transact({'from': staker1})
|
||||
# 2nd making a commitment, still no change in balance
|
||||
tx = escrow.functions.commitToNextPeriod().transact({'from': staker1})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
testerchain.time_travel(hours=1)
|
||||
assert now < testerchain.get_block_number()
|
||||
|
@ -1427,7 +1427,7 @@ def test_snapshots(testerchain, token, escrow_contract):
|
|||
assert expected_staker2_balance == get_staker_history_from_storage(staker2)
|
||||
assert expected_global_balance == get_global_history_from_storage()
|
||||
|
||||
# Staker 2 deposits some tokens and confirms activity. Since snapshots are disabled, no changes in history
|
||||
# Staker 2 deposits some tokens and makes a commitment. Since snapshots are disabled, no changes in history
|
||||
tx = token.functions.transfer(staker2, 10000).transact({'from': creator})
|
||||
testerchain.wait_for_receipt(tx)
|
||||
tx = token.functions.approve(escrow.address, 10000).transact({'from': staker2})
|
||||
|
|
|
@ -144,14 +144,14 @@ def test_staker_collects_staking_reward(testerchain,
|
|||
ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
|
||||
stakers_addresses=[staker.checksum_address],
|
||||
workers_addresses=[worker_address],
|
||||
confirm_activity=False,
|
||||
commit_to_next_period=False,
|
||||
registry=test_registry).pop()
|
||||
|
||||
# ...wait out the lock period...
|
||||
for _ in range(token_economics.minimum_locked_periods):
|
||||
testerchain.time_travel(periods=1)
|
||||
ursula.transacting_power.activate(password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
|
||||
# ...wait more...
|
||||
testerchain.time_travel(periods=2)
|
||||
|
@ -174,7 +174,7 @@ def test_staker_manages_winding_down(testerchain,
|
|||
ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
|
||||
stakers_addresses=[staker.checksum_address],
|
||||
workers_addresses=[staker.worker_address],
|
||||
confirm_activity=False,
|
||||
commit_to_next_period=False,
|
||||
registry=test_registry).pop()
|
||||
|
||||
# Enable winding down
|
||||
|
@ -184,7 +184,7 @@ def test_staker_manages_winding_down(testerchain,
|
|||
assert receipt['status'] == 1
|
||||
assert staker.locked_tokens(base_duration) != 0
|
||||
assert staker.locked_tokens(base_duration + 1) == 0
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
assert staker.locked_tokens(base_duration) != 0
|
||||
assert staker.locked_tokens(base_duration + 1) == 0
|
||||
|
||||
|
@ -194,7 +194,7 @@ def test_staker_manages_winding_down(testerchain,
|
|||
assert receipt['status'] == 1
|
||||
assert staker.locked_tokens(base_duration - 1) != 0
|
||||
assert staker.locked_tokens(base_duration) == 0
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
assert staker.locked_tokens(base_duration - 1) != 0
|
||||
assert staker.locked_tokens(base_duration) == 0
|
||||
|
||||
|
|
|
@ -12,13 +12,13 @@ from nucypher.utilities.sandbox.ursula import make_decentralized_ursulas, start_
|
|||
|
||||
@pytest.mark.slow()
|
||||
@pytest_twisted.inlineCallbacks
|
||||
def test_worker_auto_confirmations(testerchain,
|
||||
test_registry,
|
||||
staker,
|
||||
agency,
|
||||
token_economics,
|
||||
mock_transacting_power_activation,
|
||||
ursula_decentralized_test_config):
|
||||
def test_worker_auto_commitments(testerchain,
|
||||
test_registry,
|
||||
staker,
|
||||
agency,
|
||||
token_economics,
|
||||
mock_transacting_power_activation,
|
||||
ursula_decentralized_test_config):
|
||||
|
||||
mock_transacting_power_activation(account=staker.checksum_address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
|
@ -39,7 +39,7 @@ def test_worker_auto_confirmations(testerchain,
|
|||
ursula = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
|
||||
stakers_addresses=[staker.checksum_address],
|
||||
workers_addresses=[worker_address],
|
||||
confirm_activity=False,
|
||||
commit_to_next_period=False,
|
||||
registry=test_registry).pop()
|
||||
|
||||
def start():
|
||||
|
@ -52,10 +52,10 @@ def test_worker_auto_confirmations(testerchain,
|
|||
clock.advance(WorkTracker.REFRESH_RATE+1)
|
||||
|
||||
def verify(_):
|
||||
# Verify that periods were confirmed on-chain automatically
|
||||
last_active_period = staker.staking_agent.get_last_active_period(staker_address=staker.checksum_address)
|
||||
# Verify that periods were committed on-chain automatically
|
||||
last_committed_period = staker.staking_agent.get_last_committed_period(staker_address=staker.checksum_address)
|
||||
current_period = staker.staking_agent.get_current_period()
|
||||
assert (last_active_period - current_period) == 1
|
||||
assert (last_committed_period - current_period) == 1
|
||||
|
||||
# Run the callbacks
|
||||
d = threads.deferToThread(start)
|
||||
|
|
|
@ -117,7 +117,7 @@ def test_calculate_refund(testerchain, agency, policy_meta, mock_transacting_pow
|
|||
mock_transacting_power_activation(account=worker, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
testerchain.time_travel(hours=9)
|
||||
_receipt = staking_agent.confirm_activity(worker_address=worker)
|
||||
_receipt = staking_agent.commit_to_next_period(worker_address=worker)
|
||||
|
||||
mock_transacting_power_activation(account=testerchain.alice_account, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
|
@ -165,7 +165,7 @@ def test_collect_policy_fee(testerchain, agency, policy_meta, token_economics, m
|
|||
old_eth_balance = token_agent.blockchain.client.get_balance(staker)
|
||||
|
||||
for _ in range(token_economics.minimum_locked_periods):
|
||||
_receipt = staking_agent.confirm_activity(worker_address=worker)
|
||||
_receipt = staking_agent.commit_to_next_period(worker_address=worker)
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
mock_transacting_power_activation(account=staker, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
|
|
@ -150,7 +150,7 @@ def test_deposit_and_withdraw_as_staker(testerchain, agent, agency, allocation_v
|
|||
mock_transacting_power_activation(account=worker, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
for _ in range(token_economics.minimum_locked_periods):
|
||||
staking_agent.confirm_activity(worker_address=worker)
|
||||
staking_agent.commit_to_next_period(worker_address=worker)
|
||||
testerchain.time_travel(periods=1)
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
|
@ -198,9 +198,9 @@ def test_collect_policy_reward(testerchain, agent, agency, token_economics, mock
|
|||
node_addresses=[agent.contract_address])
|
||||
|
||||
mock_transacting_power_activation(account=worker, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
_receipt = staking_agent.confirm_activity(worker_address=worker)
|
||||
_receipt = staking_agent.commit_to_next_period(worker_address=worker)
|
||||
testerchain.time_travel(periods=2)
|
||||
_receipt = staking_agent.confirm_activity(worker_address=worker)
|
||||
_receipt = staking_agent.commit_to_next_period(worker_address=worker)
|
||||
|
||||
old_balance = testerchain.client.get_balance(account=agent.beneficiary)
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ def test_sampling_distribution(testerchain, token, deploy_contract, token_econom
|
|||
|
||||
staking_agent.deposit_tokens(amount=balance, lock_periods=10, sender_address=staker, staker_address=staker)
|
||||
staking_agent.set_worker(staker_address=staker, worker_address=staker)
|
||||
staking_agent.confirm_activity(staker)
|
||||
staking_agent.commit_to_next_period(staker)
|
||||
|
||||
# Wait next period and check all locked tokens
|
||||
testerchain.time_travel(hours=1)
|
||||
|
|
|
@ -179,14 +179,14 @@ def test_get_current_period(agency, testerchain):
|
|||
|
||||
|
||||
@pytest.mark.slow()
|
||||
def test_confirm_activity(agency, testerchain, mock_transacting_power_activation):
|
||||
def test_commit_to_next_period(agency, testerchain, mock_transacting_power_activation):
|
||||
_token_agent, staking_agent, _policy_agent = agency
|
||||
|
||||
staker_account, worker_account, *other = testerchain.unassigned_accounts
|
||||
|
||||
mock_transacting_power_activation(account=worker_account, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
receipt = staking_agent.confirm_activity(worker_address=worker_account)
|
||||
receipt = staking_agent.commit_to_next_period(worker_address=worker_account)
|
||||
assert receipt['status'] == 1, "Transaction Rejected"
|
||||
assert receipt['logs'][0]['address'] == staking_agent.contract_address
|
||||
|
||||
|
@ -212,8 +212,8 @@ def test_divide_stake(agency, token_economics):
|
|||
sender_address=someone,
|
||||
staker_address=someone)
|
||||
|
||||
# Confirm Activity
|
||||
_txhash = agent.confirm_activity(node_address=someone)
|
||||
# Commit to next period
|
||||
_txhash = agent.commit_to_next_period(node_address=someone)
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
receipt = agent.divide_stake(staker_address=someone,
|
||||
|
@ -290,8 +290,8 @@ def test_collect_staking_reward(agency, testerchain, mock_transacting_power_acti
|
|||
|
||||
staker_account, worker_account, *other = testerchain.unassigned_accounts
|
||||
|
||||
# Confirm Activity
|
||||
_receipt = staking_agent.confirm_activity(worker_address=worker_account)
|
||||
# Commit to next period
|
||||
_receipt = staking_agent.commit_to_next_period(worker_address=worker_account)
|
||||
testerchain.time_travel(periods=2)
|
||||
|
||||
mock_transacting_power_activation(account=staker_account, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
@ -321,7 +321,7 @@ def test_winding_down(agency, testerchain, test_registry, token_economics):
|
|||
|
||||
assert not staking_agent.is_winding_down(staker_account)
|
||||
check_last_period()
|
||||
staking_agent.confirm_activity(worker_address=worker_account)
|
||||
staking_agent.commit_to_next_period(worker_address=worker_account)
|
||||
check_last_period()
|
||||
|
||||
# Examine the last periods of sub-stakes
|
||||
|
@ -332,7 +332,7 @@ def test_winding_down(agency, testerchain, test_registry, token_economics):
|
|||
assert receipt['status'] == 1
|
||||
assert staking_agent.is_winding_down(staker_account)
|
||||
check_last_period()
|
||||
staking_agent.confirm_activity(worker_address=worker_account)
|
||||
staking_agent.commit_to_next_period(worker_address=worker_account)
|
||||
check_last_period()
|
||||
|
||||
testerchain.time_travel(periods=1)
|
||||
|
@ -342,7 +342,7 @@ def test_winding_down(agency, testerchain, test_registry, token_economics):
|
|||
assert receipt['status'] == 1
|
||||
assert not staking_agent.is_winding_down(staker_account)
|
||||
check_last_period()
|
||||
staking_agent.confirm_activity(worker_address=worker_account)
|
||||
staking_agent.commit_to_next_period(worker_address=worker_account)
|
||||
check_last_period()
|
||||
|
||||
|
||||
|
|
|
@ -126,13 +126,13 @@ def test_stake_in_idle_network(testerchain, token_economics, test_registry):
|
|||
staker.transacting_power = TransactingPower(password=INSECURE_DEVELOPMENT_PASSWORD, account=staker.checksum_address)
|
||||
staker.transacting_power.activate()
|
||||
|
||||
# Since StakingEscrow hasn't been activated yet, deposit should work but confirmation must fail
|
||||
# Since StakingEscrow hasn't been activated yet, deposit should work but making a commitment must fail
|
||||
amount = token_economics.minimum_allowed_locked
|
||||
periods = token_economics.minimum_locked_periods
|
||||
staker.initialize_stake(amount=amount, lock_periods=periods)
|
||||
staker.set_worker(account)
|
||||
with pytest.raises((TransactionFailed, ValueError)):
|
||||
staker.staking_agent.confirm_activity(worker_address=account)
|
||||
staker.staking_agent.commit_to_next_period(worker_address=account)
|
||||
|
||||
|
||||
@pytest.mark.slow()
|
||||
|
|
|
@ -115,9 +115,9 @@ def test_collect_inflation_rewards(software_stakeholder, manual_worker, testerch
|
|||
|
||||
mock_transacting_power_activation(account=manual_worker, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
# Wait out stake lock periods, manually confirming activity once per period.
|
||||
# Wait out stake lock periods, manually make a commitment once per period.
|
||||
for period in range(stake.periods_remaining-1):
|
||||
worker.confirm_activity()
|
||||
worker.commit_to_next_period()
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
mock_transacting_power_activation(account=stake.staker_address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
|
|
@ -56,7 +56,7 @@ def test_stakers_bond_to_ursulas(testerchain, test_registry, stakers, ursula_dec
|
|||
ursulas = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
|
||||
stakers_addresses=testerchain.stakers_accounts,
|
||||
workers_addresses=testerchain.ursulas_accounts,
|
||||
confirm_activity=False)
|
||||
commit_to_next_period=False)
|
||||
|
||||
assert len(ursulas) == len(stakers)
|
||||
for ursula in ursulas:
|
||||
|
|
|
@ -114,9 +114,9 @@ def test_nucypher_status_fee_range(click_runner, agency_local_registry, stakers)
|
|||
def test_nucypher_status_locked_tokens(click_runner, testerchain, agency_local_registry, stakers):
|
||||
|
||||
staking_agent = ContractAgency.get_agent(StakingEscrowAgent, registry=agency_local_registry)
|
||||
# All workers confirm activity
|
||||
# All workers make a commitment
|
||||
for ursula in testerchain.ursulas_accounts:
|
||||
staking_agent.confirm_activity(worker_address=ursula)
|
||||
staking_agent.commit_to_next_period(worker_address=ursula)
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
periods = 2
|
||||
|
|
|
@ -241,7 +241,7 @@ def test_refund(click_runner, testerchain, agency_local_registry, token_economic
|
|||
|
||||
# Do some work
|
||||
for i in range(3):
|
||||
receipt = worker.confirm_activity()
|
||||
receipt = worker.commit_to_next_period()
|
||||
assert receipt['status'] == 1
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
|
|
|
@ -180,6 +180,6 @@ def test_ursula_and_local_keystore_signer_integration(click_runner,
|
|||
assert pre_config_signer.path == ursula.signer.path
|
||||
|
||||
# ...and that transactions are signed by the keytore signer
|
||||
receipt = ursula.confirm_activity()
|
||||
receipt = ursula.commit_to_next_period()
|
||||
transaction_data = testerchain.client.w3.eth.getTransaction(receipt['transactionHash'])
|
||||
assert transaction_data['from'] == worker_account.address
|
||||
|
|
|
@ -538,10 +538,10 @@ def test_collect_rewards_integration(click_runner,
|
|||
|
||||
mock_transacting_power_activation(account=worker_address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
# Confirm for half the first stake duration
|
||||
# Make a commitments for half the first stake duration
|
||||
for _ in range(half_stake_time):
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
testerchain.time_travel(periods=1)
|
||||
current_period += 1
|
||||
|
||||
|
@ -576,7 +576,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
|
||||
for index in range(half_stake_time - 5):
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
|
||||
# Encrypt
|
||||
random_data = os.urandom(random.randrange(20, 100))
|
||||
|
@ -594,9 +594,9 @@ def test_collect_rewards_integration(click_runner,
|
|||
current_period += 1
|
||||
|
||||
# Finish the passage of time
|
||||
for _ in range(5 - 1): # minus 1 because the first period was already confirmed in test_ursula_run
|
||||
for _ in range(5 - 1): # minus 1 because the first period was already committed in test_ursula_run
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
current_period += 1
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
|
@ -607,7 +607,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
balance = testerchain.client.get_balance(beneficiary)
|
||||
|
||||
# Rewards will be unlocked after the
|
||||
# final confirmed period has passed (+1).
|
||||
# final committed period has passed (+1).
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
testerchain.time_travel(periods=1)
|
||||
current_period += 1
|
||||
|
|
|
@ -438,10 +438,10 @@ def test_collect_rewards_integration(click_runner,
|
|||
|
||||
mock_transacting_power_activation(account=worker_address, password=INSECURE_DEVELOPMENT_PASSWORD)
|
||||
|
||||
# Confirm for half the first stake duration
|
||||
# Make a commitment for half the first stake duration
|
||||
for _ in range(half_stake_time):
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
testerchain.time_travel(periods=1)
|
||||
current_period += 1
|
||||
|
||||
|
@ -476,7 +476,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
|
||||
for index in range(half_stake_time - 5):
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
|
||||
# Encrypt
|
||||
random_data = os.urandom(random.randrange(20, 100))
|
||||
|
@ -496,7 +496,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
# Finish the passage of time for the first Stake
|
||||
for _ in range(5): # plus the extended periods from stake division
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
testerchain.time_travel(periods=1)
|
||||
current_period += 1
|
||||
|
||||
|
@ -511,7 +511,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
assert testerchain.client.get_balance(burner_wallet.address) == 0
|
||||
|
||||
# Rewards will be unlocked after the
|
||||
# final confirmed period has passed (+1).
|
||||
# final committed period has passed (+1).
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
testerchain.time_travel(periods=1)
|
||||
current_period += 1
|
||||
|
@ -544,7 +544,7 @@ def test_collect_rewards_integration(click_runner,
|
|||
# Finish the passage of time... once and for all
|
||||
# Extended periods from stake division
|
||||
for _ in range(9):
|
||||
ursula.confirm_activity()
|
||||
ursula.commit_to_next_period()
|
||||
current_period += 1
|
||||
logger.debug(f">>>>>>>>>>> TEST PERIOD {current_period} <<<<<<<<<<<<<<<<")
|
||||
testerchain.time_travel(periods=1)
|
||||
|
|
|
@ -26,7 +26,7 @@ from nucypher.utilities.sandbox.constants import INSECURE_DEVELOPMENT_PASSWORD
|
|||
# Crash on server error by default
|
||||
WebEmitter._crash_on_error_default = True
|
||||
|
||||
# Dont re-lock account in background during activity confirmations
|
||||
# Dont re-lock account in background during making a commitments
|
||||
LOCK_FUNCTION = TransactingPower.lock_account
|
||||
TransactingPower.lock_account = lambda *a, **k: True
|
||||
|
||||
|
|
|
@ -670,7 +670,7 @@ def blockchain_ursulas(testerchain, stakers, ursula_decentralized_test_config):
|
|||
_ursulas = make_decentralized_ursulas(ursula_config=ursula_decentralized_test_config,
|
||||
stakers_addresses=testerchain.stakers_accounts,
|
||||
workers_addresses=testerchain.ursulas_accounts,
|
||||
confirm_activity=True)
|
||||
commit_to_next_period=True)
|
||||
for u in _ursulas:
|
||||
u.synchronous_query_timeout = .01 # We expect to never have to wait for content that is actually on-chain during tests.
|
||||
testerchain.time_travel(periods=1)
|
||||
|
|
|
@ -104,10 +104,10 @@ def test_invalid_workers_tolerance(testerchain,
|
|||
worker_address=testerchain.unassigned_accounts[-1],
|
||||
ursula_config=ursula_decentralized_test_config,
|
||||
blockchain=testerchain,
|
||||
confirm_activity=True,
|
||||
commit_to_next_period=True,
|
||||
ursulas_to_learn_about=None)
|
||||
|
||||
# Since we confirmed activity, we need to advance one period
|
||||
# Since we made a commitment, we need to advance one period
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
# The worker is valid and can be verified (even with the force option)
|
||||
|
@ -119,9 +119,9 @@ def test_invalid_workers_tolerance(testerchain,
|
|||
# OK. Now we learn about this worker.
|
||||
lonely_blockchain_learner.remember_node(worker)
|
||||
|
||||
# The worker already confirmed one period before. Let's confirm the remaining 29.
|
||||
# The worker already committed one period before. Let's commit the remaining 29.
|
||||
for i in range(29):
|
||||
worker.confirm_activity()
|
||||
worker.commit_to_next_period()
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
# The stake period has ended, and the staker wants her tokens back ("when lambo?").
|
||||
|
|
|
@ -279,15 +279,15 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
transact(staker_functions.setReStake(False), {'from': ursula2})
|
||||
transact(staker_functions.setWindDown(True), {'from': ursula1})
|
||||
transact(staker_functions.setWindDown(True), {'from': ursula2})
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula2})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula2})
|
||||
|
||||
#
|
||||
# Wait 1 period and confirm activity
|
||||
# Wait 1 period and make a commitment
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
transact_and_log("Confirm activity, first", staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact_and_log("Confirm activity, other", staker_functions.confirmActivity(), {'from': ursula2})
|
||||
transact_and_log("Make a commitment, first", staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact_and_log("Make a commitment, other", staker_functions.commitToNextPeriod(), {'from': ursula2})
|
||||
|
||||
#
|
||||
# Wait 1 period and mint tokens
|
||||
|
@ -295,16 +295,16 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
testerchain.time_travel(periods=1)
|
||||
transact_and_log("Minting (1 stake), first", staker_functions.mint(), {'from': ursula1})
|
||||
transact_and_log("Minting (1 stake), other", staker_functions.mint(), {'from': ursula2})
|
||||
transact_and_log("Confirm activity again, first", staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact_and_log("Confirm activity again, other", staker_functions.confirmActivity(), {'from': ursula2})
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula3})
|
||||
transact_and_log("Make a commitment again, first", staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact_and_log("Make a commitment again, other", staker_functions.commitToNextPeriod(), {'from': ursula2})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula3})
|
||||
|
||||
#
|
||||
# Confirm again
|
||||
# Commit again
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
transact_and_log("Confirm activity + mint, first", staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact_and_log("Confirm activity + mint, other", staker_functions.confirmActivity(), {'from': ursula2})
|
||||
transact_and_log("Make a commitment + mint, first", staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact_and_log("Make a commitment + mint, other", staker_functions.commitToNextPeriod(), {'from': ursula2})
|
||||
|
||||
#
|
||||
# Create policy
|
||||
|
@ -317,10 +317,10 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
value = number_of_periods * rate
|
||||
current_timestamp = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
||||
end_timestamp = current_timestamp + (number_of_periods - 1) * one_period
|
||||
transact_and_log("Creating policy (1 node, 10 periods, pre-confirmed), first",
|
||||
transact_and_log("Creating policy (1 node, 10 periods, pre-committed), first",
|
||||
policy_functions.createPolicy(policy_id_1, alice1, end_timestamp, [ursula1]),
|
||||
{'from': alice1, 'value': value})
|
||||
transact_and_log("Creating policy (1 node, 10 periods, pre-confirmed), other",
|
||||
transact_and_log("Creating policy (1 node, 10 periods, pre-committed), other",
|
||||
policy_functions.createPolicy(policy_id_2, alice1, end_timestamp, [ursula1]),
|
||||
{'from': alice1, 'value': value})
|
||||
|
||||
|
@ -336,38 +336,38 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
transact_and_log("Withdraw", staker_functions.withdraw(1), {'from': ursula1})
|
||||
|
||||
#
|
||||
# Confirm activity with re-stake
|
||||
# Make a commitment with re-stake
|
||||
#
|
||||
transact(staker_functions.setReStake(True), {'from': ursula1})
|
||||
transact(staker_functions.setReStake(True), {'from': ursula2})
|
||||
|
||||
# Used to remove spending for first call in a day for mint and confirmActivity
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula3})
|
||||
# Used to remove spending for first call in a day for mint and commitToNextPeriod
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula3})
|
||||
|
||||
transact_and_log("Confirm activity + mint + re-stake",
|
||||
staker_functions.confirmActivity(),
|
||||
transact_and_log("Make a commitment + mint + re-stake",
|
||||
staker_functions.commitToNextPeriod(),
|
||||
{'from': ursula2})
|
||||
transact_and_log("Confirm activity + mint + re-stake + first fee + first fee rate",
|
||||
staker_functions.confirmActivity(),
|
||||
transact_and_log("Make a commitment + mint + re-stake + first fee + first fee rate",
|
||||
staker_functions.commitToNextPeriod(),
|
||||
{'from': ursula1})
|
||||
|
||||
transact(staker_functions.setReStake(False), {'from': ursula1})
|
||||
transact(staker_functions.setReStake(False), {'from': ursula2})
|
||||
|
||||
#
|
||||
# Wait 2 periods and confirm activity after downtime
|
||||
# Wait 2 periods and make a commitment after downtime
|
||||
#
|
||||
testerchain.time_travel(periods=2)
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula3})
|
||||
transact_and_log("Confirm activity after downtime", staker_functions.confirmActivity(), {'from': ursula2})
|
||||
transact_and_log("Confirm activity after downtime + updating fee",
|
||||
staker_functions.confirmActivity(),
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula3})
|
||||
transact_and_log("Make a commitment after downtime", staker_functions.commitToNextPeriod(), {'from': ursula2})
|
||||
transact_and_log("Make a commitment after downtime + updating fee",
|
||||
staker_functions.commitToNextPeriod(),
|
||||
{'from': ursula1})
|
||||
|
||||
#
|
||||
# Ursula and Alice deposit some tokens to the escrow again
|
||||
#
|
||||
transact_and_log("Deposit tokens after confirming activity",
|
||||
transact_and_log("Deposit tokens after making a commitment",
|
||||
staker_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS),
|
||||
{'from': ursula1})
|
||||
transact(staker_functions.deposit(MIN_ALLOWED_LOCKED * 2, MIN_LOCKED_PERIODS), {'from': ursula2})
|
||||
|
@ -383,7 +383,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
testerchain.time_travel(periods=1)
|
||||
|
||||
#
|
||||
# Create policy with multiple pre-confirmed nodes
|
||||
# Create policy with multiple pre-committed nodes
|
||||
#
|
||||
policy_id_1 = os.urandom(int(Policy.POLICY_ID_LENGTH))
|
||||
policy_id_2 = os.urandom(int(Policy.POLICY_ID_LENGTH))
|
||||
|
@ -392,14 +392,14 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
value = 3 * number_of_periods * rate
|
||||
current_timestamp = testerchain.w3.eth.getBlock(block_identifier='latest').timestamp
|
||||
end_timestamp = current_timestamp + (number_of_periods - 1) * one_period
|
||||
transact_and_log("Creating policy (3 nodes, 100 periods, pre-confirmed), first",
|
||||
transact_and_log("Creating policy (3 nodes, 100 periods, pre-committed), first",
|
||||
policy_functions.createPolicy(policy_id_1, alice1, end_timestamp, [ursula1, ursula2, ursula3]),
|
||||
{'from': alice1, 'value': value})
|
||||
transact_and_log("Creating policy (3 nodes, 100 periods, pre-confirmed), other",
|
||||
transact_and_log("Creating policy (3 nodes, 100 periods, pre-committed), other",
|
||||
policy_functions.createPolicy(policy_id_2, alice1, end_timestamp, [ursula1, ursula2, ursula3]),
|
||||
{'from': alice1, 'value': value})
|
||||
value = 2 * number_of_periods * rate
|
||||
transact_and_log("Creating policy (2 nodes, 100 periods, pre-confirmed), other",
|
||||
transact_and_log("Creating policy (2 nodes, 100 periods, pre-committed), other",
|
||||
policy_functions.createPolicy(policy_id_3, alice1, end_timestamp, [ursula1, ursula2]),
|
||||
{'from': alice1, 'value': value})
|
||||
|
||||
|
@ -412,7 +412,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
transact_and_log("Last minting + first fee + first fee rate", staker_functions.mint(), {'from': ursula2})
|
||||
|
||||
#
|
||||
# Create policy again without pre-confirmed nodes
|
||||
# Create policy again without pre-committed nodes
|
||||
#
|
||||
policy_id_1 = os.urandom(int(Policy.POLICY_ID_LENGTH))
|
||||
policy_id_2 = os.urandom(int(Policy.POLICY_ID_LENGTH))
|
||||
|
@ -438,8 +438,8 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
# Mint and revoke policy
|
||||
#
|
||||
testerchain.time_travel(periods=10)
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula3})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula3})
|
||||
|
||||
testerchain.time_travel(periods=2)
|
||||
transact(staker_functions.mint(), {'from': ursula3})
|
||||
|
@ -459,7 +459,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
{'from': alice2})
|
||||
|
||||
for index in range(5):
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
testerchain.time_travel(periods=1)
|
||||
transact(staker_functions.mint(), {'from': ursula1})
|
||||
|
||||
|
@ -486,7 +486,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
# Locking tokens
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
transact_and_log("Locking tokens", staker_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS), {'from': ursula1})
|
||||
|
||||
#
|
||||
|
@ -499,14 +499,14 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
# Divide almost finished stake
|
||||
#
|
||||
testerchain.time_travel(periods=1)
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
testerchain.time_travel(periods=1)
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
|
||||
#
|
||||
# Slashing tests
|
||||
#
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
#
|
||||
|
@ -544,7 +544,7 @@ def estimate_gas(analyzer: AnalyzeGas = None) -> None:
|
|||
{'from': alice1})
|
||||
|
||||
for index in range(18):
|
||||
transact(staker_functions.confirmActivity(), {'from': ursula1})
|
||||
transact(staker_functions.commitToNextPeriod(), {'from': ursula1})
|
||||
testerchain.time_travel(periods=1)
|
||||
|
||||
transact(staker_functions.lock(MIN_ALLOWED_LOCKED, MIN_LOCKED_PERIODS), {'from': ursula1})
|
||||
|
|
Loading…
Reference in New Issue