Skip to content

Commit b1a3a88

Browse files
author
HuangYi
committed
Problem: single validator benchmark can't run natively
single validator benchmark should be runnable locally, since there are no port issues temp
1 parent 007077a commit b1a3a88

File tree

4 files changed

+50
-22
lines changed

4 files changed

+50
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## UNRELEASED
44

5+
### Bug Fixes
6+
7+
* (testground)[]() Fix running single validator benchmark locally.
8+
59
### Improvements
610

711
* [#1645](https://github.com/crypto-org-chain/cronos/pull/1645) Gen test tx in parallel even in single node.

testground/benchmark/benchmark/stateless.py

Lines changed: 41 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import shutil
55
import socket
66
import subprocess
7+
import sys
78
import tarfile
89
import tempfile
910
import time
@@ -175,7 +176,7 @@ def patchimage(toimage, src, dst, fromimage):
175176
@click.option("--outdir", default="/outputs")
176177
@click.option("--datadir", default="/data")
177178
@click.option("--cronosd", default=CONTAINER_CRONOSD_PATH)
178-
@click.option("--global-seq", default=None)
179+
@click.option("--global-seq", default=None, type=int)
179180
def run(outdir: str, datadir: str, cronosd, global_seq):
180181
datadir = Path(datadir)
181182
cfg = json.loads((datadir / "config.json").read_text())
@@ -194,14 +195,19 @@ def run(outdir: str, datadir: str, cronosd, global_seq):
194195
finally:
195196
# collect outputs
196197
output = Path("/data.tar.bz2")
197-
with tarfile.open(output, "x:bz2") as tar:
198-
tar.add(home, arcname="data", filter=output_filter(group, group_seq))
199-
outdir = Path(outdir)
200-
if outdir.exists():
201-
assert outdir.is_dir()
202-
filename = outdir / f"{group}_{group_seq}.tar.bz2"
203-
filename.unlink(missing_ok=True)
204-
shutil.copy(output, filename)
198+
try:
199+
with tarfile.open(output, "x:bz2") as tar:
200+
tar.add(home, arcname="data", filter=output_filter(group, group_seq))
201+
except OSError:
202+
# ignore if the file is not writable when running in bare metal
203+
pass
204+
else:
205+
outdir = Path(outdir)
206+
if outdir.exists():
207+
assert outdir.is_dir()
208+
filename = outdir / f"{group}_{group_seq}.tar.bz2"
209+
filename.unlink(missing_ok=True)
210+
shutil.copy(output, filename)
205211

206212

207213
@cli.command()
@@ -221,6 +227,19 @@ def generic_gen_txs(options: dict):
221227
return _gen_txs(**options)
222228

223229

230+
@cli.command()
231+
@click.option("--datadir", default="/data", type=Path)
232+
@click.option("--global-seq", default=0)
233+
def generate_load(datadir: Path, global_seq: int):
234+
cfg = json.loads((datadir / "config.json").read_text())
235+
txs = prepare_txs(cfg, datadir, global_seq)
236+
asyncio.run(transaction.send(txs))
237+
print("sent", len(txs), "txs")
238+
print("wait for 20 idle blocks")
239+
detect_idle_halted(cfg["num_idle"], 20)
240+
dump_block_stats(sys.stdout)
241+
242+
224243
def _gen_txs(
225244
outdir: str,
226245
nodes: int = 10,
@@ -248,14 +267,7 @@ def do_run(
248267
datadir: Path, home: Path, cronosd: str, group: str, global_seq: int, cfg: dict
249268
):
250269
if group == FULLNODE_GROUP or cfg.get("validator-generate-load", True):
251-
txs = transaction.load(datadir, global_seq)
252-
if txs:
253-
print("loaded", len(txs), "txs")
254-
else:
255-
print("generating", cfg["num_accounts"] * cfg["num_txs"], "txs")
256-
txs = transaction.gen(
257-
global_seq, cfg["num_accounts"], cfg["num_txs"], cfg["tx_type"]
258-
)
270+
txs = prepare_txs(cfg, datadir, global_seq)
259271
else:
260272
txs = []
261273

@@ -415,5 +427,17 @@ def wait_for_peers(home: Path):
415427
wait_for_port(ECHO_SERVER_PORT, host=host, timeout=2400)
416428

417429

430+
def prepare_txs(cfg, datadir, global_seq):
431+
txs = transaction.load(datadir, global_seq)
432+
if txs:
433+
print("loaded", len(txs), "txs")
434+
else:
435+
print("generating", cfg["num_accounts"] * cfg["num_txs"], "txs")
436+
txs = transaction.gen(
437+
global_seq, cfg["num_accounts"], cfg["num_txs"], cfg["tx_type"]
438+
)
439+
return txs
440+
441+
418442
if __name__ == "__main__":
419443
cli()

testground/benchmark/benchmark/transaction.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
import ujson
1212

1313
from .erc20 import CONTRACT_ADDRESS
14-
from .utils import gen_account, split
14+
from .utils import LOCAL_JSON_RPC, gen_account, split
1515

1616
GAS_PRICE = 1000000000
1717
CHAIN_ID = 777
18-
LOCAL_JSON_RPC = "http://localhost:8545"
1918
CONNECTION_POOL_SIZE = 1024
2019
TXS_DIR = "txs"
2120
RECIPIENT = "0x1" + "0" * 39
@@ -128,7 +127,7 @@ async def async_sendtx(session, raw):
128127

129128

130129
async def send(txs):
131-
connector = aiohttp.TCPConnector(limit=1024)
130+
connector = aiohttp.TCPConnector(limit=CONNECTION_POOL_SIZE)
132131
async with aiohttp.ClientSession(
133132
connector=connector, json_serialize=ujson.dumps
134133
) as session:

testground/benchmark/benchmark/utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
from web3._utils.transactions import fill_nonce, fill_transaction_defaults
1414

1515
CRONOS_ADDRESS_PREFIX = "crc"
16-
LOCAL_RPC = "http://localhost:26657"
16+
LOCAL_RPC = "http://127.0.0.1:26657"
17+
LOCAL_JSON_RPC = "http://127.0.0.1:8545"
1718

1819

1920
def patch_toml_doc(doc, patch):
@@ -93,7 +94,7 @@ def wait_for_block(cli, target: int, timeout=40):
9394
def wait_for_w3(timeout=40):
9495
for i in range(timeout):
9596
try:
96-
w3 = web3.Web3(web3.providers.HTTPProvider("http://localhost:8545"))
97+
w3 = web3.Web3(web3.providers.HTTPProvider(LOCAL_JSON_RPC))
9798
w3.eth.get_balance("0x0000000000000000000000000000000000000001")
9899
except: # noqa
99100
time.sleep(1)

0 commit comments

Comments
 (0)