Beispiel #1
0
 def _init_checkpoint_service(self) -> CheckpointService:
     return CheckpointService(data=self._consensus_data,
                              bus=self.internal_bus,
                              network=self._external_bus,
                              stasher=self.stasher,
                              db_manager=self.node.db_manager,
                              metrics=self.metrics)
Beispiel #2
0
def test_search_existing_key_in_audit_ledger_returns_its_index(
        audit_ledger, ordered_batches):
    for expected_seq_no, (view_no, pp_seq_no) in enumerate(ordered_batches,
                                                           start=1):
        _, actual_seq_no = CheckpointService._audit_txn_by_pp_seq_no(
            audit_ledger, pp_seq_no)
        assert expected_seq_no == actual_seq_no
Beispiel #3
0
    def __init__(self,
                 name: str,
                 validators: List[str],
                 primary_name: str,
                 timer: TimerService,
                 bus: InternalBus,
                 network: ExternalBus,
                 write_manager: WriteRequestManager = None,
                 bls_bft_replica: BlsBftReplica = None):
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = primary_name
        self._orderer = OrderingService(data=self._data,
                                        timer=timer,
                                        bus=bus,
                                        network=network,
                                        write_manager=write_manager,
                                        bls_bft_replica=bls_bft_replica)
        self._checkpointer = CheckpointService(self._data, bus, network)
        self._view_changer = ViewChangeService(self._data, timer, bus, network)

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0,
                       viewNo=0,
                       seqNoStart=0,
                       seqNoEnd=0,
                       digest='empty'))
Beispiel #4
0
    def __init__(self, name: str, validators: List[str], primary_name: str,
                 timer: TimerService, bus: InternalBus, network: ExternalBus,
                 write_manager: WriteRequestManager,
                 bls_bft_replica: BlsBftReplica=None):
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = primary_name
        config = getConfig()
        stasher = StashingRouter(config.REPLICA_STASH_LIMIT, buses=[bus, network])
        self._orderer = OrderingService(data=self._data,
                                        timer=timer,
                                        bus=bus,
                                        network=network,
                                        write_manager=write_manager,
                                        bls_bft_replica=bls_bft_replica,
                                        freshness_checker=FreshnessChecker(
                                            freshness_timeout=config.STATE_FRESHNESS_UPDATE_INTERVAL),
                                        stasher=stasher)
        self._checkpointer = CheckpointService(self._data, bus, network, stasher,
                                               write_manager.database_manager)
        self._view_changer = ViewChangeService(self._data, timer, bus, network, stasher)

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0, viewNo=0, seqNoStart=0, seqNoEnd=0,
                       digest='4F7BsTMVPKFshM1MwLf6y23cid6fL3xMpazVoF9krzUw'))
    def __init__(self,
                 name: str,
                 validators: List[str],
                 primary_name: str,
                 timer: TimerService,
                 bus: InternalBus,
                 network: ExternalBus,
                 write_manager: WriteRequestManager,
                 bls_bft_replica: BlsBftReplica = None):
        # ToDo: Maybe ConsensusSharedData should be initiated before and passed already prepared?
        self._internal_bus = bus
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = generateName(primary_name,
                                               self._data.inst_id)
        self.config = getConfig()
        self.stasher = StashingRouter(self.config.REPLICA_STASH_LIMIT,
                                      buses=[bus, network])
        self._write_manager = write_manager
        self._primaries_selector = RoundRobinNodeRegPrimariesSelector(
            self._write_manager.node_reg_handler)
        self._orderer = OrderingService(
            data=self._data,
            timer=timer,
            bus=bus,
            network=network,
            write_manager=self._write_manager,
            bls_bft_replica=bls_bft_replica,
            freshness_checker=FreshnessChecker(
                freshness_timeout=self.config.STATE_FRESHNESS_UPDATE_INTERVAL),
            primaries_selector=self._primaries_selector,
            stasher=self.stasher)
        self._checkpointer = CheckpointService(self._data, bus, network,
                                               self.stasher,
                                               write_manager.database_manager)
        self._view_changer = ViewChangeService(self._data, timer, bus, network,
                                               self.stasher,
                                               self._primaries_selector)
        self._message_requestor = MessageReqService(self._data, bus, network)

        self._add_ledgers()

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0,
                       viewNo=0,
                       seqNoStart=0,
                       seqNoEnd=0,
                       digest='4F7BsTMVPKFshM1MwLf6y23cid6fL3xMpazVoF9krzUw'))

        # ToDo: it should be done in Zero-view stage.
        write_manager.on_catchup_finished()
        self._data.primaries = self._view_changer._primaries_selector.select_primaries(
            self._data.view_no)

        # ToDo: ugly way to understand node_reg changing
        self._previous_node_reg = self._write_manager.node_reg_handler.committed_node_reg

        bus.subscribe(Ordered, self.emulate_ordered_processing)
