Esempio n. 1
0
def test_validate_commit_no_sigs(bls_bft_replicas):
    key = (0, 0)
    commit = create_commit_no_bls_sig(key)
    for sender_bls_bft in bls_bft_replicas:
        for verifier_bls_bft in bls_bft_replicas:
            assert not verifier_bls_bft.validate_commit(
                commit, sender_bls_bft.node_id, state_root)
def test_check_previous_view_view_change_prep_cert_commit(
        validator, pp_seq_no, result, view_no, inst_id):
    validator._data.legacy_vc_in_progress = True
    validator._data.view_no = view_no + 1
    validator._data.legacy_last_prepared_before_view_change = (view_no, 10)
    commit = create_commit_no_bls_sig(req_key=(view_no, pp_seq_no),
                                      inst_id=inst_id)
    assert validator.validate(commit) == result
Esempio n. 3
0
def test_ts_is_not_set_for_non_pp(primary_orderer, ts_now, sender, pp,
                                  sender_orderer):
    primary_orderer.process_prepare(
        create_prepare(req_key=(0, 1), state_root=generate_state_root()),
        sender_orderer)
    primary_orderer.process_commit(create_commit_no_bls_sig(req_key=(0, 1)),
                                   sender_orderer)
    assert len(primary_orderer.pre_prepare_tss) == 0
def test_check_previous_view_view_change_prep_cert_commit(
        validator, pp_seq_no, result):
    validator.replica.node.view_change_in_progress = True
    validator.replica.last_prepared_before_view_change = (validator.view_no -
                                                          1, 10)
    commit = create_commit_no_bls_sig(req_key=(validator.view_no - 1,
                                               pp_seq_no),
                                      inst_id=validator.inst_id)
    assert validator.validate_3pc_msg(commit) == result
def test_check_catchup_modes_in_view_change_for_prep_cert_for_commit(validator, result, mode):
    pp_seq_no = 10
    validator.replica.node.view_change_in_progress = True
    validator.replica.node.mode = mode
    validator.replica.last_prepared_before_view_change = (validator.view_no - 1,
                                                          pp_seq_no)
    commit = create_commit_no_bls_sig(req_key=(validator.view_no - 1, pp_seq_no),
                                      inst_id=validator.inst_id)
    assert validator.validate_3pc_msg(commit) == result
def create_3pc_msgs(view_no, pp_seq_no, inst_id):
    pre_prepare = create_pre_prepare_no_bls(generate_state_root(),
                                            view_no=view_no,
                                            pp_seq_no=pp_seq_no,
                                            inst_id=inst_id)
    prepare = create_prepare(req_key=(view_no, pp_seq_no),
                             state_root=generate_state_root(),
                             inst_id=inst_id)
    commit = create_commit_no_bls_sig(req_key=(view_no, pp_seq_no),
                                      inst_id=inst_id)
    return [pre_prepare, prepare, commit]
def test_check_catchup_modes_in_view_change_for_prep_cert_for_commit(
        validator, result, mode, view_no, inst_id):
    pp_seq_no = 10
    validator._data.legacy_vc_in_progress = True
    validator._data.node_mode = mode
    validator._data.view_no = view_no + 1
    validator._data.legacy_last_prepared_before_view_change = (view_no,
                                                               pp_seq_no)
    commit = create_commit_no_bls_sig(req_key=(view_no, pp_seq_no),
                                      inst_id=inst_id)
    assert validator.validate(commit) == result
def create_three_pc_msgs(replica, pp_seq_no):
    pre_prepare = create_pre_prepare_no_bls(generate_state_root(),
                                            view_no=replica.viewNo,
                                            pp_seq_no=pp_seq_no,
                                            inst_id=replica.instId)
    prepare = create_prepare(req_key=(replica.viewNo, pp_seq_no),
                             state_root=generate_state_root(),
                             inst_id=replica.instId)
    commit = create_commit_no_bls_sig(req_key=(replica.viewNo, pp_seq_no),
                                      inst_id=replica.instId)
    return [pre_prepare, prepare, commit]
