mirror of
https://github.com/status-im/das-research.git
synced 2025-02-22 11:28:11 +00:00
Merge pull request #42 from status-im/failureRate-exact
make failureRate exact
This commit is contained in:
commit
b2df64f8b9
@ -210,7 +210,6 @@ class Simulator:
|
|||||||
def run(self):
|
def run(self):
|
||||||
"""It runs the main simulation until the block is available or it gets stucked."""
|
"""It runs the main simulation until the block is available or it gets stucked."""
|
||||||
self.glob.checkRowsColumns(self.validators)
|
self.glob.checkRowsColumns(self.validators)
|
||||||
self.validators[self.proposerID].broadcastBlock()
|
|
||||||
arrived, expected, ready, validated = self.glob.checkStatus(self.validators)
|
arrived, expected, ready, validated = self.glob.checkStatus(self.validators)
|
||||||
missingSamples = expected - arrived
|
missingSamples = expected - arrived
|
||||||
missingVector = []
|
missingVector = []
|
||||||
|
@ -113,33 +113,18 @@ class Validator:
|
|||||||
|
|
||||||
def initBlock(self):
|
def initBlock(self):
|
||||||
"""It initializes the block for the proposer."""
|
"""It initializes the block for the proposer."""
|
||||||
if self.amIproposer == 1:
|
|
||||||
self.logger.debug("I am a block proposer.", extra=self.format)
|
|
||||||
self.block = Block(self.shape.blockSize)
|
|
||||||
self.block.fill()
|
|
||||||
#self.block.print()
|
|
||||||
else:
|
|
||||||
self.logger.warning("I am not a block proposer."% self.ID)
|
|
||||||
|
|
||||||
def broadcastBlock(self):
|
|
||||||
"""The block proposer broadcasts the block to all validators."""
|
|
||||||
if self.amIproposer == 0:
|
if self.amIproposer == 0:
|
||||||
self.logger.warning("I am not a block proposer", extra=self.format)
|
self.logger.warning("I am not a block proposer", extra=self.format)
|
||||||
else:
|
else:
|
||||||
self.logger.debug("Broadcasting my block...", extra=self.format)
|
self.logger.debug("Creating block...", extra=self.format)
|
||||||
order = [i for i in range(self.shape.blockSize * self.shape.blockSize)]
|
order = [i for i in range(self.shape.blockSize * self.shape.blockSize)]
|
||||||
random.shuffle(order)
|
order = random.sample(order, int((1 - self.shape.failureRate/100) * len(order)))
|
||||||
while(order):
|
for i in order:
|
||||||
i = order.pop()
|
|
||||||
if (random.randint(0,99) >= self.shape.failureRate):
|
|
||||||
self.block.data[i] = 1
|
self.block.data[i] = 1
|
||||||
else:
|
|
||||||
self.block.data[i] = 0
|
|
||||||
|
|
||||||
nbFailures = self.block.data.count(0)
|
nbFailures = self.block.data.count(0)
|
||||||
measuredFailureRate = nbFailures * 100 / (self.shape.blockSize * self.shape.blockSize)
|
measuredFailureRate = nbFailures * 100 / (self.shape.blockSize * self.shape.blockSize)
|
||||||
self.logger.debug("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
|
self.logger.debug("Number of failures: %d (%0.02f %%)", nbFailures, measuredFailureRate, extra=self.format)
|
||||||
#broadcasted.print()
|
|
||||||
|
|
||||||
def getColumn(self, index):
|
def getColumn(self, index):
|
||||||
"""It returns a given column."""
|
"""It returns a given column."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user