Skip to content

Commit

Permalink
Release v1.83.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shanevc committed Mar 15, 2021
1 parent 4cf5d89 commit 6f59c97
Show file tree
Hide file tree
Showing 25 changed files with 188 additions and 99 deletions.
6 changes: 4 additions & 2 deletions requirements-cli.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
aiohttp==3.6.2
aiohttp==3.7.3
websockets==8.1
pyhumps==1.6.1
web3==5.10.0
web3>=5.11.1, <=5.13.1
orjson==3.4.6
dataclasses==0.6
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ requests==2.22.0
ipaddress==1.0.22
cffi==1.12.2
csiphash==0.0.5
aiohttp==3.6.2
web3==5.10.0
aiohttp==3.7.3
web3>=5.11.1, <=5.13.1

# TODO: plan future work to remove this package
bloxroute-pyelliptic==1.5.10
8 changes: 4 additions & 4 deletions src/bloxroute_cli/compare_tx_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def main() -> None:
if alchemy_api_key:
alchemy_endpoint = "https://eth-mainnet.alchemyapi.io/v2/" + alchemy_api_key
eth_tx_receipt_endpoint = alchemy_endpoint
default_web3 = Web3(Web3.HTTPProvider(alchemy_endpoint)) # pyre-ignore
default_web3 = Web3(Web3.HTTPProvider(alchemy_endpoint))
if not default_web3.isConnected():
print(f"Alchemy endpoint {alchemy_endpoint} is not connected. Please check your API key and try again.")
sys.exit(0)
infura_api_key = args.infura_api_key
if infura_api_key:
infura_endpoint = "https://mainnet.infura.io/v3/" + infura_api_key
eth_tx_receipt_endpoint = infura_endpoint
default_web3 = Web3(Web3.HTTPProvider(infura_endpoint)) # pyre-ignore
default_web3 = Web3(Web3.HTTPProvider(infura_endpoint))
if not default_web3.isConnected():
print(f"Infura endpoint {infura_endpoint} is not connected. Please check your API key and try again.")
sys.exit(0)
Expand Down Expand Up @@ -75,8 +75,8 @@ def main() -> None:
sender_account = Account.from_key(sender_private_key) # pyre-ignore
sender_address = sender_account.address

nonce = default_web3.eth.getTransactionCount(sender_address)
sender_balance = default_web3.eth.getBalance(sender_address)
nonce = default_web3.eth.getTransactionCount(sender_address) # pyre-ignore
sender_balance = default_web3.eth.getBalance(sender_address) # pyre-ignore
sender_balance_in_eth = default_web3.fromWei(sender_balance, "ether") # pyre-ignore

sender_expense = num_tx_groups * gas_price_wei * gas_limit
Expand Down
2 changes: 1 addition & 1 deletion src/bxgateway/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"source_version": "v1.81.12.0"}
{"source_version": "v1.83.1.0"}
8 changes: 6 additions & 2 deletions src/bxgateway/abstract_message_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def tx_to_bx_txs(
tx_msg,
network_num: int,
transaction_flag: Optional[TransactionFlag] = None,
min_tx_network_fee: int = 0
min_tx_network_fee: int = 0,
account_id: str = constants.DECODED_EMPTY_ACCOUNT_ID
) -> List[Tuple[TxMessage, Sha256Hash, Union[bytearray, memoryview]]]:
"""
Converts blockchain transactions message to internal transaction message
Expand All @@ -64,6 +65,7 @@ def tx_to_bx_txs(
:param transaction_flag: the transaction_flag type to assign to the BDN transaction.
:param min_tx_network_fee: minimum transaction fee. If support by the network, transactions
with fees lower than this will be excluded from the result
:param account_id: gateway's account id
:return: array of tuples (transaction message, transaction hash, transaction bytes)
"""

