From 0fd01b4d5cc5eebc9640800627d82bbc7eb4fad4 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Thu, 14 Dec 2023 10:38:41 -0600 Subject: [PATCH] GH-1510 Add --activate-if which calls setfinalizer on bios contract with bls public key --- tests/TestHarness/Cluster.py | 37 +++++++++++++++++++++++--- tests/TestHarness/TestHelper.py | 3 +++ tests/distributed-transactions-test.py | 5 ++-- tests/nodeos_run_test.py | 6 ++--- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/tests/TestHarness/Cluster.py b/tests/TestHarness/Cluster.py index cc954ba36a..2d37ba3a1f 100644 --- a/tests/TestHarness/Cluster.py +++ b/tests/TestHarness/Cluster.py @@ -167,7 +167,8 @@ def setAlternateVersionLabels(self, file): # pylint: disable=too-many-statements def launch(self, pnodes=1, unstartedNodes=0, totalNodes=1, prodCount=21, topo="mesh", delay=2, onlyBios=False, dontBootstrap=False, totalProducers=None, sharedProducers=0, extraNodeosArgs="", specificExtraNodeosArgs=None, specificNodeosInstances=None, onlySetProds=False, - pfSetupPolicy=PFSetupPolicy.FULL, alternateVersionLabelsFile=None, associatedNodeLabels=None, loadSystemContract=True, nodeosLogPath=Path(Utils.TestLogRoot) / Path(f'{Path(sys.argv[0]).stem}{os.getpid()}'), genesisPath=None, + pfSetupPolicy=PFSetupPolicy.FULL, alternateVersionLabelsFile=None, associatedNodeLabels=None, loadSystemContract=True, activateIF=False, + nodeosLogPath=Path(Utils.TestLogRoot) / Path(f'{Path(sys.argv[0]).stem}{os.getpid()}'), genesisPath=None, maximumP2pPerHost=0, maximumClients=25, prodsEnableTraceApi=True): """Launch cluster. pnodes: producer nodes count @@ -519,7 +520,7 @@ def connectGroup(group, producerNodes, bridgeNodes) : return True Utils.Print("Bootstrap cluster.") - if not self.bootstrap(self.biosNode, self.startedNodesCount, prodCount + sharedProducers, totalProducers, pfSetupPolicy, onlyBios, onlySetProds, loadSystemContract): + if not self.bootstrap(launcher, self.biosNode, self.startedNodesCount, prodCount + sharedProducers, totalProducers, pfSetupPolicy, onlyBios, onlySetProds, loadSystemContract, activateIF): Utils.Print("ERROR: Bootstrap failed.") return False @@ -991,7 +992,7 @@ def parseClusterKeys(totalNodes): Utils.Print(f'Found {len(producerKeys)} producer keys') return producerKeys - def bootstrap(self, biosNode, totalNodes, prodCount, totalProducers, pfSetupPolicy, onlyBios=False, onlySetProds=False, loadSystemContract=True): + def bootstrap(self, launcher, biosNode, totalNodes, prodCount, totalProducers, pfSetupPolicy, onlyBios=False, onlySetProds=False, loadSystemContract=True, activateIF=False): """Create 'prodCount' init accounts and deposits 10000000000 SYS in each. If prodCount is -1 will initialize all possible producers. Ensure nodes are inter-connected prior to this call. One way to validate this will be to check if every node has block 1.""" @@ -1153,6 +1154,36 @@ def createSystemAccount(accountName): Utils.Print("ERROR: Failed to publish contract %s." % (contract)) return None + # enable instant finality + if activateIF: + numFins = len(launcher.network.nodes.values()) + setFinStr = f'{{"finalizer_policy": {{' + setFinStr += f' "threshold": {int(numFins * 2 / 3 + 1)}, ' + setFinStr += f' "finalizers": [' + finNum = 1 + for n in launcher.network.nodes.values(): + if n.keys[0].blspubkey is None: + continue + if len(n.producers) == 0: + continue + setFinStr += f' {{"description": "finalizer #{finNum}", ' + setFinStr += f' "fweight":1, ' + setFinStr += f' "public_key": "{n.keys[0].blspubkey}", ' + setFinStr += f' "pop": "{n.keys[0].blspop}"' + setFinStr += f' }}' + if finNum != numFins: + setFinStr += f', ' + finNum = finNum + 1 + setFinStr += f' ]' + setFinStr += f'}}}}' + if Utils.Debug: Utils.Print("setfinalizers: %s" % (setFinStr)) + Utils.Print("Setting finalizers") + opts = "--permission eosio@active" + trans = biosNode.pushMessage("eosio", "setfinalizer", setFinStr, opts) + if trans is None or not trans[0]: + Utils.Print("ERROR: Failed to set finalizers") + return None + # Create currency0000, followed by issue currency0000 contract=eosioTokenAccount.name Utils.Print("push create action to %s contract" % (contract)) diff --git a/tests/TestHarness/TestHelper.py b/tests/TestHarness/TestHelper.py index 6f3a1244ae..07790d301a 100644 --- a/tests/TestHarness/TestHelper.py +++ b/tests/TestHarness/TestHelper.py @@ -97,6 +97,9 @@ def createArgumentParser(includeArgs, applicationSpecificArgs=AppArgs(), suppres if "--dont-launch" in includeArgs: thGrp.add_argument("--dont-launch", help=argparse.SUPPRESS if suppressHelp else "Don't launch own node. Assume node is already running.", action='store_true') + if "--activate-if" in includeArgs: + thGrp.add_argument("--activate-if", help=argparse.SUPPRESS if suppressHelp else "Activate instant finality during bios boot.", + action='store_true') if "--keep-logs" in includeArgs: thGrp.add_argument("--keep-logs", help=argparse.SUPPRESS if suppressHelp else "Don't delete /node_* folders, or other test specific log directories, upon test completion", action='store_true') diff --git a/tests/distributed-transactions-test.py b/tests/distributed-transactions-test.py index 985ad83168..77e7d7bbc1 100755 --- a/tests/distributed-transactions-test.py +++ b/tests/distributed-transactions-test.py @@ -23,7 +23,7 @@ appArgs = AppArgs() extraArgs = appArgs.add_bool(flag="--speculative", help="Run nodes in read-mode=speculative") -args=TestHelper.parse_args({"-p","-n","-d","-s","--nodes-file","--seed", "--speculative" +args=TestHelper.parse_args({"-p","-n","-d","-s","--nodes-file","--seed", "--speculative", "--activate-if" ,"--dump-error-details","-v","--leave-running","--keep-logs","--unshared"}, applicationSpecificArgs=appArgs) pnodes=args.p @@ -36,6 +36,7 @@ seed=args.seed dumpErrorDetails=args.dump_error_details speculative=args.speculative +activateIF=args.activate_if Utils.Debug=debug testSuccessful=False @@ -67,7 +68,7 @@ if speculative: extraNodeosArgs = " --read-mode speculative " - if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, topo=topo, delay=delay, extraNodeosArgs=extraNodeosArgs) is False: + if cluster.launch(pnodes=pnodes, totalNodes=total_nodes, topo=topo, delay=delay, extraNodeosArgs=extraNodeosArgs, activateIF=activateIF) is False: errorExit("Failed to stand up eos cluster.") Print ("Wait for Cluster stabilization") diff --git a/tests/nodeos_run_test.py b/tests/nodeos_run_test.py index d131b993c9..e366dbcebf 100755 --- a/tests/nodeos_run_test.py +++ b/tests/nodeos_run_test.py @@ -1,7 +1,6 @@ #!/usr/bin/env python3 from TestHarness import Account, Cluster, Node, ReturnType, TestHelper, Utils, WalletMgr, CORE_SYMBOL, createAccountKeys -from pathlib import Path import decimal import re @@ -22,7 +21,7 @@ args = TestHelper.parse_args({"--host","--port","--prod-count","--defproducera_prvt_key","--defproducerb_prvt_key" ,"--dump-error-details","--dont-launch","--keep-logs","-v","--leave-running","--only-bios" - ,"--sanity-test","--wallet-port", "--error-log-path", "--unshared"}) + ,"--activate-if","--sanity-test","--wallet-port", "--error-log-path", "--unshared"}) server=args.host port=args.port debug=args.v @@ -34,6 +33,7 @@ onlyBios=args.only_bios sanityTest=args.sanity_test walletPort=args.wallet_port +activateIF=args.activate_if Utils.Debug=debug localTest=True if server == TestHelper.LOCAL_HOST else False @@ -63,7 +63,7 @@ traceNodeosArgs=" --http-max-response-time-ms 990000 --trace-rpc-abi eosio.token=" + abs_path extraNodeosArgs=traceNodeosArgs + " --plugin eosio::prometheus_plugin --database-map-mode mapped_private " specificNodeosInstances={0: "bin/nodeos"} - if cluster.launch(totalNodes=2, prodCount=prodCount, onlyBios=onlyBios, dontBootstrap=dontBootstrap, extraNodeosArgs=extraNodeosArgs, specificNodeosInstances=specificNodeosInstances) is False: + if cluster.launch(totalNodes=2, prodCount=prodCount, activateIF=activateIF, onlyBios=onlyBios, dontBootstrap=dontBootstrap, extraNodeosArgs=extraNodeosArgs, specificNodeosInstances=specificNodeosInstances) is False: cmdError("launcher") errorExit("Failed to stand up eos cluster.") else: