From 3642083f2235d1355b5f777324f0b6a19a097bf9 Mon Sep 17 00:00:00 2001 From: Leonardo Bautista-Gomez Date: Tue, 21 Mar 2023 15:16:19 +0100 Subject: [PATCH 1/2] Fixing the global random uniform distribution of topics across validators --- DAS/simulator.py | 33 +++++++++++++++++++++++++++------ DAS/validator.py | 12 ++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index 06ebd8e..de3adff 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -30,15 +30,27 @@ class Simulator: self.glob.reset() self.validators = [] 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(columns) for i in range(self.shape.numberNodes): if self.config.evenLineDistribution: - val = Validator(i, int(not i!=0), self.logger, self.shape, - rows[(i*self.shape.chi):((i+1)*self.shape.chi)], - columns[(i*self.shape.chi):((i+1)*self.shape.chi)]) + if i < int(heavyVal/self.shape.vpn2): # First start with the heavy nodes + start = i *self.shape.chi*self.shape.vpn2 + 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: val = Validator(i, int(not i!=0), self.logger, self.shape) if i == self.proposerID: @@ -47,6 +59,7 @@ class Simulator: else: val.logIDs() self.validators.append(val) + self.logger.debug("Validators initialized.", extra=self.format) def initNetwork(self): """It initializes the simulated network.""" @@ -59,6 +72,14 @@ class Simulator: for id in v.columnIDs: 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): # 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 statsTxInSlot = [v.statsTxInSlot 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], mean(statsTxInSlot[1:]), max(statsTxInSlot[1:]), mean(statsRxInSlot[1:]), max(statsRxInSlot[1:])), extra=self.format) diff --git a/DAS/validator.py b/DAS/validator.py index f869171..6b3904e 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -38,7 +38,7 @@ class Validator: """It returns the validator 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. If rows/columns are specified these are observed, otherwise (default) @@ -66,9 +66,13 @@ class Validator: else: #if shape.deterministic: # random.seed(self.ID) - 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) + if globalRandomness: + self.rowIDs = rows + 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.columnNeighbors = collections.defaultdict(dict) From 680817b97be0a5b161dfa8475f8743f5edd6333c Mon Sep 17 00:00:00 2001 From: Leonardo Bautista-Gomez Date: Thu, 23 Mar 2023 20:10:27 +0100 Subject: [PATCH 2/2] Remove global randomness parameter for validator --- DAS/simulator.py | 2 +- DAS/validator.py | 12 ++++-------- config_example.py | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/DAS/simulator.py b/DAS/simulator.py index de3adff..30c0d86 100644 --- a/DAS/simulator.py +++ b/DAS/simulator.py @@ -50,7 +50,7 @@ class Simulator: 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) + val = Validator(i, int(not i!=0), self.logger, self.shape, r, c) else: val = Validator(i, int(not i!=0), self.logger, self.shape) if i == self.proposerID: diff --git a/DAS/validator.py b/DAS/validator.py index 6b3904e..f869171 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -38,7 +38,7 @@ class Validator: """It returns the validator ID.""" return str(self.ID) - def __init__(self, ID, amIproposer, logger, shape, rows = None, columns = None, globalRandomness = True): + def __init__(self, ID, amIproposer, logger, shape, rows = None, columns = None): """It initializes the validator with the logger shape and rows/columns. If rows/columns are specified these are observed, otherwise (default) @@ -66,13 +66,9 @@ class Validator: else: #if shape.deterministic: # random.seed(self.ID) - if globalRandomness: - self.rowIDs = rows - 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) + 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.columnNeighbors = collections.defaultdict(dict) diff --git a/config_example.py b/config_example.py index b54dff1..af55fc2 100644 --- a/config_example.py +++ b/config_example.py @@ -28,7 +28,7 @@ numJobs = 3 # distribute rows/columns evenly between validators (True) # or generate it using local randomness (False) -evenLineDistribution = False +evenLineDistribution = True # Number of simulation runs with the same parameters for statistical relevance runs = range(10)