def parse_block(block_data): config.state['cur_block'] = block_data config.state['cur_block']['block_time_obj'] \ = datetime.datetime.utcfromtimestamp(config.state['cur_block']['block_time']) config.state['cur_block']['block_time_str'] = config.state['cur_block']['block_time_obj'].isoformat() for msg in config.state['cur_block']['_messages']: result = parse_message(msg) if result == 'ABORT_BLOCK_PROCESSING': # reorg return False # run block processor Functions BlockProcessor.run_active_functions() # block successfully processed, track this in our DB new_block = { 'block_index': config.state['cur_block']['block_index'], 'block_time': config.state['cur_block']['block_time_obj'], 'block_hash': config.state['cur_block']['block_hash'], } config.mongo_db.processed_blocks.insert(new_block) config.state['my_latest_block'] = new_block logger.info("Block: %i of %i [message height=%s]" % ( config.state['my_latest_block']['block_index'], config.state['cp_backend_block_index'] if config.state['cp_backend_block_index'] else '???', config.state['last_message_index'] if config.state['last_message_index'] != -1 else '???')) return True
def parse_block(block_data): config.state['cur_block'] = block_data config.state['cur_block']['block_time_obj'] \ = datetime.datetime.utcfromtimestamp(config.state['cur_block']['block_time']) config.state['cur_block']['block_time_str'] = config.state['cur_block']['block_time_obj'].isoformat() cmd = None for msg in config.state['cur_block']['_messages']: cmd = parse_message(msg) if cmd == 'break': break #logger.debug("*config.state* {}".format(config.state)) #Run Block Processor Functions BlockProcessor.run_active_functions() #block successfully processed, track this in our DB new_block = { 'block_index': config.state['cur_block']['block_index'], 'block_time': config.state['cur_block']['block_time_obj'], 'block_hash': config.state['cur_block']['block_hash'], } config.mongo_db.processed_blocks.insert(new_block) config.state['my_latest_block'] = new_block logger.info("Block: %i of %i [message height=%s]" % ( config.state['my_latest_block']['block_index'], config.state['cp_backend_block_index'] \ if config.state['cp_backend_block_index'] else '???', config.state['last_message_index'] if config.state['last_message_index'] != -1 else '???')) if config.state['cp_latest_block_index'] - cur_block_index < config.MAX_REORG_NUM_BLOCKS: #only when we are near the tip clean_mempool_tx()
def parse_block(block_data): config.state['cur_block'] = block_data config.state['cur_block']['block_time_obj'] \ = datetime.datetime.utcfromtimestamp(config.state['cur_block']['block_time']) config.state['cur_block']['block_time_str'] = config.state[ 'cur_block']['block_time_obj'].isoformat() cmd = None for msg in config.state['cur_block']['_messages']: cmd = parse_message(msg) if cmd == 'break': break #logger.debug("*config.state* {}".format(config.state)) #Run Block Processor Functions BlockProcessor.run_active_functions() #block successfully processed, track this in our DB new_block = { 'block_index': config.state['cur_block']['block_index'], 'block_time': config.state['cur_block']['block_time_obj'], 'block_hash': config.state['cur_block']['block_hash'], } config.mongo_db.processed_blocks.insert(new_block) config.state['my_latest_block'] = new_block logger.info("Block: %i of %i [message height=%s]" % ( config.state['my_latest_block']['block_index'], config.state['cp_backend_block_index'] \ if config.state['cp_backend_block_index'] else '???', config.state['last_message_index'] if config.state['last_message_index'] != -1 else '???')) if config.state[ 'cp_latest_block_index'] - cur_block_index < config.MAX_REORG_NUM_BLOCKS: #only when we are near the tip clean_mempool_tx()