Пример #1
0
    def _internal_block_put(self, block: payloads.Block, batch: WriteBatch = None) -> None:
        if batch:
            batch.put(self.BLOCK, block.hash(), block)
        else:
            self.db[self.BLOCK][block.hash()] = block
            self.db[self.BLOCK_HEIGHT_MAP][block.index] = block.hash()

        stored_value = -1
        with suppress(KeyError):
            stored_value = self._internal_bestblockheight_get()

        if block.index > stored_value:
            self._best_block_height = block.index
Пример #2
0
    def _internal_block_put(self, block: payloads.Block, batch=None):
        if batch:
            db = batch
        else:
            db = self._real_db

        block_height_bytes = block.index.to_bytes(4, 'little')
        db.put(DBPrefixes.BLOCKS + block.hash().to_array(), block.to_array())
        db.put(DBPrefixes.BLOCKS_HEIGHT_MAP + block_height_bytes, block.hash().to_array())

        # this function is only called when putting blocks to the backend via the raw view, or when committing
        # a snapshot view. Either way it is ok to persist the height
        stored_value = -1
        with suppress(KeyError):
            stored_value = self._internal_bestblockheight_get()

        if block.index > stored_value:
            db.put(DBPrefixes.BLOCKS_BEST_HEIGHT, block_height_bytes)
Пример #3
0
    def put(self, block: payloads.Block) -> None:
        """
        Store a block.

        Args:
            block: instance.

        Raises:
            ValueError: if a duplicate item is found.
        """
        block_hash = block.hash()
        super(CachedBlockAccess, self)._put(block_hash, block)
        self._height_hash_mapping.update({block.index: block_hash})