Exemple #1
0
def test_commit_works_after_catchup(alh, db_manager, initial_domain_size,
                                    initial_pool_size, initial_config_size,
                                    initial_seq_no):
    size_before = alh.ledger.size

    # apply and commit batch
    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=35,
                       txn_time=11111)
    txn_root_hash = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    alh.commit_batch(FakeSomething())

    # add txns to audit ledger emulating catchup
    caughtup_txns = 5
    txns_per_batch = 2
    add_txns_to_audit(alh,
                      count=caughtup_txns,
                      ledger_id=POOL_LEDGER_ID,
                      txns_per_batch=txns_per_batch,
                      view_no=3,
                      initial_pp_seq_no=36,
                      pp_time=11222)
    alh.on_catchup_finished()

    # apply and commit new batch
    do_apply_audit_txn(alh,
                       txns_count=3,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=45,
                       txn_time=21111)
    assert alh.ledger.uncommitted_size == alh.ledger.size + 1

    txn_root_hash = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    alh.commit_batch(FakeSomething())

    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 2 + caughtup_txns
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=45,
                    seq_no=initial_seq_no + 2 + caughtup_txns,
                    txn_time=21111,
                    txn_roots={DOMAIN_LEDGER_ID: txn_root_hash},
                    state_roots={DOMAIN_LEDGER_ID: state_root_hash},
                    pool_size=initial_pool_size +
                    txns_per_batch * caughtup_txns,
                    domain_size=initial_domain_size + 7 + 3,
                    config_size=initial_config_size,
                    last_pool_seqno=initial_seq_no + 1 + caughtup_txns,
                    last_domain_seqno=None,
                    last_config_seqno=None,
                    primaries=2 * (caughtup_txns + 1))
Exemple #2
0
def check_apply_audit_txn(alh,
                          txns_count, ledger_id,
                          view_no, pp_sq_no, txn_time, seq_no,
                          pool_size, domain_size, config_size,
                          last_pool_seqno, last_domain_seqno, last_config_seqno):
    db_manager = alh.database_manager
    uncommited_size_before = alh.ledger.uncommitted_size
    size_before = alh.ledger.size

    do_apply_audit_txn(alh,
                       txns_count=txns_count, ledger_id=ledger_id,
                       view_no=view_no, pp_sq_no=pp_sq_no, txn_time=txn_time)

    assert alh.ledger.uncommitted_size == uncommited_size_before + 1
    assert alh.ledger.size == size_before

    txn = alh.ledger.get_uncommitted_txns()[-1]
    check_audit_txn(txn=txn,
                    view_no=view_no, pp_seq_no=pp_sq_no,
                    seq_no=seq_no, txn_time=txn_time,
                    ledger_id=ledger_id,
                    txn_root=db_manager.get_ledger(ledger_id).uncommitted_root_hash,
                    state_root=db_manager.get_state(ledger_id).headHash,
                    pool_size=pool_size, domain_size=domain_size, config_size=config_size,
                    last_pool_seqno=last_pool_seqno,
                    last_domain_seqno=last_domain_seqno,
                    last_config_seqno=last_config_seqno)
Exemple #3
0
def test_transform_txn_for_catchup_rep(alh, db_manager,
                                       initial_domain_size, initial_pool_size, initial_config_size):
    do_apply_audit_txn(alh,
                       txns_count=10, ledger_id=DOMAIN_LEDGER_ID,
                       view_no=0, pp_sq_no=1, txn_time=10000,
                       has_audit_txn=True)

    audit_txn_after_serialization = \
        JsonSerializer.loads(
            JsonSerializer.dumps(
                alh.ledger.get_last_txn()
            )
        )

    transformed_audit_txn = alh.transform_txn_for_ledger(audit_txn_after_serialization)
    check_audit_txn(txn=transformed_audit_txn,
                    view_no=0, pp_seq_no=1,
                    seq_no=1, txn_time=10000,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=db_manager.get_ledger(DOMAIN_LEDGER_ID).uncommitted_root_hash,
                    state_root=db_manager.get_state(DOMAIN_LEDGER_ID).headHash,
                    pool_size=initial_pool_size,
                    domain_size=initial_domain_size + 10,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None)
