Skip to content

Commit

Permalink
Release v1.86.6
Browse files Browse the repository at this point in the history
  • Loading branch information
shanevc committed Apr 23, 2021
1 parent 42daba1 commit a99eb77
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 93 deletions.
6 changes: 4 additions & 2 deletions src/bloxroute_cli/compare_tx_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ 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) # pyre-ignore
sender_balance = default_web3.eth.getBalance(sender_address) # pyre-ignore
# pyre-ignore[29]: `web3.method.Method` is not a function.
nonce = default_web3.eth.getTransactionCount(sender_address)
# pyre-ignore[29]: `web3.method.Method` is not a function.
sender_balance = default_web3.eth.getBalance(sender_address)
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.85.9.0"}
{"source_version": "v1.86.6.0"}
1 change: 0 additions & 1 deletion src/bxgateway/abstract_message_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ def encode_raw_msg(self, raw_msg: str) -> bytes:
:return: binary encoded message
:raise ValueError: if the encoding fails
"""
# TODO: remove this method, access hex to bytes directly
return convert.hex_to_bytes(raw_msg)

def special_memory_size(self, ids: Optional[Set[int]] = None) -> SpecialTuple:
Expand Down
21 changes: 13 additions & 8 deletions src/bxgateway/connections/abstract_gateway_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,13 @@ def send_msg_to_remote_node(self, msg: AbstractMessage) -> None:

def continue_retrying_connection(self, ip: str, port: int, connection_type: ConnectionType) -> bool:
if connection_type == ConnectionType.BLOCKCHAIN_NODE:
self.num_active_blockchain_peers = len(
list(
self.connection_pool.get_by_connection_types(
(ConnectionType.BLOCKCHAIN_NODE,)
)
)
)
return self.num_active_blockchain_peers == 0 \
or ((ip, port) in self.time_blockchain_peer_conn_destroyed_by_ip and
time.time() - self.time_blockchain_peer_conn_destroyed_by_ip[(ip, port)]
Expand Down Expand Up @@ -713,16 +720,14 @@ def on_blockchain_connection_destroyed(self, connection: AbstractGatewayBlockcha
connection.peer_port,
connection.get_connection_state_details()
)
self.num_active_blockchain_peers = max(
0,
len(
list(
self.connection_pool.get_by_connection_types(
(ConnectionType.BLOCKCHAIN_NODE,)
)
self.num_active_blockchain_peers = len(
list(
self.connection_pool.get_by_connection_types(
(ConnectionType.BLOCKCHAIN_NODE,)
)
) - 1
)
)

if self.num_active_blockchain_peers > 0:
self.block_queuing_service_manager.remove_block_queuing_service(connection)

Expand Down
17 changes: 14 additions & 3 deletions src/bxgateway/messages/eth/eth_abstract_message_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

from bxcommon.models.transaction_flag import TransactionFlag
from bxcommon.messages.bloxroute.tx_message import TxMessage
from bxcommon.utils import convert
from bxcommon.utils.blockchain_utils.bdn_tx_to_bx_tx import bdn_tx_to_bx_tx
from bxcommon.utils.blockchain_utils.eth import rlp_utils, eth_common_utils
from bxcommon.utils.blockchain_utils.eth import rlp_utils, eth_common_utils, \
transaction_validation_utils
from bxcommon.utils.object_hash import Sha256Hash
from bxcommon import constants as common_constants

Expand All @@ -15,6 +17,8 @@

from bxutils import logging

import blxr_rlp as rlp

logger = logging.get_logger(__name__)


Expand Down Expand Up @@ -81,11 +85,11 @@ def tx_to_bx_txs(
tx_start_index = 0

while True:
gas_price = eth_common_utils.raw_tx_gas_price(txs_bytes, tx_start_index)
bx_tx, tx_item_length, tx_item_start = eth_common_utils.raw_tx_to_bx_tx(
bx_tx, _, tx_item_length, tx_item_start = eth_common_utils.raw_tx_to_bx_tx(
txs_bytes, tx_start_index, network_num, transaction_flag, account_id
)

gas_price = eth_common_utils.raw_tx_gas_price(txs_bytes, tx_start_index)
if gas_price >= min_tx_network_fee:
bx_tx_msgs.append((bx_tx, bx_tx.message_hash(), bx_tx.tx_val()))

Expand Down Expand Up @@ -148,3 +152,10 @@ def bx_block_to_block(self, bx_block_msg, tx_service) -> BlockDecompressionResul
:return: tuple (new block message, block hash, unknown transaction short id, unknown transaction hashes)
"""
raise NotImplementedError