Esempio n. 9
0
def test_unstash_future_view_on_need_view_change(external_bus, internal_bus,
                                                 replica_service):
    replica_service._data.view_no = 1
    replica_service._data.node_mode = Mode.participating
    external_bus.process_incoming(
        create_new_view(initial_view_no=1, stable_cp=200),
        replica_service._data.primary_name)
    external_bus.process_incoming(create_commit_no_bls_sig(req_key=(2, 10)),
                                  replica_service._data.primary_name)
    assert replica_service.stasher.stash_size(STASH_VIEW) == 2

    internal_bus.send(NeedViewChange(view_no=2))

    assert replica_service.stasher.stash_size(STASH_VIEW) == 0
    assert replica_service.stasher.stash_size(STASH_WAITING_NEW_VIEW) == 1
Esempio n. 10
0
def test_unstash_waiting_new_view_on_new_view_checkpoint_applied(
        external_bus, internal_bus, replica_service):
    replica_service._data.view_no = 2
    replica_service._data.node_mode = Mode.participating
    replica_service._data.waiting_for_new_view = True

    external_bus.process_incoming(create_commit_no_bls_sig(req_key=(2, 10)),
                                  replica_service._data.primary_name)
    assert replica_service.stasher.stash_size(STASH_WAITING_NEW_VIEW) == 1

    new_view = create_new_view(initial_view_no=1, stable_cp=200)
    replica_service._data.waiting_for_new_view = False
    internal_bus.send(
        NewViewCheckpointsApplied(view_no=2,
                                  view_changes=new_view.viewChanges,
                                  checkpoint=new_view.checkpoint,
                                  batches=new_view.batches))

    assert replica_service.stasher.stash_size(STASH_WAITING_NEW_VIEW) == 0
def test_clear_data_on_view_change_started(internal_bus, orderer):
    pp = create_pre_prepare_no_bls(
        generate_state_root(),
        view_no=0,
        pp_seq_no=10,
        inst_id=0,
        audit_txn_root="HSai3sMHKeAva4gWMabDrm1yNhezvPHfXnGyHf2ex1L4")
    prepare = create_prepare(req_key=(0, 10),
                             state_root=generate_state_root(),
                             inst_id=0)
    commit = create_commit_no_bls_sig(req_key=(0, 10), inst_id=0)
    key = (pp.viewNo, pp.ppSeqNo)

    orderer.prePrepares[key] = pp
    orderer.prepares[key] = prepare
    orderer.commits[key] = commit
    orderer.pre_prepare_tss[key][pp.auditTxnRootHash, "Node1"] = 1234
    orderer.prePreparesPendingFinReqs.append(pp)
    orderer.prePreparesPendingPrevPP[key] = pp
    orderer.sent_preprepares[key] = pp
    orderer.batches[key] = [
        pp.ledgerId, pp.discarded, pp.ppTime,
        generate_state_root(),
        len(pp.reqIdr)
    ]
    orderer.ordered.add(*key)

    internal_bus.send(ViewChangeStarted(view_no=4))

    assert not orderer.prePrepares
    assert not orderer.prepares
    assert not orderer.commits

    assert not orderer.pre_prepare_tss
    assert not orderer.prePreparesPendingFinReqs
    assert not orderer.prePreparesPendingPrevPP
    assert not orderer.sent_preprepares
    assert not orderer.batches
    assert not orderer.ordered
def commit(view_no, pp_seq_no, inst_id=0):
    return create_commit_no_bls_sig(req_key=(view_no, pp_seq_no),
                                    inst_id=inst_id)
Esempio n. 13
0
def commit(data):
    key = (data.view_no, 1)
    commit = create_commit_no_bls_sig(key, data.inst_id)
    data.commits.addVote(commit, data.name)
    return commit
Esempio n. 14
0
def test_process_commit_no_sigs(bls_bft_replicas):
    for sender_bls_bft in bls_bft_replicas:
        commit = create_commit_no_bls_sig((0, 0))
        for verifier_bls_bft in bls_bft_replicas:
            verifier_bls_bft.process_commit(commit, sender_bls_bft.node_id)