Exemple #4
0
def test_apply_revert_commit(alh, db_manager,
                             initial_domain_size, initial_pool_size, initial_config_size,
                             initial_seq_no):
    size_before = alh.ledger.size

    # apply 2 batches
    do_apply_audit_txn(alh,
                       txns_count=7, ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3, pp_sq_no=35, txn_time=11111)
    txn_root_hash_1 = db_manager.get_ledger(DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_1 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=15, ledger_id=POOL_LEDGER_ID,
                       view_no=3, pp_sq_no=36, txn_time=11112)

    # reject 2d batch
    alh.post_batch_rejected(POOL_LEDGER_ID)
    assert alh.ledger.uncommitted_size == alh.ledger.size + 1
    assert alh.ledger.size == size_before

    # commit 1st batch
    alh.commit_batch(DOMAIN_LEDGER_ID, 7, state_root_hash_1, txn_root_hash_1, 11111)
    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 1
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3, pp_seq_no=35,
                    seq_no=initial_seq_no + 1, txn_time=11111,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=txn_root_hash_1,
                    state_root=state_root_hash_1,
                    pool_size=initial_pool_size, domain_size=initial_domain_size + 7, config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None)
Exemple #5
0
def test_commit_one_batch(alh, db_manager, initial_domain_size,
                          initial_pool_size, initial_config_size,
                          initial_seq_no):
    size_before = alh.ledger.size
    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=35,
                       txn_time=11111)
    txn_root_hash = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    alh.commit_batch(DOMAIN_LEDGER_ID, 7, state_root_hash, txn_root_hash,
                     11111)

    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 1
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=35,
                    seq_no=initial_seq_no + 1,
                    txn_time=11111,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=txn_root_hash,
                    state_root=state_root_hash,
                    pool_size=initial_pool_size,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None)
Exemple #6
0
def test_commit_one_batch(alh, db_manager,
                          initial_domain_size, initial_pool_size, initial_config_size,
                          initial_seq_no):
    size_before = alh.ledger.size
    do_apply_audit_txn(alh,
                       txns_count=7, ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3, pp_sq_no=35, txn_time=11111)
    txn_root_hash = db_manager.get_ledger(DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    pool_txn_root_hash = db_manager.get_ledger(POOL_LEDGER_ID).uncommitted_root_hash
    pool_state_root_hash = db_manager.get_state(POOL_LEDGER_ID).headHash
    alh.commit_batch(FakeSomething())

    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 1
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3, pp_seq_no=35,
                    seq_no=initial_seq_no + 1, txn_time=11111,
                    txn_roots={
                        DOMAIN_LEDGER_ID: txn_root_hash,
                        POOL_LEDGER_ID: pool_txn_root_hash
                    },
                    state_roots={
                        DOMAIN_LEDGER_ID: state_root_hash,
                        POOL_LEDGER_ID: pool_state_root_hash
                    },
                    pool_size=initial_pool_size, domain_size=initial_domain_size + 7, config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None,
                    primaries=DEFAULT_PRIMARIES)
def test_revert_works_after_catchup(alh, db_manager, initial_domain_size,
                                    initial_pool_size, initial_config_size,
                                    initial_seq_no):
    size_before = alh.ledger.size

    # apply and commit batch
    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=35,
                       txn_time=11111)
    txn_root_hash = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    alh.commit_batch(DOMAIN_LEDGER_ID, 7, state_root_hash, txn_root_hash,
                     11111)

    # add txns to audit ledger emulating catchup
    caughtup_txns = 5
    txns_per_batch = 2
    add_txns_to_audit(alh,
                      count=caughtup_txns,
                      ledger_id=POOL_LEDGER_ID,
                      txns_per_batch=txns_per_batch,
                      view_no=3,
                      initial_pp_seq_no=36,
                      pp_time=11222)

    # apply and revert new batch
    do_apply_audit_txn(alh,
                       txns_count=3,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=45,
                       txn_time=21111)
    assert alh.ledger.uncommitted_size == alh.ledger.size + 1

    alh.post_batch_rejected(DOMAIN_LEDGER_ID)

    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 1 + caughtup_txns
    txn_root_hash = db_manager.get_ledger(POOL_LEDGER_ID).uncommitted_root_hash
    state_root_hash = db_manager.get_state(POOL_LEDGER_ID).headHash
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=36 + caughtup_txns - 1,
                    seq_no=initial_seq_no + 1 + caughtup_txns,
                    txn_time=11222,
                    ledger_id=POOL_LEDGER_ID,
                    txn_root=txn_root_hash,
                    state_root=state_root_hash,
                    pool_size=initial_pool_size +
                    txns_per_batch * caughtup_txns,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=1,
                    last_config_seqno=None)
