Skip to content

Commit

Permalink
Research/main parallel tx revision (#1865)
Browse files Browse the repository at this point in the history
* B1. Confusing Naming of conflict sets - Solved
* B3. Incorrect use of LongAccumulator
* B4. Truncated BigInteger Pays Incorrect Fees
* B5. Setup of new Precompiles is not correctly tracked
* B7. Determinism even on conflict (#1873)
* 2X performance improvement, and better tests (#1884)

Co-authored-by: Sergio Demian Lerner <[email protected]>
  • Loading branch information
julianlen and SergioDemianLerner committed Nov 28, 2022
1 parent ed1c600 commit eeb9623
Show file tree
Hide file tree
Showing 14 changed files with 617 additions and 282 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.LongAccumulator;

public class TransactionExecutorFactory {

Expand Down Expand Up @@ -65,17 +64,7 @@ public TransactionExecutor newInstance(
Repository track,
Block block,
long totalGasUsed) {
return newInstance(tx, txindex, coinbase, track, block, totalGasUsed, new LongAccumulator(Long::sum, 0));
}

public TransactionExecutor newInstance(
Transaction tx,
int txindex,
RskAddress coinbase,
Repository track,
Block block,
long totalGasUsed, LongAccumulator remascFees) {
return newInstance(tx, txindex, coinbase, track, block, totalGasUsed, false, 0, new HashSet<>(), remascFees);
return newInstance(tx, txindex, coinbase, track, block, totalGasUsed, false, 0, new HashSet<>());
}

public TransactionExecutor newInstance(
Expand All @@ -87,8 +76,7 @@ public TransactionExecutor newInstance(
long totalGasUsed,
boolean vmTrace,
int vmTraceOptions,
Set<DataWord> deletedAccounts,
LongAccumulator remascFees) {
Set<DataWord> deletedAccounts) {
// Tracing configuration is scattered across different files (VM, DetailedProgramTrace, etc.) and
// TransactionExecutor#extractTrace doesn't work when called independently.
// It would be great to decouple from VmConfig#vmTrace, but sadly that's a major refactor we can't do now.
Expand Down Expand Up @@ -121,8 +109,7 @@ public TransactionExecutor newInstance(
config.isRemascEnabled(),
precompiledContracts,
deletedAccounts,
blockTxSignatureCache,
remascFees
blockTxSignatureCache
);
}
}
57 changes: 35 additions & 22 deletions rskj-core/src/main/java/co/rsk/core/TransactionListExecutor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package co.rsk.core;

import co.rsk.core.bc.IReadWrittenKeysTracker;
import co.rsk.crypto.Keccak256;
import org.ethereum.core.*;
import org.ethereum.vm.DataWord;
Expand All @@ -12,15 +11,13 @@
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.LongAccumulator;

public class TransactionListExecutor implements Callable<Boolean> {

private static final Logger logger = LoggerFactory.getLogger("transactionlistexecutor");

private final TransactionExecutorFactory transactionExecutorFactory;
private final List<Transaction> transactions;
private final IReadWrittenKeysTracker readWrittenKeysTracker;
private final Block block;
private final Repository track;
private final boolean vmTrace;
Expand All @@ -32,16 +29,14 @@ public class TransactionListExecutor implements Callable<Boolean> {
private final Map<Integer, TransactionReceipt> receipts;
private final Map<Keccak256, ProgramResult> transactionResults;
private final ProgramTraceProcessor programTraceProcessor;
private final LongAccumulator remascFees;
private final LongAccumulator accumulatedFees;
private final LongAccumulator accumulatedGas;
private Coin totalFees;
private long totalGas;

private int i;
private final boolean registerProgramResults;

public TransactionListExecutor(
List<Transaction> transactions,
IReadWrittenKeysTracker readWrittenKeysTracker,
Block block,
TransactionExecutorFactory transactionExecutorFactory,
Repository track,
Expand All @@ -55,11 +50,7 @@ public TransactionListExecutor(
Map<Keccak256, ProgramResult> transactionResults,
boolean registerProgramResults,
@Nullable ProgramTraceProcessor programTraceProcessor,
LongAccumulator remascFees,
LongAccumulator accumulatedFees,
LongAccumulator accumulatedGas,
int firstTxIndex) {
this.readWrittenKeysTracker = readWrittenKeysTracker;
this.block = block;
this.transactionExecutorFactory = transactionExecutorFactory;
this.track = track;
Expand All @@ -74,10 +65,9 @@ public TransactionListExecutor(
this.registerProgramResults = registerProgramResults;
this.transactionResults = transactionResults;
this.programTraceProcessor = programTraceProcessor;
this.accumulatedFees = accumulatedFees;
this.accumulatedGas = accumulatedGas;
this.totalFees = Coin.ZERO;
this.totalGas = 0L;
this.i = firstTxIndex;
this.remascFees = remascFees;
}

@Override
Expand All @@ -95,15 +85,10 @@ public Boolean call() {
totalGasUsed,
vmTrace,
vmTraceOptions,
deletedAccounts,
remascFees
deletedAccounts
);
boolean transactionExecuted = txExecutor.executeTransaction();

if (readWrittenKeysTracker.hasCollided()) {
return false;
}

if (!acceptInvalidTransactions && !transactionExecuted) {
if (!discardInvalidTxs) {
logger.warn("block: [{}] execution interrupted because of invalid tx: [{}]",
Expand Down Expand Up @@ -158,9 +143,37 @@ public Boolean call() {

logger.trace("tx[{}] done", i);
}
accumulatedGas.accumulate(totalGasUsed);
accumulatedFees.accumulate(totalPaidFees.asBigInteger().longValue());
totalGas += totalGasUsed;
totalFees = totalFees.add(totalPaidFees);

return true;
}

public Repository getRepository() {
return this.track;
}

public Set<DataWord> getDeletedAccounts() {
return new HashSet<>(this.deletedAccounts);
}

public Map<Integer, TransactionReceipt> getReceipts() {
return this.receipts;
}

public Map<Integer, Transaction> getExecutedTransactions() {
return this.executedTransactions;
}

public Map<Keccak256, ProgramResult> getTransactionResults() {
return this.transactionResults;
}

public Coin getTotalFees() {
return this.totalFees;
}

public long getTotalGas() {
return this.totalGas;
}
}
Loading

0 comments on commit eeb9623

Please sign in to comment.