def encode_raw_msg(self, raw_msg: str) -> bytes:
msg_bytes = convert.hex_to_bytes(raw_msg)

return transaction_validation_utils.normalize_typed_transaction(
memoryview(msg_bytes)
).tobytes()
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, msg_bytes, *args, **kwargs):
def __repr__(self):
return f"BlockBodiesEthProtocolMessage<bodies_count: {len(self.get_block_bodies_bytes())}>"

def get_blocks(self):
def get_blocks(self) -> List[TransientBlockBody]:
return self.get_field_value("blocks")

def get_block_bodies_bytes(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from typing import List

import blxr_rlp as rlp
from bxcommon.messages.eth.serializers.block_header import BlockHeader
from bxcommon.messages.eth.serializers.transaction import Transaction


# pyre-fixme[13]: Attribute `transactions` is never initialized.
# pyre-fixme[13]: Attribute `uncles` is never initialized.
class TransientBlockBody(rlp.Serializable):
fields = [
("transactions", rlp.sedes.CountableList(Transaction)),
("uncles", rlp.sedes.CountableList(BlockHeader))
]

transactions: List[Transaction]
uncles: List[BlockHeader]
2 changes: 1 addition & 1 deletion src/bxgateway/rpc/external/eth_ws_proxy_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def process_transaction_with_parsed_contents(
transaction_key.transaction_hash,
parsed_tx,
FeedSource.BLOCKCHAIN_RPC,
local_region=True
local_region=True,
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ def _get_gateway_node(self) -> AbstractGatewayNode:
def _get_node_tx_message(
self
) -> Tuple[
Union[TxOntMessage, TransactionsEthProtocolMessage], List[Tuple[Sha256Hash, Union[bytearray, memoryview]]]]:
txs = []

for i in range(600):
txs.append(mock_eth_messages.get_dummy_transaction(i + 1))
Union[TxOntMessage, TransactionsEthProtocolMessage], List[Tuple[Sha256Hash, Union[bytearray, memoryview]]]
]:
txs = [
mock_eth_messages.get_dummy_transaction(1),
mock_eth_messages.get_dummy_access_list_transaction(2)
]

msg = TransactionsEthProtocolMessage(None, txs)

# pyre-fixme [7]: Expected `Tuple[Union[TransactionsEthProtocolMessage, TxOntMessage], List[Tuple[Sha256Hash, Union[bytearray, memoryview]]]]`
return msg, list(map(lambda tx: (tx.hash(), tx.contents()), msg.get_transactions()))
50 changes: 50 additions & 0 deletions src/bxgateway/testing/abstract_gateway_rpc_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
from bxcommon.network.ip_endpoint import IpEndpoint
from bxcommon.rpc import rpc_constants
from bxcommon.test_utils import helpers
from bxcommon.test_utils.fixture import eth_fixtures
from bxcommon.test_utils.mocks.mock_connection import MockConnection
from bxcommon.test_utils.mocks.mock_socket_connection import MockSocketConnection
from bxgateway.connections.eth.eth_gateway_node import EthGatewayNode
from bxgateway.connections.eth.eth_node_connection import EthNodeConnection
from bxgateway.messages.eth.eth_normal_message_converter import EthNormalMessageConverter
from bxgateway.testing.mocks.mock_blockchain_connection import MockMessageConverter
from bxutils import constants as utils_constants
from bxcommon.models.bdn_account_model_base import BdnAccountModelBase
from bxcommon.models.bdn_service_model_base import BdnServiceModelBase, FeedServiceModelBase
Expand Down Expand Up @@ -135,6 +138,53 @@ async def test_blxr_tx(self):
self.gateway_node.broadcast_messages[0][0].tx_hash()
)

