def update_funded_flag(flag_value: bool) -> None: key = "dc:isFunded" if flag_value: redis.set_sync(key, "a") # Value does not matter else: redis.delete_sync(key) register()
def set_receieved_verification_for_block_from_chain_sync(block_id: str, level: int, chain_id: str) -> None: """Signify a successful receipt from a higher level node receipt for a certain block (sync) Args: block_id: block_id of lvl 1 block for received receipt level: level of the node from the higher level receipt chain_id: id of the higher level dragonchain receipt """ # Check that this block is accepting verifications for the specified level accepting_verification_level = get_current_block_level_sync(block_id) if accepting_verification_level != level: raise exceptions.NotAcceptingVerifications( f"Block {block_id} is only accepting verifications for level {accepting_verification_level} (Not {level}) at the moment" ) set_key = verifications_key(block_id, level) p = redis.pipeline_sync() p.sadd(set_key, chain_id) p.scard(set_key) verifications = p.execute()[1] # Execute the commands and get the result of the scard operation (number of members in the set) required = dragonnet_config.DRAGONNET_CONFIG[f"l{level}"]["nodesRequired"] # Check if this block needs to be promoted to the next level if verifications >= required: if level >= 5: # If level 5, block needs no more verifications; remove it from the broadcast system remove_block_from_broadcast_system_sync(block_id) else: # Set the block to the next level and schedule it for broadcasting redis.delete_sync(storage_error_key(block_id)) set_current_block_level_sync(block_id, level + 1) schedule_block_for_broadcast_sync(block_id)
def subscribe(redis_key: str) -> None: pop_result = redis.brpop_sync(redis_key, 0, decode=False) if pop_result is None: return _, string_change_request = pop_result redis.delete_sync(f"{redis_key}:errors") _log.debug(f"New message: {string_change_request}") try: change_request = parse_json_or_fail(string_change_request) worker(change_request) _log.debug( f"Total running jobs: {len(background_scheduler.background_scheduler.get_jobs())}" ) except exceptions.TimingEventSchedulerError as e: redis.lpush_sync( f"{redis_key}:errors", json.dumps( { "timestamp": str(datetime.utcnow()), "error": str(e), "command": str(string_change_request) }, separators=(",", ":")), ) _log.exception("FailureByDesign") raise
def clear_processing_queue() -> None: """Clear the processing queue after finishing processing a block successfully""" redis.delete_sync(PROCESSING_TX_KEY)
def test_delete(self): redis.delete_sync("banana") redis.redis_client.delete.assert_called_once_with("banana")