示例#1
0
def test_commits_gc(bls_bft_replicas):
    key1 = (0, 0)
    pre_prepare1 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare1, bls_bft_replicas)

    key2 = (0, 1)
    pre_prepare2 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare2, bls_bft_replicas)

    key3 = (1, 0)
    pre_prepare3 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare3, bls_bft_replicas)

    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert key1 in bls_bft._signatures
        assert key2 in bls_bft._signatures
        assert key3 in bls_bft._signatures

    for bls_bft in bls_bft_replicas:
        bls_bft.gc((0, 1))

    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert not key1 in bls_bft._signatures
        assert not key2 in bls_bft._signatures
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)
示例#2
0
def create_valid_batch_committed():
    reqs = [
        req.as_dict for req in sdk_random_request_objects(
            10, identifier="1" * 16, protocol_version=CURRENT_PROTOCOL_VERSION)
    ]
    return BatchCommitted(reqs, DOMAIN_LEDGER_ID, get_utc_epoch(),
                          generate_state_root(), generate_state_root(), 1, 2)
def test_commits_gc(bls_bft_replicas):
    key1 = (0, 0)
    pre_prepare1 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare1, bls_bft_replicas)

    key2 = (0, 1)
    pre_prepare2 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare2, bls_bft_replicas)

    key3 = (1, 0)
    pre_prepare3 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare3, bls_bft_replicas)

    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert key1 in bls_bft._signatures
        assert key2 in bls_bft._signatures
        assert key3 in bls_bft._signatures

    for bls_bft in bls_bft_replicas:
        bls_bft.gc((0, 1))

    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert not key1 in bls_bft._signatures
        assert not key2 in bls_bft._signatures
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)
def create_invalid_batch_committed():
    return BatchCommitted(["aaaa", "bbbb"],
                          DOMAIN_LEDGER_ID,
                          get_utc_epoch(),
                          generate_state_root(),
                          generate_state_root(),
                          1,
                          2)
def pre_prepare_incorrect(state_root, request):
    if request.param == 'state_root':
        params = create_pre_prepare_params(state_root=generate_state_root())
    elif request.param == 'ledger_id':
        params = create_pre_prepare_params(state_root=state_root, ledger_id=DOMAIN_LEDGER_ID)
    elif request.param == 'timestamp':
        params = create_pre_prepare_params(state_root=state_root, timestamp=get_utc_epoch() + 1000)
    elif request.param == 'txn_root':
        params = create_pre_prepare_params(state_root=state_root, txn_root=generate_state_root())
    return PrePrepare(*params)
def create_valid_batch_committed():
    reqs = [req.as_dict for req in
            sdk_random_request_objects(10, identifier="1" * 16, protocol_version=CURRENT_PROTOCOL_VERSION)]
    return BatchCommitted(reqs,
                          DOMAIN_LEDGER_ID,
                          get_utc_epoch(),
                          generate_state_root(),
                          generate_state_root(),
                          1,
                          2)
def old_view_pp_rep():
    pp1 = create_pre_prepare_no_bls(generate_state_root(),
                                    view_no=0,
                                    pp_seq_no=1,
                                    inst_id=0)
    pp2 = create_pre_prepare_no_bls(generate_state_root(),
                                    view_no=0,
                                    pp_seq_no=1,
                                    inst_id=0)
    return OldViewPrePrepareReply(0, [pp1, pp2])
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]
示例#9
0
def create_observed_data(seq_no_start=1, seq_no_end=5):
    req_num = seq_no_end - seq_no_start + 1
    reqs = [
        req.as_dict for req in sdk_random_request_objects(
            req_num,
            identifier="1" * 16,
            protocol_version=CURRENT_PROTOCOL_VERSION)
    ]
    msg = BatchCommitted(reqs, DOMAIN_LEDGER_ID, get_utc_epoch(),
                         generate_state_root(), generate_state_root(),
                         seq_no_start, seq_no_end)
    return ObservedData(BATCH, msg)
示例#10
0
def pre_prepare_incorrect(state_root, request):
    if request.param == 'state_root':
        params = create_pre_prepare_params(state_root=generate_state_root())
    elif request.param == 'ledger_id':
        params = create_pre_prepare_params(state_root=state_root,
                                           ledger_id=DOMAIN_LEDGER_ID)
    elif request.param == 'timestamp':
        params = create_pre_prepare_params(state_root=state_root,
                                           timestamp=get_utc_epoch() + 1000)
    elif request.param == 'txn_root':
        params = create_pre_prepare_params(state_root=state_root,
                                           txn_root=generate_state_root())
    return PrePrepare(*params)
