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

Loading…
Cancel
Save