Skip to content

Commit

Permalink
Merge branch 'main' into rel/0.1.4-test18
Browse files Browse the repository at this point in the history
  • Loading branch information
fab-10 committed Feb 15, 2024
2 parents 8b153a4 + 8af6944 commit 5708353
Show file tree
Hide file tree
Showing 29 changed files with 1,017 additions and 248 deletions.
39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Changelog

## 0.1.4-test18-RC3
Test pre-release 18-RC3 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Use compressed tx size also when selecting txs from block creation [#590](https://github.com/Consensys/besu-sequencer-plugins/pull/590)

## 0.1.4-test18-RC2
Test pre-release 18-RC2 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Fix linea_estimateGas reports Internal error when value or gas price is missing [#587](https://github.com/Consensys/besu-sequencer-plugins/pull/587)

## 0.1.4-test18-RC1
Test pre-release 18-RC1 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Linea estimate gas endpoint [#585](https://github.com/Consensys/besu-sequencer-plugins/pull/585)

## 0.1.4-test17
Test pre-release 17 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* tests: drop huge random tests [#563](https://github.com/Consensys/besu-sequencer-plugins/pull/563)
* feat(modexp-data): implement MODEXP_DATA module [#547](https://github.com/Consensys/besu-sequencer-plugins/pull/547)
* feat: mechanics to capture conflations & replay them as test cases [#561](https://github.com/Consensys/besu-sequencer-plugins/pull/561)
* perf(EUC): one less column [#570](https://github.com/Consensys/besu-sequencer-plugins/pull/570)
* docs: Add basic plugins doc [#509](https://github.com/Consensys/besu-sequencer-plugins/pull/509)
* Check upfront profitability + Unprofitable txs cache and retry limit [#565](https://github.com/Consensys/besu-sequencer-plugins/pull/565)
* Avoid reprocessing txs that go over line count limit [#571](https://github.com/Consensys/besu-sequencer-plugins/pull/571)

## 0.1.4-test16
Test pre-release 16 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* fix: bug-compatibility with Geth
* fix: PubHash 16 factor

Full changeset https://github.com/Consensys/besu-sequencer-plugins/compare/v0.1.4-test15...v0.1.4-test16

## 0.1.4-test15
release rebase off of main
* add option to adjust the tx size used to calculate the profitability of a tx during block creation(#562)[https://github.com/Consensys/besu-sequencer-plugins/pull/562]

## 0.1.4-test14
release rebase off of main
Test pre-release 14 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* Fix log of line counts in case of block limit reached + minor changes [#555](https://github.com/ConsenSys/besu-sequencer-plugins/pull/555)
* build: update Corset to 9.3.0 [#554](https://github.com/ConsenSys/besu-sequencer-plugins/pull/554)

## 0.1.4-test13
Test pre-release 13 from [temp/issue-248/count-stack-only](https://github.com/Consensys/besu-sequencer-plugins/tree/temp/issue-248/count-stack-only)
* fix stackedSet [c3f226775f24508b93a758e4226a51ae386d76a5](https://github.com/Consensys/besu-sequencer-plugins/commit/c3f226775f24508b93a758e4226a51ae386d76a5)
Expand Down
1 change: 1 addition & 0 deletions acceptance-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tasks.register('acceptanceTests', Test) {
}

dependencies {
testImplementation project(":arithmetization")
testImplementation "${besuArtifactGroup}.internal:dsl:$besuVersion"
testImplementation "${besuArtifactGroup}:besu-datatypes:$besuVersion"
testImplementation "${besuArtifactGroup}.internal:eth:$besuVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public class LineaPluginTestBase extends AcceptanceTestBase {
@BeforeEach
public void setup() throws Exception {
minerNode =
besu.createCliqueNodeWithExtraCliOptions(
"miner1", LINEA_CLIQUE_OPTIONS, getTestCliOptions());
besu.createCliqueNodeWithExtraCliOptionsAndRpcApis(
"miner1", LINEA_CLIQUE_OPTIONS, getTestCliOptions(), Set.of("LINEA"));
minerNode.setTransactionPoolConfiguration(
ImmutableTransactionPoolConfiguration.builder()
.from(TransactionPoolConfiguration.DEFAULT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void transactionIsNotMinedWhenUnprofitable() throws Exception {
final Credentials credentials = Credentials.create(Accounts.GENESIS_ACCOUNT_ONE_PRIVATE_KEY);
TransactionManager txManager = new RawTransactionManager(web3j, credentials, CHAIN_ID);

final String txData = "not profitable transaction".repeat(10);
final String txData = "not profitable transaction".repeat(60);

final var txUnprofitable =
txManager.sendTransaction(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
/*
* Copyright Consensys Software Inc.
*
* 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 linea.plugin.acc.test.rpc.linea;

import static org.assertj.core.api.Assertions.assertThat;

import java.io.IOException;
import java.math.BigInteger;
import java.util.List;

import linea.plugin.acc.test.LineaPluginTestBase;
import linea.plugin.acc.test.TestCommandLineOptionsBuilder;
import net.consensys.linea.bl.TransactionProfitabilityCalculator;
import net.consensys.linea.config.LineaTransactionSelectorCliOptions;
import net.consensys.linea.config.LineaTransactionSelectorConfiguration;
import net.consensys.linea.rpc.linea.LineaEstimateGas;
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.units.bigints.UInt64;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.NodeRequests;
import org.hyperledger.besu.tests.acceptance.dsl.transaction.Transaction;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.web3j.protocol.core.Request;

public class EstimateGasTest extends LineaPluginTestBase {
private static final int VERIFICATION_GAS_COST = 1_200_000;
private static final int VERIFICATION_CAPACITY = 90_000;
private static final int GAS_PRICE_RATIO = 15;
private static final double MIN_MARGIN = 1.0;
private static final double ESTIMATE_GAS_MIN_MARGIN = 1.0;
private static final Wei MIN_GAS_PRICE = Wei.of(1_000_000_000);
public static final int MAX_TRANSACTION_GAS_LIMIT = 30_000_000;
private LineaTransactionSelectorConfiguration txSelectorConf;

@Override
public List<String> getTestCliOptions() {
return new TestCommandLineOptionsBuilder()
.set("--plugin-linea-verification-gas-cost=", String.valueOf(VERIFICATION_GAS_COST))
.set("--plugin-linea-verification-capacity=", String.valueOf(VERIFICATION_CAPACITY))
.set("--plugin-linea-gas-price-ratio=", String.valueOf(GAS_PRICE_RATIO))
.set("--plugin-linea-min-margin=", String.valueOf(MIN_MARGIN))
.set("--plugin-linea-estimate-gas-min-margin=", String.valueOf(ESTIMATE_GAS_MIN_MARGIN))
.set("--plugin-linea-max-tx-gas-limit=", String.valueOf(MAX_TRANSACTION_GAS_LIMIT))
.build();
}

@BeforeEach
public void setMinGasPrice() {
minerNode.getMiningParameters().setMinTransactionGasPrice(MIN_GAS_PRICE);
}

@BeforeEach
public void createDefaultConfigurations() {
txSelectorConf =
LineaTransactionSelectorCliOptions.create().toDomainObject().toBuilder()
.verificationCapacity(VERIFICATION_CAPACITY)
.verificationGasCost(VERIFICATION_GAS_COST)
.gasPriceRatio(GAS_PRICE_RATIO)
.minMargin(MIN_MARGIN)
.estimateGasMinMargin(ESTIMATE_GAS_MIN_MARGIN)
.build();
}

@Test
public void lineaEstimateGasMatchesEthEstimateGas() {

final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams = new CallParams(sender.getAddress(), null);

final var reqEth = new RawEstimateGasRequest(callParams);
final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respEth = reqEth.execute(minerNode.nodeRequests());
final var respLinea = reqLinea.execute(minerNode.nodeRequests());
assertThat(respEth).isEqualTo(respLinea.gasLimit());
}

@Test
public void lineaEstimateGasIsProfitable() {

final Account sender = accounts.getSecondaryBenefactor();

final CallParams callParams = new CallParams(sender.getAddress(), null);

final var reqLinea = new LineaEstimateGasRequest(callParams);
final var respLinea = reqLinea.execute(minerNode.nodeRequests());

final var gasLimit = UInt64.fromHexString(respLinea.gasLimit()).toLong();
final var baseFee = Wei.fromHexString(respLinea.baseFeePerGas());
final var priorityFee = Wei.fromHexString(respLinea.priorityFeePerGas());
final var maxGasPrice = baseFee.add(priorityFee);

final var tx =
org.hyperledger.besu.ethereum.core.Transaction.builder()
.sender(Address.fromHexString(sender.getAddress()))
.gasLimit(gasLimit)
.gasPrice(maxGasPrice)
.chainId(BigInteger.valueOf(CHAIN_ID))
.value(Wei.ZERO)
.payload(Bytes.EMPTY)
.signature(LineaEstimateGas.FAKE_SIGNATURE_FOR_SIZE_CALCULATION)
.build();

final var profitabilityCalculator = new TransactionProfitabilityCalculator(txSelectorConf);
assertThat(
profitabilityCalculator.isProfitable(
"Test",
tx,
minerNode
.getMiningParameters()
.getMinTransactionGasPrice()
.getAsBigInteger()
.doubleValue(),
maxGasPrice.getAsBigInteger().doubleValue(),
gasLimit))
.isTrue();
}

class LineaEstimateGasRequest implements Transaction<LineaEstimateGasRequest.Response> {
private final CallParams callParams;

public LineaEstimateGasRequest(final CallParams callParams) {
this.callParams = callParams;
}

@Override
public LineaEstimateGasRequest.Response execute(final NodeRequests nodeRequests) {
try {
return new Request<>(
"linea_estimateGas",
List.of(callParams),
nodeRequests.getWeb3jService(),
LineaEstimateGasResponse.class)
.send()
.getResult();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

static class LineaEstimateGasResponse extends org.web3j.protocol.core.Response<Response> {}

record Response(String gasLimit, String baseFeePerGas, String priorityFeePerGas) {}
}

class RawEstimateGasRequest implements Transaction<String> {
private final CallParams callParams;

public RawEstimateGasRequest(final CallParams callParams) {
this.callParams = callParams;
}

@Override
public String execute(final NodeRequests nodeRequests) {
try {
return new Request<>(
"eth_estimateGas",
List.of(callParams),
nodeRequests.getWeb3jService(),
RawEstimateGasResponse.class)
.send()
.getResult();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

static class RawEstimateGasResponse extends org.web3j.protocol.core.Response<String> {}
}

record CallParams(String from, String value) {}
}
2 changes: 1 addition & 1 deletion acceptance-tests/src/test/resources/clique/clique.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
"zeroBaseFee": false,
"baseFeePerGas": "1000000000",
"baseFeePerGas": "7",
"nonce": "0x0",
"timestamp": "0x6391BFF3",
"extraData": "%extraData%",
Expand Down
1 change: 1 addition & 0 deletions arithmetization/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation "${besuArtifactGroup}:evm"
implementation "${besuArtifactGroup}:plugin-api"
implementation "${besuArtifactGroup}:besu-datatypes"
implementation "${besuArtifactGroup}.internal:api:${besuVersion}"
implementation "${besuArtifactGroup}.internal:core:${besuVersion}"
implementation "${besuArtifactGroup}.internal:rlp:${besuVersion}"
implementation "${besuArtifactGroup}.internal:algorithms:${besuVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.hyperledger.besu.plugin.BesuPlugin;

@Slf4j
public abstract class AbstractLineaRequiredPlugin implements BesuPlugin {
public abstract class AbstractLineaRequiredPlugin extends AbstractLineaSharedOptionsPlugin {

/**
* Linea plugins extending this class will halt startup of Besu in case of exception during
Expand All @@ -32,6 +32,7 @@ public abstract class AbstractLineaRequiredPlugin implements BesuPlugin {
*/
@Override
public void register(final BesuContext context) {
super.register(context);
try {
log.info("Registering Linea plugin " + this.getClass().getName());

Expand All @@ -44,17 +45,4 @@ public void register(final BesuContext context) {
System.exit(1);
}
}

/**
* Linea plugins need to implement this method. Called by {@link BesuPlugin} register method
*
* @param context
*/
public abstract void doRegister(final BesuContext context);

@Override
public void start() {}

@Override
public void stop() {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright Consensys Software Inc.
*
* 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 net.consensys.linea;

import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.config.LineaTransactionSelectorCliOptions;
import net.consensys.linea.config.LineaTransactionSelectorConfiguration;
import net.consensys.linea.config.LineaTransactionValidatorCliOptions;
import net.consensys.linea.config.LineaTransactionValidatorConfiguration;
import org.hyperledger.besu.plugin.BesuContext;
import org.hyperledger.besu.plugin.BesuPlugin;
import org.hyperledger.besu.plugin.services.PicoCLIOptions;

@Slf4j
public abstract class AbstractLineaSharedOptionsPlugin implements BesuPlugin {
private static String CLI_OPTIONS_PREFIX = "linea";
private static boolean cliOptionsRegistered = false;
private static LineaTransactionSelectorCliOptions transactionSelectorCliOptions;
private static LineaTransactionValidatorCliOptions transactionValidatorCliOptions;
protected static LineaTransactionSelectorConfiguration transactionSelectorConfiguration;
protected static LineaTransactionValidatorConfiguration transactionValidatorConfiguration;

@Override
public synchronized void register(final BesuContext context) {
if (!cliOptionsRegistered) {
final PicoCLIOptions cmdlineOptions =
context
.getService(PicoCLIOptions.class)
.orElseThrow(
() ->
new IllegalStateException(
"Failed to obtain PicoCLI options from the BesuContext"));
transactionSelectorCliOptions = LineaTransactionSelectorCliOptions.create();
transactionValidatorCliOptions = LineaTransactionValidatorCliOptions.create();

cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, transactionSelectorCliOptions);
cmdlineOptions.addPicoCLIOptions(CLI_OPTIONS_PREFIX, transactionValidatorCliOptions);
cliOptionsRegistered = true;
}
}

@Override
public void beforeExternalServices() {
log.debug(
"Configuring plugin {} with transaction selector configuration: {}",
getName(),
transactionSelectorCliOptions);
transactionSelectorConfiguration = transactionSelectorCliOptions.toDomainObject();

log.debug(
"Configuring plugin {} with transaction validator configuration: {}",
getName(),
transactionValidatorCliOptions);
transactionValidatorConfiguration = transactionValidatorCliOptions.toDomainObject();
}

/**
* Linea plugins need to implement this method. Called by {@link BesuPlugin} register method
*
* @param context
*/
public abstract void doRegister(final BesuContext context);

@Override
public void start() {}

@Override
public void stop() {
cliOptionsRegistered = false;
}
}
Loading

0 comments on commit 5708353

Please sign in to comment.