def test_check_previous_view_view_change_prep_cert_non_commit(
        validator, pp_seq_no, inst_id, view_no):
    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)
    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)
    assert validator.validate(pre_prepare) == (DISCARD, OLD_VIEW)
    assert validator.validate(prepare) == (DISCARD, OLD_VIEW)
def test_check_catchup_modes_in_view_change_for_prep_cert_for_non_commit(
        validator, 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)
    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)
    assert validator.validate(pre_prepare) == (DISCARD, OLD_VIEW)
    assert validator.validate(prepare) == (DISCARD, OLD_VIEW)
def test_signatures_cached_for_commits(bls_bft_replicas):
    key1 = (0, 0)
    pre_prepare1 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare1, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)

    pre_prepare2 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare2, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)

    key2 = (0, 1)
    pre_prepare3 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare3, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 2
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)

    pre_prepare4 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare4, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 2
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)

    key3 = (1, 0)
    pre_prepare5 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare5, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)

    pre_prepare6 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare6, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)
示例#14
0
def test_signatures_cached_for_commits(bls_bft_replicas):
    key1 = (0, 0)
    pre_prepare1 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare1, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)

    pre_prepare2 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key1, pre_prepare2, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 1
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)

    key2 = (0, 1)
    pre_prepare3 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare3, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 2
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)

    pre_prepare4 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key2, pre_prepare4, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 2
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)

    key3 = (1, 0)
    pre_prepare5 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare5, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)

    pre_prepare6 = create_pre_prepare_no_bls(generate_state_root())
    process_commits_for_key(key3, pre_prepare6, bls_bft_replicas)
    for bls_bft in bls_bft_replicas:
        assert len(bls_bft._signatures) == 3
        assert len(bls_bft._signatures[key1]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key2]) == len(bls_bft_replicas)
        assert len(bls_bft._signatures[key3]) == len(bls_bft_replicas)
def pre_prepare(view_no, pp_seq_no, inst_id=0):
    return create_pre_prepare_no_bls(generate_state_root(),
                                     view_no=view_no,
                                     pp_seq_no=pp_seq_no,
                                     inst_id=inst_id)
def state_root():
    return generate_state_root()
示例#17
0
def state_root():
    return generate_state_root()
示例#18
0
def fake_state_root_hash():
    return generate_state_root()
def multi_sig_value(state_root, pool_state_root):
    return MultiSignatureValue(ledger_id=DOMAIN_LEDGER_ID,
                               state_root_hash=state_root,
                               pool_state_root_hash=pool_state_root,
                               txn_root_hash=generate_state_root(),
                               timestamp=get_utc_epoch())
示例#20
0
def create_invalid_batch_committed():
    return BatchCommitted(["aaaa", "bbbb"], DOMAIN_LEDGER_ID, get_utc_epoch(),
                          generate_state_root(), generate_state_root(), 1, 2)
示例#21
0

@pytest.fixture(scope="function")
def fake_replica(replica):
    replica.node.isParticipating = True
    replica.nonFinalisedReqs = lambda a: []
    replica._bls_bft_replica.validate_pre_prepare = lambda a, b: None
    replica._bls_bft_replica.update_prepare = lambda a, b: a
    replica._bls_bft_replica.process_prepare = lambda a, b: None
    replica._apply_pre_prepare = lambda a, b: None
    replica.primaryName = "Alpha:{}".format(replica.instId)
    replica.primaryNames[replica.viewNo] = replica.primaryName
    return replica


@pytest.fixture(scope="function", params=[generate_state_root(), None])
def pool_state_root(request):
    return request.param


@pytest.fixture(scope="function", params=[True, False])
def pre_prepare(replica, pool_state_root, fake_state_root_hash, fake_multi_sig,
                request):
    params = create_pre_prepare_params(state_root=fake_state_root_hash,
                                       view_no=replica.viewNo,
                                       pool_state_root=pool_state_root)
    pp = PrePrepare(*params)
    if request.param:
        setattr(pre_prepare, f.BLS_MULTI_SIG.nm, fake_multi_sig)

    return pp
def prepare(view_no, pp_seq_no, inst_id=0):
    return create_prepare(req_key=(view_no, pp_seq_no),
                          state_root=generate_state_root(),
                          inst_id=inst_id)
示例#23
0
def multi_sig_value(state_root, pool_state_root):
    return MultiSignatureValue(ledger_id=DOMAIN_LEDGER_ID,
                               state_root_hash=state_root,
                               pool_state_root_hash=pool_state_root,
                               txn_root_hash=generate_state_root(),
                               timestamp=get_utc_epoch())
示例#24
0
def fake_state_root_hash():
    return generate_state_root()