Beispiel #1
0
    def _find_first_parent_in_best_chain(self,
                                         block: Block) -> BaseTransaction:
        """ Find the first block in the side chain that is not voided, i.e., the block where the fork started.

        In the simple schema below, the best chain's blocks are O's, the side chain's blocks are I's, and the first
        valid block is the [O].

        O-O-O-O-[O]-O-O-O-O
                 |
                 +-I-I-I
        """
        assert block.storage is not None
        storage = block.storage

        assert len(
            block.parents
        ) > 0, 'This should never happen because the genesis is always in the best chain'
        parent_hash = block.get_block_parent_hash()
        while True:
            parent = storage.get_transaction(parent_hash)
            assert isinstance(parent, Block)
            parent_meta = parent.get_metadata()
            if not parent_meta.voided_by:
                break
            assert len(
                parent.parents
            ) > 0, 'This should never happen because the genesis is always in the best chain'
            parent_hash = parent.get_block_parent_hash()
        return parent
Beispiel #2
0
 def submit_block(self, blk: Block, fails_silently: bool = True) -> bool:
     """Used by submit block from all mining APIs.
     """
     tips = self.tx_storage.get_best_block_tips()
     parent_hash = blk.get_block_parent_hash()
     if parent_hash not in tips:
         return False
     return self.propagate_tx(blk, fails_silently=fails_silently)
Beispiel #3
0
 def submit_block(self, blk: Block, fails_silently: bool = True) -> bool:
     """Used by submit block from all mining APIs.
     """
     tips = self.tx_storage.get_best_block_tips()
     parent_hash = blk.get_block_parent_hash()
     if parent_hash not in tips:
         self.log.warn('submit_block(): Ignoring block: parent not a tip',
                       blk=blk.hash_hex)
         return False
     return self.propagate_tx(blk, fails_silently=fails_silently)