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

Optimistic parallelization of transactions to improve performance #7296

Merged
merged 49 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a768488
add Parallel Transaction Processing System
matkt Jul 2, 2024
3e9844e
merge main
matkt Jul 3, 2024
466d1ca
clean code
matkt Jul 3, 2024
a2dc27f
fix build
matkt Jul 3, 2024
c431704
change config worldstate code
matkt Jul 3, 2024
95170f7
update reference tests
matkt Jul 3, 2024
81cdd37
async commit and modify hashcode for StorageSlotKey
matkt Jul 3, 2024
96b3c23
remove preload of withdrawal address
matkt Jul 4, 2024
051236f
add logs for map size
matkt Jul 4, 2024
15b1f57
delete empty storage map
matkt Jul 4, 2024
fa801ba
remove logs
matkt Jul 4, 2024
444e991
execute commit and persist phase sequentially
ahamlat Jul 4, 2024
32c6a2f
Rollback sequential execution on persist and commit phase
ahamlat Jul 4, 2024
05b8873
clean code first step
matkt Jul 4, 2024
4728fd0
clean code
matkt Jul 5, 2024
a03843f
use int and not long for context map
matkt Jul 5, 2024
f1e7dfc
add javadoc and comment
matkt Jul 5, 2024
3a35a1a
revert preload during background processing and remove map initial ca…
matkt Jul 5, 2024
b937582
Set the executor size to the numbers of CPU threads
ahamlat Jul 9, 2024
a50dc04
add flag and tests
matkt Jul 9, 2024
7911566
merge main
matkt Jul 9, 2024
7ec17b6
clean code
matkt Jul 10, 2024
69f36b6
fix build
matkt Jul 10, 2024
6baafdc
fix tests
matkt Jul 10, 2024
594b7ec
build again
matkt Jul 10, 2024
1fa6741
fix unit tests
matkt Jul 10, 2024
184aea7
Add two new metrics to evaluate the number of parallelized transactio…
ahamlat Jul 10, 2024
18a12ac
fix flag
matkt Jul 10, 2024
afec253
Fix reference tests
ahamlat Jul 10, 2024
39afebe
Merge branch 'main' into feature/block_per_improvment
matkt Jul 10, 2024
29dd4f5
first stab at suggested refactor
garyschulte Jul 10, 2024
5a1dae4
update after Gary's comment
matkt Jul 11, 2024
96d9428
rename operation tracer method
matkt Jul 11, 2024
0143e7c
fix build
matkt Jul 11, 2024
c7f288e
merge main
matkt Jul 11, 2024
b8aebc6
fix build
matkt Jul 11, 2024
71b7fc7
Merge branch 'main' into feature/block_per_improvment
matkt Jul 12, 2024
1952cf0
add a try-with-resouces on the roundWorldState to close automatically…
ahamlat Jul 12, 2024
ed0a683
Close the worldstate in the parallel executions and ignore any except…
ahamlat Jul 12, 2024
b4f58e4
close worldstate clone correctly
matkt Jul 12, 2024
fc2a980
spotless.
ahamlat Jul 15, 2024
2a823ff
Add a changelog
ahamlat Jul 15, 2024
027be5a
Update changelog
ahamlat Jul 15, 2024
70af81f
Merge branch 'main' into feature/block_per_improvment
ahamlat Jul 16, 2024
b41c4c8
change flag name
ahamlat Jul 16, 2024
1e149f8
Small optimization, return true in the collision check as soon as one…
ahamlat Jul 17, 2024
7da7a0e
Merge branch 'main' into feature/block_per_improvment
ahamlat Jul 17, 2024
7f14f29
Merge branch 'main' into feature/block_per_improvment
ahamlat Jul 18, 2024
f9a451b
Merge branch 'main' into feature/block_per_improvment
ahamlat Jul 19, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Add support to load external profiles using `--profile` [#7265](https://github.com/hyperledger/besu/issues/7265)
- `privacy-nonce-always-increments` option enables private transactions to always increment the nonce, even if the transaction is invalid [#6593](https://github.com/hyperledger/besu/pull/6593)
- Added `block-test` subcommand to the evmtool which runs blockchain reference tests [#7293](https://github.com/hyperledger/besu/pull/7293)
- `--Xbonsai-parallel-tx-enabled` option enables executing transactions in parallel during block processing for Bonsai nodes

### Bug fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ public BesuControllerBuilder getControllerBuilder() {
.pkiBlockCreationConfiguration(maybePkiBlockCreationConfiguration())
.clock(Clock.systemUTC())
.isRevertReasonEnabled(isRevertReasonEnabled)
.isParallelTxEnabled(dataStorageConfiguration.getUnstable().isParallelTxEnabled())
.storageProvider(storageProvider)
.gasLimitCalculator(
miningParametersSupplier.get().getTargetGasLimit().isPresent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ public static class Unstable {
"Enables code storage using code hash instead of by account hash. (default: ${DEFAULT-VALUE})")
private boolean bonsaiCodeUsingCodeHashEnabled = DEFAULT_BONSAI_CODE_USING_CODE_HASH_ENABLED;

@CommandLine.Option(
hidden = true,
names = {"--Xbonsai-parallel-tx-enabled"},
arity = "1",
description =
"Enables parallelization of transactions to optimize processing speed by concurrently loading and executing necessary data in advance. (default: ${DEFAULT-VALUE})")
private Boolean isParallelTxEnabled = false;
ahamlat marked this conversation as resolved.
Show resolved Hide resolved

/** Default Constructor. */
Unstable() {}
}
Expand All @@ -142,40 +150,48 @@ public static DataStorageOptions create() {
* @param syncMode the sync mode
*/
public void validate(final CommandLine commandLine, final SyncMode syncMode) {
if (DataStorageFormat.BONSAI == dataStorageFormat && bonsaiLimitTrieLogsEnabled) {
if (SyncMode.FULL == syncMode) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
"Cannot enable %s with sync-mode %s. You must set %s or use a different sync-mode",
BONSAI_LIMIT_TRIE_LOGS_ENABLED,
SyncMode.FULL,
BONSAI_LIMIT_TRIE_LOGS_ENABLED + "=false"));
}
if (bonsaiMaxLayersToLoad < MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD + " minimum value is %d",
MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT));
}
if (bonsaiTrieLogPruningWindowSize <= 0) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE + "=%d must be greater than 0",
bonsaiTrieLogPruningWindowSize));
if (DataStorageFormat.BONSAI == dataStorageFormat) {
if (bonsaiLimitTrieLogsEnabled) {
if (SyncMode.FULL == syncMode) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
"Cannot enable %s with sync-mode %s. You must set %s or use a different sync-mode",
BONSAI_LIMIT_TRIE_LOGS_ENABLED,
SyncMode.FULL,
BONSAI_LIMIT_TRIE_LOGS_ENABLED + "=false"));
}
if (bonsaiMaxLayersToLoad < MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD + " minimum value is %d",
MINIMUM_BONSAI_TRIE_LOG_RETENTION_LIMIT));
}
if (bonsaiTrieLogPruningWindowSize <= 0) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE + "=%d must be greater than 0",
bonsaiTrieLogPruningWindowSize));
}
if (bonsaiTrieLogPruningWindowSize <= bonsaiMaxLayersToLoad) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE
+ "=%d must be greater than "
+ BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD
+ "=%d",
bonsaiTrieLogPruningWindowSize,
bonsaiMaxLayersToLoad));
}
}
if (bonsaiTrieLogPruningWindowSize <= bonsaiMaxLayersToLoad) {
} else {
if (unstableOptions.isParallelTxEnabled) {
throw new CommandLine.ParameterException(
commandLine,
String.format(
BONSAI_TRIE_LOG_PRUNING_WINDOW_SIZE
+ "=%d must be greater than "
+ BONSAI_STORAGE_FORMAT_MAX_LAYERS_TO_LOAD
+ "=%d",
bonsaiTrieLogPruningWindowSize,
bonsaiMaxLayersToLoad));
"Transaction parallelization is not supported unless operating in a 'diffbased' mode, such as Bonsai.");
}
}
}
Expand All @@ -198,6 +214,8 @@ public static DataStorageOptions fromConfig(final DataStorageConfiguration domai
domainObject.getUnstable().getBonsaiFullFlatDbEnabled();
dataStorageOptions.unstableOptions.bonsaiCodeUsingCodeHashEnabled =
domainObject.getUnstable().getBonsaiCodeStoredByCodeHashEnabled();
dataStorageOptions.unstableOptions.isParallelTxEnabled =
domainObject.getUnstable().isParallelTxEnabled();

return dataStorageOptions;
}
Expand All @@ -214,6 +232,7 @@ public DataStorageConfiguration toDomainObject() {
ImmutableDataStorageConfiguration.Unstable.builder()
.bonsaiFullFlatDbEnabled(unstableOptions.bonsaiFullFlatDbEnabled)
.bonsaiCodeStoredByCodeHashEnabled(unstableOptions.bonsaiCodeUsingCodeHashEnabled)
.isParallelTxEnabled(unstableOptions.isParallelTxEnabled)
.build())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ public abstract class BesuControllerBuilder implements MiningParameterOverrides

