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

Improve Conflict Detection in Parallelization by Considering Slots to Reduce False Positives #7923

Merged
merged 15 commits into from
Feb 17, 2025
Prev Previous commit
Next Next commit
add potential fix for transaction processing issue
Signed-off-by: Karim Taam <[email protected]>
matkt committed Jan 22, 2025

Verified

This commit was signed with the committer’s verified signature.
commit dfe6621b1657f7f0dfbdbd9152bc8e0b5a517a1a
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@
* checks for potential conflicts among transactions to ensure data integrity before applying the
* results to the world state.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
@SuppressWarnings({"unchecked", "rawtypes", "FieldCanBeLocal", "unused"})
public class ParallelizedConcurrentTransactionProcessor {

private static final int NCPU = Runtime.getRuntime().availableProcessors();
@@ -61,6 +61,8 @@ public class ParallelizedConcurrentTransactionProcessor {
private final Map<Integer, ParallelizedTransactionContext>
parallelizedTransactionContextByLocation = new ConcurrentHashMap<>();

private CompletableFuture<Void>[] completableFuturesForBackgroundTransactions;

/**
* Constructs a PreloadConcurrentTransactionProcessor with a specified transaction processor. This
* processor is responsible for the individual processing of transactions.
@@ -104,6 +106,8 @@ public void runAsyncBlock(
final BlockHashOperation.BlockHashLookup blockHashLookup,
final Wei blobGasPrice,
final PrivateMetadataUpdater privateMetadataUpdater) {

completableFuturesForBackgroundTransactions = new CompletableFuture[transactions.size()];
for (int i = 0; i < transactions.size(); i++) {
final Transaction transaction = transactions.get(i);
final int transactionLocation = i;
@@ -276,6 +280,13 @@ public Optional<TransactionProcessingResult> applyParallelizedTransactionResult(
// re-execute the transaction.
return Optional.empty();
}
} else {
// stop background processing for this transaction as useless
final CompletableFuture<Void> completableFuturesForBackgroundTransaction =
completableFuturesForBackgroundTransactions[transactionLocation];
if (completableFuturesForBackgroundTransaction != null) {
completableFuturesForBackgroundTransaction.cancel(true);
}
}
return Optional.empty();
}
Original file line number Diff line number Diff line change
@@ -124,15 +124,20 @@ public void importStateChangesFromSource(
diffBasedValue.getUpdated() != null
? copyAccount(diffBasedValue.getUpdated(), this, true)
: null;
accountsToUpdate.put(address, new DiffBasedValue<>(copyPrior, copyUpdated));
accountsToUpdate.put(
address,
new DiffBasedValue<>(copyPrior, copyUpdated, diffBasedValue.isLastStepCleared()));
});
source
.getCodeToUpdate()
.forEach(
(address, diffBasedValue) -> {
codeToUpdate.put(
address,
new DiffBasedValue<>(diffBasedValue.getPrior(), diffBasedValue.getUpdated()));
new DiffBasedValue<>(
diffBasedValue.getPrior(),
diffBasedValue.getUpdated(),
diffBasedValue.isLastStepCleared()));
});
source
.getStorageToUpdate()
@@ -149,7 +154,9 @@ public void importStateChangesFromSource(
storageConsumingMap.put(
storageSlotKey,
new DiffBasedValue<>(
uInt256DiffBasedValue.getPrior(), uInt256DiffBasedValue.getUpdated()));
uInt256DiffBasedValue.getPrior(),
uInt256DiffBasedValue.getUpdated(),
uInt256DiffBasedValue.isLastStepCleared()));
});
});
storageToClear.addAll(source.storageToClear);