def test_primaries_selection_viewno_9(primary_selector):
    validators = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta"]
    primary_selector = RoundRobinConstantNodesPrimariesSelector(validators)
    master_primary = primary_selector.select_master_primary(view_no=9)
    primaries = primary_selector.select_primaries(view_no=9)
    assert master_primary == "Gamma"
    assert primaries == ["Gamma", "Delta", "Epsilon"]
Exemplo n.º 2
0
 def __init__(self, viewNo, quorums, ledger_ids):
     node_names = ["Alpha", "Beta", "Gamma", "Delta"]
     node_stack = FakeSomething(name="fake stack",
                                connecteds=set(node_names))
     self.replicas = []
     self.viewNo = viewNo
     audit_ledger = FakeSomething(size=0,
                                  get_last_txn=lambda *args: None,
                                  getAllTxn=lambda *args, **kwargs: [])
     db_manager = DatabaseManager()
     db_manager.register_new_database(AUDIT_LEDGER_ID, audit_ledger)
     super().__init__(
         name="fake node",
         ledger_ids=ledger_ids,
         _viewNo=viewNo,
         quorums=quorums,
         nodestack=node_stack,
         utc_epoch=lambda *args: get_utc_epoch(),
         mode=Mode.participating,
         view_change_in_progress=False,
         monitor=FakeSomething(isMasterDegraded=lambda: False),
         requests=Requests(),
         onBatchCreated=lambda self, *args, **kwargs: True,
         applyReq=lambda self, *args, **kwargs: True,
         primaries=[],
         get_validators=lambda: [],
         db_manager=db_manager,
         write_manager=FakeSomething(
             database_manager=db_manager,
             apply_request=lambda req, cons_time: None),
         timer=QueueTimer(),
         poolManager=FakeSomething(
             node_names_ordered_by_rank=lambda: node_names),
         primaries_selector=RoundRobinConstantNodesPrimariesSelector(
             node_names))
Exemplo n.º 3
0
def orderer(consensus_data, internal_bus, external_bus, name, write_manager,
            txn_roots, state_roots, bls_bft_replica, tconf, stasher,
            validators):
    orderer = OrderingService(
        data=consensus_data(name),
        timer=QueueTimer(),
        bus=internal_bus,
        network=external_bus,
        write_manager=write_manager,
        bls_bft_replica=bls_bft_replica,
        freshness_checker=FreshnessChecker(
            freshness_timeout=tconf.STATE_FRESHNESS_UPDATE_INTERVAL),
        primaries_selector=RoundRobinConstantNodesPrimariesSelector(
            validators),
        stasher=stasher)
    orderer._data.node_mode = Mode.participating
    orderer._data.primary_name = "Alpha:0"
    orderer.get_txn_root_hash = lambda ledger, to_str=False: txn_roots[ledger]
    orderer.get_state_root_hash = lambda ledger, to_str=False: state_roots[
        ledger]
    orderer.requestQueues[DOMAIN_LEDGER_ID] = OrderedSet()
    orderer._revert = lambda *args, **kwargs: None
    orderer.db_manager.stores[LAST_SENT_PP_STORE_LABEL] = \
        FakeSomething(store_last_sent_pp_seq_no=lambda b, c: None)
    return orderer
Exemplo n.º 4
0
def view_change_service(internal_bus, external_bus, timer, stasher,
                        validators):
    # TODO: Use validators fixture
    data = ConsensusSharedData("some_name", genNodeNames(4), 0)
    primaries_selector = RoundRobinConstantNodesPrimariesSelector(validators)
    return ViewChangeService(data, timer, internal_bus, external_bus, stasher,
                             primaries_selector)
    def __init__(self, tmpdir, config=None):
        node_names = ['Node1', 'Node2', 'Node3', 'Node4']
        self.basedirpath = tmpdir
        self.name = node_names[0]
        self.viewNo = 0
        self.db_manager = DatabaseManager()
        self.timer = QueueTimer()
        self.f = 1
        self.replicas = dict()
        self.requests = Requests()
        self.rank = None
        self.allNodeNames = node_names
        self.nodeReg = {name: HA("127.0.0.1", 0) for name in self.allNodeNames}
        self.nodeIds = []
        self.totalNodes = len(self.allNodeNames)
        self.poolManager = FakeSomething(
            node_names_ordered_by_rank=lambda: node_names)
        self.mode = Mode.starting
        self.monitor = FakeSomething(isMasterDegraded=lambda: False)
        self.config = config or getConfigOnce()
        self.nodeStatusDB = None
        self.quorums = Quorums(self.totalNodes)
        self.nodestack = FakeSomething(connecteds=set(self.allNodeNames))
        self.write_manager = FakeSomething(
            node_reg_handler=NodeRegHandler(self.db_manager))
        self.primaries_selector = RoundRobinConstantNodesPrimariesSelector(
            node_names)
        self.replicas = {
            0: Replica(node=self, instId=0, isMaster=True, config=self.config),
            1: Replica(node=self, instId=1, isMaster=False,
                       config=self.config),
            2: Replica(node=self, instId=2, isMaster=False, config=self.config)
        }
        self.requiredNumberOfInstances = 2
        self._found = False
        self.ledgerManager = LedgerManager(self)
        ledger0 = FakeLedger(0, 10)
        ledger1 = FakeLedger(1, 5)
        self.ledgerManager.addLedger(0, ledger0)
        self.ledgerManager.addLedger(1, ledger1)
        self.quorums = Quorums(self.totalNodes)
        self.metrics = NullMetricsCollector()

        # For catchup testing
        self.view_change_in_progress = False
        self.ledgerManager.last_caught_up_3PC = (0, 0)
        self.master_last_ordered_3PC = (0, 0)
        self.seqNoDB = {}

        # callbacks
        self.onBatchCreated = lambda self, *args, **kwargs: True
