def populate_blocks(first_block: BlockHeight, last_block: BlockHeight) -> None: for h in range(first_block, last_block + 1): try: logger.info(f"Dumping tx weights+feerates for block {h}") populate_block(h) except Exception as e: logger.error( f"Exception occurred when trying to populate with txs in block {h}: {type(e)}:{str(e)}" )
def dump_tx_weights_in_block(h: BlockHeight) -> None: """ computes the weight of all transactions in block at height h and dump them to a text file in the DB_FOLDER directory """ logger.info(f"Dumping weights for block {h}") filepath = os.path.join(TX_WEIGHTS_FOLDER, f"block_{h}_tx_weights.tsv") if os.path.isfile(filepath): return # this block was already dumped # use tmp suffix until we finish with that block (in case we crash before we dumped all txs) filepath_tmp = f"{filepath}.tmp" success = __dump_tx_weights_in_block_to_file(h=h, filepath=filepath_tmp) if success: os.rename(filepath_tmp, filepath) else: logger.error(f"Failed to dump weights for transactions of block {h}")
def dump_block_feerates(h: BlockHeight) -> None: """ computes the feerate of all transactions in block at height h and dump them to a text file in the DB_FOLDER directory """ logger.info(f"Dumping feerates for block {h}") filepath = os.path.join(DATA, "feerates_tsv_files", f"block_{h}_feerates.tsv") if os.path.isfile(filepath): return # this block was already dumped # use tmp suffix until we finish with that block (in case we crash before we dumped all txs) filepath_tmp = f"{filepath}.tmp" success = __dump_block_feerates_to_file(h=h, filepath=filepath_tmp) if success: os.rename(filepath_tmp, filepath) else: logger.error(f"Failed to retrieve feerate for a transaction in block {h}")
def main(): args = parse_args() global MAX_WORKERS MAX_WORKERS = args.jobs set_bitcoin_cli(args.bitcoin_cli) if args.last_block != 0: populate_blocks(first_block=args.first_block, last_block=args.last_block) else: # we populate all blocks from first_block to the current height, indefinitely first_block = args.first_block while True: curr_height = blockchain_height() logger.info( f"Populating txs of all blocks from height {args.first_block} to current blockchain height ({curr_height})" ) populate_blocks(first_block=first_block, last_block=curr_height) logger.info("sleeping for 5 minutes") time.sleep(60 * 5)
"from first_block to the current blockchain height, indefinitely" ), ) parser.add_argument( "bitcoin_cli", choices=["master", "user"], metavar="bitcoin_cli", help="the bitcoin-cli to use. must be one of `master` or `user`", ) return parser.parse_args() if __name__ == "__main__": args = parse_args() set_bitcoin_cli(args.bitcoin_cli) if args.last_block != 0: dump_blocks_tx_weights(first_block=args.first_block, last_block=args.last_block) else: # we dump all blocks from first_block to the current height, indefinitely while True: curr_height = blockchain_height() logger.info( f"Dumping all blocks from height {args.first_block} to current blockchain height ({curr_height})" ) dump_blocks_tx_weights(first_block=args.first_block, last_block=curr_height) logger.info("sleeping for 5 minutes") time.sleep(60 * 5) # we may change first_block to curr_height, but we're leaving this # as it is in case some of the blocks failed in the last attempt