Exemple #1
0
    def test_get_events_by_block_id(self):
        """Tests that the correct events are returned by the
        ClientEventsGetRequest handler for each block id.

        """

        event_broadcaster = EventBroadcaster(
            Mock(),
            block_store=self.block_store,
            receipt_store=self.receipt_store)
        for block_id, _ in self._txn_ids_by_block_id.items():
            request = client_event_pb2.ClientEventsGetRequest()
            request.block_ids.extend([block_id])
            subscription = request.subscriptions.add()
            subscription.event_type = "sawtooth/block-commit"
            event_filter = subscription.filters.add()
            event_filter.key = "address"
            event_filter.match_string = block_id
            event_filter.filter_type = event_filter.SIMPLE_ALL

            event_filter2 = subscription.filters.add()
            event_filter2.key = "block_id"
            event_filter2.match_string = block_id
            event_filter2.filter_type = event_filter2.SIMPLE_ALL

            handler = ClientEventsGetRequestHandler(event_broadcaster)
            handler_output = handler.handle(
                "dummy_conn_id",
                request.SerializeToString())

            self.assertEqual(handler_output.message_type,
                             validator_pb2.Message.CLIENT_EVENTS_GET_RESPONSE)

            self.assertEqual(handler_output.status, HandlerStatus.RETURN)
            self.assertTrue(
                all(any(a.value == block_id
                        for a in e.attributes)
                    for e in handler_output.message_out.events),
                "Each Event has at least one attribute value that is the"
                " block id for the block.")
            self.assertEqual(handler_output.message_out.status,
                             client_event_pb2.ClientEventsGetResponse.OK)
            self.assertTrue(len(handler_output.message_out.events) > 0)
Exemple #2
0
    def test_get_events_by_block_id(self):
        """Tests that the correct events are returned by the
        ClientEventsGetRequest handler for each block id.

        """

        event_broadcaster = EventBroadcaster(
            Mock(),
            block_store=self.block_store,
            receipt_store=self.receipt_store)
        for block_id, _ in self._txn_ids_by_block_id.items():
            request = client_event_pb2.ClientEventsGetRequest()
            request.block_ids.extend([block_id])
            subscription = request.subscriptions.add()
            subscription.event_type = "sawtooth/block-commit"
            event_filter = subscription.filters.add()
            event_filter.key = "address"
            event_filter.match_string = block_id
            event_filter.filter_type = event_filter.SIMPLE_ALL

            event_filter2 = subscription.filters.add()
            event_filter2.key = "block_id"
            event_filter2.match_string = block_id
            event_filter2.filter_type = event_filter2.SIMPLE_ALL

            handler = ClientEventsGetRequestHandler(event_broadcaster)
            handler_output = handler.handle(
                "dummy_conn_id",
                request.SerializeToString())

            self.assertEqual(handler_output.message_type,
                             validator_pb2.Message.CLIENT_EVENTS_GET_RESPONSE)

            self.assertEqual(handler_output.status, HandlerStatus.RETURN)
            self.assertTrue(
                all(any(a.value == block_id
                        for a in e.attributes)
                    for e in handler_output.message_out.events),
                "Each Event has at least one attribute value that is the"
                " block id for the block.")
            self.assertEqual(handler_output.message_out.status,
                             client_event_pb2.ClientEventsGetResponse.OK)
            self.assertTrue(len(handler_output.message_out.events) > 0)
