Skip to content

Commit

Permalink
GH-1510 Add --activate-if which calls setfinalizer on bios contract w…
Browse files Browse the repository at this point in the history
…ith bls public key
  • Loading branch information
heifner committed Dec 18, 2023
1 parent 2242de7 commit 0fd01b4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 8 deletions.
37 changes: 34 additions & 3 deletions tests/TestHarness/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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))
Expand Down
3 changes: 3 additions & 0 deletions tests/TestHarness/TestHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <test_name><pid>/node_* folders, or other test specific log directories, upon test completion",
action='store_true')
Expand Down
5 changes: 3 additions & 2 deletions tests/distributed-transactions-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,6 +36,7 @@
seed=args.seed
dumpErrorDetails=args.dump_error_details
speculative=args.speculative
activateIF=args.activate_if

Utils.Debug=debug
testSuccessful=False
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions tests/nodeos_run_test.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0fd01b4

Please sign in to comment.