Esempio n. 1
0
    def handle_scrypt_output_message(self, miner_id: int, data: bytes) -> None:
        summary_hash: bytes = data

        self.increment_hash_counter()

        summary, current_height, transactions = self.mining_args[miner_id]

        evidence = construct_pow_evidence_after_scrypt(summary_hash,
                                                       self.coinstate, summary,
                                                       current_height,
                                                       transactions)

        block = Block(BlockHeader(summary, evidence), transactions)

        if block.hash() >= block.target:
            # we didn't mine the block
            return

        self.network_thread.local_peer.chain_manager.set_coinstate(
            self.coinstate)
        self.network_thread.local_peer.network_manager.broadcast_block(block)

        self.coinstate = self.coinstate.add_block(block, int(time()))

        # Originally there was a disk write in this spot. During testing of the chain.cache changes,
        # it was found there is a race condition between the mining thread and the networking thread.
        # Better to skip the write here and just let the networking thread do it.

        print(f"miner {miner_id} found block: {block_filename(block)}")

        # get new public key for miner
        self.public_key = self.wallet.get_annotated_public_key(
            "reserved for potentially mined block")
        save_wallet(self.wallet)

        self.balance = self.wallet.get_balance(
            self.coinstate) / Decimal(SASHIMI_PER_COIN)
Esempio n. 2
0
 def broadcast_block(self, block: Block) -> None:
     self.local_peer.logger.info("%15s ChainManager.broadcast_block(%s)" %
                                 ("", human(block.hash())))
     self.broadcast_message(DataMessage(DATA_BLOCK, block))
Esempio n. 3
0
def block_filename(block: Block) -> str:
    return "%08d-%s" % (block.height, human(block.hash()))