Beispiel #6
0
def test_search_key_before_first_in_audit_ledger_returns_zero(
        audit_ledger, ordered_batches):
    last_view_no, last_pp_seq_no = ordered_batches[0] if ordered_batches else (
        0, 0)
    for view_no_dec, pp_seq_no_dec in [(0, 1), (0, 2), (1, 1)]:
        pp_seq_no = last_pp_seq_no - pp_seq_no_dec
        _, seq_no = CheckpointService._audit_txn_by_pp_seq_no(
            audit_ledger, pp_seq_no)
        assert seq_no == 0
Beispiel #7
0
def test_search_key_before_first_in_audit_ledger_returns_zero(
        audit_ledger, ordered_batches):
    last_view_no, last_pp_seq_no = ordered_batches[0] if ordered_batches else (
        0, 0)
    for view_no_dec, pp_seq_no_dec in [(0, 1), (1, 0), (1, 1)]:
        view_no = last_view_no - view_no_dec
        pp_seq_no = last_pp_seq_no - pp_seq_no_dec
        seq_no = CheckpointService._audit_seq_no_from_3pc_key(
            audit_ledger, view_no, pp_seq_no)
        assert seq_no == 0
Beispiel #8
0
def test_search_key_after_last_in_audit_ledger_returns_zero(
        audit_ledger, ordered_batches):
    last_view_no, last_pp_seq_no = ordered_batches[
        -1] if ordered_batches else (0, 0)
    for view_no_inc, pp_seq_no_inc in [(0, 1), (1, 0), (1, 1)]:
        view_no = last_view_no + view_no_inc
        pp_seq_no = last_pp_seq_no + pp_seq_no_inc
        seq_no = CheckpointService._audit_seq_no_from_3pc_key(
            audit_ledger, view_no, pp_seq_no)
        assert seq_no == 0
Beispiel #9
0
def checkpoint_service(consensus_data, internal_bus,
                       bls_bft_replica, stasher, db_manager):
    checkpoint_service = CheckpointService(data=consensus_data("CheckpointService"),
                                           bus=internal_bus,
                                           network=MockNetwork(),
                                           stasher=stasher,
                                           db_manager=db_manager,
                                           old_stasher=FakeSomething(unstash_watermarks=lambda: None))
    checkpoint_service._data.node_mode = Mode.participating
    return checkpoint_service
Beispiel #10
0
def checkpoint_service(consensus_data, internal_bus, external_bus,
                       bls_bft_replica, stasher, db_manager):
    checkpoint_service = CheckpointService(
        data=consensus_data("CheckpointService"),
        bus=internal_bus,
        network=external_bus,
        stasher=stasher,
        db_manager=db_manager)
    checkpoint_service._data.node_mode = Mode.participating
    return checkpoint_service
Beispiel #11
0
    def __init__(self, name: str, validators: List[str], primary_name: str,
                 timer: TimerService, bus: InternalBus, network: ExternalBus):
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = primary_name
        self._orderer = OrderingService(self._data, bus, network)
        self._checkpointer = CheckpointService(self._data, bus, network)
        self._view_changer = ViewChangeService(self._data, timer, bus, network)

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0,
                       viewNo=0,
                       seqNoStart=0,
                       seqNoEnd=0,
                       digest='empty'))
Beispiel #12
0
    def __init__(self,
                 name: str,
                 validators: List[str],
                 primary_name: str,
                 timer: TimerService,
                 bus: InternalBus,
                 network: ExternalBus,
                 write_manager: WriteRequestManager,
                 bls_bft_replica: BlsBftReplica = None):
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = primary_name
        config = getConfig()
        stasher = StashingRouter(config.REPLICA_STASH_LIMIT)
        self._orderer = OrderingService(data=self._data,
                                        timer=timer,
                                        bus=bus,
                                        network=network,
                                        write_manager=write_manager,
                                        bls_bft_replica=bls_bft_replica,
                                        stasher=stasher)
        self._checkpointer = CheckpointService(
            self._data,
            bus,
            network,
            stasher,
            write_manager.database_manager,
            old_stasher=FakeSomething(unstash_watermarks=lambda: None))
        self._view_changer = ViewChangeService(self._data, timer, bus, network)

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0,
                       viewNo=0,
                       seqNoStart=0,
                       seqNoEnd=0,
                       digest='empty'))