private int numberOfBlocksToCache = 0;

/** whether parallel transaction processing is enabled or not */
protected boolean isParallelTxEnabled;

/** Instantiates a new Besu controller builder. */
protected BesuControllerBuilder() {}

Expand Down Expand Up @@ -529,6 +532,19 @@ public BesuControllerBuilder randomPeerPriority(final Boolean randomPeerPriority
return this;
}

/**
* Sets whether parallel transaction processing is enabled. When parallel transaction processing
* is enabled, transactions within a block can be processed in parallel and potentially improving
* performance
*
* @param isParallelTxEnabled true to enable parallel transaction
* @return the besu controller
*/
public BesuControllerBuilder isParallelTxEnabled(final boolean isParallelTxEnabled) {
this.isParallelTxEnabled = isParallelTxEnabled;
return this;
}

/**
* Build besu controller.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ protected ProtocolSchedule createProtocolSchedule() {
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,12 @@ public BesuControllerBuilder isRevertReasonEnabled(final boolean isRevertReasonE
return super.isRevertReasonEnabled(isRevertReasonEnabled);
}

@Override
public BesuControllerBuilder isParallelTxEnabled(final boolean isParallelTxEnabled) {
besuControllerBuilderSchedule.values().forEach(b -> b.isParallelTxEnabled(isParallelTxEnabled));
return super.isParallelTxEnabled(isParallelTxEnabled);
}

@Override
public BesuControllerBuilder gasLimitCalculator(final GasLimitCalculator gasLimitCalculator) {
besuControllerBuilderSchedule.values().forEach(b -> b.gasLimitCalculator(gasLimitCalculator));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,9 @@ protected ProtocolSchedule createProtocolSchedule() {
bftExtraDataCodec().get(),
evmConfiguration,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ protected ProtocolSchedule createProtocolSchedule() {
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,9 @@ protected ProtocolSchedule createProtocolSchedule() {
privacyParameters,
isRevertReasonEnabled,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,9 @@ protected ProtocolSchedule createProtocolSchedule() {
bftExtraDataCodec().get(),
evmConfiguration,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ public BesuControllerBuilder isRevertReasonEnabled(final boolean isRevertReasonE
return propagateConfig(z -> z.isRevertReasonEnabled(isRevertReasonEnabled));
}

@Override
public BesuControllerBuilder isParallelTxEnabled(final boolean isParallelTxEnabled) {
super.isParallelTxEnabled(isParallelTxEnabled);
return propagateConfig(z -> z.isParallelTxEnabled(isParallelTxEnabled));
}

@Override
public BesuControllerBuilder gasLimitCalculator(final GasLimitCalculator gasLimitCalculator) {
super.gasLimitCalculator(gasLimitCalculator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.hyperledger.besu.ethereum.forkid.ForkIdManager;
import org.hyperledger.besu.ethereum.mainnet.DefaultProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.MainnetProtocolSchedule;
import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;

import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -176,12 +177,21 @@ private static MilestoneStreamingTransitionProtocolSchedule createSchedule(
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule)
MainnetProtocolSchedule.fromConfig(
configOptions, MiningParameters.MINING_DISABLED, new BadBlockManager()));
configOptions,
MiningParameters.MINING_DISABLED,
new BadBlockManager(),
false,
new NoOpMetricsSystem()));
MilestoneStreamingProtocolSchedule postMergeProtocolSchedule =
new MilestoneStreamingProtocolSchedule(
(DefaultProtocolSchedule)
MergeProtocolSchedule.create(
configOptions, false, MiningParameters.MINING_DISABLED, new BadBlockManager()));
configOptions,
false,
MiningParameters.MINING_DISABLED,
new BadBlockManager(),
false,
new NoOpMetricsSystem()));
final MilestoneStreamingTransitionProtocolSchedule schedule =
new MilestoneStreamingTransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ public void initMocks() throws Exception {
.thenReturn(mockControllerBuilder);
when(mockControllerBuilder.clock(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.isRevertReasonEnabled(false)).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.isParallelTxEnabled(false)).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.storageProvider(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.gasLimitCalculator(any())).thenReturn(mockControllerBuilder);
when(mockControllerBuilder.requiredBlocks(any())).thenReturn(mockControllerBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.hyperledger.besu.ethereum.mainnet.feemarket.BaseFeeMarket;
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket;
import org.hyperledger.besu.evm.internal.EvmConfiguration;
import org.hyperledger.besu.plugin.services.MetricsSystem;

import java.math.BigInteger;
import java.util.HashMap;
Expand Down Expand Up @@ -64,6 +65,9 @@ public class CliqueProtocolSchedule {
* @param evmConfiguration the evm configuration
* @param miningParameters the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @param isParallelTxEnabled indicates whether parallel transaction is enabled
* @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying
* calls
* @return the protocol schedule
*/
public static ProtocolSchedule create(
Expand All @@ -74,7 +78,9 @@ public static ProtocolSchedule create(
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final BadBlockManager badBlockManager) {
final BadBlockManager badBlockManager,
final boolean isParallelTxEnabled,
final MetricsSystem metricsSystem) {

final CliqueConfigOptions cliqueConfig = config.getCliqueConfigOptions();

Expand Down Expand Up @@ -110,7 +116,9 @@ public static ProtocolSchedule create(
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager)
badBlockManager,
isParallelTxEnabled,
metricsSystem)
.createProtocolSchedule();
}

Expand All @@ -124,6 +132,9 @@ public static ProtocolSchedule create(
* @param evmConfiguration the evm configuration
* @param miningParameters the mining parameters
* @param badBlockManager the cache to use to keep invalid blocks
* @param isParallelTxEnabled indicates whether parallel transaction is enabled
* @param metricsSystem A metricSystem instance to be able to expose metrics in the underlying
* calls
* @return the protocol schedule
*/
@VisibleForTesting
Expand All @@ -134,7 +145,9 @@ public static ProtocolSchedule create(
final boolean isRevertReasonEnabled,
final EvmConfiguration evmConfiguration,
final MiningParameters miningParameters,
final BadBlockManager badBlockManager) {
final BadBlockManager badBlockManager,
final boolean isParallelTxEnabled,
final MetricsSystem metricsSystem) {
return create(
config,
forksSchedule,
Expand All @@ -143,7 +156,9 @@ public static ProtocolSchedule create(
isRevertReasonEnabled,
evmConfiguration,
miningParameters,
badBlockManager);
badBlockManager,
isParallelTxEnabled,
metricsSystem);
}

private static ProtocolSpecBuilder applyCliqueSpecificModifications(
Expand Down
Loading