Fixing the global random uniform distribution of topics across validators
This commit is contained in:
parent
125ba2ad4a
commit
3642083f22
|
@ -30,15 +30,27 @@ class Simulator:
|
||||||
self.glob.reset()
|
self.glob.reset()
|
||||||
self.validators = []
|
self.validators = []
|
||||||
if self.config.evenLineDistribution:
|
if self.config.evenLineDistribution:
|
||||||
rows = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberNodes/self.shape.blockSize)
|
|
||||||
columns = list(range(self.shape.blockSize)) * int(self.shape.chi*self.shape.numberNodes/self.shape.blockSize)
|
lightVal = int(self.shape.numberNodes * self.shape.class1ratio * self.shape.vpn1)
|
||||||
|
heavyVal = int(self.shape.numberNodes * (1-self.shape.class1ratio) * self.shape.vpn2)
|
||||||
|
totalValidators = lightVal + heavyVal
|
||||||
|
rows = list(range(self.shape.blockSize)) * (int(totalValidators/self.shape.blockSize)+1)
|
||||||
|
columns = list(range(self.shape.blockSize)) * (int(totalValidators/self.shape.blockSize)+1)
|
||||||
|
offset = heavyVal*self.shape.chi
|
||||||
random.shuffle(rows)
|
random.shuffle(rows)
|
||||||
random.shuffle(columns)
|
random.shuffle(columns)
|
||||||
for i in range(self.shape.numberNodes):
|
for i in range(self.shape.numberNodes):
|
||||||
if self.config.evenLineDistribution:
|
if self.config.evenLineDistribution:
|
||||||
val = Validator(i, int(not i!=0), self.logger, self.shape,
|
if i < int(heavyVal/self.shape.vpn2): # First start with the heavy nodes
|
||||||
rows[(i*self.shape.chi):((i+1)*self.shape.chi)],
|
start = i *self.shape.chi*self.shape.vpn2
|
||||||
columns[(i*self.shape.chi):((i+1)*self.shape.chi)])
|
end = (i+1)*self.shape.chi*self.shape.vpn2
|
||||||
|
else: # Then the solo stakers
|
||||||
|
j = i - int(heavyVal/self.shape.vpn2)
|
||||||
|
start = offset+( j *self.shape.chi)
|
||||||
|
end = offset+((j+1)*self.shape.chi)
|
||||||
|
r = rows[start:end]
|
||||||
|
c = columns[start:end]
|
||||||
|
val = Validator(i, int(not i!=0), self.logger, self.shape, r, c, self.config.evenLineDistribution)
|
||||||
else:
|
else:
|
||||||
val = Validator(i, int(not i!=0), self.logger, self.shape)
|
val = Validator(i, int(not i!=0), self.logger, self.shape)
|
||||||
if i == self.proposerID:
|
if i == self.proposerID:
|
||||||
|
@ -47,6 +59,7 @@ class Simulator:
|
||||||
else:
|
else:
|
||||||
val.logIDs()
|
val.logIDs()
|
||||||
self.validators.append(val)
|
self.validators.append(val)
|
||||||
|
self.logger.debug("Validators initialized.", extra=self.format)
|
||||||
|
|
||||||
def initNetwork(self):
|
def initNetwork(self):
|
||||||
"""It initializes the simulated network."""
|
"""It initializes the simulated network."""
|
||||||
|
@ -59,6 +72,14 @@ class Simulator:
|
||||||
for id in v.columnIDs:
|
for id in v.columnIDs:
|
||||||
columnChannels[id].append(v)
|
columnChannels[id].append(v)
|
||||||
|
|
||||||
|
# Check rows/columns distribution
|
||||||
|
#totalR = 0
|
||||||
|
#totalC = 0
|
||||||
|
#for r in rowChannels:
|
||||||
|
# totalR += len(r)
|
||||||
|
#for c in columnChannels:
|
||||||
|
# totalC += len(c)
|
||||||
|
|
||||||
for id in range(self.shape.blockSize):
|
for id in range(self.shape.blockSize):
|
||||||
|
|
||||||
# If the number of nodes in a channel is smaller or equal to the
|
# If the number of nodes in a channel is smaller or equal to the
|
||||||
|
@ -178,7 +199,7 @@ class Simulator:
|
||||||
# log TX and RX statistics
|
# log TX and RX statistics
|
||||||
statsTxInSlot = [v.statsTxInSlot for v in self.validators]
|
statsTxInSlot = [v.statsTxInSlot for v in self.validators]
|
||||||
statsRxInSlot = [v.statsRxInSlot for v in self.validators]
|
statsRxInSlot = [v.statsRxInSlot for v in self.validators]
|
||||||
self.logger.debug("step %d: TX_prod=%.1f, RX_prod=%.1f, TX_avg=%.1f, TX_max=%.1f, Rx_avg=%.1f, Rx_max=%.1f" %
|
self.logger.debug("step %d: TX_prod=%.1f, RX_prod=%.1f, TX_avg=%.1f, TX_max=%.1f, Rx_avg=%.1f, Rx_max=%.1f" %
|
||||||
(steps, statsTxInSlot[0], statsRxInSlot[0],
|
(steps, statsTxInSlot[0], statsRxInSlot[0],
|
||||||
mean(statsTxInSlot[1:]), max(statsTxInSlot[1:]),
|
mean(statsTxInSlot[1:]), max(statsTxInSlot[1:]),
|
||||||
mean(statsRxInSlot[1:]), max(statsRxInSlot[1:])), extra=self.format)
|
mean(statsRxInSlot[1:]), max(statsRxInSlot[1:])), extra=self.format)
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Validator:
|
||||||
"""It returns the validator ID."""
|
"""It returns the validator ID."""
|
||||||
return str(self.ID)
|
return str(self.ID)
|
||||||
|
|
||||||
def __init__(self, ID, amIproposer, logger, shape, rows = None, columns = None):
|
def __init__(self, ID, amIproposer, logger, shape, rows = None, columns = None, globalRandomness = True):
|
||||||
"""It initializes the validator with the logger shape and rows/columns.
|
"""It initializes the validator with the logger shape and rows/columns.
|
||||||
|
|
||||||
If rows/columns are specified these are observed, otherwise (default)
|
If rows/columns are specified these are observed, otherwise (default)
|
||||||
|
@ -66,9 +66,13 @@ class Validator:
|
||||||
else:
|
else:
|
||||||
#if shape.deterministic:
|
#if shape.deterministic:
|
||||||
# random.seed(self.ID)
|
# random.seed(self.ID)
|
||||||
vpn = self.shape.vpn1 if (self.ID <= shape.numberNodes * shape.class1ratio) else self.shape.vpn2
|
if globalRandomness:
|
||||||
self.rowIDs = rows if rows else unionOfSamples(range(self.shape.blockSize), self.shape.chi, vpn)
|
self.rowIDs = rows
|
||||||
self.columnIDs = columns if columns else unionOfSamples(range(self.shape.blockSize), self.shape.chi, vpn)
|
self.columnIDs = columns
|
||||||
|
else:
|
||||||
|
vpn = self.shape.vpn1 if (self.ID <= shape.numberNodes * shape.class1ratio) else self.shape.vpn2
|
||||||
|
self.rowIDs = rows if rows else unionOfSamples(range(self.shape.blockSize), self.shape.chi, vpn)
|
||||||
|
self.columnIDs = columns if columns else unionOfSamples(range(self.shape.blockSize), self.shape.chi, vpn)
|
||||||
self.rowNeighbors = collections.defaultdict(dict)
|
self.rowNeighbors = collections.defaultdict(dict)
|
||||||
self.columnNeighbors = collections.defaultdict(dict)
|
self.columnNeighbors = collections.defaultdict(dict)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue