[2308.05096] Optimal Flexible Consensus and its Application to Ethereum