Expand Down Expand Up @@ -113,13 +115,15 @@ def bdn_tx_to_bx_tx(
self,
raw_tx: Union[bytes, bytearray, memoryview],
network_num: int,
transaction_flag: Optional[TransactionFlag] = None
transaction_flag: Optional[TransactionFlag] = None,
account_id: str = constants.DECODED_EMPTY_ACCOUNT_ID
) -> TxMessage:
"""
Convert a raw transaction which arrived from an RPC request into bx transaction.
:param raw_tx: The raw transaction bytes.
:param network_num: the network number.
:param transaction_flag: the quota type to assign to the BDN transaction.
:param account_id: node's account id
:return: bx transaction.
"""
pass
Expand Down
98 changes: 57 additions & 41 deletions src/bxgateway/connections/abstract_gateway_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,23 @@ def __init__(

if opts.account_model:
self.account_model = opts.account_model
node_cache.update_cache_file(
opts,
# pyre-fixme[16]: `Optional` has no attribute `account_id`
accounts={opts.account_model.account_id: self.account_model},
)
else:
self.account_model = None
node_cache_info = node_cache.read(opts)
if (
node_cache_info
and node_cache_info.accounts
and node_cache_info.node_model
and node_cache_info.node_model.account_id is not None
):
# pyre-fixme[6]: Expected `str` for 1st param but got `Optional[str]`
self.account_model = node_cache_info.accounts[node_cache_info.node_model.account_id]
else:
self.account_model = None

self.quota_level = 0
self.num_active_blockchain_peers = 0
Expand Down Expand Up @@ -1050,49 +1065,50 @@ def sync_tx_services(self) -> int:
super(AbstractGatewayNode, self).sync_tx_services()
if self.opts.sync_tx_service:
retry = True
if self.opts.split_relays:
relay_tx_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_TRANSACTION,))), None
)
relay_block_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_BLOCK,))), None
)

if (
relay_tx_connection and relay_block_connection and
relay_tx_connection.is_active() and relay_block_connection.is_active()
):
if self.transaction_sync_timeout_alarm_id:
alarm_id = self.transaction_sync_timeout_alarm_id
assert alarm_id is not None
self.alarm_queue.unregister_alarm(alarm_id)
self.transaction_sync_timeout_alarm_id = None
self.transaction_sync_timeout_alarm_id = self.alarm_queue.register_alarm(
constants.TX_SERVICE_CHECK_NETWORKS_SYNCED_S, self._transaction_sync_timeout
if self.has_active_blockchain_peer():
if self.opts.split_relays:
relay_tx_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_TRANSACTION,))), None
)
relay_block_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_BLOCK,))), None
)

# the sync with relay_tx must be the last one. since each call erase the previous call alarm
relay_block_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
relay_tx_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
self._clear_transaction_service()
retry = False
else:
relay_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_ALL,))), None
)
if relay_connection and relay_connection.is_active():
if self.transaction_sync_timeout_alarm_id:
alarm_id = self.transaction_sync_timeout_alarm_id
assert alarm_id is not None
self.alarm_queue.unregister_alarm(alarm_id)
self.transaction_sync_timeout_alarm_id = None

