This repository has been archived by the owner on Jun 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Operator Cron jobs: SubmitBlock, ApplyDesposit
Operator needs to have some cron jobs. This commit adds two cron jobs that should be run by operator. First one is a job that submits a block every certain time. Second one is to move "apply deposit" job, which listens to root chain deposit event, from ChildChain to operator cron job. Reason for that is that we want ChildChain server to be scalable. Current design would lead to single node restriction. This commit does NOT include integration tests code change.
- Loading branch information
Showing
31 changed files
with
394 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[settings] | ||
line_length = 100 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
integration_tests/features/steps/challenge_double_spending_flow.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import rlp | ||
import time | ||
|
||
import rlp | ||
from behave import given, then, when | ||
from ethereum import utils | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,2 @@ | ||
class RequestFailedException(Exception): | ||
"""request failed without success http status""" | ||
|
||
|
||
class TxHistoryNotFoundException(Exception): | ||
"""tx history is not found for specific block number""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from plasma_cash.config import plasma_config | ||
from plasma_cash.dependency_config import container | ||
|
||
from .job_handler import JobHandler | ||
from .jobs.apply_deposit_job import ApplyDepositJob | ||
from .jobs.submit_block_job import SubmitBlockJob | ||
|
||
SUBMIT_BLOCK_INTERVAL = 5 | ||
APPLY_DEPOSIT_INTERVAL = 1 | ||
|
||
|
||
def setup_job_handler(job_handler): | ||
root_chain = container.get_root_chain() | ||
child_chain_client = container.get_child_chain_client() | ||
|
||
apply_deposit_job = ApplyDepositJob(root_chain, child_chain_client) | ||
submit_block_job = SubmitBlockJob(child_chain_client, plasma_config['AUTHORITY_KEY']) | ||
|
||
job_handler.add_job(submit_block_job, time_interval=SUBMIT_BLOCK_INTERVAL) | ||
job_handler.add_job(apply_deposit_job, time_interval=APPLY_DEPOSIT_INTERVAL) | ||
|
||
return job_handler | ||
|
||
|
||
if __name__ == '__main__': | ||
job_handler = JobHandler() | ||
job_handler = setup_job_handler(job_handler) | ||
job_handler.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import time | ||
from threading import Thread | ||
|
||
|
||
class JobHandler(object): | ||
def __init__(self): | ||
self.workers = [] | ||
|
||
def add_job(self, job, time_interval): | ||
worker = Thread(target=self._schedule_the_job, args=(job, time_interval,), daemon=True) | ||
self.workers.append(worker) | ||
|
||
def start(self): | ||
for worker in self.workers: | ||
worker.start() | ||
|
||
def _schedule_the_job(self, job, time_interval): | ||
while True: | ||
job.run() | ||
time.sleep(time_interval) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from .job_interface import JobInterface | ||
|
||
|
||
class ApplyDepositJob(JobInterface): | ||
|
||
def __init__(self, root_chain, child_chain): | ||
self.child_chain = child_chain | ||
self.deposit_filter = root_chain.eventFilter('Deposit', {'fromBlock': 0}) | ||
|
||
def run(self): | ||
for event in self.deposit_filter.get_new_entries(): | ||
depositor = event['args']['depositor'] | ||
amount = event['args']['amount'] | ||
uid = event['args']['uid'] | ||
self.child_chain.apply_deposit(depositor, amount, uid) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import abc | ||
|
||
|
||
class JobInterface(abc.ABC): | ||
|
||
@abc.abstractmethod | ||
def run(self): | ||
return NotImplemented |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import rlp | ||
from ethereum import utils | ||
|
||
from plasma_cash.child_chain.block import Block | ||
from plasma_cash.utils.utils import sign | ||
|
||
from .job_interface import JobInterface | ||
|
||
|
||
class SubmitBlockJob(JobInterface): | ||
|
||
def __init__(self, child_chain, key): | ||
self.child_chain = child_chain | ||
self.key = utils.normalize_key(key) | ||
|
||
def run(self): | ||
block = self._get_current_block() | ||
sig = sign(block.hash, self.key) | ||
self.child_chain.submit_block(sig.hex()) | ||
|
||
def _get_current_block(self): | ||
block = self.child_chain.get_current_block() | ||
return rlp.decode(utils.decode_hex(block), Block) |
Oops, something went wrong.