Skip to content

Instantly share code, notes, and snippets.

@hackaugusto
Created April 14, 2020 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hackaugusto/5027d00667a8d22f1ba9ff30a9c039b2 to your computer and use it in GitHub Desktop.
Save hackaugusto/5027d00667a8d22f1ba9ff30a9c039b2 to your computer and use it in GitHub Desktop.
eth_getLogs response time measurment
import time
import raiden_contracts.constants
from eth_utils import to_checksum_address
from raiden_contracts.contract_manager import (ContractManager,
contracts_precompiled_path)
from web3 import HTTPProvider, Web3
from raiden.blockchain.events import BlockchainEvents, filters_to_rpc
from raiden.network.rpc.client import JSONRPCClient
from raiden.tests.utils import factories
class T:
def __init__(self, url):
self.web3 = Web3(HTTPProvider(url))
self.latest_block = self.web3.eth.blockNumber
# self.addresses = [
# to_checksum_address(b"/\x88\xf8&\x18\x19\xc4\xd63F\x80J\x17\xaa\x93\xc3\\\xc7\x9dy"),
# to_checksum_address(b"B\xb5\xc1!\xf7a\x97[\x0f\x9c\x0f\xc1\xb5>\x08\x15\x05g\xc2%"),
# to_checksum_address(
# b"Ba\xf6\xea\xf3\xac\xf5h\xa5\xeen\x15\xbe\r\xfc\xda7\x9d\xac\x8b"
# ),
# to_checksum_address(b"4\xffL\x1c\xb4\x06\x87\xd0\xb6J\xcc\xc2AT\xd1\x87&Z?="),
# ]
self.addresses = []
def next(self, from_block, to_block):
before = time.time()
blockchain_events = self.web3.manager.request_blocking(
"eth_getLogs",
[{"fromBlock": from_block, "toBlock": to_block, "address": self.addresses}],
)
after = time.time()
elapsed = after - before
qty_blocks = to_block - from_block
return qty_blocks, elapsed, blockchain_events
# mainnet = T("http://geth.mainnet.ethnodes.brainbot.com:8545")
# goerli = T("http://geth.goerli.ethnodes.brainbot.com:8545")
mainnet = T("http://parity.mainnet.ethnodes.brainbot.com:8545")
goerli = T("http://parity.goerli.ethnodes.brainbot.com:8545")
def from_to(net, step):
# "fromBlock": 9839839,
# "toBlock": 9869758,
# from_block = net.latest_block - step
# to_block = net.latest_block - (step - 100)
from_block = net.latest_block - step
to_block = net.latest_block
return (from_block, to_block)
for step in range(0, 100_000, 1_000):
qty_blocks, mainnet_elapsed, mainnet_events = mainnet.next(*from_to(mainnet, step))
qty_blocks, goerli_elapsed, goerli_events = goerli.next(*from_to(goerli, step))
print(
f"{qty_blocks} | {mainnet_elapsed} | {len(mainnet_events)} | {goerli_elapsed} | {len(goerli_events)}"
)
# end = 2_000_000
# start = 1_900_000
# for step in range(100, 10_000, 100):
# start_ts = time.time()
# for from_block in range(start, end, step):
# to_block = from_block + step
# goerli.next(from_block, to_block)
# end_ts = time.time()
# print(f"{step} | {start_ts - end_ts}")
# privatekey = factories.make_privatekey_bin()
# rpc_client = JSONRPCClient(web3=web3, privkey=privatekey)
# chain_id = 0
# last_block_number = 0
# contract_manager = ContractManager(
# contracts_precompiled_path(raiden_contracts.constants.CONTRACTS_VERSION)
# )
# blockchain_events = BlockchainEvents(
# web3=rpc_client.web3,
# chain_id=chain_id,
# contract_manager=contract_manager,
# last_fetched_block=last_block_number,
# event_filters=filters,
# max_number_of_blocks_to_poll=100_000,
# )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment