diff --git a/testground/benchmark/benchmark/testnet.py b/testground/benchmark/benchmark/testnet.py index b44560d552..d7d9c6d7a9 100644 --- a/testground/benchmark/benchmark/testnet.py +++ b/testground/benchmark/benchmark/testnet.py @@ -112,9 +112,10 @@ def gen_txs(start, end, num_txs, nonce, msg_version): @cli.command() @click.argument("path", type=str) @click.option("--rpc", default=TESTNET_RPC) -def send_txs(path, rpc): +@click.option("--sync", default=False) +def send_txs(path, rpc, sync): txs = json.loads(Path(path).read_text()) - asyncio.run(send(txs, rpc)) + asyncio.run(send(txs, rpc, sync)) if __name__ == "__main__": diff --git a/testground/benchmark/benchmark/transaction.py b/testground/benchmark/benchmark/transaction.py index 311985d354..31853bb42d 100644 --- a/testground/benchmark/benchmark/transaction.py +++ b/testground/benchmark/benchmark/transaction.py @@ -228,8 +228,9 @@ def json_rpc_send_body(raw, method="broadcast_tx_async"): @backoff.on_predicate(backoff.expo, max_time=60, max_value=5) @backoff.on_exception(backoff.expo, aiohttp.ClientError, max_time=60, max_value=5) -async def async_sendtx(session, raw, rpc): - async with session.post(rpc, json=json_rpc_send_body(raw)) as rsp: +async def async_sendtx(session, raw, rpc, sync=False): + method = "broadcast_tx_sync" if sync else "broadcast_tx_async" + async with session.post(rpc, json=json_rpc_send_body(raw, method)) as rsp: data = await rsp.json() if "error" in data: print("send tx error, will retry,", data["error"]) @@ -237,10 +238,12 @@ async def async_sendtx(session, raw, rpc): return True -async def send(txs, rpc=LOCAL_RPC): +async def send(txs, rpc=LOCAL_RPC, sync=False): connector = aiohttp.TCPConnector(limit=CONNECTION_POOL_SIZE) async with aiohttp.ClientSession( connector=connector, json_serialize=ujson.dumps ) as session: - tasks = [asyncio.ensure_future(async_sendtx(session, raw, rpc)) for raw in txs] + tasks = [ + asyncio.ensure_future(async_sendtx(session, raw, rpc, sync)) for raw in txs + ] await asyncio.gather(*tasks)