Mechanism Design for Optimal Consensus Problems