def chkFreqPatched(tconf, request): oldChkFreq = tconf.CHK_FREQ oldLogSize = tconf.LOG_SIZE tconf.CHK_FREQ = getValueFromModule(request, "CHK_FREQ", 2) tconf.LOG_SIZE = getValueFromModule(request, "LOG_SIZE", 2 * tconf.CHK_FREQ) def reset(): tconf.CHK_FREQ = oldChkFreq tconf.LOG_SIZE = oldLogSize request.addfinalizer(reset) return tconf
def nodeCreatedAfterSomeTxns(txnPoolNodeSet, tdirWithPoolTxns, poolTxnStewardData, tconf, allPluginsPath, request): with Looper(debug=True) as looper: client, wallet = buildPoolClientAndWallet(poolTxnStewardData, tdirWithPoolTxns, clientClass=TestClient) looper.add(client) looper.run(client.ensureConnectedToNodes()) txnCount = getValueFromModule(request, "txnCount", 5) sendReqsToNodesAndVerifySuffReplies(looper, wallet, client, txnCount, timeoutPerReq=25) newStewardName = randomString() newNodeName = "Epsilon" newStewardClient, newStewardWallet, newNode = addNewStewardAndNode( looper, client, wallet, newStewardName, newNodeName, tdirWithPoolTxns, tconf, allPluginsPath=allPluginsPath, autoStart=True) yield looper, newNode, client, wallet, newStewardClient, \ newStewardWallet
def nodeCreatedAfterSomeTxns(looper, testNodeClass, do_post_node_creation, txnPoolNodeSet, tdir, tdirWithClientPoolTxns, poolTxnStewardData, tconf, allPluginsPath, request): client, wallet = buildPoolClientAndWallet(poolTxnStewardData, tdirWithClientPoolTxns, clientClass=TestClient) looper.add(client) looper.run(client.ensureConnectedToNodes()) txnCount = getValueFromModule(request, "txnCount", 5) sendReqsToNodesAndVerifySuffReplies(looper, wallet, client, txnCount) newStewardName = randomString() newNodeName = "Epsilon" newStewardClient, newStewardWallet, newNode = addNewStewardAndNode( looper, client, wallet, newStewardName, newNodeName, tdir, tdirWithClientPoolTxns, tconf, nodeClass=testNodeClass, allPluginsPath=allPluginsPath, autoStart=True, do_post_node_creation=do_post_node_creation) yield looper, newNode, client, wallet, newStewardClient, \ newStewardWallet
def fake_view_changer(request, tconf): node_count = 4 node_stack = FakeSomething( name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}, conns={"Alpha", "Beta", "Gamma", "Delta"} ) monitor = FakeSomething( isMasterDegraded=lambda: False, areBackupsDegraded=lambda: [], prettymetrics='' ) node = FakeSomething( name="SomeNode", viewNo=request.param, quorums=Quorums(getValueFromModule(request, 'nodeCount', default=node_count)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch(), config=tconf, monitor=monitor, discard=lambda a, b, c: print(b), primaries_disconnection_times=[None] * getRequiredInstances(node_count), master_primary_name='Alpha', master_replica=FakeSomething(instId=0) ) view_changer = ViewChanger(node) return view_changer
def fees(request): default_fees = {NYM: 4, XFER_PUBLIC: 0} if request.param: default_fees[XFER_PUBLIC] = 8 fees = getValueFromModule(request, "TXN_FEES", default_fees) return fees
def nodeSet(request, tdir, nodeReg, allPluginsPath): primaryDecider = getValueFromModule(request, "PrimaryDecider", None) with TestNodeSet(nodeReg=nodeReg, tmpdir=tdir, primaryDecider=primaryDecider, pluginPaths=allPluginsPath) as ns: yield ns
def fees(request): default_fees = { NYM_FEES_ALIAS: 4, XFER_PUBLIC_FEES_ALIAS: 8 } fees = getValueFromModule(request, "TXN_FEES", default_fees) return fees
def fake_view_changer(request, tconf): node_count = 4 node_stack = FakeSomething(name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}, conns={"Alpha", "Beta", "Gamma", "Delta"}) monitor = FakeSomething(isMasterDegraded=lambda: False, areBackupsDegraded=lambda: [], prettymetrics='') node = FakeSomething(name="SomeNode", timer=QueueTimer(), viewNo=request.param, quorums=Quorums( getValueFromModule(request, 'nodeCount', default=node_count)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch(), config=tconf, monitor=monitor, discard=lambda a, b, c, d: print(b), primaries_disconnection_times=[None] * getRequiredInstances(node_count), master_primary_name='Alpha', master_replica=FakeSomething( instId=0, viewNo=request.param, _consensus_data=FakeSomething( view_no=request.param, waiting_for_new_view=False)), nodeStatusDB=None) view_changer = create_view_changer(node) # TODO: This is a hack for tests compatibility, do something better view_changer.node = node return view_changer
def fake_view_changer(request, tconf): node_count = 4 node_stack = FakeSomething(name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}, conns={"Alpha", "Beta", "Gamma", "Delta"}) monitor = FakeSomething(isMasterDegraded=lambda: False, areBackupsDegraded=lambda: [], prettymetrics='') node = FakeSomething(name="SomeNode", viewNo=request.param, quorums=Quorums( getValueFromModule(request, 'nodeCount', default=node_count)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch(), config=tconf, monitor=monitor, discard=lambda a, b, c: print(b), primaries_disconnection_times=[None] * getRequiredInstances(node_count), master_primary_name='Alpha', master_replica=FakeSomething(instId=0)) view_changer = ViewChanger(node) return view_changer
def perf_chk_patched(tconf, request): old_val = tconf.PerfCheckFreq tconf.PerfCheckFreq = getValueFromModule(request, "PerfCheckFreq", 20) def reset(): tconf.PerfCheckFreq = old_val request.addfinalizer(reset) return tconf
def tconf(tconf, request): oldSize = tconf.Max3PCBatchSize tconf.Max3PCBatchSize = getValueFromModule(request, "Max3PCBatchSize", 10) def reset(): tconf.Max3PCBatchSize = oldSize request.addfinalizer(reset) return tconf
def replica(tconf, viewNo, inst_id, ledger_ids, mock_timestamp, fake_requests, txn_roots, state_roots, request): node = ReplicaFakeNode(viewNo=viewNo, quorums=Quorums( getValueFromModule(request, 'nodeCount', default=4)), ledger_ids=ledger_ids) bls_bft_replica = FakeSomething( gc=lambda *args: None, update_pre_prepare=lambda params, l_id: params, validate_pre_prepare=lambda a, b: None, validate_prepare=lambda a, b: None, update_prepare=lambda a, b: a, process_prepare=lambda a, b: None, process_pre_prepare=lambda a, b: None, process_order=lambda *args: None) replica = Replica(node, instId=inst_id, isMaster=inst_id == 0, config=tconf, bls_bft_replica=bls_bft_replica, get_current_time=mock_timestamp, get_time_for_3pc_batch=mock_timestamp) node.add_replica(replica) ReplicaFakeNode.master_last_ordered_3PC = replica.last_ordered_3pc replica._ordering_service.last_accepted_pre_prepare_time = replica.get_time_for_3pc_batch( ) replica.primaryName = "Alpha:{}".format(replica.instId) replica.primaryNames[replica.viewNo] = replica.primaryName replica._ordering_service.get_txn_root_hash = lambda ledger, to_str=False: txn_roots[ ledger] replica._ordering_service.get_state_root_hash = lambda ledger, to_str=False: state_roots[ ledger] replica._ordering_service._revert = lambda ledgerId, stateRootHash, reqCount: None replica._ordering_service.post_batch_creation = lambda three_pc_batch: None replica._ordering_service.requestQueues[DOMAIN_LEDGER_ID] = OrderedSet() replica._ordering_service._get_primaries_for_ordered = lambda pp: [ replica.primaryName ] replica._ordering_service._get_node_reg_for_ordered = lambda pp: [ "Alpha", "Beta", "Gamma", "Delta" ] def reportSuspiciousNodeEx(ex): assert False, ex replica.node.reportSuspiciousNodeEx = reportSuspiciousNodeEx return replica
def poolAfterSomeTxns( looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, request): txnCount = getValueFromModule(request, "txnCount", 5) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, txnCount) yield looper, sdk_pool_handle, sdk_wallet_client
def replica(tconf, viewNo, inst_id, request): node = ReplicaFakeNode(viewNo=viewNo, quorums=Quorums(getValueFromModule(request, 'nodeCount', default=4))) bls_bft_replica = FakeSomething( gc=lambda *args: None, update_pre_prepare=lambda params, l_id: params ) replica = Replica( node, instId=inst_id, isMaster=inst_id == 0, config=tconf, bls_bft_replica=bls_bft_replica ) ReplicaFakeNode.master_last_ordered_3PC = replica.last_ordered_3pc return replica
def poolAfterSomeTxns(looper, txnPoolNodesLooper, txnPoolNodeSet, tdirWithClientPoolTxns, poolTxnStewardData, allPluginsPath, request): client, wallet = buildPoolClientAndWallet(poolTxnStewardData, tdirWithClientPoolTxns, clientClass=TestClient) looper.run(checkNodesConnected(txnPoolNodeSet)) looper.add(client) looper.run(client.ensureConnectedToNodes()) txnCount = getValueFromModule(request, "txnCount", 5) sendReqsToNodesAndVerifySuffReplies(txnPoolNodesLooper, wallet, client, txnCount) yield looper, client, wallet
def testNodeRejectingInvalidTxns(looper, sdk_pool_handle, sdk_wallet_client, tconf, tdir, txnPoolNodeSet, patched_node, request, sdk_wallet_steward, testNodeClass, allPluginsPath, do_post_node_creation): """ A newly joined node is catching up and sends catchup requests to other nodes but one of the nodes replies with incorrect transactions. The newly joined node detects that and rejects the transactions and thus blacklists the node. Ii thus cannot complete the process till the timeout and then requests the missing transactions. """ txnCount = getValueFromModule(request, "txnCount", 5) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, txnCount) new_steward_name = randomString() new_node_name = "Epsilon" new_steward_wallet_handle, new_node = sdk_add_new_steward_and_node( looper, sdk_pool_handle, sdk_wallet_steward, new_steward_name, new_node_name, tdir, tconf, nodeClass=testNodeClass, allPluginsPath=allPluginsPath, autoStart=True, do_post_node_creation=do_post_node_creation) sdk_pool_refresh(looper, sdk_pool_handle) bad_node = patched_node do_not_tell_clients_about_newly_joined_node(txnPoolNodeSet) logger.debug('Catchup request processor of {} patched'.format(bad_node)) looper.run(checkNodesConnected(txnPoolNodeSet)) # catchup #1 -> CatchupTransactionsTimeout -> catchup #2 catchup_timeout = waits.expectedPoolCatchupTime(len(txnPoolNodeSet) + 1) timeout = 2 * catchup_timeout + tconf.CatchupTransactionsTimeout # have to skip seqno_db check because the txns are not executed # on the new node waitNodeDataEquality(looper, new_node, *txnPoolNodeSet[:-1], customTimeout=timeout) assert new_node.isNodeBlacklisted(bad_node.name)
def fake_view_changer(request, tconf): node_stack = FakeSomething(name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}) monitor = FakeSomething(isMasterDegraded=lambda: False, ) node = FakeSomething( name="SomeNode", viewNo=request.param, quorums=Quorums(getValueFromModule(request, 'nodeCount', default=4)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch(), config=tconf, monitor=monitor, discard=lambda a, b, c: print(b), ) view_changer = ViewChanger(node) return view_changer
def replica(tconf, viewNo, inst_id, ledger_ids, mock_timestamp, request): node = ReplicaFakeNode(viewNo=viewNo, quorums=Quorums(getValueFromModule(request, 'nodeCount', default=4)), ledger_ids=ledger_ids) bls_bft_replica = FakeSomething( gc=lambda *args: None, update_pre_prepare=lambda params, l_id: params ) replica = Replica( node, instId=inst_id, isMaster=inst_id == 0, config=tconf, bls_bft_replica=bls_bft_replica, get_current_time=mock_timestamp, get_time_for_3pc_batch=mock_timestamp ) ReplicaFakeNode.master_last_ordered_3PC = replica.last_ordered_3pc return replica
def sdk_node_created_after_some_txns_not_started(looper, testNodeClass, do_post_node_creation, sdk_pool_handle, sdk_wallet_client, sdk_wallet_steward, txnPoolNodeSet, tdir, tconf, allPluginsPath, request): txnCount = getValueFromModule(request, "txnCount", 5) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, txnCount) new_steward_name = randomString() new_node_name = "Epsilon" new_steward_wallet_handle, new_node = sdk_add_new_steward_and_node( looper, sdk_pool_handle, sdk_wallet_steward, new_steward_name, new_node_name, tdir, tconf, nodeClass=testNodeClass, allPluginsPath=allPluginsPath, autoStart=False, do_post_node_creation=do_post_node_creation) sdk_pool_refresh(looper, sdk_pool_handle) yield looper, new_node, sdk_pool_handle, new_steward_wallet_handle
def checkpoint_size(tconf, request): oldChkFreq = tconf.CHK_FREQ oldLogSize = tconf.LOG_SIZE oldMax3PCBatchSize = tconf.Max3PCBatchSize tconf.Max3PCBatchSize = 3 tconf.CHK_FREQ = getValueFromModule(request, "CHK_FREQ", 2) tconf.LOG_SIZE = 2 * tconf.CHK_FREQ def reset(): tconf.CHK_FREQ = oldChkFreq tconf.LOG_SIZE = oldLogSize tconf.Max3PCBatchSize = oldMax3PCBatchSize request.addfinalizer(reset) return tconf.CHK_FREQ * tconf.Max3PCBatchSize
def signatures(request, roles): ''' Combinations of all signature types and signature count. Example: - roles=[A, B] - sig_count=1..3 =>[(), (A: 1), (B:1), (A: 2), (B: 2), (A: 3), (B: 3), (A:1, B: 1), (A:2, B: 1), (A:1, B: 2), (A:2, B: 2), (A:1, B: 3), (A:3, B: 1), (A:3, B: 3), (A:2, B: 3), (A:3, B: 2)] ''' max_sig_count = getValueFromModule(request, "MAX_SIG_COUNT", 3) all_sigs_count = list(range(1, max_sig_count)) return [{role: sig_count for role, sig_count in zip(roles, sigs_count)} for sigs_count in product(all_sigs_count, repeat=len(roles))]
def replica(tconf, request): node_stack = FakeSomething(name="fake stack", connecteds={"Alpha", "Beta", "Gamma", "Delta"}) node = FakeSomething(name="fake node", ledger_ids=[0], viewNo=request.param, quorums=Quorums( getValueFromModule(request, 'nodeCount', default=4)), nodestack=node_stack, utc_epoch=lambda *args: get_utc_epoch()) bls_bft_replica = FakeSomething(gc=lambda *args: None, ) replica = Replica(node, instId=0, isMaster=False, config=tconf, bls_bft_replica=bls_bft_replica) return replica
def sdk_node_created_after_some_txns_not_started( looper, testNodeClass, do_post_node_creation, sdk_pool_handle, sdk_wallet_client, sdk_wallet_steward, txnPoolNodeSet, tdir, tconf, allPluginsPath, request): txnCount = getValueFromModule(request, "txnCount", 5) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, txnCount) new_steward_name = randomString() new_node_name = "Epsilon" new_steward_wallet_handle, new_node = sdk_add_new_steward_and_node( looper, sdk_pool_handle, sdk_wallet_steward, new_steward_name, new_node_name, tdir, tconf, nodeClass=testNodeClass, allPluginsPath=allPluginsPath, autoStart=False, do_post_node_creation=do_post_node_creation) sdk_pool_refresh(looper, sdk_pool_handle) yield looper, new_node, sdk_pool_handle, new_steward_wallet_handle
def sdk_node_created_after_some_txns(looper, testNodeClass, do_post_node_creation, sdk_pool_handle, sdk_wallet_client, sdk_wallet_steward, txnPoolNodeSet, tdir, tconf, allPluginsPath, request, setup): def post_node_creation(node): write_rh = WriteConfHandler(node.db_manager) read_rh = ReadConfHandler(node.db_manager) node.write_manager.register_req_handler(write_rh) node.read_manager.register_req_handler(read_rh) ca = node.clientAuthNr.core_authenticator ca._write_types.add(write_rh.txn_type) ca._query_types.add(read_rh.txn_type) do_post_node_creation(node) return node txnCount = getValueFromModule(request, "txnCount", 5) sdk_send_random_and_check(looper, txnPoolNodeSet, sdk_pool_handle, sdk_wallet_client, txnCount) new_steward_name = randomString() new_node_name = "Epsilon" new_steward_wallet_handle, new_node = sdk_add_new_steward_and_node( looper, sdk_pool_handle, sdk_wallet_steward, new_steward_name, new_node_name, tdir, tconf, nodeClass=testNodeClass, allPluginsPath=allPluginsPath, autoStart=True, do_post_node_creation=post_node_creation) sdk_pool_refresh(looper, sdk_pool_handle) yield looper, new_node, sdk_pool_handle, new_steward_wallet_handle
def nodeCreatedAfterSomeTxns( txnPoolNodesLooper, txnPoolNodeSet, tdirWithPoolTxns, poolTxnStewardData, tconf, allPluginsPath, request ): # with Looper(debug=True) as looper: client, wallet = buildPoolClientAndWallet(poolTxnStewardData, tdirWithPoolTxns, clientClass=TestClient) txnPoolNodesLooper.add(client) txnPoolNodesLooper.run(client.ensureConnectedToNodes()) txnCount = getValueFromModule(request, "txnCount", 5) sendReqsToNodesAndVerifySuffReplies(txnPoolNodesLooper, wallet, client, txnCount, timeoutPerReq=25) newStewardName = randomString() newNodeName = "Epsilon" newStewardClient, newStewardWallet, newNode = addNewStewardAndNode( txnPoolNodesLooper, client, wallet, newStewardName, newNodeName, tdirWithPoolTxns, tconf, allPluginsPath=allPluginsPath, autoStart=True, ) yield txnPoolNodesLooper, newNode, client, wallet, newStewardClient, newStewardWallet
def transfer_amount(request): return getValueFromModule(request, "TRANSFER_AMOUNT", 20)
def outputs_strategy(request): return getValueFromModule(request, "OUTPUTS_STRATEGY", OutputsStrategy.transfer_some_equal)
def inputs_strategy(request): return getValueFromModule(request, "INPUTS_STRATEGY", InputsStrategy.all_utxos)
def mint_amount(request): return getValueFromModule(request, "MINT_AMOUNT", 1000)
def mint_utxos_num(request): return getValueFromModule(request, "MINT_UTXOS_NUM", 3)
def mint_strategy(request): return getValueFromModule(request, "MINT_STRATEGY", MintStrategy.first_only)
def addresses_num(request): return getValueFromModule(request, "ADDRESSES_NUM", 2)
def fClient(request, client1: Client): makeClientFaulty(client1, getValueFromModule(request, "clientFault")) return client1
def faultyNodes(request): return getValueFromModule(request, "faultyNodes", 0)