예제 #1
0
 def run_test(self):
     start_p2p_connection(self.nodes)
     n_generate_batch = 1000
     n_attack_blocks = 15000
     self.log.info(f"Attacker start to prepare {n_attack_blocks} blocks")
     attack_blocks = create_chain_of_blocks(
         parent_hash=self.nodes[0].p2p.genesis.hash,
         parent_height=0,
         count=n_attack_blocks)
     self.log.info("Honest node generate")
     for _ in range(int(20000 / n_generate_batch)):
         batch_generate(self.nodes[0], n_generate_batch, self.log)
     cnt = self.nodes[0].getblockcount()
     self.log.info("Honest node block count: " + str(cnt))
     for b in attack_blocks:
         self.nodes[0].p2p.send_protocol_msg(NewBlock(b))
     honest_cnt = 20000 + 1
     for _ in range(1000):
         batch_generate(self.nodes[0], n_generate_batch, self.log)
         honest_cnt += n_generate_batch
         cnt = self.nodes[0].getblockcount()
         self.log.info("Honest node block count: " + str(cnt) + " " +
                       str(honest_cnt))
         if honest_cnt + n_attack_blocks == cnt:
             self.log.info("All attack blocks are processed!")
             break
예제 #2
0
 def generate_block(self):
     # if not hasattr(self, "parent_hash"):
     #     self.parent_hash = make_genesis().hash_hex()
     # self.parent_hash = self.node.generate_block_with_parent(self.parent_hash)
     block = create_block(parent_hash=self.parent_hash, height=self.height)
     self.node.p2p.send_protocol_msg(NewBlock(block=block))
     self.parent_hash = block.hash
     self.height += 1