Пример #1
0
 def validate_uncle(self, block, uncle):
     """
     Validate the given uncle in the context of the given block.
     """
     if uncle.block_number >= block.number:
         raise ValidationError(
             "Uncle number ({0}) is higher than block number ({1})".format(
                 uncle.block_number, block.number))
     try:
         parent_header = get_block_header_by_hash(uncle.parent_hash, self.chaindb)
     except HeaderNotFound:
         raise ValidationError(
             "Uncle ancestor not found: {0}".format(uncle.parent_hash))
     if uncle.block_number != parent_header.block_number + 1:
         raise ValidationError(
             "Uncle number ({0}) is not one above ancestor's number ({1})".format(
                 uncle.block_number, parent_header.block_number))
     if uncle.timestamp < parent_header.timestamp:
         raise ValidationError(
             "Uncle timestamp ({0}) is before ancestor's timestamp ({1})".format(
                 uncle.timestamp, parent_header.timestamp))
     if uncle.gas_used > uncle.gas_limit:
         raise ValidationError(
             "Uncle's gas usage ({0}) is above the limit ({1})".format(
                 uncle.gas_used, uncle.gas_limit))
Пример #2
0
    def get_prev_hashes(cls, last_block_hash, db):
        if last_block_hash == GENESIS_PARENT_HASH:
            return

        block_header = get_block_header_by_hash(last_block_hash, db)

        for _ in range(MAX_PREV_HEADER_DEPTH):
            yield block_header.hash
            try:
                block_header = get_parent_header(block_header, db)
            except (IndexError, BlockNotFound):
                break
Пример #3
0
    def get_prev_hashes(cls, last_block_hash, db):
        if last_block_hash == GENESIS_PARENT_HASH:
            return

        block_header = get_block_header_by_hash(last_block_hash, db)

        for _ in range(MAX_PREV_HEADER_DEPTH):
            yield block_header.hash
            try:
                block_header = get_parent_header(block_header, db)
            except (IndexError, BlockNotFound):
                break
Пример #4
0
    def get_prev_headers(cls, last_block_hash, db):
        prev_headers = []

        if last_block_hash == GENESIS_PARENT_HASH:
            return prev_headers

        block_header = get_block_header_by_hash(last_block_hash, db)

        for _ in range(MAX_PREV_HEADER_DEPTH):
            prev_headers.append(block_header)
            try:
                block_header = get_parent_header(block_header, db)
            except (IndexError, BlockNotFound):
                break
        return prev_headers
Пример #5
0
 def validate_uncle(self, block, uncle):
     if uncle.block_number >= block.number:
         raise ValidationError(
             "Uncle number ({0}) is higher than block number ({1})".format(
                 uncle.block_number, block.number))
     try:
         parent_header = get_block_header_by_hash(uncle.parent_hash, self.chaindb)
     except BlockNotFound:
         raise ValidationError(
             "Uncle ancestor not found: {0}".format(uncle.parent_hash))
     if uncle.block_number != parent_header.block_number + 1:
         raise ValidationError(
             "Uncle number ({0}) is not one above ancestor's number ({1})".format(
                 uncle.block_number, parent_header.block_number))
     if uncle.timestamp < parent_header.timestamp:
         raise ValidationError(
             "Uncle timestamp ({0}) is before ancestor's timestamp ({1})".format(
                 uncle.timestamp, parent_header.timestamp))
     if uncle.gas_used > uncle.gas_limit:
         raise ValidationError(
             "Uncle's gas usage ({0}) is above the limit ({1})".format(
                 uncle.gas_used, uncle.gas_limit))