From c366c05616fa67b2634fd4f894a7b8039870132c Mon Sep 17 00:00:00 2001 From: Csaba Kiraly Date: Tue, 14 Mar 2023 15:26:48 +0100 Subject: [PATCH] handle overlap for multiple validators per node correctly Signed-off-by: Csaba Kiraly --- DAS/tools.py | 6 ++++++ DAS/validator.py | 13 ++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/DAS/tools.py b/DAS/tools.py index cd26850..2b47b11 100644 --- a/DAS/tools.py +++ b/DAS/tools.py @@ -79,3 +79,9 @@ def sampleLine(line, limit): r[i] = 1 limit -= 1 return r + +def unionOfSamples(population, sampleSize, times): + selected = set() + for t in range(times): + selected |= set(random.sample(population, sampleSize)) + return selected diff --git a/DAS/validator.py b/DAS/validator.py index b0fbede..9abb125 100644 --- a/DAS/validator.py +++ b/DAS/validator.py @@ -4,7 +4,7 @@ import random import collections import logging from DAS.block import * -from DAS.tools import shuffled, shuffledDict +from DAS.tools import shuffled, shuffledDict, unionOfSamples from bitarray.util import zeros from collections import deque from itertools import chain @@ -60,12 +60,7 @@ class Validator: elif self.shape.chi > self.shape.blockSize: self.logger.error("Chi has to be smaller than %d" % self.shape.blockSize, extra=self.format) else: - if self.amIproposer: - self.chi = 1 # not used - elif self.ID <= shape.numberNodes * shape.class1ratio: - self.chi = shape.chi * shape.vpn1 - else: - self.chi = shape.chi * shape.vpn2 # TODO: union of random subsets vpn2 times + self.chi = shape.chi if amIproposer: self.rowIDs = range(shape.blockSize) self.columnIDs = range(shape.blockSize) @@ -75,11 +70,11 @@ class Validator: if rows: self.rowIDs = rows else: - self.rowIDs = random.sample(range(self.shape.blockSize), self.chi) + self.rowIDs = unionOfSamples(range(self.shape.blockSize), self.chi, self.shape.vpn1) if columns: self.columnIDs = columns else: - self.columnIDs = random.sample(range(self.shape.blockSize), self.chi) + self.columnIDs = unionOfSamples(range(self.shape.blockSize), self.chi, self.shape.vpn1) self.rowNeighbors = collections.defaultdict(dict) self.columnNeighbors = collections.defaultdict(dict)