Allow worker to attempt period commitment as part of it's initialization.

pull/2137/head
Kieran R. Prasch 2020-07-15 10:11:20 -07:00 committed by jMyles
parent c68af1de9c
commit 85806613f1
6 changed files with 27 additions and 10 deletions

View File

@ -1299,7 +1299,7 @@ class Worker(NucypherTokenActor):
self.stakes = StakeList(registry=self.registry, checksum_address=self.checksum_address)
self.stakes.refresh()
self.work_tracker = work_tracker or WorkTracker(worker=self)
self.work_tracker.start(act_now=False)
self.work_tracker.start(act_now=start_working_now)
def block_until_ready(self, poll_rate: int = None, timeout: int = None):
"""

View File

@ -533,7 +533,7 @@ class WorkTracker:
self._tracking_task.stop()
self.log.info(f"STOPPED WORK TRACKING")
def start(self, act_now: bool = False, requirement_func: Callable = None, force: bool = False) -> None:
def start(self, act_now: bool = True, requirement_func: Callable = None, force: bool = False) -> None:
"""
High-level stake tracking initialization, this function aims
to be safely called at any time - For example, it is okay to call

View File

@ -1047,9 +1047,11 @@ class Ursula(Teacher, Character, Worker):
# Prepare a TransactingPower from worker node's transacting keys
_transacting_power = TransactingPower(account=worker_address,
password=client_password,
signer=self.signer,
cache=True)
password=client_password,
signer=self.signer,
cache=True)
self.transacting_power = _transacting_power
self._crypto_power.consume_power_up(_transacting_power)
self._set_checksum_address(checksum_address)

View File

@ -61,20 +61,18 @@ def test_worker_auto_commitments(mocker,
commit_to_next_period=False,
registry=test_registry).pop()
commit_spy.assert_not_called()
initial_period = staker.staking_agent.get_current_period()
def start():
# Start running the worker
start_pytest_ursula_services(ursula=ursula)
ursula.work_tracker.start(act_now=True)
def time_travel(_):
testerchain.time_travel(periods=1)
clock.advance(WorkTracker.REFRESH_RATE+1)
return clock
def verify(_):
def verify(clock):
# 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()

View File

@ -1,3 +1,20 @@
"""
This file is part of nucypher.
nucypher is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
nucypher is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with nucypher. If not, see <https://www.gnu.org/licenses/>.
"""
import datetime
import json
import os

View File

@ -205,4 +205,4 @@ def test_mass_treasure_map_placement(fleet_of_highperf_mocked_ursulas,
# Takes about .8 on jMyles' laptop; still the bulk of init time.
# Assuming this is 10 percent of the fleet, that's another 8 second savings for first policy enactment.
assert maturation_time.total_seconds() < 2
assert maturation_time.total_seconds() < 2