def check_apply_audit_txn(alh,
                          txns_count,
                          ledger_ids,
                          view_no,
                          pp_sq_no,
                          txn_time,
                          seq_no,
                          pool_size,
                          domain_size,
                          config_size,
                          last_pool_seqno,
                          last_domain_seqno,
                          last_config_seqno,
                          primaries,
                          other_sizes={},
                          original_view_no=None,
                          digest=''):
    db_manager = alh.database_manager
    uncommited_size_before = alh.ledger.uncommitted_size
    size_before = alh.ledger.size

    do_apply_audit_txn(alh,
                       txns_count=txns_count,
                       ledger_id=ledger_ids[0],
                       view_no=view_no,
                       pp_sq_no=pp_sq_no,
                       txn_time=txn_time,
                       original_view_no=original_view_no,
                       digest=digest)

    assert alh.ledger.uncommitted_size == uncommited_size_before + 1
    assert alh.ledger.size == size_before

    txn = alh.ledger.get_uncommitted_txns()[-1]
    expected_view_no = original_view_no if original_view_no is not None else view_no
    check_audit_txn(txn=txn,
                    view_no=expected_view_no,
                    pp_seq_no=pp_sq_no,
                    seq_no=seq_no,
                    txn_time=txn_time,
                    txn_roots={
                        ledger_id:
                        db_manager.get_ledger(ledger_id).uncommitted_root_hash
                        for ledger_id in ledger_ids
                    },
                    state_roots={
                        ledger_id: db_manager.get_state(ledger_id).headHash
                        for ledger_id in ledger_ids
                    },
                    pool_size=pool_size,
                    domain_size=domain_size,
                    config_size=config_size,
                    last_pool_seqno=last_pool_seqno,
                    last_domain_seqno=last_domain_seqno,
                    last_config_seqno=last_config_seqno,
                    primaries=primaries,
                    other_sizes=other_sizes,
                    digest=digest)
Exemple #9
0
def test_apply_revert_commit(alh, db_manager, initial_domain_size,
                             initial_pool_size, initial_config_size,
                             initial_seq_no):
    size_before = alh.ledger.size

    # apply 2 batches
    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=35,
                       txn_time=11111)
    txn_root_hash_1 = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_1 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash
    txn_root_hash_2 = db_manager.get_ledger(
        POOL_LEDGER_ID).uncommitted_root_hash
    state_root_hash_2 = db_manager.get_state(POOL_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=15,
                       ledger_id=POOL_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=36,
                       txn_time=11112)

    # reject 2d batch
    alh.post_batch_rejected(POOL_LEDGER_ID)
    assert alh.ledger.uncommitted_size == alh.ledger.size + 1
    assert alh.ledger.size == size_before

    # commit 1st batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 1
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=35,
                    seq_no=initial_seq_no + 1,
                    txn_time=11111,
                    txn_roots={
                        DOMAIN_LEDGER_ID: txn_root_hash_1,
                        POOL_LEDGER_ID: txn_root_hash_2
                    },
                    state_roots={
                        DOMAIN_LEDGER_ID: state_root_hash_1,
                        POOL_LEDGER_ID: state_root_hash_2
                    },
                    pool_size=initial_pool_size,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None,
                    primaries=DEFAULT_PRIMARIES,
                    node_reg=DEFAULT_NODE_REG)
