Skip to content

Commit

Permalink
GH-1512 Refactor activateInstantFinality method so it can be called a…
Browse files Browse the repository at this point in the history
…fter bootstrap
  • Loading branch information
heifner committed Feb 6, 2024
1 parent 4e92a59 commit 22086f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
24 changes: 10 additions & 14 deletions tests/TestHarness/Cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def connectGroup(group, producerNodes, bridgeNodes) :
node = Node(self.host, self.port + nodeNum, nodeNum, Path(instance.data_dir_name),
Path(instance.config_dir_name), eosdcmd, unstarted=instance.dont_start,
launch_time=launcher.launch_time, walletMgr=self.walletMgr, nodeosVers=self.nodeosVers)
node.keys = instance.keys
if nodeNum == Node.biosNodeId:
self.biosNode = node
else:
Expand Down Expand Up @@ -993,34 +994,29 @@ def parseClusterKeys(totalNodes):
Utils.Print(f'Found {len(producerKeys)} producer keys')
return producerKeys

def activateInstantFinality(self, launcher, biosFinalizer, pnodes):
def activateInstantFinality(self, biosFinalizer=True):
# call setfinalizer
numFins = 0
for n in launcher.network.nodes.values():
if not n.keys or not n.keys[0].blspubkey:
for n in (self.nodes + [self.biosNode]):
if not n or not n.keys or not n.keys[0].blspubkey:
continue
if not n.producers:
continue
if n.index == Node.biosNodeId and not biosFinalizer:
if n.nodeId == Node.biosNodeId and not biosFinalizer:
continue
numFins = numFins + 1

threshold = int(numFins * 2 / 3 + 1)
if threshold > 2 and threshold == numFins:
# nodes are often stopped, so do not require all node votes
threshold = threshold - 1
# pnodes does not include biosNode
if Utils.Debug: Utils.Print(f"threshold: {threshold}, numFins: {numFins}, pnodes: {pnodes}")
if Utils.Debug: Utils.Print(f"threshold: {threshold}, numFins: {numFins}")
setFinStr = f'{{"finalizer_policy": {{'
setFinStr += f' "threshold": {threshold}, '
setFinStr += f' "finalizers": ['
finNum = 1
for n in launcher.network.nodes.values():
if n.index == Node.biosNodeId and not biosFinalizer:
continue
if not n.keys or not n.keys[0].blspubkey:
for n in (self.nodes + [self.biosNode]):
if not n or not n.keys or not n.keys[0].blspubkey:
continue
if not n.producers:
if n.nodeId == Node.biosNodeId and not biosFinalizer:
continue
setFinStr += f' {{"description": "finalizer #{finNum}", '
setFinStr += f' "weight":1, '
Expand Down Expand Up @@ -1109,7 +1105,7 @@ def bootstrap(self, launcher, biosNode, totalNodes, prodCount, totalProducers,
return None

if activateIF:
self.activateInstantFinality(launcher, biosFinalizer, self.productionNodesCount)
self.activateInstantFinality(biosFinalizer)

Utils.Print("Creating accounts: %s " % ", ".join(producerKeys.keys()))
producerKeys.pop(eosioName)
Expand Down
10 changes: 10 additions & 0 deletions tests/TestHarness/Node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import sys
from pathlib import Path
from typing import List
from dataclasses import InitVar, dataclass, field, is_dataclass, asdict

from datetime import datetime
from datetime import timedelta
Expand All @@ -21,6 +22,14 @@
from .testUtils import unhandledEnumType
from .testUtils import ReturnType

@dataclass
class KeyStrings(object):
pubkey: str
privkey: str
blspubkey: str = None
blsprivkey: str = None
blspop: str = None

# pylint: disable=too-many-public-methods
class Node(Transactions):
# Node number is used as an addend to determine the node listen ports.
Expand Down Expand Up @@ -66,6 +75,7 @@ def __init__(self, host, port, nodeId: int, data_dir: Path, config_dir: Path, cm
self.config_dir=config_dir
self.launch_time=launch_time
self.isProducer=False
self.keys: List[KeyStrings] = field(default_factory=list)
self.configureVersion()

def configureVersion(self):
Expand Down

0 comments on commit 22086f6

Please sign in to comment.