def validate_uncles
      return false if Utils.keccak256_rlp(uncles) != uncles_hash
      return false if uncles.size > config[:max_uncles]

      uncles.each do |uncle|
        raise InvalidUncles, "Cannot find uncle prevhash in db" unless db.include?(uncle.prevhash)
        if uncle.number == number
          logger.error "uncle at same block height", block: self
          return false
        end
      end

      max_uncle_depth = config[:max_uncle_depth]
      ancestor_chain = [self] + get_ancestor_list(max_uncle_depth+1)
      raise ValueError, "invalid ancestor chain" unless ancestor_chain.size == [number+1, max_uncle_depth+2].min

      # Uncles of this block cannot be direct ancestors and cannot also be
      # uncles included 1-6 blocks ago.
      ineligible = []
      ancestor_chain.safe_slice(1..-1).each {|a| ineligible.concat a.uncles }
      ineligible.concat(ancestor_chain.map {|a| a.header })

      eligible_ancestor_hashes = ancestor_chain.safe_slice(2..-1).map(&:full_hash)

      uncles.each do |uncle|
        parent = Block.find env, uncle.prevhash
        return false if uncle.difficulty != Block.calc_difficulty(parent, uncle.timestamp)
        return false if uncle.number != parent.number + 1
        return false if uncle.timestamp < parent.timestamp
        return false unless uncle.check_pow

        unless eligible_ancestor_hashes.include?(uncle.prevhash)
          eligible = eligible_ancestor_hashes.map {|h| Utils.encode_hex(h) }
          logger.error "Uncle does not have a valid ancestor", block: self, eligible: eligible, uncle_prevhash: Utils.encode_hex(uncle.prevhash)
          return false
        end

        if ineligible.include?(uncle)
          logger.error "Duplicate uncle", block: self, uncle: Utils.encode_hex(Utils.keccak256_rlp(uncle))
          return false
        end

        # FIXME: what if uncles include previously rewarded uncle?
        ineligible.push uncle
      end

      true
    end
def validate_uncles
      return false if Utils.keccak256_rlp(uncles) != uncles_hash
      return false if uncles.size > config[:max_uncles]

      uncles.each do |uncle|
        raise InvalidUncles, "Cannot find uncle prevhash in db" unless db.include?(uncle.prevhash)
        if uncle.number == number
          logger.error "uncle at same block height", block: self
          return false
        end
      end

      max_uncle_depth = config[:max_uncle_depth]
      ancestor_chain = [self] + get_ancestor_list(max_uncle_depth+1)
      raise ValueError, "invalid ancestor chain" unless ancestor_chain.size == [number+1, max_uncle_depth+2].min

      # Uncles of this block cannot be direct ancestors and cannot also be
      # uncles included 1-6 blocks ago.
      ineligible = []
      ancestor_chain.safe_slice(1..-1).each {|a| ineligible.concat a.uncles }
      ineligible.concat(ancestor_chain.map {|a| a.header })

      eligible_ancestor_hashes = ancestor_chain.safe_slice(2..-1).map(&:full_hash)

      uncles.each do |uncle|
        parent = Block.find env, uncle.prevhash
        return false if uncle.difficulty != Block.calc_difficulty(parent, uncle.timestamp)
        return false if uncle.number != parent.number + 1
        return false if uncle.timestamp < parent.timestamp
        return false unless uncle.check_pow

        unless eligible_ancestor_hashes.include?(uncle.prevhash)
          eligible = eligible_ancestor_hashes.map {|h| Utils.encode_hex(h) }
          logger.error "Uncle does not have a valid ancestor", block: self, eligible: eligible, uncle_prevhash: Utils.encode_hex(uncle.prevhash)
          return false
        end

        if ineligible.include?(uncle)
          logger.error "Duplicate uncle", block: self, uncle: Utils.encode_hex(Utils.keccak256_rlp(uncle))
          return false
        end

        # FIXME: what if uncles include previously rewarded uncle?
        ineligible.push uncle
      end

      true
    end
Validate the uncles of this block.