Beispiel #13
0
 def __init__(self, name: str, validators: List[str], primary_name: str,
              timer: TimerService, bus: InternalBus, network: ExternalBus):
     self._data = ConsensusDataProvider(name, validators, primary_name)
     self._orderer = OrderingService(self._data, bus, network)
     self._checkpointer = CheckpointService(self._data, bus, network)
     self._view_changer = ViewChangeService(self._data, timer, bus, network)
Beispiel #14
0
def cp_key(view_no: int, pp_seq_no: int) -> CheckpointService.CheckpointKey:
    return CheckpointService.CheckpointKey(view_no=view_no,
                                           pp_seq_no=pp_seq_no,
                                           digest=cp_digest(pp_seq_no))
Beispiel #15
0
    def __init__(self, name: str, validators: List[str], primary_name: str,
                 timer: TimerService, bus: InternalBus, network: ExternalBus,
                 write_manager: WriteRequestManager,
                 bls_bft_replica: BlsBftReplica = None):
        # ToDo: Maybe ConsensusSharedData should be initiated before and passed already prepared?
        self._network = network
        self._data = ConsensusSharedData(name, validators, 0)
        self._data.primary_name = generateName(primary_name, self._data.inst_id)
        self._timer = timer
        self.config = getConfig()
        self.stasher = StashingRouter(self.config.REPLICA_STASH_LIMIT, buses=[bus, network])
        self._write_manager = write_manager
        self._primaries_selector = RoundRobinNodeRegPrimariesSelector(self._write_manager.node_reg_handler)

        self._freshness_checker = FreshnessChecker(freshness_timeout=self.config.STATE_FRESHNESS_UPDATE_INTERVAL)
        for ledger_id in [POOL_LEDGER_ID, DOMAIN_LEDGER_ID, CONFIG_LEDGER_ID]:
            self._freshness_checker.register_ledger(ledger_id=ledger_id,
                                                    initial_time=self.get_time_for_3pc_batch())

        self._orderer = OrderingService(data=self._data,
                                        timer=self._timer,
                                        bus=bus,
                                        network=network,
                                        write_manager=self._write_manager,
                                        bls_bft_replica=bls_bft_replica,
                                        freshness_checker=self._freshness_checker,
                                        get_time_for_3pc_batch=self.get_time_for_3pc_batch,
                                        stasher=self.stasher)
        self._checkpointer = CheckpointService(self._data, bus, network, self.stasher,
                                               write_manager.database_manager)
        self._view_changer = ViewChangeService(self._data, self._timer, bus, network, self.stasher, self._primaries_selector)
        self._view_change_trigger = ViewChangeTriggerService(data=self._data,
                                                             timer=self._timer,
                                                             bus=bus,
                                                             network=network,
                                                             db_manager=write_manager.database_manager,
                                                             is_master_degraded=lambda: False,
                                                             stasher=self.stasher)
        self._primary_connection_monitor = PrimaryConnectionMonitorService(data=self._data,
                                                                           timer=self._timer,
                                                                           bus=bus,
                                                                           network=network)
        self._freshness_monitor = FreshnessMonitorService(data=self._data,
                                                          timer=self._timer,
                                                          bus=bus,
                                                          network=network,
                                                          freshness_checker=self._freshness_checker,
                                                          get_time_for_3pc_batch=self.get_time_for_3pc_batch)
        self._message_requestor = MessageReqService(self._data, bus, network)

        self._add_ledgers()

        # TODO: This is just for testing purposes only
        self._data.checkpoints.append(
            Checkpoint(instId=0, viewNo=0, seqNoStart=0, seqNoEnd=0,
                       digest='4F7BsTMVPKFshM1MwLf6y23cid6fL3xMpazVoF9krzUw'))

        # ToDo: it should be done in Zero-view stage.
        write_manager.on_catchup_finished()

        # Simulate node behavior
        self._internal_bus = bus
        self._internal_bus.subscribe(NodeNeedViewChange, self.process_node_need_view_change)
        self._internal_bus.subscribe(Ordered, self.emulate_ordered_processing)

        # ToDo: ugly way to understand node_reg changing
        self._previous_node_reg = self._write_manager.node_reg_handler.committed_node_reg
Beispiel #16
0
 def __init__(self, name: str, network: ExternalBus):
     self._data = ConsensusDataProvider(name)
     self._orderer = OrderingService(self._data, network)
     self._checkpointer = CheckpointService(self._data, network)
     self._view_changer = ViewChangeService(self._data, network)