Beispiel #1
0
def get_receieved_verifications_for_block_and_level_sync(block_id: str, level: int) -> set:
    """Get a set of chain_ids for properly receieved receipts from a higher level for a certain block (sync)
    Args:
        block_id: block_id to check for received receipts
        level: Which higher level of receipts to fetch for block_id
    Returns:
        Python set of chain ids (str)
    """
    return redis.smembers_sync(verifications_key(block_id, level))
Beispiel #2
0
def list_registered_transaction_types_v1() -> Dict[str, Any]:
    """
    Lists out the current registered transaction types
    """
    _log.info("Listing out existing transaction types")
    transaction_types = redis.smembers_sync(transaction_type_dao.TYPE_LIST_KEY)
    transaction_type_list = [storage.get_json_from_object(f"{transaction_type_dao.FOLDER}/TYPES/{txn_type}") for txn_type in transaction_types]

    return {"transaction_types": transaction_type_list}
Beispiel #3
0
def process_claims_backlog() -> None:
    claims_set = redis.smembers_sync(
        FAILED_CLAIMS_KEY)  # used sadd to make a set
    _log.info(f"Claim backlog count: {len(claims_set)}")
    for claim_check_id in claims_set:
        try:
            matchmaking.resolve_claim_check(claim_check_id)
        except Exception:
            _log.exception(
                "Failure to finalize claim in matchmaking.  Skipping the rest of the retry queue."
            )
            return  # short-circuit and exit early, matchmaking still unreachable
        redis.srem_sync(FAILED_CLAIMS_KEY, claim_check_id
                        )  # claim successfully finalized, remove from backlog
Beispiel #4
0
def rehydrate_transaction_types() -> None:
    existing_list = redis.smembers_sync("type_list_key")
    if len(existing_list) > 0:
        _log.info("redis is already populated")
        return

    transaction_types = filter(lambda x: len(x.split("/")) == 3,
                               storage.list_objects("TRANSACTION_TYPES"))
    txn_types = list(map(lambda x: x.split("/")[2], transaction_types))
    _log.info("Inserting new list into redis")
    if len(txn_types) > 0:
        response_number = redis.sadd_sync("type_list_key", *txn_types)
        if response_number > 0:
            _log.info("Succeeded in updating redis")
        _log.info(f"response number --> {response_number}")
    else:
        _log.info("No transaction types found to be updated...")
def increment_storage_error_sync(block_id: str, current_level: int) -> None:
    """When getting a storage error/inconsistency between redis/storage, this should be called
    This will roll-back a block to a previous level for verifications if FAULT_TOLERATION is surpassed for a block

    Basically, the state in redis can be a mis-representation of what's in actual storage, and if this occurs, we need to roll back
    the block verifications state and remove any bogus verifications from redis that aren't truly saved in storage, which happens on occasion
    Args:
        block_id: the block_id to increment a storage error
        current_level: the current block verification level state (should be in broadcast:block:state)
    """
    # Don't do anything if at or below level two because no verifications are required yet
    if current_level <= 2:
        return
    error_key = storage_error_key(block_id)
    current_count = int(redis.get_sync(error_key, decode=False) or 0)
    if current_count < FAULT_TOLERATION:
        redis.set_sync(error_key, str(current_count + 1))
        return
    # Beyond fault toleration, we must rollback this block

    # First find all verifications actually in storage
    prefix = f"BLOCK/{block_id}-l{current_level - 1}"
    good_verifications = set()
    for key in storage.list_objects(prefix):
        good_verifications.add(re.search(f"^{prefix}-(.*)",
                                         key).group(1))  # noqa: T484

    # Now find all verifications the system thinks we have in redis
    redis_verifications_key = verifications_key(block_id, current_level - 1)
    all_verifications = redis.smembers_sync(redis_verifications_key)

    # Remove all bad verifications recorded in redis that aren't in storage, and demote block to previous level
    p = redis.pipeline_sync()
    p.srem(redis_verifications_key,
           *all_verifications.difference(good_verifications))
    p.delete(error_key)
    p.set(state_key(block_id), str(current_level - 1))
    p.execute()
Beispiel #6
0
 def test_smembers(self):
     redis.smembers_sync("banana")
     redis.redis_client.smembers.assert_called_once_with("banana")