fix consensus issue. (#1803)

intermediate values of the base fee can be higher than maximum value encoded by a long. Now using BigInteger to compute intermediate fee delta.

Signed-off-by: Abdelhamid Bakhta <abdelhamid.bakhta@consensys.net>
pull/1806/head
Abdelhamid Bakhta 4 years ago committed by GitHub
parent d06393d50f
commit ea41076e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      ethereum/core/src/main/java/org/hyperledger/besu/ethereum/core/fees/EIP1559.java

@ -14,12 +14,13 @@
*/
package org.hyperledger.besu.ethereum.core.fees;
import static java.lang.Math.floorDiv;
import static java.lang.Math.max;
import org.hyperledger.besu.config.experimental.ExperimentalEIPs;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import java.math.BigInteger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -45,19 +46,19 @@ public class EIP1559 {
return parentBaseFee;
} else if (parentBlockGasUsed > targetGasUsed) {
gasDelta = parentBlockGasUsed - targetGasUsed;
feeDelta =
max(
floorDiv(
floorDiv(parentBaseFee * gasDelta, targetGasUsed),
feeMarket.getBasefeeMaxChangeDenominator()),
1);
final BigInteger pBaseFee = BigInteger.valueOf(parentBaseFee);
final BigInteger gDelta = BigInteger.valueOf(gasDelta);
final BigInteger target = BigInteger.valueOf(targetGasUsed);
final BigInteger denominator = BigInteger.valueOf(feeMarket.getBasefeeMaxChangeDenominator());
feeDelta = max(pBaseFee.multiply(gDelta).divide(target).divide(denominator).longValue(), 1);
baseFee = parentBaseFee + feeDelta;
} else {
gasDelta = targetGasUsed - parentBlockGasUsed;
feeDelta =
floorDiv(
floorDiv(parentBaseFee * gasDelta, targetGasUsed),
feeMarket.getBasefeeMaxChangeDenominator());
final BigInteger pBaseFee = BigInteger.valueOf(parentBaseFee);
final BigInteger gDelta = BigInteger.valueOf(gasDelta);
final BigInteger target = BigInteger.valueOf(targetGasUsed);
final BigInteger denominator = BigInteger.valueOf(feeMarket.getBasefeeMaxChangeDenominator());
feeDelta = pBaseFee.multiply(gDelta).divide(target).divide(denominator).longValue();
baseFee = parentBaseFee - feeDelta;
}
LOG.trace(

Loading…
Cancel
Save