示例#1
0
def requests():
    def _getDigest(req: Request):
        return sha256(req.identifier.encode())

    requests = Requests()
    for id in req_identifiers:
        req = Request(id)
        req.getDigest = functools.partial(_getDigest, req)
        requests.add(req)

    assert len(requests) == 3
    return requests
示例#2
0
def requests():
    def _getDigest(req: Request):
        return sha256(req.identifier.encode())

    requests = Requests()
    for id in req_identifiers:
        req = Request(id)
        req.getDigest = functools.partial(_getDigest, req)
        requests.add(req)

    assert len(requests) == 3
    return requests
示例#3
0
def requests():
    def _getDigest(req: Request):
        return sha256(req.identifier.encode())

    requests = Requests()

    req = Request("1")
    req.getDigest = functools.partial(_getDigest, req)
    requests.add(req)

    assert len(requests) == 1
    return requests, req.key
示例#4
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,
                      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,
                          future_primary_handler=FakeSomething(
                              primaries={},
                              get_primaries=lambda *args: [])),
                      timer=QueueTimer(),
                      poolManager=FakeSomething(
                          node_names_ordered_by_rank=lambda: node_names))
    def __init__(self, name: str, validators: List[str], inst_id: int):
        self._name = name
        self.inst_id = inst_id
        self.view_no = 0
        self.waiting_for_new_view = False
        self.primaries = []

        self.legacy_vc_in_progress = False
        self.requests = Requests()
        self.last_ordered_3pc = (0, 0)
        self.primary_name = None
        # seqNoEnd of the last stabilized checkpoint
        self.stable_checkpoint = 0
        # Checkpoint messages which the current node sent.
        self.checkpoints = SortedListWithKey(
            key=lambda checkpoint: checkpoint.seqNoEnd)
        # List of PrePrepare messages, for which quorum of Prepare messages is not reached yet
        self.preprepared = []  # type:  List[PrePrepare]
        # List of PrePrepare messages, for which quorum of Prepare messages is reached
        self.prepared = []  # type:  List[PrePrepare]
        self._validators = None
        self._quorums = None
        self.set_validators(validators)
        self._low_watermark = 0
        self.log_size = getConfig().LOG_SIZE
        self.high_watermark = self.low_watermark + self.log_size
        self.pp_seq_no = 0
        self.node_mode = Mode.starting
        # ToDo: it should be set in view_change_service before view_change starting
        self.legacy_last_prepared_before_view_change = None
    def __init__(self, name: str, validators: List[str], inst_id: int):
        self._name = name
        self.inst_id = inst_id
        self.view_no = 0
        self.last_ordered_3pc = (0, 0)
        self.waiting_for_new_view = False
        self.primaries = []

        self._legacy_vc_in_progress = False
        self._is_participating = False
        self._requests = Requests()
        self._last_ordered_3pc = (0, 0)
        self.primary_name = None
        self.stable_checkpoint = 0
        self.checkpoints = SortedListWithKey(
            key=lambda checkpoint: checkpoint.seqNoEnd)
        self.preprepared = []  # type:  List[PrePrepare]
        self.prepared = []  # type:  List[PrePrepare]
        self._validators = None
        self._quorums = None
        self.set_validators(validators)
        self.low_watermark = 0
        self.log_size = 300  # TODO: use config value
        self.high_watermark = self.low_watermark + self.log_size
        self._total_nodes = len(self.validators)
        self.pp_seq_no = 0
        self.node_mode = Mode.starting
        # ToDo: it should be set in view_change_service before view_change starting
        self.legacy_last_prepared_before_view_change = None
示例#7
0
 def __init__(self, viewNo, quorums, ledger_ids):
     node_stack = FakeSomething(
         name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"})
     self.replicas = []
     self.viewNo = viewNo
     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,
                      pre_view_change_in_progress=False,
                      requests=Requests(),
                      onBatchCreated=lambda self, *args, **kwargs: True,
                      applyReq=lambda self, *args, **kwargs: True,
                      primaries=[],
                      get_validators=lambda: [],
                      db_manager=None,
                      internal_bus=InternalBus(),
                      write_manager=FakeSomething(
                          database_manager=DatabaseManager(),
                          apply_request=lambda req, cons_time: None),
                      timer=QueueTimer())
def replica(replica):
    replica.node.requests = Requests()
    replica.isMaster = True
    replica.node.replica = replica
    replica.node.doDynamicValidation = functools.partial(randomDynamicValidation, replica.node)
    replica.node.applyReq = lambda self, *args, **kwargs: True
    replica.stateRootHash = lambda self, *args, **kwargs: base58.b58encode(randomString(32)).decode()
    replica.txnRootHash = lambda self, *args, **kwargs: base58.b58encode(randomString(32)).decode()
    replica.node.onBatchCreated = lambda self, *args, **kwargs: True
    replica.requestQueues[DOMAIN_LEDGER_ID] = OrderedSet()
    return replica
def replica(r):
    r.stateRootHash = lambda ledger_id, to_str=False: "EuDgqga9DNr4bjH57Rdq6BRtvCN1PV9UX5Mpnm9gbMA" + str(ledger_id + 1)
    r.txnRootHash = lambda ledger_id, to_str=False: "AuDgqga9DNr4bjH57Rdq6BRtvCN1PV9UX5Mpnm9gbMA" + str(ledger_id + 1)
    r.node.onBatchCreated = lambda *args: None
    r.isMaster = True
    r.node.requests = Requests()
    r._bls_bft_replica.process_order = lambda *args: None
    r.node.last_sent_pp_store_helper = FakeSomething()
    r.node.last_sent_pp_store_helper.store_last_sent_pp_seq_no = lambda *args: None

    r.last_accepted_pre_prepare_time = r.get_current_time()

    return r
    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