def test_reject_batch(alh, db_manager, initial_domain_size, initial_pool_size,
                      initial_config_size):
    uncommited_size_before = alh.ledger.uncommitted_size
    size_before = alh.ledger.size

    do_apply_audit_txn(alh,
                       txns_count=5,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=37,
                       txn_time=11112)
    txn_root_hash_1 = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_1 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash

    txn_root_hash_2_pre = db_manager.get_ledger(
        POOL_LEDGER_ID).uncommitted_root_hash
    state_root_hash_2_pre = db_manager.get_state(POOL_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=6,
                       ledger_id=POOL_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=38,
                       txn_time=11113)
    txn_root_hash_2 = db_manager.get_ledger(
        POOL_LEDGER_ID).uncommitted_root_hash
    state_root_hash_2 = db_manager.get_state(POOL_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=CONFIG_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=39,
                       txn_time=11114)
    txn_root_hash_3 = db_manager.get_ledger(
        CONFIG_LEDGER_ID).uncommitted_root_hash
    state_root_hash_3 = db_manager.get_state(CONFIG_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=8,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=40,
                       txn_time=11115)

    assert alh.ledger.uncommitted_size == uncommited_size_before + 4
    assert alh.ledger.size == size_before

    alh.post_batch_rejected(DOMAIN_LEDGER_ID)
    assert alh.ledger.uncommitted_size == uncommited_size_before + 3
    assert alh.ledger.size == size_before
    check_audit_txn(txn=alh.ledger.get_last_txn(),
                    view_no=3,
                    pp_seq_no=39,
                    seq_no=3,
                    txn_time=11114,
                    txn_roots={
                        CONFIG_LEDGER_ID: txn_root_hash_3,
                    },
                    state_roots={
                        CONFIG_LEDGER_ID: state_root_hash_3,
                    },
                    pool_size=initial_pool_size + 6,
                    domain_size=initial_domain_size + 5,
                    config_size=initial_config_size + 7,
                    last_pool_seqno=2,
                    last_domain_seqno=1,
                    last_config_seqno=None,
                    primaries=2)

    alh.post_batch_rejected(DOMAIN_LEDGER_ID)
    assert alh.ledger.uncommitted_size == uncommited_size_before + 2
    assert alh.ledger.size == size_before
    check_audit_txn(txn=alh.ledger.get_last_txn(),
                    view_no=3,
                    pp_seq_no=38,
                    seq_no=2,
                    txn_time=11113,
                    txn_roots={
                        POOL_LEDGER_ID: txn_root_hash_2,
                    },
                    state_roots={
                        POOL_LEDGER_ID: state_root_hash_2,
                    },
                    pool_size=initial_pool_size + 6,
                    domain_size=initial_domain_size + 5,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=1,
                    last_config_seqno=None,
                    primaries=1)

    alh.post_batch_rejected(DOMAIN_LEDGER_ID)
    assert alh.ledger.uncommitted_size == uncommited_size_before + 1
    assert alh.ledger.size == size_before
    check_audit_txn(txn=alh.ledger.get_last_txn(),
                    view_no=3,
                    pp_seq_no=37,
                    seq_no=1,
                    txn_time=11112,
                    txn_roots={
                        DOMAIN_LEDGER_ID: txn_root_hash_1,
                        POOL_LEDGER_ID: txn_root_hash_2_pre
                    },
                    state_roots={
                        DOMAIN_LEDGER_ID: state_root_hash_1,
                        POOL_LEDGER_ID: state_root_hash_2_pre
                    },
                    pool_size=initial_pool_size,
                    domain_size=initial_domain_size + 5,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None,
                    primaries=DEFAULT_PRIMARIES)

    alh.post_batch_rejected(DOMAIN_LEDGER_ID)
    assert alh.ledger.uncommitted_size == uncommited_size_before
    assert alh.ledger.size == size_before
    assert alh.ledger.get_last_txn() is None
def test_commit_multiple_batches(alh, db_manager, initial_domain_size,
                                 initial_pool_size, initial_config_size,
                                 initial_seq_no):
    size_before = alh.ledger.size

    # apply 5 3PC batches
    do_apply_audit_txn(alh,
                       txns_count=7,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=35,
                       txn_time=11111)
    txn_root_hash_1 = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_1 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=15,
                       ledger_id=POOL_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=36,
                       txn_time=11112)
    txn_root_hash_2 = db_manager.get_ledger(
        POOL_LEDGER_ID).uncommitted_root_hash
    state_root_hash_2 = db_manager.get_state(POOL_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=5,
                       ledger_id=CONFIG_LEDGER_ID,
                       view_no=3,
                       pp_sq_no=37,
                       txn_time=11112)
    txn_root_hash_3 = db_manager.get_ledger(
        CONFIG_LEDGER_ID).uncommitted_root_hash
    state_root_hash_3 = db_manager.get_state(CONFIG_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=10,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=4,
                       pp_sq_no=1,
                       txn_time=11115)
    txn_root_hash_4 = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_4 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash

    do_apply_audit_txn(alh,
                       txns_count=20,
                       ledger_id=DOMAIN_LEDGER_ID,
                       view_no=4,
                       pp_sq_no=2,
                       txn_time=11119)
    txn_root_hash_5 = db_manager.get_ledger(
        DOMAIN_LEDGER_ID).uncommitted_root_hash
    state_root_hash_5 = db_manager.get_state(DOMAIN_LEDGER_ID).headHash

    assert alh.ledger.uncommitted_size == alh.ledger.size + 5

    # commit 1st batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size + 4
    assert alh.ledger.size == size_before + 1
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=35,
                    seq_no=initial_seq_no + 1,
                    txn_time=11111,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=txn_root_hash_1,
                    state_root=state_root_hash_1,
                    pool_size=initial_pool_size,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=None,
                    last_config_seqno=None,
                    primaries=1)

    # commit 2d batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size + 3
    assert alh.ledger.size == size_before + 2
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=36,
                    seq_no=initial_seq_no + 2,
                    txn_time=11112,
                    ledger_id=POOL_LEDGER_ID,
                    txn_root=txn_root_hash_2,
                    state_root=state_root_hash_2,
                    pool_size=initial_pool_size + 15,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size,
                    last_pool_seqno=None,
                    last_domain_seqno=initial_seq_no + 1,
                    last_config_seqno=None,
                    primaries=2)

    # commit 3d batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size + 2
    assert alh.ledger.size == size_before + 3
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=3,
                    pp_seq_no=37,
                    seq_no=initial_seq_no + 3,
                    txn_time=11112,
                    ledger_id=CONFIG_LEDGER_ID,
                    txn_root=txn_root_hash_3,
                    state_root=state_root_hash_3,
                    pool_size=initial_pool_size + 15,
                    domain_size=initial_domain_size + 7,
                    config_size=initial_config_size + 5,
                    last_pool_seqno=initial_seq_no + 2,
                    last_domain_seqno=initial_seq_no + 1,
                    last_config_seqno=None,
                    primaries=3)

    # commit 4th batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size + 1
    assert alh.ledger.size == size_before + 4
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=4,
                    pp_seq_no=1,
                    seq_no=initial_seq_no + 4,
                    txn_time=11115,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=txn_root_hash_4,
                    state_root=state_root_hash_4,
                    pool_size=initial_pool_size + 15,
                    domain_size=initial_domain_size + 7 + 10,
                    config_size=initial_config_size + 5,
                    last_pool_seqno=initial_seq_no + 2,
                    last_domain_seqno=None,
                    last_config_seqno=initial_seq_no + 3,
                    primaries=4)

    # commit 5th batch
    alh.commit_batch(FakeSomething())
    assert alh.ledger.uncommitted_size == alh.ledger.size
    assert alh.ledger.size == size_before + 5
    check_audit_txn(txn=alh.ledger.get_last_committed_txn(),
                    view_no=4,
                    pp_seq_no=2,
                    seq_no=initial_seq_no + 5,
                    txn_time=11119,
                    ledger_id=DOMAIN_LEDGER_ID,
                    txn_root=txn_root_hash_5,
                    state_root=state_root_hash_5,
                    pool_size=initial_pool_size + 15,
                    domain_size=initial_domain_size + 7 + 10 + 20,
                    config_size=initial_config_size + 5,
                    last_pool_seqno=initial_seq_no + 2,
                    last_domain_seqno=None,
                    last_config_seqno=initial_seq_no + 3,
                    primaries=5)