def test_node_txn_edge_primaries(pool_with_edge_primaries, node_req):
    pool = pool_with_edge_primaries
    current_view_no = pool.view_no
    expected_view_no = current_view_no + 1
    expected_primaries = RoundRobinConstantNodesPrimariesSelector.select_primaries_round_robin(
        expected_view_no, pool.validators, pool.f + 1)
    req = node_req(pool.size)
    pool.sim_send_requests([req])
    random_interval = 1000
    RepeatingTimer(pool.timer, random_interval, partial(order_requests, pool))
    pool.timer.wait_for(
        lambda: all([n._data.view_no == expected_view_no for n in pool.nodes]))
    pool.timer.wait_for(lambda: all(
        [n._data.primaries == expected_primaries for n in pool.nodes]))
 def _service(name):
     data = consensus_data(name)
     digest = cp_digest(DEFAULT_STABLE_CHKP)
     cp = Checkpoint(instId=0,
                     viewNo=initial_view_no,
                     seqNoStart=0,
                     seqNoEnd=DEFAULT_STABLE_CHKP,
                     digest=digest)
     data.checkpoints.append(cp)
     primaries_selector = RoundRobinConstantNodesPrimariesSelector(
         validators)
     service = ViewChangeService(data, timer, internal_bus, external_bus,
                                 stasher, primaries_selector)
     return service
    def _service(name):
        data = consensus_data(name)
        data.node_mode = Mode.participating
        digest = cp_digest(DEFAULT_STABLE_CHKP)
        cp = Checkpoint(instId=0, viewNo=initial_view_no, seqNoStart=0, seqNoEnd=DEFAULT_STABLE_CHKP, digest=digest)
        data.checkpoints.append(cp)

        ViewChangeTriggerService(data=data,
                                 timer=timer,
                                 bus=internal_bus,
                                 network=external_bus,
                                 db_manager=DatabaseManager(),
                                 stasher=stasher,
                                 is_master_degraded=lambda: False)

        primaries_selector = RoundRobinConstantNodesPrimariesSelector(validators)
        service = ViewChangeService(data, timer, internal_bus, external_bus, stasher, primaries_selector)
        return service
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")]
def test_ordered_cleaning(tconf):
    global_view_no = 2

    node = FakeSomething(
        name="fake node",
        ledger_ids=[0],
        viewNo=global_view_no,
        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._consensus_data.view_no = global_view_no
    total = []

    num_requests_per_view = 3
    for viewNo in range(global_view_no + 1):
        for seqNo in range(num_requests_per_view):
            reqId = viewNo, seqNo
            replica._ordering_service._add_to_ordered(*reqId)
            total.append(reqId)

    # gc is called after stable checkpoint, since no request executed
    # in this test starting it manually
    replica._ordering_service.gc(100)
    # Requests with view lower then previous view
    # should not be in ordered
    assert len(replica._ordering_service.ordered) == len(
        total[num_requests_per_view:])
Exemplo n.º 11
0
def primary_in_view(validators, view_no):
    return RoundRobinConstantNodesPrimariesSelector(
        validators).select_primaries(view_no=view_no)[0]
Exemplo n.º 12
0
def test_primaries_selection_viewno_5(primary_selector):
    validators = ["Alpha", "Beta", "Gamma", "Delta", "Epsilon", "Zeta", "Eta"]
    primary_selector = RoundRobinConstantNodesPrimariesSelector(validators)
    primaries = primary_selector.select_primaries(view_no=5)
    assert primaries == ["Zeta", "Eta", "Alpha"]
Exemplo n.º 13
0
def primary_selector(validators):
    return RoundRobinConstantNodesPrimariesSelector(validators)