コード例 #1
0
def test_primary_names_cleaning(tconf):
    node = FakeSomething(
        name="fake node",
        ledger_ids=[0],
        viewNo=0,
    )
    bls_bft_replica = FakeSomething(
        gc=lambda *args: None,
    )

    replica = Replica(node, instId=0, config=tconf, bls_bft_replica=bls_bft_replica)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0")]

    node.viewNo += 1
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
           [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
           [(2, "Node3:0"), (3, "Node4:0")]
コード例 #2
0
def test_primary_names_cleaning():

    node = FakeSomething(
        name="fake node",
        ledger_ids=[0],
        viewNo=0,
    )
    bls_bft_replica = FakeSomething(gc=lambda *args: None, )

    replica = Replica(node, instId=0, bls_bft_replica=bls_bft_replica)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
        [(0, "Node1:0")]

    node.viewNo += 1
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
        [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
        [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
        [(2, "Node3:0"), (3, "Node4:0")]
コード例 #3
0
def test_primary_names_cleaning():

    node = FakeNode(
        name="fake node",
        ledger_ids=[0],
        viewNo=0,
    )

    replica = Replica(node, instId=0)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
        [(0, "Node1:0")]

    node.viewNo += 1
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
        [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
        [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
        [(2, "Node3:0"), (3, "Node4:0")]
コード例 #4
0
def test_primary_names_cleaning(tconf):
    node = FakeSomething(
        name="fake node",
        ledger_ids=[0],
        viewNo=0,
        utc_epoch=get_utc_epoch,
        get_validators=lambda: [],
        db_manager=DatabaseManager(),
        requests=[],
        mode=Mode.participating,
        timer=QueueTimer(),
        quorums=Quorums(4),
        write_manager=None,
        poolManager=FakeSomething(node_names_ordered_by_rank=lambda: []),
        primaries_selector=RoundRobinConstantNodesPrimariesSelector(
            ["Alpha", "Beta", "Gamma", "Delta"]))
    bls_bft_replica = FakeSomething(gc=lambda *args: None, )

    replica = Replica(node,
                      instId=0,
                      config=tconf,
                      bls_bft_replica=bls_bft_replica)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
           [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
           [(2, "Node3:0"), (3, "Node4:0")]
コード例 #5
0
def replica(tconf, viewNo, inst_id, ledger_ids, mock_timestamp, fake_requests,
            txn_roots, state_roots, request):
    node = ReplicaFakeNode(viewNo=viewNo,
                           quorums=Quorums(
                               getValueFromModule(request,
                                                  'nodeCount',
                                                  default=4)),
                           ledger_ids=ledger_ids)
    bls_bft_replica = FakeSomething(
        gc=lambda *args: None,
        update_pre_prepare=lambda params, l_id: params,
        validate_pre_prepare=lambda a, b: None,
        validate_prepare=lambda a, b: None,
        update_prepare=lambda a, b: a,
        process_prepare=lambda a, b: None,
        process_pre_prepare=lambda a, b: None,
        process_order=lambda *args: None)
    replica = Replica(node,
                      instId=inst_id,
                      isMaster=inst_id == 0,
                      config=tconf,
                      bls_bft_replica=bls_bft_replica,
                      get_current_time=mock_timestamp,
                      get_time_for_3pc_batch=mock_timestamp)
    node.add_replica(replica)
    ReplicaFakeNode.master_last_ordered_3PC = replica.last_ordered_3pc

    replica._ordering_service.last_accepted_pre_prepare_time = replica.get_time_for_3pc_batch(
    )
    replica.primaryName = "Alpha:{}".format(replica.instId)
    replica.primaryNames[replica.viewNo] = replica.primaryName

    replica._ordering_service.get_txn_root_hash = lambda ledger, to_str=False: txn_roots[
        ledger]
    replica._ordering_service.get_state_root_hash = lambda ledger, to_str=False: state_roots[
        ledger]
    replica._ordering_service._revert = lambda ledgerId, stateRootHash, reqCount: None
    replica._ordering_service.post_batch_creation = lambda three_pc_batch: None

    replica._ordering_service.requestQueues[DOMAIN_LEDGER_ID] = OrderedSet()

    replica._ordering_service._get_primaries_for_ordered = lambda pp: [
        replica.primaryName
    ]
    replica._ordering_service._get_node_reg_for_ordered = lambda pp: [
        "Alpha", "Beta", "Gamma", "Delta"
    ]

    def reportSuspiciousNodeEx(ex):
        assert False, ex

    replica.node.reportSuspiciousNodeEx = reportSuspiciousNodeEx

    return replica
コード例 #6
0
def test_primary_names_cleaning(tconf):
    node = FakeSomething(name="fake node",
                         ledger_ids=[0],
                         viewNo=0,
                         utc_epoch=get_utc_epoch,
                         get_validators=lambda: [],
                         internal_bus=InternalBus(),
                         db_manager=DatabaseManager(),
                         requests=[],
                         mode=Mode.participating,
                         timer=QueueTimer(),
                         quorums=Quorums(4),
                         write_manager=None)
    bls_bft_replica = FakeSomething(gc=lambda *args: None, )

    replica = Replica(node,
                      instId=0,
                      config=tconf,
                      bls_bft_replica=bls_bft_replica)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
           [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
           [(2, "Node3:0"), (3, "Node4:0")]
コード例 #7
0
def test_primary_names_cleaning(tconf):
    node = FakeSomething(
        name="fake node",
        ledger_ids=[0],
        viewNo=0,
        utc_epoch=get_utc_epoch,
        get_validators=lambda: [],
    )
    bls_bft_replica = FakeSomething(gc=lambda *args: None, )

    replica = Replica(node,
                      instId=0,
                      config=tconf,
                      bls_bft_replica=bls_bft_replica)

    replica.primaryName = "Node1:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node2:0"
    assert list(replica.primaryNames.items()) == \
           [(0, "Node1:0"), (1, "Node2:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node3:0"
    assert list(replica.primaryNames.items()) == \
           [(1, "Node2:0"), (2, "Node3:0")]

    node.viewNo += 1
    replica._consensus_data.view_no = node.viewNo
    replica.primaryName = "Node4:0"
    assert list(replica.primaryNames.items()) == \
           [(2, "Node3:0"), (3, "Node4:0")]