mirror of https://github.com/hyperledger/besu
feat: add fixed basefee options (#6562)
* feat: add fixed basefee options Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> * Refactor zero base fee to be extension of fixed base fee Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> * feat: use MiningParameters to fixed base fee Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> * feat: add mining parameters arg on protocol schedule builder * feat: add miningParameters on gray glacier and prague Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> * feat: add miningParameters on gray glacier and prague Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> * feat: add miningParameters on paris,shanghai,future,experimental Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> --------- Signed-off-by: Suraneti Rodsuwan <suraneti.rod@gmail.com> Signed-off-by: Matthew Whitehead <matthew1001@gmail.com> Signed-off-by: Suraneti <suraneti.rod@gmail.com> Co-authored-by: Matthew Whitehead <matthew1001@gmail.com> Co-authored-by: Sally MacFarlane <macfarla.github@gmail.com>pull/6748/head
parent
de0704afbf
commit
feb1764199
@ -0,0 +1,41 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.mainnet.feemarket; |
||||
|
||||
import org.hyperledger.besu.datatypes.Wei; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
public class FixedBaseFeeMarket extends LondonFeeMarket { |
||||
|
||||
public FixedBaseFeeMarket(final long londonForkBlockNumber, final Wei fixedBaseFee) { |
||||
super(londonForkBlockNumber, Optional.of(fixedBaseFee)); |
||||
} |
||||
|
||||
@Override |
||||
public Wei computeBaseFee( |
||||
final long blockNumber, |
||||
final Wei parentBaseFee, |
||||
final long parentBlockGasUsed, |
||||
final long targetGasUsed) { |
||||
|
||||
return baseFeeInitialValue; |
||||
} |
||||
|
||||
@Override |
||||
public ValidationMode baseFeeValidationMode(final long blockNumber) { |
||||
return ValidationMode.NONE; |
||||
} |
||||
} |
@ -0,0 +1,152 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.mainnet.feemarket; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import org.hyperledger.besu.crypto.KeyPair; |
||||
import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; |
||||
import org.hyperledger.besu.datatypes.BlobGas; |
||||
import org.hyperledger.besu.datatypes.TransactionType; |
||||
import org.hyperledger.besu.datatypes.Wei; |
||||
import org.hyperledger.besu.ethereum.core.Transaction; |
||||
import org.hyperledger.besu.ethereum.core.TransactionTestFixture; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
import org.junit.jupiter.api.BeforeEach; |
||||
import org.junit.jupiter.api.Test; |
||||
|
||||
public class FixedBaseFeeMarketTest { |
||||
|
||||
private static final KeyPair KEY_PAIR1 = |
||||
SignatureAlgorithmFactory.getInstance().generateKeyPair(); |
||||
private static final long FORK_BLOCK = 0; |
||||
private FixedBaseFeeMarket fixedBaseFeeMarket; |
||||
|
||||
@BeforeEach |
||||
public void setUp() throws Exception { |
||||
fixedBaseFeeMarket = new FixedBaseFeeMarket(FORK_BLOCK, Wei.ONE); |
||||
} |
||||
|
||||
@Test |
||||
public void getBasefeeMaxChangeDenominatorShouldUseLondonDefault() { |
||||
assertThat(fixedBaseFeeMarket.getBasefeeMaxChangeDenominator()) |
||||
.isEqualTo(LondonFeeMarket.DEFAULT_BASEFEE_MAX_CHANGE_DENOMINATOR); |
||||
} |
||||
|
||||
@Test |
||||
public void getInitialBasefeeShouldBeZero() { |
||||
assertThat(fixedBaseFeeMarket.getInitialBasefee()).isEqualTo(Wei.ONE); |
||||
} |
||||
|
||||
@Test |
||||
public void getSlackCoefficientShouldUseLondonDefault() { |
||||
assertThat(fixedBaseFeeMarket.getSlackCoefficient()) |
||||
.isEqualTo(LondonFeeMarket.DEFAULT_SLACK_COEFFICIENT); |
||||
} |
||||
|
||||
@Test |
||||
public void getTransactionPriceCalculatorShouldBeEIP1559() { |
||||
// only eip1559 will read the fee per gas values
|
||||
final Transaction transaction = |
||||
new TransactionTestFixture() |
||||
.type(TransactionType.EIP1559) |
||||
.maxFeePerGas(Optional.of(Wei.of(8))) |
||||
.maxPriorityFeePerGas(Optional.of(Wei.of(8))) |
||||
.gasPrice(null) |
||||
.createTransaction(KEY_PAIR1); |
||||
|
||||
assertThat( |
||||
fixedBaseFeeMarket |
||||
.getTransactionPriceCalculator() |
||||
.price(transaction, Optional.of(Wei.ZERO))) |
||||
.isEqualTo(Wei.of(8)); |
||||
} |
||||
|
||||
@Test |
||||
public void satisfiesFloorTxCostWhenGasFeeIsNonZero() { |
||||
final Transaction transaction = |
||||
new TransactionTestFixture() |
||||
.type(TransactionType.FRONTIER) |
||||
.gasPrice(Wei.of(7)) |
||||
.createTransaction(KEY_PAIR1); |
||||
assertThat(fixedBaseFeeMarket.satisfiesFloorTxFee(transaction)).isTrue(); |
||||
} |
||||
|
||||
@Test |
||||
public void satisfiesFloorTxCostWhenGasFeeIsZero() { |
||||
final Transaction transaction = |
||||
new TransactionTestFixture() |
||||
.type(TransactionType.EIP1559) |
||||
.maxFeePerGas(Optional.of(Wei.ZERO)) |
||||
.maxPriorityFeePerGas(Optional.of(Wei.ZERO)) |
||||
.gasPrice(null) |
||||
.createTransaction(KEY_PAIR1); |
||||
assertThat(fixedBaseFeeMarket.satisfiesFloorTxFee(transaction)).isFalse(); |
||||
} |
||||
|
||||
@Test |
||||
public void computeBaseFeeReturnsFixedValue() { |
||||
assertThat(fixedBaseFeeMarket.computeBaseFee(1L, Wei.of(1), 1L, 2L)).isEqualTo(Wei.ONE); |
||||
} |
||||
|
||||
@Test |
||||
public void baseFeeValidationModeShouldBeNoneWhenIsForkBlock() { |
||||
assertThat(fixedBaseFeeMarket.baseFeeValidationMode(FORK_BLOCK)) |
||||
.isEqualTo(BaseFeeMarket.ValidationMode.NONE); |
||||
} |
||||
|
||||
@Test |
||||
public void baseFeeValidationModeShouldBeNoneWhenIsNotForkBlock() { |
||||
assertThat(fixedBaseFeeMarket.baseFeeValidationMode(FORK_BLOCK + 1)) |
||||
.isEqualTo(BaseFeeMarket.ValidationMode.NONE); |
||||
} |
||||
|
||||
@Test |
||||
public void gasLimitValidationModeShouldBeInitialWhenIsForkBlock() { |
||||
assertThat(fixedBaseFeeMarket.gasLimitValidationMode(FORK_BLOCK)) |
||||
.isEqualTo(BaseFeeMarket.ValidationMode.INITIAL); |
||||
} |
||||
|
||||
@Test |
||||
public void gasLimitValidationModeShouldBeOngoingWhenIsNotForkBlock() { |
||||
assertThat(fixedBaseFeeMarket.gasLimitValidationMode(FORK_BLOCK + 1)) |
||||
.isEqualTo(BaseFeeMarket.ValidationMode.ONGOING); |
||||
} |
||||
|
||||
@Test |
||||
public void isBeforeForkBlockShouldBeTrue() { |
||||
final FixedBaseFeeMarket fixedBaseFeeMarket = new FixedBaseFeeMarket(10, Wei.ONE); |
||||
assertThat(fixedBaseFeeMarket.isBeforeForkBlock(9)).isTrue(); |
||||
} |
||||
|
||||
@Test |
||||
public void isBeforeForkBlockShouldBeFalse() { |
||||
final FixedBaseFeeMarket fixedBaseFeeMarket = new FixedBaseFeeMarket(10, Wei.ONE); |
||||
assertThat(fixedBaseFeeMarket.isBeforeForkBlock(10)).isFalse(); |
||||
assertThat(fixedBaseFeeMarket.isBeforeForkBlock(11)).isFalse(); |
||||
} |
||||
|
||||
@Test |
||||
public void implementsDataFeedShouldReturnFalse() { |
||||
assertThat(fixedBaseFeeMarket.implementsDataFee()).isFalse(); |
||||
} |
||||
|
||||
@Test |
||||
public void dataPriceShouldReturnsZero() { |
||||
assertThat(fixedBaseFeeMarket.blobGasPricePerGas(BlobGas.ONE)).isEqualTo(Wei.ZERO); |
||||
} |
||||
} |
@ -0,0 +1,75 @@ |
||||
/* |
||||
* Copyright Hyperledger Besu Contributors. |
||||
* |
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
||||
* the License. You may obtain a copy of the License at |
||||
* |
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* |
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
||||
* specific language governing permissions and limitations under the License. |
||||
* |
||||
* SPDX-License-Identifier: Apache-2.0 |
||||
*/ |
||||
package org.hyperledger.besu.ethereum.mainnet.headervalidationrules; |
||||
|
||||
import static java.lang.Long.MAX_VALUE; |
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
|
||||
import org.hyperledger.besu.datatypes.Wei; |
||||
import org.hyperledger.besu.ethereum.core.BlockHeader; |
||||
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; |
||||
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket; |
||||
import org.hyperledger.besu.ethereum.mainnet.feemarket.FixedBaseFeeMarket; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
import org.junit.jupiter.params.ParameterizedTest; |
||||
import org.junit.jupiter.params.provider.CsvSource; |
||||
|
||||
public class GasLimitElasticityValidationRuleFixedBaseFeeMarketTest { |
||||
|
||||
private static final Optional<BaseFeeMarket> fixedBaseFeeMarket = |
||||
Optional.of(new FixedBaseFeeMarket(10, Wei.ONE)); |
||||
|
||||
public GasLimitRangeAndDeltaValidationRule uut = |
||||
new GasLimitRangeAndDeltaValidationRule(5000, MAX_VALUE, fixedBaseFeeMarket); |
||||
|
||||
@ParameterizedTest |
||||
@CsvSource({ |
||||
"20000000, 10000000, 10, true", |
||||
"20019530, 10000000, 10, true", |
||||
"20019531, 10000000, 10, false", |
||||
"19980470, 10000000, 10, true", |
||||
"19980469, 10000000, 10, false", |
||||
"20000000, 20000000, 11, true", |
||||
"20019530, 20000000, 11, true", |
||||
"20019531, 20000000, 11, false", |
||||
"19980470, 20000000, 11, true", |
||||
"19980469, 20000000, 11, false", |
||||
"40039061, 40000000, 11, true", |
||||
"40039062, 40000000, 11, false", |
||||
"39960939, 40000000, 11, true", |
||||
"39960938, 40000000, 11, false", |
||||
"4999, 40000000, 11, false" |
||||
}) |
||||
public void test( |
||||
final long headerGasLimit, |
||||
final long parentGasLimit, |
||||
final long headerNumber, |
||||
final boolean expectedResult) { |
||||
|
||||
final BlockHeaderTestFixture blockHeaderBuilder = new BlockHeaderTestFixture(); |
||||
|
||||
blockHeaderBuilder.number(headerNumber); |
||||
blockHeaderBuilder.gasLimit(headerGasLimit); |
||||
final BlockHeader header = blockHeaderBuilder.buildHeader(); |
||||
|
||||
blockHeaderBuilder.number(headerNumber - 1); |
||||
blockHeaderBuilder.gasLimit(parentGasLimit); |
||||
final BlockHeader parent = blockHeaderBuilder.buildHeader(); |
||||
|
||||
assertThat(uut.validate(header, parent)).isEqualTo(expectedResult); |
||||
} |
||||
} |
Loading…
Reference in new issue