(self, headers)
return new_start_idx
Raises ValueError if headers path don't extend from anywhere in this view.

        Returns False if the headers don't improve the path.

        If the headers DO improve the path, return the value of the block index of
        the first header.

        So you need to rewind to "new_start_idx" before applying the new blocks.
Raises ValueError if headers path don't extend from anywhere in this view.
Raises ValueError if headers path don t extend from anywhere in this view .
def do_headers_improve_path(self, headers):
        """
        Raises ValueError if headers path don't extend from anywhere in this view.

        Returns False if the headers don't improve the path.

        If the headers DO improve the path, return the value of the block index of
        the first header.

        So you need to rewind to "new_start_idx" before applying the new blocks.
        """
        tuples = []
        if len(self.node_tuples) == 0:
            if headers[0].previous_block_hash != HASH_INITIAL_BLOCK:
                return False
            the_tuple = GENESIS_TUPLE
        else:
            the_tuple = self.tuple_for_hash(headers[0].previous_block_hash)
            if the_tuple is None:
                return False
        new_start_idx = the_tuple[0] + 1
        total_work = the_tuple[-1]
        expected_prior_hash = the_tuple[1]
        for idx, h in enumerate(headers):
            if h.previous_block_hash != expected_prior_hash:
                raise ValueError(
                    "headers are not properly linked: no known block with hash %s" % b2h_rev(
                        h.previous_block_hash))
            total_work += 1  # TODO: make this difficulty/work instead of path size
            expected_prior_hash = h.hash()
            tuples.append((idx + new_start_idx, expected_prior_hash, total_work))
        if total_work <= self.last_block_tuple()[-1]:
            return False

        # the headers DO improve things

        old_tuples = self.node_tuples
        self._set_tuples(t for t in old_tuples if t[0] < new_start_idx)
        self._add_tuples(tuples)
        return new_start_idx
def do_headers_improve_path ( self , headers ) : tuples = [ ] if len ( self . node_tuples ) == 0 : if headers [ 0 ] . previous_block_hash != HASH_INITIAL_BLOCK : return False the_tuple = GENESIS_TUPLE else : the_tuple = self . tuple_for_hash ( headers [ 0 ] . previous_block_hash ) if the_tuple is None : return False new_start_idx = the_tuple [ 0 ] + 1 total_work = the_tuple [ - 1 ] expected_prior_hash = the_tuple [ 1 ] for idx , h in enumerate ( headers ) : if h . previous_block_hash != expected_prior_hash : raise ValueError ( "headers are not properly linked: no known block with hash %s" % b2h_rev ( h . previous_block_hash ) ) total_work += 1 # TODO: make this difficulty/work instead of path size expected_prior_hash = h . hash ( ) tuples . append ( ( idx + new_start_idx , expected_prior_hash , total_work ) ) if total_work <= self . last_block_tuple ( ) [ - 1 ] : return False # the headers DO improve things old_tuples = self . node_tuples self . _set_tuples ( t for t in old_tuples if t [ 0 ] < new_start_idx ) self . _add_tuples ( tuples ) return new_start_idx