Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Ethereum Consensus API #49

Merged
merged 3 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions chainbench/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from locust import runners

from chainbench.tools.discovery.rpc import DiscoveryResult
from chainbench.user import EVMMethods
from chainbench.user import EvmMethods
from chainbench.util.cli import (
ContextData,
ensure_results_dir,
Expand Down Expand Up @@ -53,7 +53,7 @@ def cli(ctx: Context):

def validate_method(ctx: Context, param: Parameter, value: str) -> str:
if value is not None:
method_list = [task_to_method(task) for task in get_subclass_methods(EVMMethods)]
method_list = [task_to_method(task) for task in get_subclass_methods(EvmMethods)]
if value not in method_list:
raise click.BadParameter(
f"Method {value} is not supported. " f"Use 'chainbench list methods' to list all available methods."
Expand Down Expand Up @@ -386,12 +386,12 @@ def start(


def validate_clients(ctx: Context, param: Parameter, value: str) -> list[str]:
from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

if value is not None:
input_client_list = value.split(",")
client_list: list[str] = []
for client in RPCDiscovery.get_clients():
for client in RpcDiscovery.get_clients():
client_list.extend(client.get_cli_argument_names())
for client_name in input_client_list:
if client_name not in client_list:
Expand Down Expand Up @@ -423,9 +423,9 @@ def discover(endpoint: str | None, clients: list[str]) -> None:
click.echo("Target endpoint is required.")
sys.exit(1)

from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

rpc_discovery = RPCDiscovery(endpoint, clients)
rpc_discovery = RpcDiscovery(endpoint, clients)
click.echo(f"Please wait, discovering methods available on {endpoint}...")

def get_discovery_result(method: str) -> None:
Expand All @@ -445,9 +445,9 @@ def _list() -> None:
help="Lists all available client options for method discovery.",
)
def clients() -> None:
from chainbench.tools.discovery.rpc import RPCDiscovery
from chainbench.tools.discovery.rpc import RpcDiscovery

for client in RPCDiscovery.get_clients():
for client in RpcDiscovery.get_clients():
for unique_client in client.get_name_and_version():
click.echo(unique_client)

Expand All @@ -472,7 +472,7 @@ def profiles(profile_dir: Path) -> None:
help="Lists all available evm methods.",
)
def methods() -> None:
task_list = get_subclass_methods(EVMMethods)
task_list = get_subclass_methods(EvmMethods)
for task in task_list:
click.echo(task_to_method(task))

Expand Down
32 changes: 16 additions & 16 deletions chainbench/profile/avalanche/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
"""
from locust import constant_pacing, tag, task

from chainbench.user import EVMUser
from chainbench.user import EvmUser
from chainbench.util.rng import get_rng


class AvalancheProfile(EVMUser):
class AvalancheProfile(EvmUser):
wait_time = constant_pacing(1)
weight = 91

@task(100)
def call_task(self):
self.make_call(
self.make_rpc_call(
name="call",
method="eth_call",
params=[
Expand All @@ -41,53 +41,53 @@ def call_task(self):

@task(50)
def get_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_number",
method="eth_getBlockByNumber",
params=self._block_params_factory(),
),

@task(17)
def get_transaction_receipt_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_receipt",
method="eth_getTransactionReceipt",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(15)
def chain_id_task(self):
self.make_call(
self.make_rpc_call(
name="chain_id",
method="eth_chainId",
),

@task(15)
def block_number_task(self):
self.make_call(
self.make_rpc_call(
name="block_number",
method="eth_blockNumber",
),

@task(11)
def get_balance_task(self):
self.make_call(
self.make_rpc_call(
name="get_balance",
method="eth_getBalance",
params=self._get_account_and_block_number_params_factory_latest(get_rng()),
),

@task(10)
def get_transaction_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_by_hash",
method="eth_getTransactionByHash",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(5)
def estimate_gas_task(self):
self.make_call(
self.make_rpc_call(
name="estimate_gas",
method="eth_estimateGas",
params=[
Expand All @@ -101,42 +101,42 @@ def estimate_gas_task(self):

@task(4)
def client_version_task(self):
self.make_call(
self.make_rpc_call(
name="client_version",
method="web3_clientVersion",
),

@task(3)
def get_block_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_hash",
method="eth_getBlockByHash",
params=self._block_by_hash_params_factory(get_rng()),
),

@task(3)
def gas_price_task(self):
self.make_call(
self.make_rpc_call(
name="gas_price",
method="eth_gasPrice",
),

@task(3)
def max_priority_fee_per_gas_task(self):
self.make_call(
self.make_rpc_call(
name="max_priority_fee_per_gas",
method="eth_maxPriorityFeePerGas",
),


class AvalancheGetLogsProfile(EVMUser):
class AvalancheGetLogsProfile(EvmUser):
wait_time = constant_pacing(10)
weight = 9

@tag("get-logs")
@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
24 changes: 12 additions & 12 deletions chainbench/profile/bsc/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@
"""
from locust import constant_pacing, tag, task

from chainbench.user import EVMUser
from chainbench.user import EvmUser
from chainbench.util.rng import get_rng


class BscProfile(EVMUser):
class BscProfile(EvmUser):
wait_time = constant_pacing(1)
weight = 89

@task(100)
def call_task(self):
self.make_call(
self.make_rpc_call(
name="call",
method="eth_call",
params=[
Expand All @@ -40,67 +40,67 @@ def call_task(self):

@task(93)
def get_transaction_receipt_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_receipt",
method="eth_getTransactionReceipt",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(28)
def block_number_task(self):
self.make_call(
self.make_rpc_call(
name="block_number",
method="eth_blockNumber",
),

@task(18)
def chain_id_task(self):
self.make_call(
self.make_rpc_call(
name="chain_id",
method="eth_chainId",
),

@task(13)
def get_block_by_number_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_number",
method="eth_getBlockByNumber",
params=self._block_params_factory(),
),

@task(9)
def get_transaction_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_transaction_by_hash",
method="eth_getTransactionByHash",
params=self._transaction_by_hash_params_factory(get_rng()),
),

@task(5)
def get_balance_task(self):
self.make_call(
self.make_rpc_call(
name="get_balance",
method="eth_getBalance",
params=self._get_account_and_block_number_params_factory_latest(get_rng()),
),

@task(3)
def get_block_by_hash_task(self):
self.make_call(
self.make_rpc_call(
name="get_block_by_hash",
method="eth_getBlockByHash",
params=self._block_by_hash_params_factory(get_rng()),
),


class BscGetLogsProfile(EVMUser):
class BscGetLogsProfile(EvmUser):
wait_time = constant_pacing(10)
weight = 12

@tag("get-logs")
@task
def get_logs_task(self):
self.make_call(
self.make_rpc_call(
name="get_logs",
method="eth_getLogs",
params=self._get_logs_params_factory(get_rng()),
Expand Down
27 changes: 27 additions & 0 deletions chainbench/profile/ethereum/consensus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Ethereum Consensus profile.
"""
from locust import constant_pacing

from chainbench.user.ethereum import EthConsensusMethods

# mypy: ignore_errors


class EthereumConsensusProfile(EthConsensusMethods):
wait_time = constant_pacing(1)
tasks = {
EthConsensusMethods.eth_v1_beacon_states_validators_random_ids_task: 698,
EthConsensusMethods.eth_v1_beacon_states_validators_head_task: 23,
EthConsensusMethods.eth_v1_beacon_states_head_committees_random_epoch_task: 10,
EthConsensusMethods.eth_v1_beacon_states_validators_random_validator_status_task: 10,
EthConsensusMethods.eth_v1_beacon_states_random_state_id_finality_checkpoints_task: 10,
EthConsensusMethods.eth_v2_beacon_blocks_random_block_id_task: 8,
EthConsensusMethods.eth_v2_beacon_blocks_head_task: 6,
EthConsensusMethods.eth_v1_beacon_headers_head_task: 4,
EthConsensusMethods.eth_v1_config_spec_task: 3,
EthConsensusMethods.eth_v1_node_health_task: 2,
EthConsensusMethods.eth_v2_beacon_blocks_finalized_task: 1,
EthConsensusMethods.eth_v1_beacon_headers_random_block_id_task: 1,
EthConsensusMethods.eth_v1_node_version_task: 1,
}
Loading
Loading