diff --git a/src/dexorder/bin/main.py b/src/dexorder/bin/main.py index fd56066..d17cff4 100644 --- a/src/dexorder/bin/main.py +++ b/src/dexorder/bin/main.py @@ -88,16 +88,21 @@ async def main(): db_state = DbState(BlockData.by_opt('db')) with db.transaction(): state = await db_state.load() - if state is None: - log.info('no state in database') - if redis_state: - await redis_state.clear() - else: - current_blockstate.set(state) - current_fork.set(state.root_fork) - global activate_orders_needed - activate_orders_needed = True - log.info(f'loaded state from db for root block {state.root_branch.height}') + if state is None: + log.info('no state in database') + if redis_state: + await redis_state.clear() + else: + current_blockstate.set(state) + current_fork.set(state.root_fork) + global activate_orders_needed + activate_orders_needed = True + log.info(f'loaded state from db for root block {state.root_branch.height}') + if redis_state: + # load initial state + log.info('initializing redis with root state') + await redis_state.save(state.root_fork, state.diffs_by_branch[state.root_branch.id]) + runner = BlockStateRunner(state, publish_all=publish_all if redis_state else None) setup_logevent_triggers(runner) # OHLC printing hard-disabled for main. Use the finaldata process. @@ -108,10 +113,6 @@ async def main(): runner.on_promotion.append(db_state.finalize) if redis_state: runner.on_head_update.append(redis_state.save) - if db: - # load initial state - log.info('initializing redis with root state') - await redis_state.save(state.root_fork, state.diffs_by_branch[state.root_branch]) runner.on_promotion.append(finalize_transactions) try: