44import shutil
55import socket
66import subprocess
7+ import sys
78import tarfile
89import tempfile
910import 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 )
179180def 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+
224243def _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+
418442if __name__ == "__main__" :
419443 cli ()
0 commit comments