self.transaction_sync_timeout_alarm_id = self.alarm_queue.register_alarm(
constants.TX_SERVICE_CHECK_NETWORKS_SYNCED_S, self._transaction_sync_timeout
if (
relay_tx_connection and relay_block_connection and
relay_tx_connection.is_active() and relay_block_connection.is_active()
):
if self.transaction_sync_timeout_alarm_id:
alarm_id = self.transaction_sync_timeout_alarm_id
assert alarm_id is not None
self.alarm_queue.unregister_alarm(alarm_id)
self.transaction_sync_timeout_alarm_id = None
self.transaction_sync_timeout_alarm_id = self.alarm_queue.register_alarm(
constants.TX_SERVICE_CHECK_NETWORKS_SYNCED_S, self._transaction_sync_timeout
)

# the sync with relay_tx must be the last one. since each call erase the previous call alarm
relay_block_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
relay_tx_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
self._clear_transaction_service()
retry = False
else:
relay_connection: Optional[AbstractRelayConnection] = next(
iter(self.connection_pool.get_by_connection_types((ConnectionType.RELAY_ALL,))), None
)
relay_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
self._clear_transaction_service()
retry = False
if relay_connection and relay_connection.is_active():
if self.transaction_sync_timeout_alarm_id:
alarm_id = self.transaction_sync_timeout_alarm_id
assert alarm_id is not None
self.alarm_queue.unregister_alarm(alarm_id)
self.transaction_sync_timeout_alarm_id = None

self.transaction_sync_timeout_alarm_id = self.alarm_queue.register_alarm(
constants.TX_SERVICE_CHECK_NETWORKS_SYNCED_S, self._transaction_sync_timeout
)
relay_connection.tx_sync_service.send_tx_service_sync_req(self.network_num)
self._clear_transaction_service()
retry = False

if retry:
logger.info("Relay connection is not ready to sync transaction state with BDN. Scheduling retry.")
Expand Down
8 changes: 5 additions & 3 deletions src/bxgateway/connections/abstract_relay_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from bxcommon.connections.connection_type import ConnectionType
from bxcommon.connections.internal_node_connection import InternalNodeConnection
from bxcommon.feed.feed import FeedKey
from bxcommon.messages.abstract_message_factory import AbstractMessageFactory
from bxcommon.messages.bloxroute.abstract_cleanup_message import AbstractCleanupMessage
from bxcommon.messages.bloxroute.bdn_performance_stats_message import BdnPerformanceStatsMessage
from bxcommon.messages.bloxroute.blockchain_network_message import RefreshBlockchainNetworkMessage
Expand Down Expand Up @@ -318,8 +317,11 @@ def msg_disconnect_relay_peer(self, _msg: DisconnectRelayPeerMessage) -> None:
Drop relay peer request handler. Forces a gateway to drop its relay connection and request a new one
:return: None
"""
self.log_info("Received disconnect request. Dropping.")
self.mark_for_close(should_retry=False)
if self.peer_ip in set([outbound_peer.ip for outbound_peer in self.node.opts.outbound_peers if outbound_peer]):
self.log_info("Received disconnect request. Not dropping because relay peer is static.")
else:
self.log_info("Received disconnect request. Dropping.")
self.mark_for_close(should_retry=False)

def log_connection_mem_stats(self) -> None:
"""
Expand Down
27 changes: 16 additions & 11 deletions src/bxgateway/connections/eth/eth_base_connection_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
from typing import TYPE_CHECKING, cast, Optional, Union

from bxcommon.connections.connection_type import ConnectionType
from bxcommon.models.blockchain_peer_info import BlockchainPeerInfo
from bxcommon.utils import convert
from bxgateway import gateway_constants
from bxcommon.utils.blockchain_utils.eth import eth_common_constants
from bxgateway.connections.abstract_blockchain_connection_protocol import AbstractBlockchainConnectionProtocol
from bxgateway.messages.eth.protocol.block_headers_eth_protocol_message import BlockHeadersEthProtocolMessage
from bxgateway.messages.eth.protocol.disconnect_eth_protocol_message import DisconnectEthProtocolMessage
from bxgateway.messages.eth.protocol.eth_protocol_message_factory import EthProtocolMessageFactory
from bxgateway.messages.eth.protocol.eth_protocol_message_type import EthProtocolMessageType
from bxgateway.messages.eth.protocol.hello_eth_protocol_message import HelloEthProtocolMessage
from bxgateway.messages.eth.protocol.pong_eth_protocol_message import PongEthProtocolMessage
Expand Down Expand Up @@ -133,18 +131,26 @@ def msg_hello(self, msg: HelloEthProtocolMessage):

def msg_status(self, msg: Union[StatusEthProtocolMessage, StatusEthProtocolMessageV63]):
self.connection.log_trace("Status message received.")
try:
protocol_version = msg.get_eth_version()
except Exception:
status_msg = StatusEthProtocolMessageV63(msg.rawbytes())
protocol_version = status_msg.get_eth_version()
else:
status_msg = msg

self.connection_status.status_message_received = True

for peer in self.node.blockchain_peers:
if self.node.is_blockchain_peer(self.connection.peer_ip, self.connection.peer_port):
peer.connection_established = True

chain_difficulty_from_status_msg = msg.get_chain_difficulty()
chain_difficulty_from_status_msg = status_msg.get_chain_difficulty()
chain_difficulty = int(self.node.opts.chain_difficulty, 16)
fork_id = msg.get_fork_id()
fork_id = status_msg.get_fork_id()
if isinstance(chain_difficulty_from_status_msg, int) and chain_difficulty_from_status_msg > chain_difficulty:
chain_difficulty = chain_difficulty_from_status_msg
self._enqueue_status_message(chain_difficulty, fork_id)
self._enqueue_status_message(chain_difficulty, fork_id, protocol_version)

def msg_disconnect(self, msg):
self.connection_status.disconnect_message_received = True
Expand Down Expand Up @@ -216,16 +222,15 @@ def _enqueue_hello_message(self):
self.connection.enqueue_msg(hello_msg)
self.connection_status.hello_message_sent = True

def _enqueue_status_message(self, chain_difficulty: int, fork_id):
def _enqueue_status_message(self, chain_difficulty: int, fork_id, protocol_version: int):
network_id = self.node.opts.network_id
chain_head_hash = convert.hex_to_bytes(self.node.opts.genesis_hash)
genesis_hash = convert.hex_to_bytes(self.node.opts.genesis_hash)
eth_protocol_version = self._get_eth_protocol_version()
genesis_hash = chain_head_hash

if eth_common_constants.ETH_PROTOCOL_VERSION == gateway_constants.ETH_PROTOCOL_VERSION_63:
if protocol_version == gateway_constants.ETH_PROTOCOL_VERSION_63:
status_msg = StatusEthProtocolMessageV63(
None,
eth_protocol_version,
protocol_version,
network_id,
chain_difficulty,
chain_head_hash,
Expand All @@ -234,7 +239,7 @@ def _enqueue_status_message(self, chain_difficulty: int, fork_id):
else:
status_msg = StatusEthProtocolMessage(
None,
eth_protocol_version,
protocol_version,
network_id,
chain_difficulty,
chain_head_hash,
Expand Down
2 changes: 1 addition & 1 deletion src/bxgateway/gateway_opts.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def opts_defaults(cls, opts) -> Namespace:

if not opts.cookie_file_path:
opts.cookie_file_path = gateway_constants.COOKIE_FILE_PATH_TEMPLATE.format(
"{}_{}".format(get_sdn_hostname(opts.sdn_url), opts.external_ip)
"{}_{}".format(get_sdn_hostname(opts.sdn_url), opts.external_port)
)

opts.min_peer_relays_count = 1
Expand Down
17 changes: 13 additions & 4 deletions src/bxgateway/messages/btc/abstract_btc_message_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from bxcommon.utils.blockchain_utils.bdn_tx_to_bx_tx import bdn_tx_to_bx_tx
from bxcommon.utils.object_hash import Sha256Hash
from bxcommon.utils.proxy.vector_proxy import VectorProxy
from bxcommon import constants as common_constants

from bxgateway import btc_constants
from bxgateway.abstract_message_converter import AbstractMessageConverter, BlockDecompressionResult
Expand Down Expand Up @@ -136,19 +137,27 @@ def tx_to_bx_txs(
tx_msg,
network_num: int,
transaction_flag: Optional[TransactionFlag] = None,
min_tx_network_fee: int = 0
min_tx_network_fee: int = 0,
account_id: str = common_constants.DECODED_EMPTY_ACCOUNT_ID
) -> List[Tuple[TxMessage, Sha256Hash, Union[bytearray, memoryview]]]:
if not isinstance(tx_msg, TxBtcMessage):
raise TypeError("tx_msg is expected to be of type TxBTCMessage")

bx_tx_msg = TxMessage(tx_msg.tx_hash(), network_num, tx_val=tx_msg.tx(), transaction_flag=transaction_flag)
bx_tx_msg = TxMessage(
tx_msg.tx_hash(),
network_num,
tx_val=tx_msg.tx(),
transaction_flag=transaction_flag,
account_id=account_id
)

return [(bx_tx_msg, tx_msg.tx_hash(), tx_msg.tx())]

def bdn_tx_to_bx_tx(
self,
raw_tx: Union[bytes, bytearray, memoryview],
network_num: int,
transaction_flag: Optional[TransactionFlag] = None
transaction_flag: Optional[TransactionFlag] = None,
account_id: str = common_constants.DECODED_EMPTY_ACCOUNT_ID
) -> TxMessage:
return bdn_tx_to_bx_tx(raw_tx, network_num, transaction_flag)
return bdn_tx_to_bx_tx(raw_tx, network_num, transaction_flag, account_id)
Loading

0 comments on commit 6f59c97

Please sign in to comment.