-
Notifications
You must be signed in to change notification settings - Fork 897
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a tx selector to skip txs from the same sender after the first no…
…t selected Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
- Loading branch information
Showing
10 changed files
with
327 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
...dger/besu/ethereum/blockcreation/txselection/selectors/SkipSenderTransactionSelector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright contributors to Besu. | ||
* | ||
* 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.blockcreation.txselection.selectors; | ||
|
||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.ethereum.blockcreation.txselection.BlockSelectionContext; | ||
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionEvaluationContext; | ||
import org.hyperledger.besu.ethereum.blockcreation.txselection.TransactionSelectionResults; | ||
import org.hyperledger.besu.ethereum.processing.TransactionProcessingResult; | ||
import org.hyperledger.besu.plugin.data.TransactionSelectionResult; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class SkipSenderTransactionSelector extends AbstractTransactionSelector { | ||
private static final Logger LOG = LoggerFactory.getLogger(SkipSenderTransactionSelector.class); | ||
private final Set<Address> skippedSenders = new HashSet<>(); | ||
|
||
public SkipSenderTransactionSelector(final BlockSelectionContext context) { | ||
super(context); | ||
} | ||
|
||
@Override | ||
public TransactionSelectionResult evaluateTransactionPreProcessing( | ||
final TransactionEvaluationContext evaluationContext, | ||
final TransactionSelectionResults ignored) { | ||
final var sender = evaluationContext.getTransaction().getSender(); | ||
if (skippedSenders.contains(sender)) { | ||
LOG.atTrace() | ||
.setMessage("Not selecting tx {} since its sender {} is in the skip list") | ||
.addArgument(() -> evaluationContext.getPendingTransaction().toTraceLog()) | ||
.addArgument(sender) | ||
.log(); | ||
|
||
return TransactionSelectionResult.SENDER_WITH_PREVIOUS_TX_NOT_SELECTED; | ||
} | ||
return TransactionSelectionResult.SELECTED; | ||
} | ||
|
||
@Override | ||
public TransactionSelectionResult evaluateTransactionPostProcessing( | ||
final TransactionEvaluationContext evaluationContext, | ||
final TransactionSelectionResults blockTransactionResults, | ||
final TransactionProcessingResult processingResult) { | ||
// All necessary checks were done in the pre-processing method, so nothing to do here. | ||
return TransactionSelectionResult.SELECTED; | ||
} | ||
|
||
/** | ||
* When a transaction is not selected we can skip processing any following transaction from the | ||
* same sender, since it will never be selected due to the nonce gap, so we add the sender to the | ||
* skip list. | ||
* | ||
* @param evaluationContext The current selection context | ||
* @param transactionSelectionResult The transaction selection result | ||
*/ | ||
@Override | ||
public void onTransactionNotSelected( | ||
final TransactionEvaluationContext evaluationContext, | ||
final TransactionSelectionResult transactionSelectionResult) { | ||
final var sender = evaluationContext.getTransaction().getSender(); | ||
skippedSenders.add(sender); | ||
LOG.trace("Sender {} added to the skip list", sender); | ||
} | ||
} |
Oops, something went wrong.