Skip to content

Commit

Permalink
GH-1510 WIP: Move instant finality activation before bios setting in …
Browse files Browse the repository at this point in the history
…bootstrap. This doesn't work. Need to move to using boot contract.
  • Loading branch information
heifner committed Dec 15, 2023
1 parent eeebc41 commit 21d51d3
Showing 1 changed file with 52 additions and 43 deletions.
95 changes: 52 additions & 43 deletions tests/TestHarness/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,55 @@ def parseClusterKeys(totalNodes):
Utils.Print(f'Found {len(producerKeys)} producer keys')
return producerKeys

def activateInstantFinality(self, launcher):
# publish bios contract with setfinalizer
contract = "eosio.bios"
contractDir = str(self.libTestingContractsPath / contract)
wasmFile = "%s.wasm" % (contract)
abiFile = "%s.abi" % (contract)
Utils.Print("Publish %s contract" % (contract))
# assumes eosio already in wallet
eosioAccount=Account("eosio")
trans = self.biosNode.publishContract(eosioAccount, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None
Node.validateTransaction(trans)

# call setfinalizer
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' "weight":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 = self.biosNode.pushMessage("eosio", "setfinalizer", setFinStr, opts)
if trans is None or not trans[0]:
Utils.Print("ERROR: Failed to set finalizers")
return None
Node.validateTransaction(trans[1])
transId = Node.getTransId(trans[1])
if not self.biosNode.waitForTransFinalization(transId, timeout=21*12*3):
Utils.Print("ERROR: Failed to validate transaction %s got rolled into a LIB block on server port %d." % (transId, biosNode.port))
return None

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 @@ -1028,6 +1077,9 @@ def bootstrap(self, launcher, biosNode, totalNodes, prodCount, totalProducers,
Utils.Print("ERROR: Failed to import %s account keys into ignition wallet." % (eosioName))
return None

if activateIF:
self.activateInstantFinality(launcher)

contract="eosio.bios"
contractDir= str(self.libTestingContractsPath / contract)
if PFSetupPolicy.hasPreactivateFeature(pfSetupPolicy):
Expand Down Expand Up @@ -1154,49 +1206,6 @@ def createSystemAccount(accountName):
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None

# enable instant finality
if activateIF:
# publish bios contract with setfinalizer
contract = "eosio.bios"
contractDir = str(self.libTestingContractsPath / contract)
wasmFile = "%s.wasm" % (contract)
abiFile = "%s.abi" % (contract)
Utils.Print("Publish %s contract" % (contract))
trans = biosNode.publishContract(eosioAccount, contractDir, wasmFile, abiFile, waitForTransBlock=True)
if trans is None:
Utils.Print("ERROR: Failed to publish contract %s." % (contract))
return None
Node.validateTransaction(trans)

# call setfinalizer
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' "weight":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

0 comments on commit 21d51d3

Please sign in to comment.