Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce TransactionSelectionContext to pass data between selectors and plugin #30

Merged
merged 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use TransactionSelectionContext in all the methods of the plugin sele…
…ctor

Signed-off-by: Fabio Di Fabio <fabio.difabio@consensys.net>
  • Loading branch information
fab-10 committed Jan 9, 2024
commit 7308514f48912fa41747b1a3fff511786d649d41
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ private TransactionSelectionResult handleTransactionSelected(
evaluationContext, timeoutSelectionResult, txWorldStateUpdater);
}

pluginTransactionSelector.onTransactionSelected(
evaluationContext.getPendingTransaction(), processingResult);
pluginTransactionSelector.onTransactionSelected(evaluationContext, processingResult);
blockWorldStateUpdater = worldState.updater();
LOG.atTrace()
.setMessage("Selected {} for block creation, evaluated in {}")
Expand All @@ -440,7 +439,7 @@ private TransactionSelectionResult handleTransactionNotSelected(

transactionSelectionResults.updateNotSelected(
evaluationContext.getTransaction(), selectionResult);
pluginTransactionSelector.onTransactionNotSelected(pendingTransaction, selectionResult);
pluginTransactionSelector.onTransactionNotSelected(evaluationContext, selectionResult);
LOG.atTrace()
.setMessage("Not selected {} for block creation with result {}, evaluated in {}")
.addArgument(pendingTransaction::toTraceLog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,21 +726,22 @@ public void transactionSelectionPluginShouldBeNotifiedWhenTransactionSelectionCo

selector.buildTransactionListForBlock();

ArgumentCaptor<PendingTransaction> argumentCaptor =
ArgumentCaptor.forClass(PendingTransaction.class);
@SuppressWarnings("unchecked")
ArgumentCaptor<TransactionEvaluationContext<PendingTransaction>> argumentCaptor =
ArgumentCaptor.forClass(TransactionEvaluationContext.class);

// selected transaction must be notified to the selector
verify(transactionSelector)
.onTransactionSelected(argumentCaptor.capture(), any(TransactionProcessingResult.class));
PendingTransaction selected = argumentCaptor.getValue();
PendingTransaction selected = argumentCaptor.getValue().getPendingTransaction();
assertThat(selected.getTransaction()).isEqualTo(transaction);

// unselected transaction must be notified to the selector with correct reason
verify(transactionSelector)
.onTransactionNotSelected(
argumentCaptor.capture(),
eq(TransactionSelectionResult.invalid(invalidReason.toString())));
PendingTransaction rejectedTransaction = argumentCaptor.getValue();
PendingTransaction rejectedTransaction = argumentCaptor.getValue().getPendingTransaction();
assertThat(rejectedTransaction.getTransaction()).isEqualTo(invalidTransaction);
}

Expand Down
2 changes: 1 addition & 1 deletion plugin-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Calculated : ${currentHash}
tasks.register('checkAPIChanges', FileStateChecker) {
description = "Checks that the API for the Plugin-API project does not change without deliberate thought"
files = sourceSets.main.allJava.files
knownHash = 'huR8kAtuiOvjy2384yFZh4PI971rEH14QMjnra3aWTE='
knownHash = 'IGq+V3KaStHCRFkeK3KwPxJYKO4RX9YM1O4JYITk8S8='
}
check.dependsOn('checkAPIChanges')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ TransactionSelectionResult evaluateTransactionPostProcessing(
/**
* Method called when a transaction is selected to be added to a block.
*
* @param pendingTransaction The transaction that has been selected.
* @param evaluationContext The current selection context
* @param processingResult The result of processing the selected transaction.
*/
default void onTransactionSelected(
final PendingTransaction pendingTransaction,
final TransactionEvaluationContext<? extends PendingTransaction> evaluationContext,
final TransactionProcessingResult processingResult) {}
/**
* Method called when a transaction is not selected to be added to a block.
*
* @param pendingTransaction The transaction that has not been selected.
* @param evaluationContext The current selection context
* @param transactionSelectionResult The transaction selection result
*/
default void onTransactionNotSelected(
final PendingTransaction pendingTransaction,
final TransactionEvaluationContext<? extends PendingTransaction> evaluationContext,
final TransactionSelectionResult transactionSelectionResult) {}
}
Loading