def write_req_manager(db): manager = WriteRequestManager(db) write_req_handler = NodeHandler(db, None) batch_req_handler = DomainBatchHandler(db) manager.register_req_handler(write_req_handler) manager.register_batch_handler(batch_req_handler) # We do not need to check request handler workability handler = manager.request_handlers[NODE][0] handler.static_validation = lambda request: 1 handler.dynamic_validation = lambda request: 1 handler.update_state = lambda txn, updated_state, request, is_committed: 1 handler.apply_request = lambda request, batch_ts, prev_result: (1, 1, 1) handler.apply_forced_request = lambda request: 1 handler.transform_txn_for_ledger = lambda txn: 1 # Same for batches handler = manager.batch_handlers[DOMAIN_LEDGER_ID][0] handler.post_batch_applied = lambda batch, prev_handler_result: 1 handler.commit_batch = lambda batch, prev_handler_result=None: 1 handler.post_batch_rejected = lambda ledger_id, prev_handler_result: 1 return manager
def node_handler(): data_manager = DatabaseManager() bls = FakeSomething() handler = NodeHandler(data_manager, bls) state = PruningState(KeyValueStorageInMemory()) data_manager.register_new_database(handler.ledger_id, FakeSomething(), state) return handler
def node_handler(): data_manager = DatabaseManager() bls = FakeSomething() handler = NodeHandler(data_manager, bls) state = State() state.txn_list = {} state.get = lambda key, is_committed: state.txn_list.get(key, None) state.set = lambda key, value: state.txn_list.update({key: value}) data_manager.register_new_database(handler.ledger_id, FakeSomething(), state) return handler
def test_write_request_manager_chain_of_responsib_apply(write_req_manager: WriteRequestManager, node_req, db): write_req_manager.request_handlers[NODE] = [] handlers = write_req_manager.request_handlers[NODE] check_list = [FakeSomething(), FakeSomething(), FakeSomething()] node_req.check_list = check_list for check in check_list: check.check_field = False def modify_check_list(request, batch_ts, prev_result): assert not all(check.check_field for check in check_list) f_check = next(check for check in request.check_list if check.check_field is False) f_check.check_field = True return 1, 1, 1 for i in range(3): handler = NodeHandler(db, None) handler.apply_request = modify_check_list handlers.append(handler) write_req_manager.apply_request(node_req, 0) assert all(check.check_field for check in check_list)
def register_pool_req_handlers(self): node_handler = NodeHandler(self.node.db_manager, self.node.bls_bft.bls_crypto_verifier) self.node.write_manager.register_req_handler(node_handler)