def __init__(self, url, port, delegates: list, signing_key): self.log = get_logger("Delegate-{}".format(port)) self.port = port self.url = url sub_url = 'tcp://127.0.0.1:{}'.format(Constants.Witness.PubPort) rep_url = 'tcp://*:{}'.format(port) self.log.info("Spinning up delegate /w sub_url={}, rep_url={}".format(sub_url, rep_url)) self.delegates = list(filter(lambda d: d['port'] is not port, delegates)) self.log.debug("delegate list (excluding self): {}".format(self.delegates)) self.signing_key = signing_key # consensus variables self.merkle = None self.signature = b'too soon bro' self.signatures = [] # NOTE -- might have to deepcopy below self.left_in_consensus = list(self.delegates) self.subscriber_pipe, self.subscriber_process = zmq_listener(zmq.SUB, CONNECT, sub_url) self.subscriber_process.start() self.consensus_replier_pipe, self.consensus_replier_process = zmq_two_ways(zmq.REP, BIND, rep_url) self.consensus_replier_process.start() callbacks = [(self.subscriber_pipe, self.handle_message), (self.consensus_replier_pipe, self.handle_message)] self.router = Router(callbacks) self.router.start() # Queue + Interpreter self.queue = TransactionQueueDriver(db=str(self.port)[-1:]) self.interpreter = VanillaInterpreter(port=str(self.port)) # Flush queue on boot self.log.debug("Delegate flushing queue on boot") self.queue.dequeue_all()
def test_dump(self): log = get_logger("Dumpatron6000") log.important3("DUMPATRON6000 REPORTING FOR DUTY") # Bootstrap master self.execute_python('masternode', run_mn, async=True, profiling=self.PROFILE_TYPE) # Bootstrap witnesses for i, nodename in enumerate(self.groups['witness']): self.execute_python(nodename, wrap_func(run_witness, i), async=True, profiling=self.PROFILE_TYPE) # Bootstrap delegates for i, nodename in enumerate(self.groups['delegate']): self.execute_python(nodename, wrap_func(run_delegate, i), async=True, profiling=self.PROFILE_TYPE) input("Press any key to begin the dump...") log.important3("Dumpatron6000 dumping transactions!") self.execute_python('mgmt', wrap_func(dump_it, volume=self.VOLUME), async=True, profiling=self.PROFILE_TYPE) input("Press any key to initiate teardown") log.important3("Dumpatron6000 initiating system teardown") God.teardown_all("http://{}".format(self.ports['masternode']['8080']))
def __init__(self): self.log = get_logger('Witness') self.log.debug("Creating witness...") self.sub_url = 'tcp://127.0.0.1:{}'.format(Constants.Witness.SubPort) self.pub_url = 'tcp://127.0.0.1:{}'.format( Constants.Witness.PubPort) #'ipc://witness' self.subscriber_pipe, self.subscriber_process = zmq_listener( socket_type=zmq.SUB, connection_type=CONNECT, url=self.sub_url) self.subscriber_process.start() self.publisher_pipe, self.publisher_process = zmq_sender( socket_type=zmq.PUB, connection_type=BIND, url=self.pub_url) self.publisher_process.start() callbacks = [(self.subscriber_pipe, self.handle_message)] self.router = Router(callbacks) self.router.start() self.log.info('Witness has appeared (this is main thread).') STATES = [WitnessBootState, WitnessLiveState] StateMachine.__init__(self, WitnessBootState, STATES)
def __init__(self, state_machine=None): super().__init__(state_machine) self.log = get_logger("Witness.LiveState")
from sanic import Sanic from sanic.response import json, text from cilantro.logger.base import get_logger from cilantro.messages.transaction.container import TransactionContainer from cilantro.constants.masternode import WEB_SERVER_PORT, NUM_WORKERS from cilantro.messages.signals.kill_signal import KillSignal import os # This must be imported for Metaclass registration from cilantro.messages.transaction.contract import ContractTransaction app = Sanic(__name__) log = get_logger(__name__) @app.route("/", methods=[ "POST", ]) async def contract_tx(request): tx_bytes = request.body container = TransactionContainer.from_bytes(tx_bytes) tx = container.open() app.queue.put(tx) log.spam("proc id {} just put a tx in queue! queue size = {}".format( os.getpid(), app.queue.qsize())) return text('ok put tx in queue...current queue size is {}'.format( app.queue.qsize())) @app.route("/teardown-network", methods=[ "POST",
def hello(): from cilantro.logger.base import get_logger import os log = get_logger('hello') log.critical('hello') log.critical(os.getenv('HOST_NAME'))
def world(): from cilantro.logger.base import get_logger log = get_logger('world') log.important('world')
from cilantro.utils.test.god import God from cilantro.storage.contracts import run_contract from cilantro.logger.base import get_logger, overwrite_logger_level from cilantro.storage.db import DB from cilantro.storage.tables import DB_NAME from cilantro.storage.templating import ContractTemplate from cilantro.protocol.interpreter import SenecaInterpreter from seneca.seneca_internal.storage.mysql_spits_executer import Executer import time checkpoint_freq = 64 log = get_logger("SenecaTester") RECEIVER_VK = '324ee2e3544a8853a3c5a0ef0946b929aa488cbe7e7ee31a0fef9585ce398502' SENDER_VK = 'a103715914a7aae8dd8fddba945ab63a169dfe6e37f79b4a58bcf85bfd681694' AMOUNT = 1 CODE_STR = \ """ import currency currency.transfer_coins('324ee2e3544a8853a3c5a0ef0946b929aa488cbe7e7ee31a0fef9585ce398502', 1) """ # def generate_contract_codes(num_contracts) -> list: # return [ContractTemplate.interpolate_template('currency', amount=AMOUNT, receiver=RECEIVER_VK) for _ in range(num_contracts)] # return [CODE_STR for _ in range(num_contracts)] def run_contracts_in_interpreter(num_contracts=100): interpreter = SenecaInterpreter()