Exemple #12
0
def test_audit_ledger_updated_after_freshness_updated(looper, tconf,
                                                      txnPoolNodeSet,
                                                      initial_domain_size,
                                                      initial_pool_size,
                                                      initial_config_size):
    # 1. Wait for the first freshness update
    looper.run(
        eventually(check_freshness_updated_for_all,
                   txnPoolNodeSet,
                   timeout=2 * FRESHNESS_TIMEOUT))

    audit_size_initial = [node.auditLedger.size for node in txnPoolNodeSet]
    view_no = txnPoolNodeSet[0].master_replica.last_ordered_3pc[0]
    pp_seq_no = txnPoolNodeSet[0].master_replica.last_ordered_3pc[1]
    initial_seq_no = txnPoolNodeSet[0].auditLedger.size

    # 2. Wait for the second freshness update
    bls_multi_sigs_after_first_update = get_all_multi_sig_values_for_all_nodes(
        txnPoolNodeSet)
    looper.run(
        eventually(check_updated_bls_multi_sig_for_all_ledgers,
                   txnPoolNodeSet,
                   bls_multi_sigs_after_first_update,
                   FRESHNESS_TIMEOUT,
                   timeout=FRESHNESS_TIMEOUT + 5))

    # 3. check that there is audit ledger txn created for each ledger updated as a freshness check
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=3)
    for node in txnPoolNodeSet:
        check_audit_txn(txn=node.auditLedger.getBySeqNo(node.auditLedger.size -
                                                        2),
                        view_no=view_no,
                        pp_seq_no=pp_seq_no + 1,
                        seq_no=initial_seq_no + 1,
                        txn_time=node.master_replica._ordering_service.
                        last_accepted_pre_prepare_time,
                        txn_roots={
                            POOL_LEDGER_ID:
                            node.getLedger(POOL_LEDGER_ID).tree.root_hash
                        },
                        state_roots={
                            POOL_LEDGER_ID:
                            node.getState(POOL_LEDGER_ID).committedHeadHash
                        },
                        pool_size=initial_pool_size,
                        domain_size=initial_domain_size,
                        config_size=initial_config_size,
                        last_pool_seqno=None,
                        last_domain_seqno=2,
                        last_config_seqno=3,
                        primaries=pp_seq_no + 1 - 1)

        check_audit_txn(txn=node.auditLedger.getBySeqNo(node.auditLedger.size -
                                                        1),
                        view_no=view_no,
                        pp_seq_no=pp_seq_no + 2,
                        seq_no=initial_seq_no + 2,
                        txn_time=node.master_replica._ordering_service.
                        last_accepted_pre_prepare_time,
                        txn_roots={
                            DOMAIN_LEDGER_ID:
                            node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash
                        },
                        state_roots={
                            DOMAIN_LEDGER_ID:
                            node.getState(DOMAIN_LEDGER_ID).committedHeadHash
                        },
                        pool_size=initial_pool_size,
                        domain_size=initial_domain_size,
                        config_size=initial_config_size,
                        last_pool_seqno=4,
                        last_domain_seqno=None,
                        last_config_seqno=3,
                        primaries=pp_seq_no + 2 - 1)

        check_audit_txn(txn=node.auditLedger.getBySeqNo(node.auditLedger.size),
                        view_no=view_no,
                        pp_seq_no=pp_seq_no + 3,
                        seq_no=initial_seq_no + 3,
                        txn_time=node.master_replica._ordering_service.
                        last_accepted_pre_prepare_time,
                        txn_roots={
                            CONFIG_LEDGER_ID:
                            node.getLedger(CONFIG_LEDGER_ID).tree.root_hash
                        },
                        state_roots={
                            CONFIG_LEDGER_ID:
                            node.getState(CONFIG_LEDGER_ID).committedHeadHash
                        },
                        pool_size=initial_pool_size,
                        domain_size=initial_domain_size,
                        config_size=initial_config_size,
                        last_pool_seqno=4,
                        last_domain_seqno=5,
                        last_config_seqno=None,
                        primaries=pp_seq_no + 3 - 1)