@async_test
async def test_blxr_tx_ethereum_berlin(self):
self.gateway_node.message_converter = EthNormalMessageConverter()
self.gateway_node.network_num = 5

# legacy
result = await self.request(BxJsonRpcRequest(
"1",
RpcRequestType.BLXR_TX,
{
rpc_constants.TRANSACTION_PARAMS_KEY: convert.bytes_to_hex(
eth_fixtures.LEGACY_TRANSACTION
),
rpc_constants.STATUS_TRACK_PARAMS_KEY: "True"
}
))
self.assertEqual("1", result.id)
self.assertIsNone(result.error)
self.assertEqual(eth_fixtures.LEGACY_TRANSACTION_HASH, result.result["tx_hash"])

self.assertEqual(1, len(self.gateway_node.broadcast_messages))
self.assertEqual(
Sha256Hash(convert.hex_to_bytes(eth_fixtures.LEGACY_TRANSACTION_HASH)),
self.gateway_node.broadcast_messages[0][0].tx_hash()
)

# access list
result = await self.request(BxJsonRpcRequest(
"1",
RpcRequestType.BLXR_TX,
{
rpc_constants.TRANSACTION_PARAMS_KEY: convert.bytes_to_hex(
eth_fixtures.ACCESS_LIST_TRANSACTION
),
rpc_constants.STATUS_TRACK_PARAMS_KEY: "True"
}
))
self.assertEqual("1", result.id)
self.assertIsNone(result.error)
self.assertEqual(eth_fixtures.ACCESS_LIST_TRANSACTION_HASH, result.result["tx_hash"])

self.assertEqual(2, len(self.gateway_node.broadcast_messages))
self.assertEqual(
Sha256Hash(convert.hex_to_bytes(eth_fixtures.ACCESS_LIST_TRANSACTION_HASH)),
self.gateway_node.broadcast_messages[1][0].tx_hash()
)

@async_test
async def test_blxr_tx_expired(self):
self.gateway_node.account_model.is_account_valid = MagicMock(return_value=False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def _get_gateway_node(self) -> AbstractGatewayNode:
def _get_node_tx_message(
self
) -> Tuple[
Union[TxOntMessage, TransactionsEthProtocolMessage], List[Tuple[Any, Any]]]:
Union[TxOntMessage, TransactionsEthProtocolMessage], List[Tuple[Any, Any]]
]:
magic = 123456
version = 1
tx_contents = helpers.generate_bytearray(200)
Expand Down
44 changes: 35 additions & 9 deletions src/bxgateway/testing/mocks/mock_eth_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
from bxgateway.messages.eth.protocol.transactions_eth_protocol_message import \
TransactionsEthProtocolMessage
from bxcommon.messages.eth.serializers.block import Block
from bxcommon.messages.eth.serializers.transaction import Transaction
from bxcommon.messages.eth.serializers.transaction import Transaction, LegacyTransaction, \
AccessListTransaction
from bxgateway.messages.eth.serializers.transient_block_body import \
TransientBlockBody

