def test_replicas_prepare_time(looper, txnPoolNodeSet, sdk_pool_handle,
                               sdk_wallet_client):
    # Check that each replica's PREPARE time is same as the PRE-PREPARE time
    sent_batches = 5
    for i in range(sent_batches):
        sdk_send_random_and_check(looper,
                                  txnPoolNodeSet,
                                  sdk_pool_handle,
                                  sdk_wallet_client,
                                  count=2)
        looper.runFor(1)

    for node in txnPoolNodeSet:
        for r in node.replicas:
            rec_prps = defaultdict(list)
            for p in recvd_prepares(r):
                rec_prps[(p.viewNo, p.ppSeqNo)].append(p)
            pp_coll = r.sentPrePrepares if r.isPrimary else r.prePrepares
            for key, pp in pp_coll.items():
                for p in rec_prps[key]:
                    assert pp.ppTime == p.ppTime

            # `last_accepted_pre_prepare_time` is the time of the last PRE-PREPARE
            assert r.last_accepted_pre_prepare_time == pp_coll.peekitem(
                -1)[1].ppTime

            # The ledger should store time for each txn and it should be same
            # as the time for that PRE-PREPARE
            if r.isMaster:
                for iv in node.txn_seq_range_to_3phase_key[DOMAIN_LEDGER_ID]:
                    three_pc_key = iv.data
                    for seq_no in range(iv.begin, iv.end):
                        assert node.domainLedger.getBySeqNo(
                            seq_no)[TXN_TIME] == pp_coll[three_pc_key].ppTime
def test_replicas_prepare_time(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client):
    # Check that each replica's PREPARE time is same as the PRE-PREPARE time
    sent_batches = 5
    for i in range(sent_batches):
        sdk_send_random_and_check(looper,
                                  txnPoolNodeSet,
                                  sdk_pool_handle,
                                  sdk_wallet_client,
                                  count=2)
        looper.runFor(1)

    for node in txnPoolNodeSet:
        for r in node.replicas.values():
            rec_prps = defaultdict(list)
            for p in recvd_prepares(r):
                rec_prps[(p.viewNo, p.ppSeqNo)].append(p)
            pp_coll = r.sentPrePrepares if r.isPrimary else r.prePrepares
            for key, pp in pp_coll.items():
                for p in rec_prps[key]:
                    assert pp.ppTime == p.ppTime

            # `last_accepted_pre_prepare_time` is the time of the last PRE-PREPARE
            assert r.last_accepted_pre_prepare_time == pp_coll.peekitem(-1)[
                1].ppTime

            # The ledger should store time for each txn and it should be same
            # as the time for that PRE-PREPARE
            if r.isMaster:
                for iv in node.txn_seq_range_to_3phase_key[DOMAIN_LEDGER_ID]:
                    three_pc_key = iv.data
                    for seq_no in range(iv.begin, iv.end):
                        assert get_txn_time(node.domainLedger.getBySeqNo(seq_no))\
                               == pp_coll[three_pc_key].ppTime
Exemplo n.º 3
0
def test_replicas_prepare_time(looper, txnPoolNodeSet, sdk_pool_handle,
                               sdk_wallet_client):
    last_domain_seq_no = txnPoolNodeSet[0].domainLedger.size + 1

    # Check that each replica's PREPARE time is same as the PRE-PREPARE time
    sent_batches = 5
    for i in range(sent_batches):
        sdk_send_random_and_check(looper,
                                  txnPoolNodeSet,
                                  sdk_pool_handle,
                                  sdk_wallet_client,
                                  count=2)
        looper.runFor(1)

    for node in txnPoolNodeSet:
        for r in node.replicas.values():
            rec_prps = defaultdict(list)
            for p in recvd_prepares(r):
                rec_prps[(p.viewNo, p.ppSeqNo)].append(p)
            pp_coll = r._ordering_service.sent_preprepares if r.isPrimary else r._ordering_service.prePrepares
            for key, pp in pp_coll.items():
                for p in rec_prps[key]:
                    assert pp.ppTime == p.ppTime

            # `last_accepted_pre_prepare_time` is the time of the last PRE-PREPARE
            assert r._ordering_service.last_accepted_pre_prepare_time == pp_coll.peekitem(
                -1)[1].ppTime

            # The ledger should store time for each txn and it should be same
            # as the time for that PRE-PREPARE
            if not r.isMaster:
                continue

            for _, audit_txn in node.auditLedger.getAllTxn():
                audit_txn_data = get_payload_data(audit_txn)
                three_pc_key = (audit_txn_data[AUDIT_TXN_VIEW_NO],
                                audit_txn_data[AUDIT_TXN_PP_SEQ_NO])
                domain_seq_no = audit_txn_data[AUDIT_TXN_LEDGERS_SIZE][
                    DOMAIN_LEDGER_ID]
                for seq_no in range(last_domain_seq_no, domain_seq_no + 1):
                    assert get_txn_time(node.domainLedger.getBySeqNo(seq_no)) \
                           == pp_coll[three_pc_key].ppTime
                last_domain_seq_no = domain_seq_no + 1