def receive_newblock(proto, t_block, chain_difficulty)
      logger.debug 'newblock', proto: proto, block: t_block, chain_difficulty: chain_difficulty, client: proto.peer.remote_client_version

      if @chain.include?(t_block.header.full_hash)
        raise AssertError, 'chain difficulty mismatch' unless chain_difficulty == @chain.get(t_block.header.full_hash).chain_difficulty
      end

      @protocols[proto] = chain_difficulty

      if @chainservice.knows_block(t_block.header.full_hash)
        logger.debug 'known block'
        return
      end

      expected_difficulty = @chain.head.chain_difficulty + t_block.header.difficulty
      if chain_difficulty >= @chain.head.chain_difficulty
        # broadcast duplicates filtering is done in chainservice
        logger.debug 'sufficient difficulty, broadcasting', client: proto.peer.remote_client_version
        @chainservice.broadcast_newblock t_block, chain_difficulty, proto
      else
        age = @chain.head.number - t_block.header.number
        logger.debug "low difficulty", client: proto.peer.remote_client_version, chain_difficulty: chain_difficulty, expected_difficulty: expected_difficulty, block_age: age

        if age > MAX_NEWBLOCK_AGE
          logger.debug 'newblock is too old, not adding', block_age: age, max_age: MAX_NEWBLOCK_AGE
          return
        end
      end

      if @chainservice.knows_block(t_block.header.prevhash)
        logger.debug 'adding block'
        @chainservice.add_block t_block, proto
      else
        logger.debug 'missing parent'
        if @synctask
          logger.debug 'existing task, discarding'
        else
          @synctask = SyncTask.new self, proto, t_block.header.full_hash, chain_difficulty
        end
      end
    end
def receive_newblock(proto, t_block, chain_difficulty)
      logger.debug 'newblock', proto: proto, block: t_block, chain_difficulty: chain_difficulty, client: proto.peer.remote_client_version

      if @chain.include?(t_block.header.full_hash)
        raise AssertError, 'chain difficulty mismatch' unless chain_difficulty == @chain.get(t_block.header.full_hash).chain_difficulty
      end

      @protocols[proto] = chain_difficulty

      if @chainservice.knows_block(t_block.header.full_hash)
        logger.debug 'known block'
        return
      end

      expected_difficulty = @chain.head.chain_difficulty + t_block.header.difficulty
      if chain_difficulty >= @chain.head.chain_difficulty
        # broadcast duplicates filtering is done in chainservice
        logger.debug 'sufficient difficulty, broadcasting', client: proto.peer.remote_client_version
        @chainservice.broadcast_newblock t_block, chain_difficulty, proto
      else
        age = @chain.head.number - t_block.header.number
        logger.debug "low difficulty", client: proto.peer.remote_client_version, chain_difficulty: chain_difficulty, expected_difficulty: expected_difficulty, block_age: age

        if age > MAX_NEWBLOCK_AGE
          logger.debug 'newblock is too old, not adding', block_age: age, max_age: MAX_NEWBLOCK_AGE
          return
        end
      end

      if @chainservice.knows_block(t_block.header.prevhash)
        logger.debug 'adding block'
        @chainservice.add_block t_block, proto
      else
        logger.debug 'missing parent'
        if @synctask
          logger.debug 'existing task, discarding'
        else
          @synctask = SyncTask.new self, proto, t_block.header.full_hash, chain_difficulty
        end
      end
    end
Called if there's a newblock announced on the network.