def add(dispatcher,
        gossip,
        context_manager,
        executor,
        completer,
        block_store,
        batch_tracker,
        merkle_db,
        get_current_root,
        receipt_store,
        event_broadcaster,
        permission_verifier,
        thread_pool,
        sig_pool,
        block_publisher,
        metrics_registry=None):

    # -- Transaction Processor -- #
    dispatcher.add_handler(
        validator_pb2.Message.TP_RECEIPT_ADD_DATA_REQUEST,
        tp_state_handlers.TpReceiptAddDataHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_EVENT_ADD_REQUEST,
        tp_state_handlers.TpEventAddHandler(context_manager), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_DELETE_REQUEST,
        tp_state_handlers.TpStateDeleteHandler(context_manager), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_GET_REQUEST,
        tp_state_handlers.TpStateGetHandler(context_manager), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_SET_REQUEST,
        tp_state_handlers.TpStateSetHandler(context_manager), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_REGISTER_REQUEST,
        processor_handlers.ProcessorRegisterHandler(executor.processors),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_UNREGISTER_REQUEST,
        processor_handlers.ProcessorUnRegisterHandler(executor.processors),
        thread_pool)

    # -- Client -- #
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        BatchListPermissionVerifier(permission_verifier=permission_verifier),
        sig_pool)

    # Submit
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        ClientBatchSubmitBackpressureHandler(
            block_publisher.can_accept_batch,
            block_publisher.get_current_queue_info,
            metrics_registry=metrics_registry), thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
                           signature_verifier.BatchListSignatureVerifier(),
                           sig_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
                           structure_verifier.BatchListStructureVerifier(),
                           thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        CompleterBatchListBroadcastHandler(completer, gossip), thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
                           client_handlers.BatchSubmitFinisher(batch_tracker),
                           thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
                           client_handlers.BatchStatusRequest(batch_tracker),
                           thread_pool)

    # State
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_LIST_REQUEST,
        client_handlers.StateListRequest(merkle_db, block_store), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_GET_REQUEST,
        client_handlers.StateGetRequest(merkle_db, block_store), thread_pool)

    # Blocks
    dispatcher.add_handler(validator_pb2.Message.CLIENT_BLOCK_LIST_REQUEST,
                           client_handlers.BlockListRequest(block_store),
                           thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_ID_REQUEST,
        client_handlers.BlockGetByIdRequest(block_store), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_NUM_REQUEST,
        client_handlers.BlockGetByNumRequest(block_store), thread_pool)

    # Batches
    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_LIST_REQUEST,
                           client_handlers.BatchListRequest(block_store),
                           thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_BATCH_GET_REQUEST,
                           client_handlers.BatchGetRequest(block_store),
                           thread_pool)

    # Transactions
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_LIST_REQUEST,
        client_handlers.TransactionListRequest(block_store), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_GET_REQUEST,
        client_handlers.TransactionGetRequest(block_store), thread_pool)

    # Receipts
    dispatcher.add_handler(validator_pb2.Message.CLIENT_RECEIPT_GET_REQUEST,
                           ClientReceiptGetRequestHandler(receipt_store),
                           thread_pool)

    # Events
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeValidationHandler(event_broadcaster), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeHandler(event_broadcaster), thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_UNSUBSCRIBE_REQUEST,
        ClientEventsUnsubscribeHandler(event_broadcaster), thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_EVENTS_GET_REQUEST,
                           ClientEventsGetRequestHandler(event_broadcaster),
                           thread_pool)

    dispatcher.add_handler(validator_pb2.Message.CLIENT_PEERS_GET_REQUEST,
                           client_handlers.PeersGetRequest(gossip),
                           thread_pool)