def test_audit_ledger_view_change(looper, txnPoolNodeSet,
                                  sdk_pool_handle, sdk_wallet_client, sdk_wallet_steward,
                                  initial_domain_size, initial_pool_size, initial_config_size,
                                  tdir,
                                  tconf,
                                  allPluginsPath,
                                  view_no, pp_seq_no,
                                  initial_seq_no,
                                  monkeypatch):
    '''
    1. Send a NODE transaction and add a 7th Node for adding a new instance,
    but delay Ordered messages.
    2. Send a NYM txn.
    3. Reset delays in executing force_process_ordered
    4. Check that an audit txn for the NYM txn uses primary list from uncommitted
    audit with a new list of primaries.
    '''
    other_nodes = txnPoolNodeSet[:-1]
    slow_node = txnPoolNodeSet[-1]
    # Add a new steward for creating a new node
    new_steward_wallet_handle = sdk_add_new_nym(looper,
                                                sdk_pool_handle,
                                                sdk_wallet_steward,
                                                alias="newSteward",
                                                role=STEWARD_STRING)

    audit_size_initial = [node.auditLedger.size for node in txnPoolNodeSet]

    ordereds = []
    monkeypatch.setattr(slow_node, 'try_processing_ordered', lambda msg: ordereds.append(msg))

    with delay_rules([n.nodeIbStasher for n in txnPoolNodeSet], icDelay()):

        # Send NODE txn fo 7th node
        new_node = sdk_add_new_node(looper,
                                    sdk_pool_handle,
                                    new_steward_wallet_handle,
                                    "Theta",
                                    tdir,
                                    tconf,
                                    allPluginsPath)

        txnPoolNodeSet.append(new_node)
        looper.run(checkNodesConnected(other_nodes + [new_node]))

        sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                                  sdk_wallet_client, 1)

        check_audit_ledger_updated(audit_size_initial, [slow_node],
                                   audit_txns_added=0)
        looper.run(eventually(check_audit_ledger_uncommitted_updated,
                              audit_size_initial, [slow_node], 2))

        def patch_force_process_ordered():
            for msg in list(ordereds):
                slow_node.replicas[msg.instId].outBox.append(msg)
                ordereds.remove(msg)
            monkeypatch.undo()
            slow_node.force_process_ordered()

        assert ordereds
        monkeypatch.setattr(slow_node, 'force_process_ordered', patch_force_process_ordered)

    looper.run(eventually(lambda: assertExp(all(n.viewNo == 1 for n in txnPoolNodeSet))))
    ensureElectionsDone(looper=looper, nodes=txnPoolNodeSet)
    looper.run(eventually(lambda: assertExp(not ordereds)))

    for node in txnPoolNodeSet:
        last_txn = node.auditLedger.get_last_txn()
        last_txn['txn']['data']['primaries'] = node._get_last_audited_primaries()
        check_audit_txn(txn=last_txn,
                        view_no=view_no + 1, pp_seq_no=1,
                        seq_no=initial_seq_no + 4,
                        txn_time=node.master_replica._ordering_service.last_accepted_pre_prepare_time,
                        txn_roots={DOMAIN_LEDGER_ID: node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash},
                        state_roots={DOMAIN_LEDGER_ID: node.getState(DOMAIN_LEDGER_ID).committedHeadHash},
                        pool_size=initial_pool_size + 1, domain_size=initial_domain_size + 2,
                        config_size=initial_config_size,
                        last_pool_seqno=2,
                        last_domain_seqno=1,
                        last_config_seqno=None,
                        primaries=node.write_manager.future_primary_handler.get_last_primaries() or node.primaries)
