def handle_multi_sig_create(source, message: xrdlegacy_pb2.LegacyMessage): """ Handles Multi Sig Transaction :param source: :param message: :return: """ P2PBaseObserver._validate_message(message, xrdlegacy_pb2.LegacyMessage.MC) try: tx = Transaction.from_pbdata(message.mcData) except Exception as e: logger.error( 'multi_sig_create txn rejected - unable to decode serialised data - closing connection' ) logger.exception(e) source.loseConnection() return if source.factory.master_mr.isRequested(tx.get_message_hash(), source): source.factory.add_unprocessed_txn(tx, source.peer.ip)
def handle_lattice(source, message: xrdlegacy_pb2.LegacyMessage): """ Receives Lattice Public Key Transaction :param source: :param message: :return: """ P2PBaseObserver._validate_message(message, xrdlegacy_pb2.LegacyMessage.LT) try: tx = Transaction.from_pbdata(message.ltData) except Exception as e: logger.error( 'lattice_public_key rejected - unable to decode serialised data - closing connection' ) logger.exception(e) source.loseConnection() return if source.factory.master_mr.isRequested(tx.get_message_hash(), source): source.factory.add_unprocessed_txn(tx, source.peer.ip)
def handle_token_transaction(source, message: xrdlegacy_pb2.LegacyMessage): """ Token Transaction This function processes whenever a Transaction having subtype TOKEN is received. :return: """ P2PBaseObserver._validate_message(message, xrdlegacy_pb2.LegacyMessage.TK) try: tx = Transaction.from_pbdata(message.tkData) except Exception as e: logger.error( 'Token Txn rejected - unable to decode serialised data - closing connection' ) logger.exception(e) source.loseConnection() return if source.factory.master_mr.isRequested(tx.get_message_hash(), source): source.factory.add_unprocessed_txn(tx, source.peer.ip)
def handle_tx(source, message: xrdlegacy_pb2.LegacyMessage): """ Transaction Executed whenever a new TX type message is received. :return: """ P2PBaseObserver._validate_message(message, xrdlegacy_pb2.LegacyMessage.TX) try: tx = Transaction.from_pbdata(message.txData) except Exception as e: logger.error( 'Message Txn rejected - unable to decode serialised data - closing connection' ) logger.exception(e) source.loseConnection() return # NOTE: Connects to MR if source.factory.master_mr.isRequested(tx.get_message_hash(), source): source.factory.add_unprocessed_txn(tx, source.peer.ip)
def prepare_next_unmined_block_template(self, mining_address, tx_pool, parent_block: Block, parent_difficulty, dev_config: DevConfig): miner = self.get_miner(parent_block.block_number + 1, dev_config) try: logger.debug('Miner-Try - prepare_next_unmined_block_template') with self.lock: logger.debug( 'Miner-Locked - prepare_next_unmined_block_template') logger.debug( 'Miner-TryCancel - prepare_next_unmined_block_template') miner.cancel() logger.debug( 'Miner-Cancel - prepare_next_unmined_block_template') self._mining_block = self.create_block( last_block=parent_block, mining_nonce=0, tx_pool=tx_pool, miner_address=mining_address) parent_metadata = self._chain_manager.get_block_metadata( parent_block.headerhash) self._measurement = self._chain_manager.get_measurement( dev_config, self._mining_block.timestamp, self._mining_block.prev_headerhash, parent_metadata) self._current_difficulty, self._current_target = DifficultyTracker.get( measurement=self._measurement, parent_difficulty=parent_difficulty, dev_config=dev_config) except Exception as e: logger.warning("Exception in start_mining") logger.exception(e)
def handle_push_block(self, source, message: xrdlegacy_pb2.LegacyMessage): """ Push Block This function processes requested blocks received while syncing. Block received under this function are directly added to the main chain i.e. chain.blockchain It is expected to receive only one block for a given blocknumber. :return: """ # FIXME: Later rename P2PBaseObserver._validate_message(message, xrdlegacy_pb2.LegacyMessage.PB) if message.pbData is None: return try: block = Block(message.pbData.block) source.factory.block_received(source, block) except Exception as e: logger.error( 'block rejected - unable to decode serialised data %s', source.peer) logger.exception(e)