From b56f96157cc4ae1aca334d2e9349384b89e40880 Mon Sep 17 00:00:00 2001 From: Maurice Poirrier Chuden Date: Mon, 9 Dec 2024 21:03:21 -0300 Subject: [PATCH] feat: random interval while mining using a random interval we can simulate a cycling attack using mitigations currently implemented --- resources/scenarios/miner_std.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/scenarios/miner_std.py b/resources/scenarios/miner_std.py index 3fa06c7d3..1eb5e14b8 100755 --- a/resources/scenarios/miner_std.py +++ b/resources/scenarios/miner_std.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 +from random import randint from time import sleep from commander import Commander @@ -35,6 +36,12 @@ def add_options(self, parser): type=int, help="Number of seconds between block generation (default 60 seconds)", ) + parser.add_argument( + "--random-interval", + dest="random_interval", + action="store_true", + help="Should the interval be randomized between 0 and the interval value", + ) parser.add_argument( "--mature", dest="mature", @@ -71,7 +78,10 @@ def run_test(self): ) except Exception as e: self.log.error(f"node {miner.node.index} error: {e}") - sleep(self.options.interval) + if self.options.random_interval: + sleep(randint(0, self.options.interval)) + else: + sleep(self.options.interval) def main():