Exemple #4
0
    def __init__(self,
                 bind_network,
                 bind_component,
                 endpoint,
                 peering,
                 seeds_list,
                 peer_list,
                 data_dir,
                 config_dir,
                 identity_signing_key,
                 scheduler_type,
                 permissions,
                 network_public_key=None,
                 network_private_key=None,
                 roles=None,
                 metrics_registry=None):
        """Constructs a validator instance.

        Args:
            bind_network (str): the network endpoint
            bind_component (str): the component endpoint
            endpoint (str): the zmq-style URI of this validator's
                publically reachable endpoint
            peering (str): The type of peering approach. Either 'static'
                or 'dynamic'. In 'static' mode, no attempted topology
                buildout occurs -- the validator only attempts to initiate
                peering connections with endpoints specified in the
                peer_list. In 'dynamic' mode, the validator will first
                attempt to initiate peering connections with endpoints
                specified in the peer_list and then attempt to do a
                topology buildout starting with peer lists obtained from
                endpoints in the seeds_list. In either mode, the validator
                will accept incoming peer requests up to max_peers.
            seeds_list (list of str): a list of addresses to connect
                to in order to perform the initial topology buildout
            peer_list (list of str): a list of peer addresses
            data_dir (str): path to the data directory
            config_dir (str): path to the config directory
            identity_signing_key (str): key validator uses for signing
        """
        db_filename = os.path.join(data_dir,
                                   'merkle-{}.lmdb'.format(bind_network[-2:]))
        LOGGER.debug('database file is %s', db_filename)

        merkle_db = LMDBNoLockDatabase(db_filename, 'c')

        delta_db_filename = os.path.join(
            data_dir, 'state-deltas-{}.lmdb'.format(bind_network[-2:]))
        LOGGER.debug('state delta store file is %s', delta_db_filename)
        state_delta_db = LMDBNoLockDatabase(delta_db_filename, 'c')

        receipt_db_filename = os.path.join(
            data_dir, 'txn_receipts-{}.lmdb'.format(bind_network[-2:]))
        LOGGER.debug('txn receipt store file is %s', receipt_db_filename)
        receipt_db = LMDBNoLockDatabase(receipt_db_filename, 'c')

        state_delta_store = StateDeltaStore(state_delta_db)
        receipt_store = TransactionReceiptStore(receipt_db)

        context_manager = ContextManager(merkle_db, state_delta_store)
        self._context_manager = context_manager

        state_view_factory = StateViewFactory(merkle_db)

        block_db_filename = os.path.join(
            data_dir, 'block-{}.lmdb'.format(bind_network[-2:]))
        LOGGER.debug('block store file is %s', block_db_filename)

        block_db = LMDBNoLockDatabase(block_db_filename, 'c')
        block_store = BlockStore(block_db)

        batch_tracker = BatchTracker(block_store)

        # setup network
        self._dispatcher = Dispatcher(metrics_registry=metrics_registry)

        thread_pool = ThreadPoolExecutor(max_workers=10)
        sig_pool = ThreadPoolExecutor(max_workers=3)

        self._thread_pool = thread_pool
        self._sig_pool = sig_pool

        self._service = Interconnect(bind_component,
                                     self._dispatcher,
                                     secured=False,
                                     heartbeat=False,
                                     max_incoming_connections=20,
                                     monitor=True,
                                     max_future_callback_workers=10,
                                     metrics_registry=metrics_registry)

        executor = TransactionExecutor(
            service=self._service,
            context_manager=context_manager,
            settings_view_factory=SettingsViewFactory(
                StateViewFactory(merkle_db)),
            scheduler_type=scheduler_type,
            invalid_observers=[batch_tracker],
            metrics_registry=metrics_registry)

        self._executor = executor
        self._service.set_check_connections(executor.check_connections)

        state_delta_processor = StateDeltaProcessor(self._service,
                                                    state_delta_store,
                                                    block_store)
        event_broadcaster = EventBroadcaster(self._service, block_store,
                                             receipt_store)

        zmq_identity = hashlib.sha512(
            time.time().hex().encode()).hexdigest()[:23]

        network_thread_pool = ThreadPoolExecutor(max_workers=10)
        self._network_thread_pool = network_thread_pool

        self._network_dispatcher = Dispatcher(
            metrics_registry=metrics_registry)

        secure = False
        if network_public_key is not None and network_private_key is not None:
            secure = True

        self._network = Interconnect(
            bind_network,
            dispatcher=self._network_dispatcher,
            zmq_identity=zmq_identity,
            secured=secure,
            server_public_key=network_public_key,
            server_private_key=network_private_key,
            heartbeat=True,
            public_endpoint=endpoint,
            connection_timeout=30,
            max_incoming_connections=100,
            max_future_callback_workers=10,
            authorize=True,
            public_key=signing.generate_pubkey(identity_signing_key),
            priv_key=identity_signing_key,
            roles=roles,
            metrics_registry=metrics_registry)

        self._gossip = Gossip(self._network,
                              endpoint=endpoint,
                              peering_mode=peering,
                              initial_seed_endpoints=seeds_list,
                              initial_peer_endpoints=peer_list,
                              minimum_peer_connectivity=3,
                              maximum_peer_connectivity=10,
                              topology_check_frequency=1)

        completer = Completer(block_store, self._gossip)

        block_sender = BroadcastBlockSender(completer, self._gossip)
        batch_sender = BroadcastBatchSender(completer, self._gossip)
        chain_id_manager = ChainIdManager(data_dir)

        identity_view_factory = IdentityViewFactory(
            StateViewFactory(merkle_db))

        id_cache = IdentityCache(identity_view_factory,
                                 block_store.chain_head_state_root)

        permission_verifier = PermissionVerifier(
            permissions, block_store.chain_head_state_root, id_cache)

        identity_observer = IdentityObserver(to_update=id_cache.invalidate,
                                             forked=id_cache.forked)

        # Create and configure journal
        self._journal = Journal(
            block_store=block_store,
            state_view_factory=StateViewFactory(merkle_db),
            block_sender=block_sender,
            batch_sender=batch_sender,
            transaction_executor=executor,
            squash_handler=context_manager.get_squash_handler(),
            identity_signing_key=identity_signing_key,
            chain_id_manager=chain_id_manager,
            data_dir=data_dir,
            config_dir=config_dir,
            permission_verifier=permission_verifier,
            check_publish_block_frequency=0.1,
            block_cache_purge_frequency=30,
            block_cache_keep_time=300,
            batch_observers=[batch_tracker],
            chain_observers=[
                state_delta_processor, event_broadcaster, receipt_store,
                batch_tracker, identity_observer
            ],
            metrics_registry=metrics_registry)

        self._genesis_controller = GenesisController(
            context_manager=context_manager,
            transaction_executor=executor,
            completer=completer,
            block_store=block_store,
            state_view_factory=state_view_factory,
            identity_key=identity_signing_key,
            data_dir=data_dir,
            config_dir=config_dir,
            chain_id_manager=chain_id_manager,
            batch_sender=batch_sender)

        responder = Responder(completer)

        completer.set_on_batch_received(self._journal.on_batch_received)
        completer.set_on_block_received(self._journal.on_block_received)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_ADD_RECEIPT_DATA_REQUEST,
            tp_state_handlers.TpAddReceiptDataHandler(context_manager),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_ADD_EVENT_REQUEST,
            tp_state_handlers.TpAddEventHandler(context_manager), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_STATE_DEL_REQUEST,
            tp_state_handlers.TpStateDeleteHandler(context_manager),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_STATE_GET_REQUEST,
            tp_state_handlers.TpStateGetHandler(context_manager), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_STATE_SET_REQUEST,
            tp_state_handlers.TpStateSetHandler(context_manager), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_REGISTER_REQUEST,
            processor_handlers.ProcessorRegisterHandler(executor.processors),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.TP_UNREGISTER_REQUEST,
            processor_handlers.ProcessorUnRegisterHandler(executor.processors),
            thread_pool)

        # Set up base network handlers
        self._network_dispatcher.add_handler(
            validator_pb2.Message.NETWORK_PING,
            PingHandler(network=self._network), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.NETWORK_CONNECT,
            ConnectHandler(network=self._network), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.NETWORK_DISCONNECT,
            DisconnectHandler(network=self._network), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.AUTHORIZATION_VIOLATION,
            AuthorizationViolationHandler(network=self._network,
                                          gossip=self._gossip),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.AUTHORIZATION_TRUST_REQUEST,
            AuthorizationTrustRequestHandler(
                network=self._network,
                permission_verifier=permission_verifier,
                gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.AUTHORIZATION_CHALLENGE_REQUEST,
            AuthorizationChallengeRequestHandler(network=self._network),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.AUTHORIZATION_CHALLENGE_SUBMIT,
            AuthorizationChallengeSubmitHandler(
                network=self._network,
                permission_verifier=permission_verifier,
                gossip=self._gossip), network_thread_pool)

        # Set up gossip handlers
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_GET_PEERS_REQUEST,
            GetPeersRequestHandler(gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_GET_PEERS_RESPONSE,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_GET_PEERS_RESPONSE,
            GetPeersResponseHandler(gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_REGISTER,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_REGISTER,
            PeerRegisterHandler(gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_UNREGISTER,
            PeerUnregisterHandler(gossip=self._gossip), network_thread_pool)

        # GOSSIP_MESSAGE 1) Sends acknowledgement to the sender
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE, GossipMessageHandler(),
            network_thread_pool)

        # GOSSIP_MESSAGE 2) Verify Network Permissions
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        # GOSSIP_MESSAGE 3) Verifies signature
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            signature_verifier.GossipMessageSignatureVerifier(), sig_pool)

        # GOSSIP_MESSAGE 4) Verifies batch structure
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            structure_verifier.GossipHandlerStructureVerifier(),
            network_thread_pool)

        # GOSSIP_MESSAGE 4) Verifies that the node is allowed to publish a
        # block
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            NetworkConsensusPermissionHandler(
                network=self._network,
                permission_verifier=permission_verifier,
                gossip=self._gossip), network_thread_pool)

        # GOSSIP_MESSAGE 5) Determines if we should broadcast the
        # message to our peers. It is important that this occur prior
        # to the sending of the message to the completer, as this step
        # relies on whether the  gossip message has previously been
        # seen by the validator to determine whether or not forwarding
        # should occur
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            GossipBroadcastHandler(gossip=self._gossip, completer=completer),
            network_thread_pool)

        # GOSSIP_MESSAGE 6) Send message to completer
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_MESSAGE,
            CompleterGossipHandler(completer), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_REQUEST,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_REQUEST,
            BlockResponderHandler(responder, self._gossip),
            network_thread_pool)

        # GOSSIP_BLOCK_RESPONSE 1) Sends ack to the sender
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            GossipBlockResponseHandler(), network_thread_pool)

        # GOSSIP_MESSAGE 2) Verify Network Permissions
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        # GOSSIP_BLOCK_RESPONSE 3) Verifies signature
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            signature_verifier.GossipBlockResponseSignatureVerifier(),
            sig_pool)

        # GOSSIP_BLOCK_RESPONSE 4) Check batch structure
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            structure_verifier.GossipBlockResponseStructureVerifier(),
            network_thread_pool)

        # GOSSIP_BLOCK_RESPONSE 5) Send message to completer
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            CompleterGossipBlockResponseHandler(completer),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BLOCK_RESPONSE,
            ResponderBlockResponseHandler(responder, self._gossip),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_BY_BATCH_ID_REQUEST,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_BY_BATCH_ID_REQUEST,
            BatchByBatchIdResponderHandler(responder, self._gossip),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_BY_TRANSACTION_ID_REQUEST,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_BY_TRANSACTION_ID_REQUEST,
            BatchByTransactionIdResponderHandler(responder, self._gossip),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            NetworkPermissionHandler(network=self._network,
                                     permission_verifier=permission_verifier,
                                     gossip=self._gossip), network_thread_pool)

        # GOSSIP_BATCH_RESPONSE 1) Sends ack to the sender
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            GossipBatchResponseHandler(), network_thread_pool)

        # GOSSIP_BATCH_RESPONSE 2) Verifies signature
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            signature_verifier.GossipBatchResponseSignatureVerifier(),
            sig_pool)

        # GOSSIP_BATCH_RESPONSE 3) Check batch structure
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            structure_verifier.GossipBatchResponseStructureVerifier(),
            network_thread_pool)

        # GOSSIP_BATCH_RESPONSE 4) Send message to completer
        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            CompleterGossipBatchResponseHandler(completer),
            network_thread_pool)

        self._network_dispatcher.add_handler(
            validator_pb2.Message.GOSSIP_BATCH_RESPONSE,
            ResponderBatchResponseHandler(responder, self._gossip),
            network_thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            BatchListPermissionVerifier(
                permission_verifier=permission_verifier), sig_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            signature_verifier.BatchListSignatureVerifier(), sig_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            structure_verifier.BatchListStructureVerifier(),
            network_thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            CompleterBatchListBroadcastHandler(completer, self._gossip),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
            client_handlers.BatchSubmitFinisher(batch_tracker), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
            client_handlers.BatchStatusRequest(batch_tracker), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_STATE_LIST_REQUEST,
            client_handlers.StateListRequest(merkle_db,
                                             self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_STATE_GET_REQUEST,
            client_handlers.StateGetRequest(merkle_db,
                                            self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BLOCK_LIST_REQUEST,
            client_handlers.BlockListRequest(self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BLOCK_GET_REQUEST,
            client_handlers.BlockGetRequest(self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_LIST_REQUEST,
            client_handlers.BatchListRequest(self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_BATCH_GET_REQUEST,
            client_handlers.BatchGetRequest(self._journal.get_block_store()),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_TRANSACTION_LIST_REQUEST,
            client_handlers.TransactionListRequest(
                self._journal.get_block_store()), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_TRANSACTION_GET_REQUEST,
            client_handlers.TransactionGetRequest(
                self._journal.get_block_store()), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_STATE_CURRENT_REQUEST,
            client_handlers.StateCurrentRequest(
                self._journal.get_current_root), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_RECEIPT_GET_REQUEST,
            ClientReceiptGetRequestHandler(receipt_store), thread_pool)

        # State Delta Subscription Handlers
        self._dispatcher.add_handler(
            validator_pb2.Message.STATE_DELTA_SUBSCRIBE_REQUEST,
            StateDeltaSubscriberValidationHandler(state_delta_processor),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.STATE_DELTA_SUBSCRIBE_REQUEST,
            StateDeltaAddSubscriberHandler(state_delta_processor), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.STATE_DELTA_UNSUBSCRIBE_REQUEST,
            StateDeltaUnsubscriberHandler(state_delta_processor), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.STATE_DELTA_GET_EVENTS_REQUEST,
            StateDeltaGetEventsHandler(block_store, state_delta_store),
            thread_pool)

        # Client Events Handlers
        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
            ClientEventsSubscribeValidationHandler(event_broadcaster),
            thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
            ClientEventsSubscribeHandler(event_broadcaster), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_EVENTS_UNSUBSCRIBE_REQUEST,
            ClientEventsUnsubscribeHandler(event_broadcaster), thread_pool)

        self._dispatcher.add_handler(
            validator_pb2.Message.CLIENT_EVENTS_GET_REQUEST,
            ClientEventsGetRequestHandler(event_broadcaster), thread_pool)
Exemple #5
0
def add(
    dispatcher, gossip,
    context_manager, executor, completer, block_store, batch_tracker,
    merkle_db, get_current_root, receipt_store, state_delta_processor,
    state_delta_store, event_broadcaster, permission_verifier, thread_pool,
    sig_pool,
):

    # -- Transaction Processor -- #
    dispatcher.add_handler(
        validator_pb2.Message.TP_ADD_RECEIPT_DATA_REQUEST,
        tp_state_handlers.TpAddReceiptDataHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_ADD_EVENT_REQUEST,
        tp_state_handlers.TpAddEventHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_DEL_REQUEST,
        tp_state_handlers.TpStateDeleteHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_GET_REQUEST,
        tp_state_handlers.TpStateGetHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_STATE_SET_REQUEST,
        tp_state_handlers.TpStateSetHandler(context_manager),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_REGISTER_REQUEST,
        processor_handlers.ProcessorRegisterHandler(executor.processors),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.TP_UNREGISTER_REQUEST,
        processor_handlers.ProcessorUnRegisterHandler(executor.processors),
        thread_pool)

    # -- Client -- #
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        BatchListPermissionVerifier(
            permission_verifier=permission_verifier
        ),
        sig_pool)

    # Submit
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        signature_verifier.BatchListSignatureVerifier(),
        sig_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        structure_verifier.BatchListStructureVerifier(),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        CompleterBatchListBroadcastHandler(
            completer, gossip),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        client_handlers.BatchSubmitFinisher(batch_tracker),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
        client_handlers.BatchStatusRequest(batch_tracker),
        thread_pool)

    # State
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_LIST_REQUEST,
        client_handlers.StateListRequest(
            merkle_db,
            block_store),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_GET_REQUEST,
        client_handlers.StateGetRequest(
            merkle_db,
            block_store),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_CURRENT_REQUEST,
        client_handlers.StateCurrentRequest(
            get_current_root), thread_pool)

    # Blocks
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_LIST_REQUEST,
        client_handlers.BlockListRequest(block_store),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_REQUEST,
        client_handlers.BlockGetRequest(block_store),
        thread_pool)

    # Batches
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_LIST_REQUEST,
        client_handlers.BatchListRequest(block_store),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_GET_REQUEST,
        client_handlers.BatchGetRequest(block_store),
        thread_pool)

    # Transactions
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_LIST_REQUEST,
        client_handlers.TransactionListRequest(
            block_store),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_GET_REQUEST,
        client_handlers.TransactionGetRequest(
            block_store),
        thread_pool)

    # Receipts
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_RECEIPT_GET_REQUEST,
        ClientReceiptGetRequestHandler(receipt_store),
        thread_pool)

    # Events
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeValidationHandler(event_broadcaster),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeHandler(event_broadcaster),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_UNSUBSCRIBE_REQUEST,
        ClientEventsUnsubscribeHandler(event_broadcaster),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_GET_REQUEST,
        ClientEventsGetRequestHandler(event_broadcaster),
        thread_pool)

    # -- State Delta -- #
    dispatcher.add_handler(
        validator_pb2.Message.STATE_DELTA_SUBSCRIBE_REQUEST,
        StateDeltaSubscriberValidationHandler(state_delta_processor),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.STATE_DELTA_SUBSCRIBE_REQUEST,
        StateDeltaAddSubscriberHandler(state_delta_processor),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.STATE_DELTA_UNSUBSCRIBE_REQUEST,
        StateDeltaUnsubscriberHandler(state_delta_processor),
        thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.STATE_DELTA_GET_EVENTS_REQUEST,
        StateDeltaGetEventsHandler(block_store, state_delta_store),
        thread_pool)