def test_audit_ledger_updated_after_ordering(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client,
        sdk_wallet_stewards, initial_domain_size, initial_pool_size,
        initial_config_size, view_no, pp_seq_no, initial_seq_no):
    '''
    Order 2 domain txns, 2 pool txns, and then 1 domain txn
    Check that audit ledger is correctly updated in all cases
    '''
    # 1st domain txn
    audit_size_initial = [node.auditLedger.size for node in txnPoolNodeSet]
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=1)
    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 1,
            seq_no=initial_seq_no + 1,
            txn_time=node.master_replica.last_accepted_pre_prepare_time,
            ledger_id=DOMAIN_LEDGER_ID,
            txn_root=node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash,
            state_root=node.getState(DOMAIN_LEDGER_ID).committedHeadHash,
            pool_size=initial_pool_size,
            domain_size=initial_domain_size + 1,
            config_size=initial_config_size,
            last_pool_seqno=None,
            last_domain_seqno=None,
            last_config_seqno=None)

    # 2d domain txn
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=2)
    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 2,
            seq_no=initial_seq_no + 2,
            txn_time=node.master_replica.last_accepted_pre_prepare_time,
            ledger_id=DOMAIN_LEDGER_ID,
            txn_root=node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash,
            state_root=node.getState(DOMAIN_LEDGER_ID).committedHeadHash,
            pool_size=initial_pool_size,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=None,
            last_domain_seqno=None,
            last_config_seqno=None)

    # 1st pool txn
    sdk_change_bls_key(looper,
                       txnPoolNodeSet,
                       txnPoolNodeSet[3],
                       sdk_pool_handle,
                       sdk_wallet_stewards[3],
                       check_functional=False)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=3)
    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 3,
            seq_no=initial_seq_no + 3,
            txn_time=node.master_replica.last_accepted_pre_prepare_time,
            ledger_id=POOL_LEDGER_ID,
            txn_root=node.getLedger(POOL_LEDGER_ID).tree.root_hash,
            state_root=node.getState(POOL_LEDGER_ID).committedHeadHash,
            pool_size=initial_pool_size + 1,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=None,
            last_domain_seqno=2,
            last_config_seqno=None)

    # 2d pool txn
    sdk_change_bls_key(looper,
                       txnPoolNodeSet,
                       txnPoolNodeSet[3],
                       sdk_pool_handle,
                       sdk_wallet_stewards[3],
                       check_functional=False)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=4)
    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 4,
            seq_no=initial_seq_no + 4,
            txn_time=node.master_replica.last_accepted_pre_prepare_time,
            ledger_id=POOL_LEDGER_ID,
            txn_root=node.getLedger(POOL_LEDGER_ID).tree.root_hash,
            state_root=node.getState(POOL_LEDGER_ID).committedHeadHash,
            pool_size=initial_pool_size + 2,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=None,
            last_domain_seqno=2,
            last_config_seqno=None)

    # one more domain txn
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=5)
    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 5,
            seq_no=initial_seq_no + 5,
            txn_time=node.master_replica.last_accepted_pre_prepare_time,
            ledger_id=DOMAIN_LEDGER_ID,
            txn_root=node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash,
            state_root=node.getState(DOMAIN_LEDGER_ID).committedHeadHash,
            pool_size=initial_pool_size + 2,
            domain_size=initial_domain_size + 3,
            config_size=initial_config_size,
            last_pool_seqno=4,
            last_domain_seqno=None,
            last_config_seqno=None)
