2022-11-30 14:28:27 +00:00
|
|
|
#!/bin/python
|
|
|
|
|
2022-12-20 10:13:54 +00:00
|
|
|
import networkx as nx
|
2023-01-23 17:04:54 +00:00
|
|
|
import logging, random
|
2023-03-27 21:11:40 +00:00
|
|
|
import pandas as pd
|
2023-03-14 10:16:43 +00:00
|
|
|
from functools import partial, partialmethod
|
2022-11-30 14:28:27 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from DAS.tools import *
|
2023-01-16 21:43:52 +00:00
|
|
|
from DAS.results import *
|
2022-11-30 14:28:27 +00:00
|
|
|
from DAS.observer import *
|
2023-12-07 11:48:56 +00:00
|
|
|
from DAS.node import *
|
2022-11-30 14:28:27 +00:00
|
|
|
|
|
|
|
class Simulator:
|
2023-02-15 14:06:42 +00:00
|
|
|
"""This class implements the main DAS simulator."""
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2023-03-30 11:41:50 +00:00
|
|
|
def __init__(self, shape, config, execID):
|
2023-02-15 14:06:42 +00:00
|
|
|
"""It initializes the simulation with a set of parameters (shape)."""
|
2023-01-23 17:04:54 +00:00
|
|
|
self.shape = shape
|
2023-03-06 14:15:57 +00:00
|
|
|
self.config = config
|
2022-11-30 14:28:27 +00:00
|
|
|
self.format = {"entity": "Simulator"}
|
2023-03-30 11:41:50 +00:00
|
|
|
self.execID = execID
|
|
|
|
self.result = Result(self.shape, self.execID)
|
2023-02-08 19:10:26 +00:00
|
|
|
self.validators = []
|
|
|
|
self.logger = []
|
2023-02-23 11:16:43 +00:00
|
|
|
self.logLevel = config.logLevel
|
2023-02-08 19:10:26 +00:00
|
|
|
self.proposerID = 0
|
|
|
|
self.glob = []
|
2023-03-27 21:16:05 +00:00
|
|
|
self.execID = execID
|
2023-04-20 13:58:13 +00:00
|
|
|
self.distR = []
|
|
|
|
self.distC = []
|
|
|
|
self.nodeRows = []
|
|
|
|
self.nodeColumns = []
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2023-03-20 10:29:06 +00:00
|
|
|
# In GossipSub the initiator might push messages without participating in the mesh.
|
|
|
|
# proposerPublishOnly regulates this behavior. If set to true, the proposer is not
|
|
|
|
# part of the p2p distribution graph, only pushes segments to it. If false, the proposer
|
|
|
|
# might get back segments from other peers since links are symmetric.
|
|
|
|
self.proposerPublishOnly = True
|
|
|
|
|
|
|
|
# If proposerPublishOnly == True, this regulates how many copies of each segment are
|
|
|
|
# pushed out by the proposer.
|
|
|
|
# 1: the data is sent out exactly once on rows and once on columns (2 copies in total)
|
|
|
|
# self.shape.netDegree: default behavior similar (but not same) to previous code
|
2024-03-01 11:32:19 +00:00
|
|
|
self.proposerPublishToR = config.evalConf(self, config.proposerPublishToR, shape)
|
|
|
|
self.proposerPublishToC = config.evalConf(self, config.proposerPublishToR, shape)
|
2023-03-20 10:29:06 +00:00
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
def initValidators(self):
|
2023-02-15 14:06:42 +00:00
|
|
|
"""It initializes all the validators in the network."""
|
2023-01-23 17:04:54 +00:00
|
|
|
self.glob = Observer(self.logger, self.shape)
|
2022-11-30 14:28:27 +00:00
|
|
|
self.validators = []
|
2024-02-18 16:46:16 +00:00
|
|
|
evenLineDistribution = False
|
|
|
|
if evenLineDistribution:
|
2023-03-21 14:16:19 +00:00
|
|
|
|
2023-04-20 13:58:13 +00:00
|
|
|
lightNodes = int(self.shape.numberNodes * self.shape.class1ratio)
|
|
|
|
heavyNodes = self.shape.numberNodes - lightNodes
|
|
|
|
lightVal = lightNodes * self.shape.vpn1
|
|
|
|
heavyVal = heavyNodes * self.shape.vpn2
|
2023-03-21 14:16:19 +00:00
|
|
|
totalValidators = lightVal + heavyVal
|
2024-02-27 20:35:51 +00:00
|
|
|
totalRows = totalValidators * self.shape.custodyRows
|
|
|
|
totalColumns = totalValidators * self.shape.custodyCols
|
|
|
|
rows = list(range(self.shape.nbRows)) * (int(totalRows/self.shape.nbRows)+1)
|
|
|
|
columns = list(range(self.shape.nbCols)) * (int(totalColumns/self.shape.nbCols)+1)
|
2023-04-20 13:58:13 +00:00
|
|
|
rows = rows[0:totalRows]
|
2024-02-18 13:22:57 +00:00
|
|
|
columns = columns[0:totalColumns]
|
2023-03-06 14:15:57 +00:00
|
|
|
random.shuffle(rows)
|
|
|
|
random.shuffle(columns)
|
2024-02-27 20:35:51 +00:00
|
|
|
offsetR = lightVal*self.shape.custodyRows
|
|
|
|
offsetC = lightVal*self.shape.custodyCols
|
2023-04-20 13:58:13 +00:00
|
|
|
self.logger.debug("There is a total of %d nodes, %d light and %d heavy." % (self.shape.numberNodes, lightNodes, heavyNodes), extra=self.format)
|
|
|
|
self.logger.debug("There is a total of %d validators, %d in light nodes and %d in heavy nodes" % (totalValidators, lightVal, heavyVal), extra=self.format)
|
2024-02-27 20:35:51 +00:00
|
|
|
self.logger.debug("Shuffling a total of %d rows to be assigned (X=%d)" % (len(rows), self.shape.custodyRows), extra=self.format)
|
|
|
|
self.logger.debug("Shuffling a total of %d columns to be assigned (X=%d)" % (len(columns), self.shape.custodyCols), extra=self.format)
|
2023-03-29 14:42:09 +00:00
|
|
|
self.logger.debug("Shuffled rows: %s" % str(rows), extra=self.format)
|
|
|
|
self.logger.debug("Shuffled columns: %s" % str(columns), extra=self.format)
|
|
|
|
|
2023-03-30 11:49:01 +00:00
|
|
|
assignedRows = []
|
|
|
|
assignedCols = []
|
2024-01-20 19:57:17 +00:00
|
|
|
maliciousNodesCount = int((self.shape.maliciousNodes / 100) * self.shape.numberNodes)
|
2024-01-22 20:16:18 +00:00
|
|
|
remainingMaliciousNodes = maliciousNodesCount
|
|
|
|
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(self.shape.numberNodes):
|
2024-01-22 20:16:18 +00:00
|
|
|
if i == 0:
|
2024-01-20 19:57:17 +00:00
|
|
|
amImalicious_value = 0
|
|
|
|
else:
|
2024-01-22 20:16:18 +00:00
|
|
|
if not self.config.randomizeMaliciousNodes:
|
|
|
|
# Assign based on predefined pattern when randomization is turned off
|
|
|
|
if i < maliciousNodesCount + 1:
|
|
|
|
amImalicious_value = 1
|
|
|
|
else:
|
|
|
|
amImalicious_value = 0
|
|
|
|
else:
|
|
|
|
# Randomly assign amImalicious_value when randomization is turned on
|
|
|
|
if remainingMaliciousNodes > 0 and random.random() < (self.shape.maliciousNodes / 100):
|
|
|
|
amImalicious_value = 1
|
|
|
|
remainingMaliciousNodes -= 1
|
|
|
|
else:
|
|
|
|
amImalicious_value = 0
|
|
|
|
|
2024-02-18 16:46:16 +00:00
|
|
|
if evenLineDistribution:
|
2023-04-18 13:45:51 +00:00
|
|
|
if i < int(lightVal/self.shape.vpn1): # First start with the light nodes
|
2024-02-27 20:35:51 +00:00
|
|
|
startR = i *self.shape.custodyRows*self.shape.vpn1
|
|
|
|
endR = (i+1)*self.shape.custodyRows*self.shape.vpn1
|
|
|
|
startC = i *self.shape.custodyCols*self.shape.vpn1
|
|
|
|
endC = (i+1)*self.shape.custodyCols*self.shape.vpn1
|
2023-04-18 13:45:51 +00:00
|
|
|
else:
|
|
|
|
j = i - int(lightVal/self.shape.vpn1)
|
2024-02-27 20:35:51 +00:00
|
|
|
startR = offsetR+( j *self.shape.custodyRows*self.shape.vpn2)
|
|
|
|
endR = offsetR+((j+1)*self.shape.custodyRows*self.shape.vpn2)
|
|
|
|
startC = offsetC+( j *self.shape.custodyCols*self.shape.vpn2)
|
|
|
|
endC = offsetC+((j+1)*self.shape.custodyCols*self.shape.vpn2)
|
2023-07-12 11:44:23 +00:00
|
|
|
r = rows[startR:endR]
|
|
|
|
c = columns[startC:endC]
|
2024-03-04 10:54:25 +00:00
|
|
|
val = Node(i, int(not i!=0), amImalicious_value, self.logger, self.shape, self.config, r, c)
|
2023-04-20 13:58:13 +00:00
|
|
|
self.logger.debug("Node %d has row IDs: %s" % (val.ID, val.rowIDs), extra=self.format)
|
|
|
|
self.logger.debug("Node %d has column IDs: %s" % (val.ID, val.columnIDs), extra=self.format)
|
2023-03-30 11:49:01 +00:00
|
|
|
assignedRows = assignedRows + list(r)
|
|
|
|
assignedCols = assignedCols + list(c)
|
2023-04-20 13:58:13 +00:00
|
|
|
self.nodeRows.append(val.rowIDs)
|
|
|
|
self.nodeColumns.append(val.columnIDs)
|
2023-03-29 14:42:09 +00:00
|
|
|
|
2023-03-06 14:15:57 +00:00
|
|
|
else:
|
2024-02-27 20:35:51 +00:00
|
|
|
if self.shape.custodyCols > self.shape.nbCols:
|
|
|
|
self.logger.error("custodyCols has to be smaller than %d" % self.shape.nbCols)
|
|
|
|
elif self.shape.custodyRows > self.shape.nbRows:
|
|
|
|
self.logger.error("custodyRows has to be smaller than %d" % self.shape.nbRows)
|
2023-12-12 12:31:39 +00:00
|
|
|
|
|
|
|
vs = []
|
|
|
|
nodeClass = 1 if (i <= self.shape.numberNodes * self.shape.class1ratio) else 2
|
|
|
|
vpn = self.shape.vpn1 if (nodeClass == 1) else self.shape.vpn2
|
|
|
|
for v in range(vpn):
|
2024-02-27 20:35:51 +00:00
|
|
|
vs.append(initValidator(self.shape.nbRows, self.shape.custodyRows, self.shape.nbCols, self.shape.custodyCols))
|
2024-03-04 10:54:25 +00:00
|
|
|
val = Node(i, int(not i!=0), amImalicious_value, self.logger, self.shape, self.config, vs)
|
2022-11-30 14:28:27 +00:00
|
|
|
if i == self.proposerID:
|
|
|
|
val.initBlock()
|
|
|
|
else:
|
|
|
|
val.logIDs()
|
|
|
|
self.validators.append(val)
|
2023-03-29 14:42:09 +00:00
|
|
|
|
2023-03-30 11:49:01 +00:00
|
|
|
assignedRows.sort()
|
|
|
|
assignedCols.sort()
|
|
|
|
self.logger.debug("Rows assigned: %s" % str(assignedRows), extra=self.format)
|
|
|
|
self.logger.debug("Columns assigned: %s" % str(assignedCols), extra=self.format)
|
2023-03-21 14:16:19 +00:00
|
|
|
self.logger.debug("Validators initialized.", extra=self.format)
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2023-01-23 17:04:54 +00:00
|
|
|
def initNetwork(self):
|
2023-02-15 14:06:42 +00:00
|
|
|
"""It initializes the simulated network."""
|
2024-02-27 20:35:51 +00:00
|
|
|
rowChannels = [[] for i in range(self.shape.nbRows)]
|
|
|
|
columnChannels = [[] for i in range(self.shape.nbCols)]
|
2022-12-20 10:13:54 +00:00
|
|
|
for v in self.validators:
|
2023-02-23 19:58:16 +00:00
|
|
|
if not (self.proposerPublishOnly and v.amIproposer):
|
|
|
|
for id in v.rowIDs:
|
|
|
|
rowChannels[id].append(v)
|
|
|
|
for id in v.columnIDs:
|
|
|
|
columnChannels[id].append(v)
|
2022-12-20 10:13:54 +00:00
|
|
|
|
2023-03-21 14:16:19 +00:00
|
|
|
# Check rows/columns distribution
|
2023-03-29 14:42:09 +00:00
|
|
|
for r in rowChannels:
|
2023-04-20 13:58:13 +00:00
|
|
|
self.distR.append(len(r))
|
2023-03-29 14:42:09 +00:00
|
|
|
for c in columnChannels:
|
2023-04-20 13:58:13 +00:00
|
|
|
self.distC.append(len(c))
|
|
|
|
self.logger.debug("Number of validators per row; Min: %d, Max: %d" % (min(self.distR), max(self.distR)), extra=self.format)
|
|
|
|
self.logger.debug("Number of validators per column; Min: %d, Max: %d" % (min(self.distC), max(self.distC)), extra=self.format)
|
2023-03-21 14:16:19 +00:00
|
|
|
|
2024-02-27 20:35:51 +00:00
|
|
|
for id in range(self.shape.nbRows):
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2023-02-15 01:50:03 +00:00
|
|
|
# If the number of nodes in a channel is smaller or equal to the
|
|
|
|
# requested degree, a fully connected graph is used. For n>d, a random
|
|
|
|
# d-regular graph is set up. (For n=d+1, the two are the same.)
|
2023-03-20 16:09:17 +00:00
|
|
|
if not rowChannels[id]:
|
|
|
|
self.logger.error("No nodes for row %d !" % id, extra=self.format)
|
|
|
|
continue
|
|
|
|
elif (len(rowChannels[id]) <= self.shape.netDegree):
|
2023-02-15 01:50:03 +00:00
|
|
|
self.logger.debug("Graph fully connected with degree %d !" % (len(rowChannels[id]) - 1), extra=self.format)
|
|
|
|
G = nx.complete_graph(len(rowChannels[id]))
|
|
|
|
else:
|
|
|
|
G = nx.random_regular_graph(self.shape.netDegree, len(rowChannels[id]))
|
2022-12-20 10:13:54 +00:00
|
|
|
if not nx.is_connected(G):
|
2023-01-16 21:43:52 +00:00
|
|
|
self.logger.error("Graph not connected for row %d !" % id, extra=self.format)
|
2022-12-20 10:13:54 +00:00
|
|
|
for u, v in G.edges:
|
|
|
|
val1=rowChannels[id][u]
|
|
|
|
val2=rowChannels[id][v]
|
2024-02-27 20:35:51 +00:00
|
|
|
val1.rowNeighbors[id].update({val2.ID : Neighbor(val2, 0, self.shape.nbCols)})
|
|
|
|
val2.rowNeighbors[id].update({val1.ID : Neighbor(val1, 0, self.shape.nbCols)})
|
2023-07-12 11:21:27 +00:00
|
|
|
|
2024-02-27 20:35:51 +00:00
|
|
|
for id in range(self.shape.nbCols):
|
2023-01-23 17:04:54 +00:00
|
|
|
|
2023-03-20 16:09:17 +00:00
|
|
|
if not columnChannels[id]:
|
|
|
|
self.logger.error("No nodes for column %d !" % id, extra=self.format)
|
|
|
|
continue
|
|
|
|
elif (len(columnChannels[id]) <= self.shape.netDegree):
|
2023-02-15 01:50:03 +00:00
|
|
|
self.logger.debug("Graph fully connected with degree %d !" % (len(columnChannels[id]) - 1), extra=self.format)
|
|
|
|
G = nx.complete_graph(len(columnChannels[id]))
|
|
|
|
else:
|
|
|
|
G = nx.random_regular_graph(self.shape.netDegree, len(columnChannels[id]))
|
2022-12-20 10:13:54 +00:00
|
|
|
if not nx.is_connected(G):
|
2023-01-16 21:43:52 +00:00
|
|
|
self.logger.error("Graph not connected for column %d !" % id, extra=self.format)
|
2022-12-20 10:13:54 +00:00
|
|
|
for u, v in G.edges:
|
|
|
|
val1=columnChannels[id][u]
|
|
|
|
val2=columnChannels[id][v]
|
2024-02-27 20:35:51 +00:00
|
|
|
val1.columnNeighbors[id].update({val2.ID : Neighbor(val2, 1, self.shape.nbRows)})
|
|
|
|
val2.columnNeighbors[id].update({val1.ID : Neighbor(val1, 1, self.shape.nbRows)})
|
2022-12-20 10:13:54 +00:00
|
|
|
|
2023-02-23 19:58:16 +00:00
|
|
|
for v in self.validators:
|
|
|
|
if (self.proposerPublishOnly and v.amIproposer):
|
|
|
|
for id in v.rowIDs:
|
2024-03-01 11:32:19 +00:00
|
|
|
count = min(self.proposerPublishToR, len(rowChannels[id]))
|
2023-02-23 19:58:16 +00:00
|
|
|
publishTo = random.sample(rowChannels[id], count)
|
|
|
|
for vi in publishTo:
|
2024-02-27 20:35:51 +00:00
|
|
|
v.rowNeighbors[id].update({vi.ID : Neighbor(vi, 0, self.shape.nbCols)})
|
2023-02-23 19:58:16 +00:00
|
|
|
for id in v.columnIDs:
|
2024-03-01 11:32:19 +00:00
|
|
|
count = min(self.proposerPublishToC, len(columnChannels[id]))
|
2023-02-23 19:58:16 +00:00
|
|
|
publishTo = random.sample(columnChannels[id], count)
|
|
|
|
for vi in publishTo:
|
2024-02-27 20:35:51 +00:00
|
|
|
v.columnNeighbors[id].update({vi.ID : Neighbor(vi, 1, self.shape.nbRows)})
|
2022-12-20 10:13:54 +00:00
|
|
|
|
2023-02-15 01:51:47 +00:00
|
|
|
if self.logger.isEnabledFor(logging.DEBUG):
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(0, self.shape.numberNodes):
|
2023-02-15 01:51:47 +00:00
|
|
|
self.logger.debug("Val %d : rowN %s", i, self.validators[i].rowNeighbors, extra=self.format)
|
|
|
|
self.logger.debug("Val %d : colN %s", i, self.validators[i].columnNeighbors, extra=self.format)
|
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
def initLogger(self):
|
2023-02-15 14:06:42 +00:00
|
|
|
"""It initializes the logger."""
|
2023-03-14 10:16:43 +00:00
|
|
|
logging.TRACE = 5
|
|
|
|
logging.addLevelName(logging.TRACE, 'TRACE')
|
|
|
|
logging.Logger.trace = partialmethod(logging.Logger.log, logging.TRACE)
|
|
|
|
logging.trace = partial(logging.log, logging.TRACE)
|
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
logger = logging.getLogger("DAS")
|
2023-03-03 10:26:00 +00:00
|
|
|
if len(logger.handlers) == 0:
|
|
|
|
logger.setLevel(self.logLevel)
|
|
|
|
ch = logging.StreamHandler()
|
|
|
|
ch.setLevel(self.logLevel)
|
|
|
|
ch.setFormatter(CustomFormatter())
|
|
|
|
logger.addHandler(ch)
|
2022-11-30 14:28:27 +00:00
|
|
|
self.logger = logger
|
|
|
|
|
2023-03-29 14:42:09 +00:00
|
|
|
def printDiagnostics(self):
|
|
|
|
"""Print all required diagnostics to check when a block does not become available"""
|
|
|
|
for val in self.validators:
|
|
|
|
(a, e) = val.checkStatus()
|
|
|
|
if e-a > 0 and val.ID != 0:
|
|
|
|
self.logger.warning("Node %d is missing %d samples" % (val.ID, e-a), extra=self.format)
|
|
|
|
for r in val.rowIDs:
|
|
|
|
row = val.getRow(r)
|
|
|
|
if row.count() < len(row):
|
|
|
|
self.logger.debug("Row %d: %s" % (r, str(row)), extra=self.format)
|
|
|
|
neiR = val.rowNeighbors[r]
|
|
|
|
for nr in neiR:
|
|
|
|
self.logger.debug("Row %d, Neighbor %d sent: %s" % (r, val.rowNeighbors[r][nr].node.ID, val.rowNeighbors[r][nr].received), extra=self.format)
|
|
|
|
self.logger.debug("Row %d, Neighbor %d has: %s" % (r, val.rowNeighbors[r][nr].node.ID, self.validators[val.rowNeighbors[r][nr].node.ID].getRow(r)), extra=self.format)
|
|
|
|
for c in val.columnIDs:
|
|
|
|
col = val.getColumn(c)
|
|
|
|
if col.count() < len(col):
|
|
|
|
self.logger.debug("Column %d: %s" % (c, str(col)), extra=self.format)
|
|
|
|
neiC = val.columnNeighbors[c]
|
|
|
|
for nc in neiC:
|
|
|
|
self.logger.debug("Column %d, Neighbor %d sent: %s" % (c, val.columnNeighbors[c][nc].node.ID, val.columnNeighbors[c][nc].received), extra=self.format)
|
|
|
|
self.logger.debug("Column %d, Neighbor %d has: %s" % (c, val.columnNeighbors[c][nc].node.ID, self.validators[val.columnNeighbors[c][nc].node.ID].getColumn(c)), extra=self.format)
|
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
def run(self):
|
2023-02-15 14:06:42 +00:00
|
|
|
"""It runs the main simulation until the block is available or it gets stucked."""
|
2022-11-30 14:28:27 +00:00
|
|
|
self.glob.checkRowsColumns(self.validators)
|
2023-04-18 14:12:46 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
|
|
|
if i == self.proposerID:
|
2024-02-02 17:57:38 +00:00
|
|
|
# self.validators[i].initBlock()
|
|
|
|
self.logger.warning("I am a block proposer.", extra=self.format)
|
2023-04-18 14:12:46 +00:00
|
|
|
else:
|
|
|
|
self.validators[i].logIDs()
|
2023-04-09 21:21:23 +00:00
|
|
|
arrived, expected, ready, validatedall, validated = self.glob.checkStatus(self.validators)
|
2022-12-20 10:13:54 +00:00
|
|
|
missingSamples = expected - arrived
|
2023-01-16 21:43:52 +00:00
|
|
|
missingVector = []
|
2023-03-27 21:11:40 +00:00
|
|
|
progressVector = []
|
2023-03-21 07:34:28 +00:00
|
|
|
trafficStatsVector = []
|
2024-01-20 19:57:17 +00:00
|
|
|
malicious_nodes_not_added_count = 0
|
2023-01-13 15:51:27 +00:00
|
|
|
steps = 0
|
2024-03-27 20:38:47 +00:00
|
|
|
|
2023-01-26 00:12:13 +00:00
|
|
|
while(True):
|
2023-01-16 21:43:52 +00:00
|
|
|
missingVector.append(missingSamples)
|
2024-02-18 16:46:16 +00:00
|
|
|
self.logger.debug("Expected Samples: %d" % expected, extra=self.format)
|
|
|
|
self.logger.debug("Missing Samples: %d" % missingSamples, extra=self.format)
|
2022-11-30 14:28:27 +00:00
|
|
|
oldMissingSamples = missingSamples
|
2023-02-15 01:55:06 +00:00
|
|
|
self.logger.debug("PHASE SEND %d" % steps, extra=self.format)
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
2024-02-02 17:57:38 +00:00
|
|
|
if not self.validators[i].amImalicious:
|
|
|
|
self.validators[i].send()
|
2023-02-15 01:55:06 +00:00
|
|
|
self.logger.debug("PHASE RECEIVE %d" % steps, extra=self.format)
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(1,self.shape.numberNodes):
|
2022-12-20 10:13:54 +00:00
|
|
|
self.validators[i].receiveRowsColumns()
|
2023-02-15 01:55:06 +00:00
|
|
|
self.logger.debug("PHASE RESTORE %d" % steps, extra=self.format)
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(1,self.shape.numberNodes):
|
2022-12-07 14:46:45 +00:00
|
|
|
self.validators[i].restoreRows()
|
|
|
|
self.validators[i].restoreColumns()
|
2023-02-15 01:55:06 +00:00
|
|
|
self.logger.debug("PHASE LOG %d" % steps, extra=self.format)
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
2022-11-30 14:28:27 +00:00
|
|
|
self.validators[i].logRows()
|
|
|
|
self.validators[i].logColumns()
|
2023-02-24 09:21:28 +00:00
|
|
|
|
|
|
|
# log TX and RX statistics
|
2023-03-21 07:34:28 +00:00
|
|
|
trafficStats = self.glob.getTrafficStats(self.validators)
|
2023-03-30 11:41:50 +00:00
|
|
|
self.logger.debug("step %d: %s" %
|
2023-03-21 07:34:28 +00:00
|
|
|
(steps, trafficStats), extra=self.format)
|
2023-03-13 14:03:55 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
2023-01-25 23:34:21 +00:00
|
|
|
self.validators[i].updateStats()
|
2023-03-21 07:34:28 +00:00
|
|
|
trafficStatsVector.append(trafficStats)
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2023-04-09 21:21:23 +00:00
|
|
|
missingSamples, sampleProgress, nodeProgress, validatorAllProgress, validatorProgress = self.glob.getProgress(self.validators)
|
2023-06-11 17:30:10 +00:00
|
|
|
self.logger.info("step %d, arrived %0.02f %%, ready %0.02f %%, validatedall %0.02f %%, , validated %0.02f %%"
|
2023-04-09 21:21:23 +00:00
|
|
|
% (steps, sampleProgress*100, nodeProgress*100, validatorAllProgress*100, validatorProgress*100), extra=self.format)
|
2023-03-27 21:11:40 +00:00
|
|
|
|
|
|
|
cnS = "samples received"
|
|
|
|
cnN = "nodes ready"
|
|
|
|
cnV = "validators ready"
|
|
|
|
cnT0 = "TX builder mean"
|
|
|
|
cnT1 = "TX class1 mean"
|
|
|
|
cnT2 = "TX class2 mean"
|
|
|
|
cnR1 = "RX class1 mean"
|
|
|
|
cnR2 = "RX class2 mean"
|
|
|
|
cnD1 = "Dup class1 mean"
|
|
|
|
cnD2 = "Dup class2 mean"
|
|
|
|
|
2024-03-01 09:46:24 +00:00
|
|
|
# if custody is based on the requirements of underlying individual
|
|
|
|
# validators, we can get detailed data on how many validated.
|
|
|
|
# Otherwise, we can only use the weighted average.
|
|
|
|
if self.config.validatorBasedCustody:
|
|
|
|
cnVv = validatorProgress
|
|
|
|
else:
|
|
|
|
cnVv = validatorAllProgress
|
|
|
|
|
2023-03-27 21:11:40 +00:00
|
|
|
progressVector.append({
|
|
|
|
cnS:sampleProgress,
|
|
|
|
cnN:nodeProgress,
|
2024-03-01 09:46:24 +00:00
|
|
|
cnV:cnVv,
|
2023-03-27 21:11:40 +00:00
|
|
|
cnT0: trafficStats[0]["Tx"]["mean"],
|
|
|
|
cnT1: trafficStats[1]["Tx"]["mean"],
|
|
|
|
cnT2: trafficStats[2]["Tx"]["mean"],
|
|
|
|
cnR1: trafficStats[1]["Rx"]["mean"],
|
|
|
|
cnR2: trafficStats[2]["Rx"]["mean"],
|
|
|
|
cnD1: trafficStats[1]["RxDup"]["mean"],
|
|
|
|
cnD2: trafficStats[2]["RxDup"]["mean"],
|
|
|
|
})
|
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
if missingSamples == oldMissingSamples:
|
2023-03-30 12:26:14 +00:00
|
|
|
if len(missingVector) > self.config.steps4StopCondition:
|
2023-03-30 14:10:10 +00:00
|
|
|
if missingSamples == missingVector[-self.config.steps4StopCondition]:
|
2023-03-30 12:26:14 +00:00
|
|
|
self.logger.debug("The block cannot be recovered, failure rate %d!" % self.shape.failureRate, extra=self.format)
|
2023-04-13 11:39:33 +00:00
|
|
|
if self.config.diagnostics:
|
|
|
|
self.printDiagnostics()
|
2023-03-30 12:26:14 +00:00
|
|
|
break
|
2023-01-25 20:51:59 +00:00
|
|
|
missingVector.append(missingSamples)
|
2022-11-30 14:28:27 +00:00
|
|
|
elif missingSamples == 0:
|
2023-03-30 11:41:50 +00:00
|
|
|
self.logger.debug("The entire block is available at step %d, with failure rate %d !" % (steps, self.shape.failureRate), extra=self.format)
|
2023-01-25 20:51:59 +00:00
|
|
|
missingVector.append(missingSamples)
|
2022-11-30 14:28:27 +00:00
|
|
|
break
|
2023-04-10 20:05:48 +00:00
|
|
|
steps += 1
|
2024-03-24 21:00:18 +00:00
|
|
|
|
2022-11-30 14:28:27 +00:00
|
|
|
|
2024-01-20 19:57:17 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
|
|
|
if not self.validators[i].amIaddedToQueue :
|
|
|
|
malicious_nodes_not_added_count += 1
|
|
|
|
|
2024-02-02 17:57:38 +00:00
|
|
|
for i in range(0,self.shape.numberNodes):
|
|
|
|
column_ids = []
|
|
|
|
row_ids = []
|
|
|
|
for rID in self.validators[i].rowIDs:
|
|
|
|
row_ids.append(rID)
|
|
|
|
for cID in self.validators[i].columnIDs:
|
|
|
|
column_ids.append(cID)
|
|
|
|
|
|
|
|
self.logger.debug("List of columnIDs for %d node: %s", i, column_ids, extra=self.format)
|
|
|
|
self.logger.debug("List of rowIDs for %d node: %s", i, row_ids, extra=self.format)
|
|
|
|
|
2024-01-20 19:57:17 +00:00
|
|
|
self.logger.debug("Number of malicious nodes not added to the send queue: %d" % malicious_nodes_not_added_count, extra=self.format)
|
|
|
|
malicious_nodes_not_added_percentage = (malicious_nodes_not_added_count * 100)/(self.shape.numberNodes)
|
|
|
|
self.logger.debug("Percentage of malicious nodes not added to the send queue: %d" % malicious_nodes_not_added_percentage, extra=self.format)
|
|
|
|
|
2023-03-27 21:11:40 +00:00
|
|
|
progress = pd.DataFrame(progressVector)
|
2023-04-20 13:58:13 +00:00
|
|
|
if self.config.saveRCdist:
|
|
|
|
self.result.addMetric("rowDist", self.distR)
|
|
|
|
self.result.addMetric("columnDist", self.distC)
|
2023-03-27 21:11:40 +00:00
|
|
|
if self.config.saveProgress:
|
|
|
|
self.result.addMetric("progress", progress.to_dict(orient='list'))
|
2023-03-30 11:41:50 +00:00
|
|
|
self.result.populate(self.shape, self.config, missingVector)
|
2024-01-20 19:57:17 +00:00
|
|
|
self.result.copyValidators(self.validators)
|
2023-01-25 20:51:59 +00:00
|
|
|
return self.result
|