示例#11
0
 def __init__(self, viewNo, quorums, ledger_ids):
     node_stack = FakeSomething(
         name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"})
     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,
                      requests=Requests(),
                      onBatchCreated=lambda self, *args, **kwargs: True,
                      applyReq=lambda self, *args, **kwargs: True)
示例#12
0
    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 __init__(self,
                 name: str,
                 validators: List[str],
                 inst_id: int,
                 is_master: bool = True):
        self._name = name
        self.inst_id = inst_id
        self.view_no = 0
        self.waiting_for_new_view = False
        self.primaries = []
        self.is_master = is_master

        self.legacy_vc_in_progress = False
        self.requests = Requests()
        self.last_ordered_3pc = (0, 0)
        # Indicates name of the primary replica of this protocol instance.
        # None in case the replica does not know who the primary of the
        # instance is
        # TODO: Replace this by read-only property which uses primaries and inst_id
        self.primary_name = None
        # seqNoEnd of the last stabilized checkpoint
        self.stable_checkpoint = 0
        # Checkpoint messages which the current node sent.
        # TODO: Replace sorted list with dict
        self.checkpoints = SortedListWithKey(
            key=lambda checkpoint: checkpoint.seqNoEnd)
        self.checkpoints.append(self.initial_checkpoint)
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is not reached yet
        self.preprepared = []  # type:  List[BatchID]
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is reached
        self.prepared = []  # type:  List[BatchID]
        self._validators = None
        self.quorums = None
        # a list of validator node names ordered by rank (historical order of adding)
        self.set_validators(validators)
        self.low_watermark = 0
        self.log_size = getConfig().LOG_SIZE
        self.high_watermark = self.low_watermark + self.log_size
        self.pp_seq_no = 0
        self.node_mode = Mode.starting
        # ToDo: it should be set in view_change_service before view_change starting
        # 3 phase key for the last prepared certificate before view change
        # started, applicable only to master instance
        self.legacy_last_prepared_before_view_change = None
示例#14
0
    def __init__(self, tmpdir, config=None):
        self.basedirpath = tmpdir
        self.name = 'Node1'
        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.totalNodes = len(self.allNodeNames)
        self.mode = Mode.starting
        self.config = config or getConfigOnce()
        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, ownedByNode=True)
        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 = ViewChanger(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 = {}
示例#15
0
    def __init__(self,
                 name: str,
                 validators: List[str],
                 inst_id: int,
                 is_master: bool = True):
        self._name = name
        self.inst_id = inst_id
        self.view_no = 0
        self.waiting_for_new_view = False
        self.primaries = []
        self.is_master = is_master

        self.legacy_vc_in_progress = False
        self.requests = Requests()
        self.last_ordered_3pc = (0, 0)
        # Indicates name of the primary replica of this protocol instance.
        # None in case the replica does not know who the primary of the
        # instance is
        # TODO: Replace this by read-only property which uses primaries and inst_id
        self.primary_name = None
        # seqNoEnd of the last stabilized checkpoint
        self.stable_checkpoint = 0
        # Checkpoint messages which the current node sent.
        # TODO: Replace sorted list with dict
        self.checkpoints = SortedListWithKey(
            key=lambda checkpoint: checkpoint.seqNoEnd)
        self.checkpoints.append(self.initial_checkpoint)
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is not reached yet
        self.preprepared = []  # type:  List[BatchID]
        # List of BatchIDs of PrePrepare messages for which quorum of Prepare messages is reached
        self.prepared = []  # type:  List[BatchID]
        self._validators = None
        self.quorums = None
        self.view_change_votes = ViewChangeVotesForView(
            Quorums(len(validators)))
        # a list of validator node names ordered by rank (historical order of adding)
        self.set_validators(validators)
        self.low_watermark = 0
        self.log_size = getConfig().LOG_SIZE
        self.high_watermark = self.low_watermark + self.log_size
        self.pp_seq_no = 0
        self.node_mode = Mode.starting
        # ToDo: it should be set in view_change_service before view_change starting
        # 3 phase key for the last prepared certificate before view change
        # started, applicable only to master instance
        self.legacy_last_prepared_before_view_change = None
        self.prev_view_prepare_cert = None

        # Dictionary of sent PRE-PREPARE that are stored by primary replica
        # which it has broadcasted to all other non primary replicas
        # Key of dictionary is a 2 element tuple with elements viewNo,
        # pre-prepare seqNo and value is the received PRE-PREPARE
        self.sent_preprepares = SortedDict(lambda k: (k[0], k[1]))
        # type: Dict[Tuple[int, int], PrePrepare]

        # Dictionary of all Prepare requests. Key of dictionary is a 2
        # element tuple with elements viewNo, seqNo and value is a 2 element
        # tuple containing request digest and set of sender node names(sender
        # replica names in case of multiple protocol instances)
        # (viewNo, seqNo) -> ((identifier, reqId), {senders})
        self.prepares = Prepares()
        # type: Dict[Tuple[int, int], Tuple[Tuple[str, int], Set[str]]]

        self.commits = Commits()
        # type: Dict[Tuple[int, int], Tuple[Tuple[str, int], Set[str]]]

        # Tracks for which keys PRE-PREPAREs have been requested.
        # Cleared in `gc`
        self.requested_pre_prepares = {}