Skip to content

Commit

Permalink
feat: Report rejected transactions to an external service for tx pool…
Browse files Browse the repository at this point in the history
… validators used by LineaTransactionPoolValidatorPlugin (#85)

* Extract reporting endpoint URI cli option
* Linea Transaction Pool Validator to report rejected tx
* Linea node type and refactored request builder
* Update unit tests to use refactored generateSaveRejectedTxJsonRpc
* Use transactionSelectionResult.toString in LineaTransactionSelector
* Use Mutually exclusive = false for co-dep cli options
* Add unit test for cli options. Change endpoint type to URL
* JsonRpcManager - Use plugin identifier to create sub directories to store rpc calls
* JsonRpcManager convert submitNewJsonRpcCall to do async chaining before calling submitJsonRpcCall
* Add rej tx reporting to all tx pool validators
  • Loading branch information
usmansaleem authored Oct 3, 2024
1 parent fcd99a4 commit 8e9fe21
Show file tree
Hide file tree
Showing 28 changed files with 773 additions and 174 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Changelog

## Next release
* feat: Report rejected transactions to an external service [#69](https://github.com/Consensys/linea-sequencer/pull/69)
* feat: Report rejected transactions to an external service for validators used by LineaTransactionPoolValidatorPlugin [#85](https://github.com/Consensys/linea-sequencer/pull/85)
* feat: Report rejected transactions to an external service for LineaTransactionSelector used by LineaTransactionSelectorPlugin [#69](https://github.com/Consensys/linea-sequencer/pull/69)

## 0.6.0-rc1.1
* bump linea-arithmetization version to 0.6.0-rc1 [#71](https://github.com/Consensys/linea-sequencer/pull/71)
Expand Down
1 change: 1 addition & 0 deletions gradle/dependency-management.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dependencyManagement {
entry "dsl"
entry "eth"
entry "rlp"
entry "besu"
}

dependencySet(group: 'ch.qos.logback', version: '1.5.6') {
Expand Down
2 changes: 1 addition & 1 deletion sequencer/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ dependencies {
testImplementation "${besuArtifactGroup}:besu-datatypes"
testImplementation "${besuArtifactGroup}.internal:core"
testImplementation "${besuArtifactGroup}.internal:rlp"
testImplementation "${besuArtifactGroup}.internal:core"
testImplementation "${besuArtifactGroup}:plugin-api"
testImplementation "${besuArtifactGroup}.internal:besu"
testImplementation "org.awaitility:awaitility"

// workaround for bug https://github.com/dnsjava/dnsjava/issues/329, remove when upgraded upstream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import net.consensys.linea.compress.LibCompress;
import net.consensys.linea.config.LineaProfitabilityCliOptions;
import net.consensys.linea.config.LineaProfitabilityConfiguration;
import net.consensys.linea.config.LineaRejectedTxReportingCliOptions;
import net.consensys.linea.config.LineaRejectedTxReportingConfiguration;
import net.consensys.linea.config.LineaRpcCliOptions;
import net.consensys.linea.config.LineaRpcConfiguration;
import net.consensys.linea.config.LineaTracerCliOptions;
Expand Down Expand Up @@ -68,6 +70,9 @@ public Map<String, LineaOptionsPluginConfiguration> getLineaPluginConfigMap() {
configMap.put(
LineaTracerCliOptions.CONFIG_KEY, LineaTracerCliOptions.create().asPluginConfig());

configMap.put(
LineaRejectedTxReportingCliOptions.CONFIG_KEY,
LineaRejectedTxReportingCliOptions.create().asPluginConfig());
return configMap;
}

Expand Down Expand Up @@ -96,6 +101,11 @@ public LineaTracerConfiguration tracerConfiguration() {
getConfigurationByKey(LineaTracerCliOptions.CONFIG_KEY).optionsConfig();
}

public LineaRejectedTxReportingConfiguration rejectedTxReportingConfiguration() {
return (LineaRejectedTxReportingConfiguration)
getConfigurationByKey(LineaRejectedTxReportingCliOptions.CONFIG_KEY).optionsConfig();
}

@Override
public void start() {
super.start();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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.config;

/** Linea node type that is used when reporting rejected transactions. */
public enum LineaNodeType {
SEQUENCER,
RPC,
P2P
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* 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.config;

import java.net.URL;
import java.util.Optional;

import com.google.common.base.MoreObjects;
import net.consensys.linea.plugins.LineaCliOptions;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Option;

/** The Linea Rejected Transaction Reporting CLI options. */
public class LineaRejectedTxReportingCliOptions implements LineaCliOptions {
/**
* The configuration key used in AbstractLineaPrivateOptionsPlugin to identify the cli options.
*/
public static final String CONFIG_KEY = "rejected-tx-reporting-config";

/** The rejected transaction endpoint. */
public static final String REJECTED_TX_ENDPOINT = "--plugin-linea-rejected-tx-endpoint";

/** The Linea node type. */
public static final String LINEA_NODE_TYPE = "--plugin-linea-node-type";

@ArgGroup(exclusive = false)
DependentOptions dependentOptions; // will be null if no options from this group are specified

static class DependentOptions {
@Option(
names = {REJECTED_TX_ENDPOINT},
hidden = true,
required = true, // required within the group
paramLabel = "<URL>",
description =
"Endpoint URI for reporting rejected transactions. Specify a valid URI to enable reporting.")
URL rejectedTxEndpoint = null;

@Option(
names = {LINEA_NODE_TYPE},
hidden = true,
required = true, // required within the group
paramLabel = "<NODE_TYPE>",
description =
"Linea Node type to use when reporting rejected transactions. (default: ${DEFAULT-VALUE}. Valid values: ${COMPLETION-CANDIDATES})")
LineaNodeType lineaNodeType = null;
}

/** Default constructor. */
private LineaRejectedTxReportingCliOptions() {}

/**
* Create Linea Rejected Transaction Reporting CLI options.
*
* @return the Linea Rejected Transaction Reporting CLI options
*/
public static LineaRejectedTxReportingCliOptions create() {
return new LineaRejectedTxReportingCliOptions();
}

/**
* Instantiates a new Linea rejected tx reporting cli options from Configuration object
*
* @param config An instance of LineaRejectedTxReportingConfiguration
*/
public static LineaRejectedTxReportingCliOptions fromConfig(
final LineaRejectedTxReportingConfiguration config) {
final LineaRejectedTxReportingCliOptions options = create();
// both options are required.
if (config.rejectedTxEndpoint() != null && config.lineaNodeType() != null) {
final var depOpts = new DependentOptions();
depOpts.rejectedTxEndpoint = config.rejectedTxEndpoint();
depOpts.lineaNodeType = config.lineaNodeType();
options.dependentOptions = depOpts;
}

return options;
}

@Override
public LineaRejectedTxReportingConfiguration toDomainObject() {
final var rejectedTxEndpoint =
Optional.ofNullable(dependentOptions).map(o -> o.rejectedTxEndpoint).orElse(null);
final var lineaNodeType =
Optional.ofNullable(dependentOptions).map(o -> o.lineaNodeType).orElse(null);

return LineaRejectedTxReportingConfiguration.builder()
.rejectedTxEndpoint(rejectedTxEndpoint)
.lineaNodeType(lineaNodeType)
.build();
}

@Override
public String toString() {
final var rejectedTxEndpoint =
Optional.ofNullable(dependentOptions).map(o -> o.rejectedTxEndpoint).orElse(null);
final var lineaNodeType =
Optional.ofNullable(dependentOptions).map(o -> o.lineaNodeType).orElse(null);

return MoreObjects.toStringHelper(this)
.add(REJECTED_TX_ENDPOINT, rejectedTxEndpoint)
.add(LINEA_NODE_TYPE, lineaNodeType)
.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.config;

import java.net.URL;

import lombok.Builder;
import net.consensys.linea.plugins.LineaOptionsConfiguration;

/** Linea Rejected Transactions Reporting Configuration */
@Builder(toBuilder = true)
public record LineaRejectedTxReportingConfiguration(
URL rejectedTxEndpoint, LineaNodeType lineaNodeType) implements LineaOptionsConfiguration {}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package net.consensys.linea.config;

import java.net.URI;

import com.google.common.base.MoreObjects;
import jakarta.validation.constraints.Positive;
import net.consensys.linea.plugins.LineaCliOptions;
Expand All @@ -41,8 +39,6 @@ public class LineaTransactionSelectorCliOptions implements LineaCliOptions {
public static final String UNPROFITABLE_RETRY_LIMIT = "--plugin-linea-unprofitable-retry-limit";
public static final int DEFAULT_UNPROFITABLE_RETRY_LIMIT = 10;

public static final String REJECTED_TX_ENDPOINT = "--plugin-linea-rejected-tx-endpoint";

@Positive
@CommandLine.Option(
names = {MAX_BLOCK_CALLDATA_SIZE},
Expand Down Expand Up @@ -86,13 +82,6 @@ public class LineaTransactionSelectorCliOptions implements LineaCliOptions {
"Max number of unprofitable transactions we retry on each block creation (default: ${DEFAULT-VALUE})")
private int unprofitableRetryLimit = DEFAULT_UNPROFITABLE_RETRY_LIMIT;

@CommandLine.Option(
names = {REJECTED_TX_ENDPOINT},
hidden = true,
paramLabel = "<URI>",
description = "Endpoint URI for reporting rejected transactions (default: ${DEFAULT-VALUE})")
private URI rejectedTxEndpoint = null;

private LineaTransactionSelectorCliOptions() {}

/**
Expand All @@ -118,7 +107,6 @@ public static LineaTransactionSelectorCliOptions fromConfig(
options.maxGasPerBlock = config.maxGasPerBlock();
options.unprofitableCacheSize = config.unprofitableCacheSize();
options.unprofitableRetryLimit = config.unprofitableRetryLimit();
options.rejectedTxEndpoint = config.rejectedTxEndpoint();
return options;
}

Expand All @@ -135,7 +123,6 @@ public LineaTransactionSelectorConfiguration toDomainObject() {
.maxGasPerBlock(maxGasPerBlock)
.unprofitableCacheSize(unprofitableCacheSize)
.unprofitableRetryLimit(unprofitableRetryLimit)
.rejectedTxEndpoint(rejectedTxEndpoint)
.build();
}

Expand All @@ -147,7 +134,6 @@ public String toString() {
.add(MAX_GAS_PER_BLOCK, maxGasPerBlock)
.add(UNPROFITABLE_CACHE_SIZE, unprofitableCacheSize)
.add(UNPROFITABLE_RETRY_LIMIT, unprofitableRetryLimit)
.add(REJECTED_TX_ENDPOINT, rejectedTxEndpoint)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

package net.consensys.linea.config;

import java.net.URI;

import lombok.Builder;
import net.consensys.linea.plugins.LineaOptionsConfiguration;

Expand All @@ -27,6 +25,5 @@ public record LineaTransactionSelectorConfiguration(
int overLinesLimitCacheSize,
long maxGasPerBlock,
int unprofitableCacheSize,
int unprofitableRetryLimit,
URI rejectedTxEndpoint)
int unprofitableRetryLimit)
implements LineaOptionsConfiguration {}
Loading

0 comments on commit 8e9fe21

Please sign in to comment.