Exemple #15
0
def test_audit_ledger_updated_after_ordering(
        looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client,
        sdk_wallet_stewards, initial_domain_size, initial_pool_size,
        initial_config_size, view_no, pp_seq_no, initial_seq_no):
    """
    Order 2 domain txns, 2 pool txns, and then 1 domain txn
    Check that audit ledger is correctly updated in all cases
    """

    # 1st domain txn
    audit_size_initial = [node.auditLedger.size for node in txnPoolNodeSet]
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=1)

    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 1,
            seq_no=initial_seq_no + 1,
            txn_time=node.master_replica._ordering_service.
            last_accepted_pre_prepare_time,
            txn_roots={
                POOL_LEDGER_ID: node.getLedger(POOL_LEDGER_ID).tree.root_hash,
                DOMAIN_LEDGER_ID:
                node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash
            },
            state_roots={
                POOL_LEDGER_ID:
                node.getState(POOL_LEDGER_ID).committedHeadHash,
                DOMAIN_LEDGER_ID:
                node.getState(DOMAIN_LEDGER_ID).committedHeadHash
            },
            pool_size=initial_pool_size,
            domain_size=initial_domain_size + 1,
            config_size=initial_config_size,
            last_pool_seqno=None,
            last_domain_seqno=None,
            last_config_seqno=None,
            primaries=node.primaries,
            digest=node.master_replica._consensus_data.prepared[pp_seq_no + 1 -
                                                                1].pp_digest,
            node_reg=[n.name for n in txnPoolNodeSet])

    # 2d domain txn
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=2)

    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 2,
            seq_no=initial_seq_no + 2,
            txn_time=node.master_replica._ordering_service.
            last_accepted_pre_prepare_time,
            txn_roots={
                DOMAIN_LEDGER_ID:
                node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash
            },
            state_roots={
                DOMAIN_LEDGER_ID:
                node.getState(DOMAIN_LEDGER_ID).committedHeadHash
            },
            pool_size=initial_pool_size,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=1,
            last_domain_seqno=None,
            last_config_seqno=None,
            primaries=1,
            digest=node.master_replica._consensus_data.prepared[pp_seq_no + 2 -
                                                                1].pp_digest,
            node_reg=1)

    # 1st pool txn
    sdk_change_bls_key(looper,
                       txnPoolNodeSet,
                       txnPoolNodeSet[3],
                       sdk_pool_handle,
                       sdk_wallet_stewards[3],
                       check_functional=False)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=3)

    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 3,
            seq_no=initial_seq_no + 3,
            txn_time=node.master_replica._ordering_service.
            last_accepted_pre_prepare_time,
            txn_roots={
                POOL_LEDGER_ID: node.getLedger(POOL_LEDGER_ID).tree.root_hash
            },
            state_roots={
                POOL_LEDGER_ID: node.getState(POOL_LEDGER_ID).committedHeadHash
            },
            pool_size=initial_pool_size + 1,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=1,
            last_domain_seqno=2,
            last_config_seqno=None,
            primaries=2,
            digest=node.master_replica._consensus_data.prepared[pp_seq_no + 3 -
                                                                1].pp_digest,
            node_reg=2)

    # 2d pool txn
    sdk_change_bls_key(looper,
                       txnPoolNodeSet,
                       txnPoolNodeSet[3],
                       sdk_pool_handle,
                       sdk_wallet_stewards[3],
                       check_functional=False)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=4)

    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 4,
            seq_no=initial_seq_no + 4,
            txn_time=node.master_replica._ordering_service.
            last_accepted_pre_prepare_time,
            txn_roots={
                POOL_LEDGER_ID: node.getLedger(POOL_LEDGER_ID).tree.root_hash
            },
            state_roots={
                POOL_LEDGER_ID: node.getState(POOL_LEDGER_ID).committedHeadHash
            },
            pool_size=initial_pool_size + 2,
            domain_size=initial_domain_size + 2,
            config_size=initial_config_size,
            last_pool_seqno=2,
            last_domain_seqno=2,
            last_config_seqno=None,
            primaries=3,
            digest=node.master_replica._consensus_data.prepared[pp_seq_no + 4 -
                                                                1].pp_digest,
            node_reg=3)

    # one more domain txn
    sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle,
                              sdk_wallet_client, 1)
    check_audit_ledger_updated(audit_size_initial,
                               txnPoolNodeSet,
                               audit_txns_added=5)

    for node in txnPoolNodeSet:
        check_audit_txn(
            txn=node.auditLedger.get_last_txn(),
            view_no=view_no,
            pp_seq_no=pp_seq_no + 5,
            seq_no=initial_seq_no + 5,
            txn_time=node.master_replica._ordering_service.
            last_accepted_pre_prepare_time,
            txn_roots={
                DOMAIN_LEDGER_ID:
                node.getLedger(DOMAIN_LEDGER_ID).tree.root_hash
            },
            state_roots={
                DOMAIN_LEDGER_ID:
                node.getState(DOMAIN_LEDGER_ID).committedHeadHash
            },
            pool_size=initial_pool_size + 2,
            domain_size=initial_domain_size + 3,
            config_size=initial_config_size,
            last_pool_seqno=4,
            last_domain_seqno=None,
            last_config_seqno=None,
            primaries=4,
            digest=node.master_replica._consensus_data.prepared[pp_seq_no + 5 -
                                                                1].pp_digest,
            node_reg=4)