Skip to content

Commit

Permalink
feat: Rejected transaction reporting due to trace line limits
Browse files Browse the repository at this point in the history
 -- Remove other rejected transactions reporting
  • Loading branch information
usmansaleem committed Nov 27, 2024
1 parent 0535705 commit 0d9f9da
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 83 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Changelog

## Next release
* feat: Report rejected transactions only due to trace limit overflows to an external service.
* 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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public LineaTransactionPoolValidatorFactory(
public PluginTransactionPoolValidator createTransactionValidator() {
final var validators =
new PluginTransactionPoolValidator[] {
new AllowedAddressValidator(denied, rejectedTxJsonRpcManager),
new GasLimitValidator(txPoolValidatorConf, rejectedTxJsonRpcManager),
new CalldataValidator(txPoolValidatorConf, rejectedTxJsonRpcManager),
new AllowedAddressValidator(denied),
new GasLimitValidator(txPoolValidatorConf),
new CalldataValidator(txPoolValidatorConf),
new ProfitabilityValidator(
besuConfiguration, blockchainService, profitabilityConf, rejectedTxJsonRpcManager),
besuConfiguration, blockchainService, profitabilityConf),
new SimulationValidator(
blockchainService,
transactionSimulationService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,11 @@ public class AllowedAddressValidator implements PluginTransactionPoolValidator {
Address.fromHexString("0x000000000000000000000000000000000000000a"));

private final Set<Address> denied;
private final Optional<JsonRpcManager> rejectedTxJsonRpcManager;

@Override
public Optional<String> validateTransaction(
final Transaction transaction, final boolean isLocal, final boolean hasPriority) {
final Optional<String> errMsg =
validateSender(transaction).or(() -> validateRecipient(transaction));
errMsg.ifPresent(reason -> reportRejectedTransaction(transaction, reason));
return errMsg;
return validateSender(transaction).or(() -> validateRecipient(transaction));
}

private Optional<String> validateRecipient(final Transaction transaction) {
Expand Down Expand Up @@ -90,19 +86,4 @@ private Optional<String> validateSender(final Transaction transaction) {
}
return Optional.empty();
}

private void reportRejectedTransaction(final Transaction transaction, final String reason) {
rejectedTxJsonRpcManager.ifPresent(
jsonRpcManager -> {
final String jsonRpcCall =
JsonRpcRequestBuilder.generateSaveRejectedTxJsonRpc(
jsonRpcManager.getNodeType(),
transaction,
Instant.now(),
Optional.empty(), // block number is not available
reason,
List.of());
jsonRpcManager.submitNewJsonRpcCallAsync(jsonRpcCall);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
@RequiredArgsConstructor
public class CalldataValidator implements PluginTransactionPoolValidator {
final LineaTransactionPoolValidatorConfiguration txPoolValidatorConf;
final Optional<JsonRpcManager> rejectedTxJsonRpcManager;

@Override
public Optional<String> validateTransaction(
Expand All @@ -41,24 +40,8 @@ public Optional<String> validateTransaction(
"Calldata of transaction is greater than the allowed max of "
+ txPoolValidatorConf.maxTxCalldataSize();
log.debug(errMsg);
reportRejectedTransaction(transaction, errMsg);
return Optional.of(errMsg);
}
return Optional.empty();
}

private void reportRejectedTransaction(final Transaction transaction, final String reason) {
rejectedTxJsonRpcManager.ifPresent(
jsonRpcManager -> {
final String jsonRpcCall =
JsonRpcRequestBuilder.generateSaveRejectedTxJsonRpc(
jsonRpcManager.getNodeType(),
transaction,
Instant.now(),
Optional.empty(), // block number is not available
reason,
List.of());
jsonRpcManager.submitNewJsonRpcCallAsync(jsonRpcCall);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@RequiredArgsConstructor
public class GasLimitValidator implements PluginTransactionPoolValidator {
final LineaTransactionPoolValidatorConfiguration txPoolValidatorConf;
final Optional<JsonRpcManager> rejectedTxJsonRpcManager;

@Override
public Optional<String> validateTransaction(
Expand All @@ -44,24 +43,8 @@ public Optional<String> validateTransaction(
"Gas limit of transaction is greater than the allowed max of "
+ txPoolValidatorConf.maxTxGasLimit();
log.debug(errMsg);
reportRejectedTransaction(transaction, errMsg);
return Optional.of(errMsg);
}
return Optional.empty();
}

private void reportRejectedTransaction(final Transaction transaction, final String reason) {
rejectedTxJsonRpcManager.ifPresent(
jsonRpcManager -> {
final String jsonRpcCall =
JsonRpcRequestBuilder.generateSaveRejectedTxJsonRpc(
jsonRpcManager.getNodeType(),
transaction,
Instant.now(),
Optional.empty(), // block number is not available
reason,
List.of());
jsonRpcManager.submitNewJsonRpcCallAsync(jsonRpcCall);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,15 @@ public class ProfitabilityValidator implements PluginTransactionPoolValidator {
final BlockchainService blockchainService;
final LineaProfitabilityConfiguration profitabilityConf;
final TransactionProfitabilityCalculator profitabilityCalculator;
final Optional<JsonRpcManager> rejectedTxJsonRpcManager;

public ProfitabilityValidator(
final BesuConfiguration besuConfiguration,
final BlockchainService blockchainService,
final LineaProfitabilityConfiguration profitabilityConf,
final Optional<JsonRpcManager> rejectedTxJsonRpcManager) {
final LineaProfitabilityConfiguration profitabilityConf) {
this.besuConfiguration = besuConfiguration;
this.blockchainService = blockchainService;
this.profitabilityConf = profitabilityConf;
this.profitabilityCalculator = new TransactionProfitabilityCalculator(profitabilityConf);
this.rejectedTxJsonRpcManager = rejectedTxJsonRpcManager;
}

@Override
Expand All @@ -68,8 +65,7 @@ public Optional<String> validateTransaction(
.getNextBlockBaseFee()
.orElseThrow(() -> new RuntimeException("We only support a base fee market"));

final Optional<String> errMsg =
profitabilityCalculator.isProfitable(
return profitabilityCalculator.isProfitable(
"Txpool",
transaction,
profitabilityConf.txPoolMinMargin(),
Expand All @@ -79,8 +75,6 @@ public Optional<String> validateTransaction(
besuConfiguration.getMinGasPrice())
? Optional.empty()
: Optional.of("Gas price too low");
errMsg.ifPresent(s -> reportRejectedTransaction(transaction, s));
return errMsg;
}

return Optional.empty();
Expand All @@ -98,19 +92,4 @@ private Wei calculateUpfrontGasPrice(final Transaction transaction, final Wei ba
baseFee.add(Wei.fromQuantity(transaction.getMaxPriorityFeePerGas().get()))))
.orElseGet(() -> Wei.fromQuantity(transaction.getGasPrice().get()));
}

private void reportRejectedTransaction(final Transaction transaction, final String reason) {
rejectedTxJsonRpcManager.ifPresent(
jsonRpcManager -> {
final String jsonRpcCall =
JsonRpcRequestBuilder.generateSaveRejectedTxJsonRpc(
jsonRpcManager.getNodeType(),
transaction,
Instant.now(),
Optional.empty(), // block number is not available
reason,
List.of());
jsonRpcManager.submitNewJsonRpcCallAsync(jsonRpcCall);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ public Optional<String> validateTransaction(
"Invalid transaction"
+ simulationResult.getInvalidReason().map(ir -> ": " + ir).orElse("");
log.debug(errMsg);
reportRejectedTransaction(transaction, errMsg);
return Optional.of(errMsg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
*/
package net.consensys.linea.sequencer.txselection.selectors;

import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.BLOCK_MODULE_LINE_COUNT_FULL;
import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW;
import static net.consensys.linea.sequencer.txselection.LineaTransactionSelectionResult.TX_MODULE_LINE_COUNT_OVERFLOW_CACHED;

import java.time.Instant;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import lombok.extern.slf4j.Slf4j;
import net.consensys.linea.config.LineaProfitabilityConfiguration;
Expand All @@ -41,6 +47,7 @@ public class LineaTransactionSelector implements PluginTransactionSelector {
private TraceLineLimitTransactionSelector traceLineLimitTransactionSelector;
private final List<PluginTransactionSelector> selectors;
private final Optional<JsonRpcManager> rejectedTxJsonRpcManager;
private final Set<String> rejectedTransactionReasonsMap = new HashSet<>();

public LineaTransactionSelector(
final BlockchainService blockchainService,
Expand All @@ -51,6 +58,14 @@ public LineaTransactionSelector(
final Map<String, Integer> limitsMap,
final Optional<JsonRpcManager> rejectedTxJsonRpcManager) {
this.rejectedTxJsonRpcManager = rejectedTxJsonRpcManager;

// only report rejected transaction selection result from TraceLineLimitTransactionSelector
if (rejectedTxJsonRpcManager.isPresent()) {
rejectedTransactionReasonsMap.add(TX_MODULE_LINE_COUNT_OVERFLOW.toString());
rejectedTransactionReasonsMap.add(TX_MODULE_LINE_COUNT_OVERFLOW_CACHED.toString());
rejectedTransactionReasonsMap.add(BLOCK_MODULE_LINE_COUNT_FULL.toString());
}

selectors =
createTransactionSelectors(
blockchainService,
Expand Down Expand Up @@ -163,7 +178,8 @@ public void onTransactionNotSelected(

rejectedTxJsonRpcManager.ifPresent(
jsonRpcManager -> {
if (transactionSelectionResult.discard()) {
if (transactionSelectionResult.discard()
&& rejectedTransactionReasonsMap.contains(transactionSelectionResult.toString())) {
jsonRpcManager.submitNewJsonRpcCallAsync(
JsonRpcRequestBuilder.generateSaveRejectedTxJsonRpc(
jsonRpcManager.getNodeType(),
Expand Down

0 comments on commit 0d9f9da

Please sign in to comment.