Exemple #1
0
def orderer(consensus_data, internal_bus, external_bus, name, write_manager,
            txn_roots, state_roots, bls_bft_replica, tconf, stasher):
    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),
        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)
    future_primaries_handler = FuturePrimariesBatchHandler(
        write_manager.database_manager, FakeSomething(nodeReg={}, nodeIds=[]))
    future_primaries_handler.get_primaries = lambda *args, **kwargs: orderer._data.primaries
    write_manager.register_batch_handler(future_primaries_handler)
    return orderer
def replica_service(replica_service):
    write_manager = replica_service._write_manager
    future_primaries_handler = FuturePrimariesBatchHandler(
        write_manager.database_manager, FakeSomething(nodeReg={}, nodeIds=[]))
    future_primaries_handler._get_primaries = lambda *args, **kwargs: replica_service._data.primaries
    write_manager.register_batch_handler(future_primaries_handler)
    return replica_service
def orderer(
    _orderer,
    is_primary,
):
    # ToDo: For now, future_primary_handler is depended from the node.
    # And for now we need to patching set_node_state functionality
    write_manager = _orderer._write_manager
    future_primaries_handler = FuturePrimariesBatchHandler(
        write_manager.database_manager,
        FakeSomething(nodeReg={},
                      nodeIds=[],
                      primaries=_orderer._data.primaries))
    write_manager.register_batch_handler(future_primaries_handler)

    _orderer._validator = OrderingServiceMsgValidator(_orderer._data)
    _orderer.name = 'Alpha:0'
    _orderer._data.primary_name = 'some_node:0' if not is_primary else orderer.name

    def _apply_and_validate_applied_pre_prepare_fake(pp, sender):
        global applied_pre_prepares
        applied_pre_prepares += 1

    _orderer._can_process_pre_prepare = lambda pp, sender: None
    _orderer._apply_and_validate_applied_pre_prepare = _apply_and_validate_applied_pre_prepare_fake

    return _orderer
Exemple #4
0
 def register_pool_batch_handlers(self):
     pool_b_h = PoolBatchHandler(self.node.db_manager)
     future_primaries_handler = FuturePrimariesBatchHandler(
         self.node.db_manager, self.node)
     self.node.write_manager.register_batch_handler(pool_b_h)
     self.node.write_manager.register_batch_handler(
         future_primaries_handler)
Exemple #5
0
def replica_service(replica_service):
    write_manager = replica_service._write_manager
    future_primaries_handler = FuturePrimariesBatchHandler(
        write_manager.database_manager,
        FakeSomething(nodeReg={},
                      nodeIds=[],
                      primaries=replica_service._data.primaries))
    write_manager.register_batch_handler(future_primaries_handler)
    return replica_service
Exemple #6
0
 def _register_audit_batch_handlers(self):
     # FuturePrimariesBatchHandler is needed to select the list of primaries nodes
     # before recording a 3pc patch to the ledger into the audit. It means that this batch handler
     # should be executed before AuditBatchHandler
     # TODO: This should be moved into LedgersBootstrap somehow
     future_primaries_handler = FuturePrimariesBatchHandler(
         self.db_manager, self.node)
     for lid in self.ledger_ids:
         self.write_manager.register_batch_handler(future_primaries_handler,
                                                   ledger_id=lid)
     super()._register_audit_batch_handlers()
Exemple #7
0
    def __init__(self,
                 node_count: int = 4,
                 random: Optional[SimRandom] = None):
        self._random = random if random else DefaultSimRandom()
        self._timer = MockTimer()
        self._network = SimNetwork(self._timer, self._random,
                                   self._serialize_deserialize)
        self._nodes = []
        validators = genNodeNames(node_count)
        # ToDo: maybe it should be a random too?
        primary_name = validators[0]

        genesis_txns = create_pool_txn_data(
            node_names=validators,
            crypto_factory=create_default_bls_crypto_factory(),
            get_free_port=partial(random.integer, 9000, 9999))['txns']

        for name in validators:
            # TODO: emulate it the same way as in Replica, that is sender must have 'node_name:inst_id' form
            replica_name = generateName(name, 0)
            handler = partial(self.network._send_message, replica_name)
            write_manager = create_test_write_req_manager(name, genesis_txns)
            replica = ReplicaService(replica_name,
                                     validators,
                                     primary_name,
                                     self._timer,
                                     InternalBus(),
                                     self.network.create_peer(name, handler),
                                     write_manager=write_manager,
                                     bls_bft_replica=MockBlsBftReplica())
            # ToDo: For now, future_primary_handler is depended from the node.
            # And for now we need to patching set_node_state functionality
            future_primaries_handler = FuturePrimariesBatchHandler(
                write_manager.database_manager,
                FakeSomething(nodeReg={}, nodeIds=[]))
            future_primaries_handler._get_primaries = lambda *args, **kwargs: replica._data.primaries
            write_manager.register_batch_handler(future_primaries_handler)
            # ToDo: also, it should be done at the zero-view stage.
            write_manager.future_primary_handler.set_node_state()
            replica.config.NEW_VIEW_TIMEOUT = 30 * 1000
            self._nodes.append(replica)
Exemple #8
0
def replica_service(validators, primary, timer,
                    internal_bus, external_bus):
    genesis_txns = create_pool_txn_data(
        node_names=validators,
        crypto_factory=create_default_bls_crypto_factory(),
        get_free_port=lambda: 8090)['txns']
    replica = ReplicaService("Alpha:0",
                             validators, primary,
                             timer,
                             internal_bus,
                             external_bus,
                             write_manager=create_test_write_req_manager("Alpha", genesis_txns),
                             bls_bft_replica=FakeSomething(gc=lambda key: None))

    future_primaries_handler = FuturePrimariesBatchHandler(replica._write_manager.database_manager,
                                                           FakeSomething(nodeReg={},
                                                                         nodeIds=[]))
    future_primaries_handler._get_primaries = lambda *args, **kwargs: replica._data.primaries
    replica._write_manager.register_batch_handler(future_primaries_handler)

    return replica
def future_primaries(node):
    fp = FuturePrimariesBatchHandler(FakeSomething(), node)
    return fp
def future_primaries(node, audit_ledger):
    fp = FuturePrimariesBatchHandler(
        FakeSomething(get_ledger=lambda *args: audit_ledger), node)
    fp.primaries[node.viewNo] = list(node.primaries)
    return fp
Exemple #11
0
 def _register_pool_batch_handlers(self):
     super()._register_pool_batch_handlers()
     # TODO: This should be moved into LedgersBootstrap somehow
     future_primaries_handler = FuturePrimariesBatchHandler(
         self.db_manager, self.node)
     self.write_manager.register_batch_handler(future_primaries_handler)