def initialize(window_size, logger): database = lib.get_db() # Special case for new pool startup block_zero = None while block_zero is None: logger.warn("Waiting for the first block record in the database") time.sleep(1) block_zero = Blocks.get_earliest() print("block_zero={}".format(block_zero)) stat_height = max(0, block_zero.height + window_size) seed_stat = Pool_stats( height=stat_height, timestamp=datetime.utcnow(), active_miners=0, shares_processed=0, share_counts=None, total_blocks_found=0, total_shares_processed=0, dirty=False, ) database.db.createDataObj(seed_stat) seed_share = Worker_shares( height=stat_height, user_id=1, timestamp=datetime.utcnow(), ) database.db.createDataObj(seed_share)
def initialize(avg_over_range, logger): database = lib.get_db() # Special case for new pool startup - Need 3 stats records to bootstrap block_zero = None while block_zero is None: logger.warn("Waiting for the first block record in the database") time.sleep(1) block_zero = Blocks.get_earliest() print("block_zero={}".format(block_zero)) height = block_zero.height # Create avg_over_range dummy block records prior to block_zero print("Create block filtters: {} - {}".format(height-avg_over_range, height)) for h in range(height-avg_over_range, height): print("Creating fillter at height {}".format(h)) new_block = Blocks(hash = "x", version = 0, height = h, previous = "x", timestamp = datetime.utcnow(), output_root = "x", range_proof_root = "x", kernel_root = "x", nonce = 0, edge_bits = 29, total_difficulty = block_zero.total_difficulty, secondary_scaling = 0, num_inputs = 0, num_outputs = 0, num_kernels = 0, fee = 0, lock_height = 0, total_kernel_offset = "x", state = "filler") database.db.getSession().add(new_block) database.db.getSession().commit() seed_stat0 = Grin_stats( height=height-2, timestamp=block_zero.timestamp, difficulty=block_zero.total_difficulty) database.db.createDataObj(seed_stat0) seed_stat1 = Grin_stats( height=height-1, timestamp=block_zero.timestamp, difficulty=block_zero.total_difficulty) database.db.createDataObj(seed_stat1) seed_stat2 = Grin_stats( height=height, timestamp=block_zero.timestamp, difficulty=block_zero.total_difficulty) database.db.createDataObj(seed_stat2) return height