Expand Down Expand Up @@ -54,7 +55,7 @@ def get_dummy_transaction(
else:
to_address = convert.hex_to_bytes(to_address_str)
# create transaction object with dummy values multiplied by nonce to be able generate txs with different values
return Transaction(
return LegacyTransaction(
nonce,
gas_price,
3 * nonce,
Expand All @@ -63,7 +64,32 @@ def get_dummy_transaction(
helpers.generate_bytes(15 * nonce),
v,
6 * nonce,
7 * nonce)
7 * nonce
)


def get_dummy_access_list_transaction(
nonce: int, gas_price: Optional[int] = None, v: int = 27, to_address_str: Optional[str] = None
) -> Transaction:
if gas_price is None:
gas_price = 2 * nonce
if to_address_str is None:
to_address = helpers.generate_bytes(eth_common_constants.ADDRESS_LEN)
else:
to_address = convert.hex_to_bytes(to_address_str)
return AccessListTransaction(
8 * nonce,
nonce,
gas_price,
3 * nonce,
to_address,
4 * nonce,
helpers.generate_bytes(15 * nonce),
[],
v,
6 * nonce,
7 * nonce
)


def get_dummy_block_header(
Expand Down Expand Up @@ -129,17 +155,18 @@ def get_dummy_block(nonce, header=None):


def new_block_eth_protocol_message(
nonce: int,
block_number: Optional[int] = None,
prev_block_hash: Optional[Sha256Hash] = None
nonce: int,
block_number: Optional[int] = None,
prev_block_hash: Optional[Sha256Hash] = None
) -> NewBlockEthProtocolMessage:
header = get_dummy_block_header(nonce, block_number=block_number, prev_block_hash=prev_block_hash)
header = get_dummy_block_header(nonce, block_number=block_number,
prev_block_hash=prev_block_hash)
block = get_dummy_block(nonce, header)
return NewBlockEthProtocolMessage(None, block, nonce * 5 + 10)


# reference
# https://etherscan.io/tx/0x00278cf7120dbbbee72eb7bdaaa2eac8ec41ef931c30fd6d218bdad1b2b2324e

EIP_155_TRANSACTION_HASH = "00278cf7120dbbbee72eb7bdaaa2eac8ec41ef931c30fd6d218bdad1b2b2324e"
EIP_155_TRANSACTION_GAS_PRICE = 53_000_000_000
EIP_155_TRANSACTION_BYTES = bytearray(
Expand All @@ -161,7 +188,6 @@ def new_block_eth_protocol_message(
EIP_155_TRANSACTION_BYTES
)


NOT_EIP_155_TRANSACTION_HASH = "f4996a6631c6c685b6c34a30d129917b8d502988feb1d7e930035e207e9761dc"
NOT_EIP_155_TRANSACTION_BYTES = bytearray(
b"\xf8\xae\xf8\xac\x83\x01\x88\x8c\x85\x077\xbev\x00\x82\xea`\x94\xa1\xb1\x9b\xcdP\xa2K\xe0\xcb9\x9c\x1e\xc0\xf7\xcaTk\x94\xa2\xb0\x80\xb8D\xa9\x05\x9c\xbb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x0f0\"q\xd0\xdf\xbdf\xc5\xf7\x8a2\x16.\xeb\xf0\xa8\xb3Q.\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00uI\x1c\xca\x15\x13<\x00\x1b\xa0\x19\x04f\xba\x93\x0f|\xd8\xf4\xf0\xe0\xfcVK\xfbu\xcb+U\xd0\x80\x7f\xe0\xa7C\xe5\x86\xc2\'WQ\x8e\xa0k\xb1\x1a\x08\x99FI>J\xa7U\x9dW\x8d\xa3\x98b\xd8\xd1D\xf2\xb3\xc4\x9a\xfe\x9f\xa3Y\x1b\xab\x05-"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/rpc/provider/test_ws_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ async def test_eth_pending_transactions_feed_subscribe_filters3(self):
eth_tx_message.tx_hash(),
eth_tx_message.tx_val(),
FeedSource.BLOCKCHAIN_SOCKET,
local_region=True
local_region=True,
)
expected_tx_hash = f"0x{str(eth_transaction.tx_hash)}"
to2 = "0x1111111111111111111111111111111111111111"
Expand Down
5 changes: 3 additions & 2 deletions test/unit/connections/test_abstract_gateway_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ def test_last_active_blockchain_peer_queuing_service_not_destroyed(self):
self.assertIsNotNone(node.block_queuing_service_manager.get_block_queuing_service(blockchain_conn2))
self.assertTrue(blockchain_conn2 in node.block_queuing_service_manager.blockchain_peer_to_block_queuing_service)

node.connection_pool.delete(blockchain_conn2)
node.on_blockchain_connection_destroyed(blockchain_conn2)
self.assertFalse(blockchain_conn2 in node.block_queuing_service_manager.blockchain_peer_to_block_queuing_service)
node.connection_pool.delete(blockchain_conn2)


node.connection_pool.delete(blockchain_conn)
node.on_blockchain_connection_destroyed(blockchain_conn)
self.assertTrue(blockchain_conn in node.block_queuing_service_manager.blockchain_peer_to_block_queuing_service)

Expand Down
Loading

0 comments on commit a99eb77

Please sign in to comment.