Exemple #6
0
def add(
        dispatcher,
        gossip,
        completer,
        block_store,
        batch_tracker,
        merkle_db,
        get_current_root,
        receipt_store,
        event_broadcaster,
        permission_verifier,
        thread_pool,
        client_thread_pool,
        sig_pool,
        journal,
        public_key,
):

    # -- Client -- #
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        BatchListPermissionVerifier(
            permission_verifier=permission_verifier
        ),
        sig_pool)

    # Submit
    dispatcher.set_preprocessor(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        client_handlers.client_batch_submit_request_preprocessor,
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        ClientBatchSubmitBackpressureHandler(
            public_key,
            journal.is_batch_pool_full),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        signature_verifier.BatchListSignatureVerifier(),
        sig_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        structure_verifier.BatchListStructureVerifier(),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        CompleterBatchListBroadcastHandler(
            completer, gossip),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_SUBMIT_REQUEST,
        client_handlers.BatchSubmitFinisher(batch_tracker),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_STATUS_REQUEST,
        client_handlers.BatchStatusRequest(batch_tracker),
        client_thread_pool)

    # State
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_LIST_REQUEST,
        client_handlers.StateListRequest(
            merkle_db,
            block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATE_GET_REQUEST,
        client_handlers.StateGetRequest(
            merkle_db,
            block_store),
        client_thread_pool)

    # Blocks
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_LIST_REQUEST,
        client_handlers.BlockListRequest(block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_ID_REQUEST,
        client_handlers.BlockGetByIdRequest(block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_NUM_REQUEST,
        client_handlers.BlockGetByNumRequest(block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_BATCH_ID_REQUEST,
        client_handlers.BlockGetByBatchRequest(block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BLOCK_GET_BY_TRANSACTION_ID_REQUEST,
        client_handlers.BlockGetByTransactionRequest(block_store),
        client_thread_pool)

    # Batches
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_LIST_REQUEST,
        client_handlers.BatchListRequest(block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_BATCH_GET_REQUEST,
        client_handlers.BatchGetRequest(block_store),
        client_thread_pool)

    # Transactions
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_LIST_REQUEST,
        client_handlers.TransactionListRequest(
            block_store),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_TRANSACTION_GET_REQUEST,
        client_handlers.TransactionGetRequest(
            block_store),
        client_thread_pool)

    # Receipts
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_RECEIPT_GET_REQUEST,
        ClientReceiptGetRequestHandler(receipt_store),
        client_thread_pool)

    # Events
    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeValidationHandler(event_broadcaster),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_SUBSCRIBE_REQUEST,
        ClientEventsSubscribeHandler(event_broadcaster),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_UNSUBSCRIBE_REQUEST,
        ClientEventsUnsubscribeHandler(event_broadcaster),
        client_thread_pool)

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_EVENTS_GET_REQUEST,
        ClientEventsGetRequestHandler(event_broadcaster),
        client_thread_pool)

    # Peers

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_PEERS_GET_REQUEST,
        client_handlers.PeersGetRequest(gossip),
        thread_pool)

    # Status

    dispatcher.add_handler(
        validator_pb2.Message.CLIENT_STATUS_GET_REQUEST,
        client_handlers.StatusGetRequest(gossip),
        thread_pool)

    # Ping

    dispatcher.add_handler(
        validator_pb2.Message.PING_RESPONSE,
        PingResponseHandler(),
        thread_pool)