def reload_cached(): """ Recomputes all the cached values that normally get refreshed by tasks. Good to run if celery has been down, site just setup, etc. """ update_pplns_est() update_online_workers() cache_user_donation() server_status() from simplecoin.utils import get_block_stats current_app.logger.info( "Refreshing the block stats (luck, effective return, orphan %)") cache.delete_memoized(get_block_stats) get_block_stats()
def add_block(self, user, height, total_value, transaction_fees, bits, hash_hex, merged=None, worker=None, **kwargs): """ Insert a discovered block & blockchain data user: should be a username/wallet address of who found block height: should be the height of the given block in the blockchain total_value: should be an integer representation of the value of the newly discovered block. E.G. DOGE = 2364681.04976814 network_value = 236468104976814 transaction_fees: should be an integer amount awarded due to transactions handled by the block. E.G. transaction fees on new block = 6.5 transaction_fees = 650000000 """ if merged is True: merged = 'MON' logger.warn( "Received an add block notification!\nUser: {}\nHeight: {}\n" "Total Height: {}\nTransaction Fees: {}\nBits: {}\nHash Hex: {}" .format(user, height, total_value, transaction_fees, bits, hash_hex)) try: last = last_block_share_id_nocache(merged) block = Block.create(user, height, total_value, transaction_fees, bits, hash_hex, time_started=last_block_time_nocache(merged), merged_type=merged, worker=worker) try: db.session.flush() except sqlalchemy.exc.IntegrityError: logger.warn("A duplicate block notification was received, ignoring...!") db.session.rollback() return count = (db.session.query(func.sum(Share.shares)). filter(Share.id > last). filter(Share.id <= block.last_share_id).scalar()) or 128 block.shares_to_solve = count db.session.commit() payout.delay(hash=hash_hex) # Expire cache values for round cache.delete_memoized(last_block_share_id) cache.delete_memoized(last_block_time) cache.delete_memoized(get_round_shares) except Exception as exc: logger.error("Unhandled exception in add_block", exc_info=True) db.session.rollback() raise self.retry(exc=exc)
def add_block(self, user, height, total_value, transaction_fees, bits, hash_hex, merged=None, worker=None, **kwargs): """ Insert a discovered block & blockchain data user: should be a username/wallet address of who found block height: should be the height of the given block in the blockchain total_value: should be an integer representation of the value of the newly discovered block. E.G. DOGE = 2364681.04976814 network_value = 236468104976814 transaction_fees: should be an integer amount awarded due to transactions handled by the block. E.G. transaction fees on new block = 6.5 transaction_fees = 650000000 """ if merged is True: merged = 'MON' logger.warn( "Received an add block notification!\nUser: {}\nHeight: {}\n" "Total Height: {}\nTransaction Fees: {}\nBits: {}\nHash Hex: {}". format(user, height, total_value, transaction_fees, bits, hash_hex)) try: last = last_block_share_id_nocache(merged) block = Block.create(user, height, total_value, transaction_fees, bits, hash_hex, time_started=last_block_time_nocache(merged), merged_type=merged, worker=worker) try: db.session.flush() except sqlalchemy.exc.IntegrityError: logger.warn( "A duplicate block notification was received, ignoring...!") db.session.rollback() return count = (db.session.query(func.sum( Share.shares)).filter(Share.id > last).filter( Share.id <= block.last_share_id).scalar()) or 128 block.shares_to_solve = count db.session.commit() # Expire cache values for round cache.delete_memoized(last_block_share_id) cache.delete_memoized(last_block_time) cache.delete_memoized(get_round_shares) except Exception as exc: logger.error("Unhandled exception in add_block", exc_info=True) db.session.rollback() raise self.retry(exc=exc)