def fake_view_changer(request, tconf): node_count = 4 node_stack = FakeSomething(name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}, conns={"Alpha", "Beta", "Gamma", "Delta"}) monitor = FakeSomething(isMasterDegraded=lambda: False, areBackupsDegraded=lambda: [], prettymetrics='') node = FakeSomething(name="SomeNode", timer=QueueTimer(), viewNo=request.param, quorums=Quorums( getValueFromModule(request, 'nodeCount', default=node_count)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch(), config=tconf, monitor=monitor, discard=lambda a, b, c, d: print(b), primaries_disconnection_times=[None] * getRequiredInstances(node_count), master_primary_name='Alpha', master_replica=FakeSomething(instId=0), nodeStatusDB=None) view_changer = create_view_changer(node) # TODO: This is a hack for tests compatibility, do something better view_changer.node = node return view_changer
def test_get_msgs_from_rxMsgs_queue(create_node_and_not_start, looper): node = create_node_and_not_start node.view_changer = create_view_changer(node) node.view_changer.pre_vc_strategy = VCStartMsgStrategy(view_changer, node) node.view_changer.view_no = 0 """pre_view_change stage""" node.view_changer.start_view_change(1) assert node.view_changer.view_no == 0 prepare = Prepare( 0, 0, 1, get_utc_epoch(), 'f99937241d4c891c08e92a3cc25966607315ca66b51827b170d492962d58a9be', 'CZecK1m7VYjSNCC7pGHj938DSW2tfbqoJp1bMJEtFqvG', '7WrAMboPTcMaQCU1raoj28vnhu2bPMMd2Lr9tEcsXeCJ') inst_change = InstanceChange(1, 25) m = node.nodeInBox.popleft() assert isinstance(m[0], ViewChangeStartMessage) node.nodestack.addRemote('someNode', genHa(), b'1DYuELN<SHbv1?NJ=][4De%^Hge887B0I!s<YGdD', 'pubkey') node.nodestack.rxMsgs.append((json.dumps(prepare._asdict()), 'pubkey')) node.nodestack.rxMsgs.append((json.dumps(inst_change._asdict()), 'pubkey')) node.msgHasAcceptableViewNo = lambda *args, **kwargs: True """While processing ViewChangeStartMessage from nodeInBox queue, should be: - move msgs from rxMsgs queue to nodeInBox queue - process all 3PC msgs (for Prepare msg it should be moved to inBox queue of master_replica) - add ViewChangeContinue msg into master_replica's inBox queue - all not 3PC msgs will be stashed in strategy queue""" looper.run(node.process_one_node_message(m)) m = node.master_replica.inBox.popleft() assert isinstance(m[0], Prepare) m = node.master_replica.inBox.popleft() assert isinstance(m, ViewChangeContinueMessage) m = node.view_changer.pre_vc_strategy.stashedNodeInBox.popleft() assert isinstance(m[0], InstanceChange)
def view_changer(): config = FakeSomething(ViewChangeWindowSize=1, ForceViewChangeFreq=0) node = FakeSomething(name="fake node", ledger_ids=[0], config=config, quorums=Quorums(7)) view_changer = create_view_changer(node) return view_changer
def __init__(self, *args, **kwargs): from plenum.common.stacks import nodeStackClass, clientStackClass self.NodeStackClass = nodeStackClass self.ClientStackClass = clientStackClass Node.__init__(self, *args, **kwargs) self.view_changer = create_view_changer(self, TestViewChanger) TestNodeCore.__init__(self, *args, **kwargs) # Balances of all client self.balances = {} # type: Dict[str, int] # Txns of all clients, each txn is a tuple like (from, to, amount) self.txns = [] # type: List[Tuple]
def __init__(self, tmpdir, config=None): node_names = ['Node1', 'Node2', 'Node3', 'Node4'] self.basedirpath = tmpdir self.name = node_names[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() 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.view_changer = create_view_changer(self) 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 restart_node(looper, txnPoolNodeSet, node_to_disconnect, tconf, tdir, allPluginsPath, wait_node_data_equality=True): idx = txnPoolNodeSet.index(node_to_disconnect) disconnect_node_and_ensure_disconnected(looper, txnPoolNodeSet, node_to_disconnect) looper.removeProdable(name=node_to_disconnect.name) # add node_to_disconnect to pool node_to_disconnect = start_stopped_node(node_to_disconnect, looper, tconf, tdir, allPluginsPath) node_to_disconnect.view_changer = create_view_changer(node_to_disconnect, ViewChanger) txnPoolNodeSet[idx] = node_to_disconnect looper.run(checkNodesConnected(txnPoolNodeSet)) if wait_node_data_equality: waitNodeDataEquality(looper, node_to_disconnect, *txnPoolNodeSet)
def __init__(self, tmpdir, config=None): self.basedirpath = tmpdir self.name = 'Node1' self.internal_bus = InternalBus() self.db_manager = DatabaseManager() self.timer = QueueTimer() self.f = 1 self.replicas = dict() self.requests = Requests() self.rank = None self.allNodeNames = [self.name, 'Node2', 'Node3', 'Node4'] self.nodeReg = {name: HA("127.0.0.1", 0) for name in self.allNodeNames} self.nodeIds = [] self.totalNodes = len(self.allNodeNames) self.mode = Mode.starting self.config = config or getConfigOnce() self.nodeStatusDB = None 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._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.view_changer = create_view_changer(self) self.elector = PrimarySelector(self) self.metrics = NullMetricsCollector() # For catchup testing self.catchup_rounds_without_txns = 0 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 view_changer(fake_node): view_changer = create_view_changer(fake_node) fake_node.view_changer = view_changer fake_node.viewNo = view_changer.view_no fake_node.master_replica.node = fake_node return view_changer
def newViewChanger(self): return create_view_changer(self, TestViewChangerWithAdjustedViewNo)
def newViewChanger(self): view_changer = self.view_changer if self.view_changer is not None \ else create_view_changer(self, TestViewChanger) # TODO: This is a hack for tests compatibility, do something better view_changer.node = self return view_changer