def reset_db_state(): """boom! blow away all applicable collections in mongo""" config.mongo_db.processed_blocks.drop() # create/update default app_config object config.mongo_db.app_config.update( {}, { 'db_version': config.DB_VERSION, # counterblockd database version 'running_testnet': config.TESTNET, 'counterpartyd_db_version_major': None, 'counterpartyd_db_version_minor': None, 'counterpartyd_running_testnet': None, 'last_block_assets_compiled': config. BLOCK_FIRST, # for asset data compilation in tasks.py (resets on reparse as well) }, upsert=True) app_config = config.mongo_db.app_config.find()[0] # reinitialize some internal counters config.state['my_latest_block'] = {'block_index': 0} config.state['last_message_index'] = -1 # call any rollback processors for any extension modules RollbackProcessor.run_active_functions(None) return app_config
def rollback(max_block_index): """called if there are any records for blocks higher than this in the database? If so, they were impartially created and we should get rid of them NOTE: after calling this function, you should always trigger a "continue" statement to reiterate the processing loop (which will get a new cp_latest_block from counterpartyd and resume as appropriate) """ assert isinstance(max_block_index, int) and max_block_index >= config.BLOCK_FIRST if not config.mongo_db.processed_blocks.find_one( {"block_index": max_block_index}): raise Exception( "Can't roll back to specified block index: %i doesn't exist in database" % max_block_index) logger.warn("Pruning to block %i ..." % (max_block_index)) config.mongo_db.processed_blocks.remove( {"block_index": { "$gt": max_block_index }}) config.state['last_message_index'] = -1 config.state['caught_up'] = False cache.clear_block_info_cache() config.state[ 'my_latest_block'] = config.mongo_db.processed_blocks.find_one( {"block_index": max_block_index}) or config.LATEST_BLOCK_INIT # call any rollback processors for any extension modules RollbackProcessor.run_active_functions(max_block_index)
def rollback(max_block_index): """called if there are any records for blocks higher than this in the database? If so, they were impartially created and we should get rid of them NOTE: after calling this function, you should always trigger a "continue" statement to reiterate the processing loop (which will get a new cp_latest_block from counterpartyd and resume as appropriate) """ assert isinstance(max_block_index, (int, long)) and max_block_index >= config.BLOCK_FIRST if not config.mongo_db.processed_blocks.find_one({"block_index": max_block_index}): raise Exception("Can't roll back to specified block index: %i doesn't exist in database" % max_block_index) logger.warn("Pruning to block %i ..." % (max_block_index)) config.mongo_db.processed_blocks.remove({"block_index": {"$gt": max_block_index}}) config.state['last_message_index'] = -1 config.state['caught_up'] = False cache.blockinfo_cache.clear() config.state['my_latest_block'] = config.mongo_db.processed_blocks.find_one({"block_index": max_block_index}) or config.LATEST_BLOCK_INIT #call any rollback processors for any extension modules RollbackProcessor.run_active_functions(max_block_index)
def reset_db_state(): """boom! blow away all applicable collections in mongo""" config.mongo_db.processed_blocks.drop() #create/update default app_config object config.mongo_db.app_config.update({}, { 'db_version': config.DB_VERSION, #counterblockd database version 'running_testnet': config.TESTNET, 'counterpartyd_db_version_major': None, 'counterpartyd_db_version_minor': None, 'counterpartyd_running_testnet': None, 'last_block_assets_compiled': config.BLOCK_FIRST, #for asset data compilation in tasks.py (resets on reparse as well) }, upsert=True) app_config = config.mongo_db.app_config.find()[0] #reinitialize some internal counters config.state['my_latest_block'] = {'block_index': 0} config.state['last_message_index'] = -1 #call any rollback processors for any extension modules RollbackProcessor.run_active_functions(None) return app_config