Esempio n. 1
0
    def add_new_node(self, name):
        if name not in self.validators:
            self.validators.append(name)

        # 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, self._genesis_txns)
        write_manager.node_reg_handler.committed_node_reg_at_beginning_of_view[0] = self._genesis_validators
        write_manager.node_reg_handler.uncommitted_node_reg_at_beginning_of_view[0] = self._genesis_validators
        _internal_bus = InternalBus()
        self._internal_buses[name] = _internal_bus
        self._subscribe_to_internal_msgs(name)
        replica = ReplicaService(replica_name,
                                 self.validators,
                                 self._primary_name,
                                 self._timer,
                                 _internal_bus,
                                 self.network.create_peer(name, handler),
                                 write_manager=write_manager,
                                 bls_bft_replica=MockBlsBftReplica())
        replica._data.node_mode = Mode.participating
        self._nodes.append(replica)
        self._update_connecteds()
        logger.info("Node {} was added into pool".format(name))
Esempio n. 2
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)
            write_manager.node_reg_handler.node_reg_at_beginning_of_view[
                0] = validators
            replica = ReplicaService(replica_name,
                                     validators,
                                     primary_name,
                                     self._timer,
                                     InternalBus(),
                                     self.network.create_peer(name, handler),
                                     write_manager=write_manager,
                                     bls_bft_replica=MockBlsBftReplica())
            replica.config.NEW_VIEW_TIMEOUT = 30 * 1000
            self._nodes.append(replica)
Esempio n. 3
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)
     validators = genNodeNames(node_count)
     primary_name = validators[0]
     self._nodes = [
         ReplicaService(name, validators, primary_name, self._timer,
                        InternalBus(), self.network.create_peer(name))
         for name in validators
     ]
Esempio n. 4
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']
    return 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))
Esempio n. 5
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)
        validators = genNodeNames(node_count)
        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']

        self._nodes = [ReplicaService(name, validators, primary_name,
                                      self._timer, InternalBus(), self.network.create_peer(name),
                                      write_manager=create_test_write_req_manager(name, genesis_txns))
                       for name in validators]
Esempio n. 6
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)
Esempio n. 7
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