def enqueue_msg(self, msg: AbstractMessage, prepend: bool = False):
        """
        Enqueues the contents of a Message instance, msg, to our outputbuf and attempts to send it if the underlying
        socket has room in the send buffer.

        :param msg: message
        :param prepend: if the message should be bumped to the front of the outputbuf
        """
        self._log_message(msg.log_level(), "Enqueued message: {}", msg)
        self.enqueue_msg_bytes(msg.rawbytes(), prepend)
Exemple #2
0
    def broadcast_transactions_to_node(
            self, msg: AbstractMessage,
            broadcasting_conn: Optional[AbstractConnection]) -> bool:
        msg = cast(TransactionsEthProtocolMessage, msg)
        if self.opts.filter_txs_factor > 0:
            assert len(msg.get_transactions()) == 1
            transaction = msg.get_transactions()[0]

            if (float(transaction.gas_price) < self.average_gas_price.average *
                    self.opts.filter_txs_factor):
                logger.trace(
                    "Skipping sending transaction {} with gas price: {}. Average was {}",
                    transaction.hash(), float(transaction.gas_price),
                    self.average_gas_price.average)
                return False

        return super().broadcast_transactions_to_node(msg, broadcasting_conn)
    def compare_current_to_old(
        self,
        converted_old_message: AbstractMessage,
        original_old_message: AbstractMessage,
    ):
        """
        This method is run on every message comparison, when comparing
        the current version converted to the older version.

        Override this if a change is made that affects every message.
        """
        self.assertEqual(
            constants.STARTING_SEQUENCE_BYTES,
            converted_old_message.rawbytes()
            [:constants.STARTING_SEQUENCE_BYTES_LEN],
        )
        self.assertEqual(
            # pyre-fixme[16]: `AbstractMessage` has no attribute `msg_type`.
            original_old_message.msg_type(),
            converted_old_message.msg_type(),
        )
        self.assertEqual(
            # pyre-fixme[16]: `AbstractMessage` has no attribute `payload_len`.
            original_old_message.payload_len(),
            converted_old_message.payload_len(),
        )
        self.assertEqual(
            # pyre-fixme[16]: `AbstractMessage` has no attribute `get_control_flags`.
            original_old_message.get_control_flags(),
            converted_old_message.get_control_flags(),
        )
Exemple #4
0
    def broadcast_transactions_to_nodes(
            self, msg: AbstractMessage,
            broadcasting_conn: Optional[AbstractConnection]) -> bool:
        msg = cast(TransactionsEthProtocolMessage, msg)

        if self.opts.filter_txs_factor > 0:
            average_block_gas_filter = self.average_block_gas_price.average * self.opts.filter_txs_factor
        else:
            average_block_gas_filter = 0
        min_gas_price_from_node = self.min_tx_from_node_gas_price.current_minimum

        gas_price_filter = max(average_block_gas_filter,
                               min_gas_price_from_node)

        if gas_price_filter > 0:
            assert len(msg.get_transactions()) == 1
            transaction = msg.get_transactions()[0]

            gas_price = float(transaction.gas_price)

            if gas_price < gas_price_filter:
                logger.trace(
                    "Skipping sending transaction {} with gas price: {}. Average was {}. Minimum from node was {}.",
                    transaction.hash(), float(transaction.gas_price),
                    average_block_gas_filter, min_gas_price_from_node)
                tx_stats.add_tx_by_hash_event(
                    transaction.hash(),
                    TransactionStatEventType.TX_FROM_BDN_IGNORE_LOW_GAS_PRICE,
                    self.network_num,
                    peers=[broadcasting_conn],
                    more_info=
                    "Tx gas price {}. Average block gas price: {}. Node min gas price {}."
                    .format(gas_price, average_block_gas_filter,
                            min_gas_price_from_node))
                return False

        return super().broadcast_transactions_to_nodes(msg, broadcasting_conn)
    def enqueue_msg(self, msg: AbstractMessage, prepend: bool = False):
        if not self.is_alive():
            return

        self.outputbuf.enqueue_msgbytes(msg.rawbytes())
        self.enqueued_messages.append(msg)
 def gateway_2_receive_message_from_gateway(self, message: AbstractMessage):
     helpers.receive_node_message(self.gateway_2, self.gateway_fileno_2,
                                  message.rawbytes())
 def gateway_1_receive_message_from_blockchain(self,
                                               message: AbstractMessage):
     helpers.receive_node_message(self.gateway_1, self.blockchain_fileno_1,
                                  message.rawbytes())
Exemple #8
0
 def build_block_header_message(
         self, block_hash: Sha256Hash,
         _block_message: AbstractBlockMessage) -> AbstractMessage:
     return AbstractMessage()