def process_grin_logmessage(line, database): global LOGGER # Looking for: "Jun 07 02:07:48.470 INFO (Server ID: StratumServer) Got share for block: hash 1a4480ad, height 99845, nonce 14139347905838955360, difficulty 9/1, submitted by 192.168.2.100:13415" if "Got share for block:" in line: match = re.search( r'^(.+) INFO .+ Got share for block: hash (.+), height (\d+), nonce (\d+), difficulty (\d+)/(\d+), submitted by (.+)$', line) s_timestamp = match.group(1) s_hash = match.group(2) s_height = int(match.group(3)) s_nonce = match.group(4) s_share_difficulty = int(match.group(5)) s_network_difficulty = int(match.group(6)) s_worker = match.group(7) sql_timestamp = lib.to_sqltimestamp(s_timestamp) if s_share_difficulty >= s_network_difficulty: share_is_solution = True else: share_is_solution = False # Create a new record new_grin_share = Grin_shares(hash=s_hash, height=s_height, nonce=s_nonce, actual_difficulty=s_share_difficulty, net_difficulty=s_network_difficulty, timestamp=sql_timestamp, found_by=s_worker, is_solution=share_is_solution) duplicate = database.db.createDataObj_ignore_duplicates(new_grin_share) database.db.getSession().commit() if duplicate: LOGGER.warn("Duplicate GrinShare: {}".format(new_grin_share)) else: LOGGER.warn("Added GrinShare: {}".format(new_grin_share)) # If this is a full solution found by us, also add it as a pool block if s_share_difficulty >= s_network_difficulty: new_pool_block = Pool_blocks(hash=s_hash, height=s_height, nonce=s_nonce, actual_difficulty=s_share_difficulty, net_difficulty=s_network_difficulty, timestamp=sql_timestamp, found_by=s_worker, state="new") duplicate = database.db.createDataObj_ignore_duplicates( new_pool_block) database.db.getSession().commit() if duplicate: LOGGER.warn("Duplicate Pool Block: {}".format(new_pool_block)) else: LOGGER.warn("Added Pool Block: {}".format(new_pool_block)) sys.stdout.flush()
def addPoolBlock(self, share): if share.is_valid == False: return new_pool_block = Pool_blocks(hash=share.hash, height=share.height, nonce=share.nonce, actual_difficulty=share.share_difficulty, net_difficulty=share.network_difficulty, timestamp=share.timestamp, found_by=share.found_by, state="new") duplicate = lib.get_db().db.createDataObj_ignore_duplicates( new_pool_block) if duplicate: self.LOGGER.warn("Failed to add duplicate Pool Block: {}".format( new_pool_block.height)) else: self.LOGGER.warn("Added Pool Block: {}".format( new_pool_block.height))
def addPoolBlock(logger, timestamp, height, hash, found_by, serverid): global POOLBLOCK_MUTEX POOLBLOCK_MUTEX.acquire() database = lib.get_db() try: logger.warn( "Adding A PoolBlock: Timestamp: {}, ServerID: {}, Height: {}, Hash: {}" .format(timestamp, serverid, height, hash)) state = "new" this_block = Blocks.get_by_height(height) while this_block is None: this_block = Blocks.get_by_height(height) time.sleep(1) nonce = this_block.nonce actual_difficulty = grin.difficulty(this_block.hash, this_block.edge_bits, this_block.secondary_scaling) net_difficulty = grin.get_network_difficulty(height) # Create the DB record new_pool_block = Pool_blocks(hash=hash, height=height, nonce=nonce, actual_difficulty=actual_difficulty, net_difficulty=net_difficulty, timestamp=timestamp, found_by=found_by, state=state) duplicate = lib.get_db().db.createDataObj_ignore_duplicates( new_pool_block) if duplicate: logger.warn( "Failed to add duplicate Pool Block: {}".format(height)) else: logger.warn("Added Pool Block: {}".format(height)) finally: POOLBLOCK_MUTEX.release()