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

Fleet mode #6003

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
59e0652
modify besu for fleet mode
matkt Oct 6, 2023
e1331db
add modification for fleet mode
matkt Oct 9, 2023
ad0f6c1
fix storage root with fleet mode
matkt Oct 11, 2023
43e1674
update sync service
matkt Oct 13, 2023
1269e55
fix fleet reorg
matkt Oct 16, 2023
df55e18
clean code and add receipts methods
matkt Oct 17, 2023
6277f64
remove logs
matkt Oct 18, 2023
f0086be
not pruning block during the initial sync
matkt Oct 18, 2023
cf5138e
Merge commit '03a8335bf94e613fff8e4564b432069588e8e6a3' into feature/…
matkt Oct 19, 2023
9a3166f
remove log
matkt Oct 19, 2023
8f5d67b
merge pruning block for fleet mode
matkt Oct 23, 2023
c6fd96e
merge main
matkt Oct 23, 2023
36dc614
disable discovery correctly
matkt Oct 25, 2023
7266fcd
Revert "merge pruning block for fleet mode"
matkt Oct 31, 2023
cbba17e
reduce min pruning block to 512
matkt Oct 31, 2023
7be7252
fix: double calls to trace{Start,End}Transaction (#6247)
delehef Dec 6, 2023
4eadb19
migrate to junit5 (#6234)
macfarla Dec 6, 2023
248462f
fixes for problems discovered in main (#6248)
garyschulte Dec 6, 2023
41f3f75
Pki - migrate to junit 5 (#6235)
macfarla Dec 7, 2023
bdb8ab3
junit 5 ftw (#6253)
macfarla Dec 7, 2023
daa1c14
removed unnecessary use of static temp dir (#6251)
macfarla Dec 7, 2023
651bba3
Remove parallelism usage from mainnet AT (#6252)
gfukushima Dec 7, 2023
0827ffa
fix log params (#6254)
macfarla Dec 7, 2023
d834f80
add dependency on jar task (#6255)
macfarla Dec 7, 2023
c4f7a94
Fix and test that the BlockAwareOperationTracer methods are invoked t…
fab-10 Dec 7, 2023
cc18b2f
squash merge of problem commits
garyschulte Dec 7, 2023
9ed1166
re-merge main without DCO problem
garyschulte Dec 7, 2023
a6799aa
Merge remote-tracking branch 'origin/main' into feature/fleet-mode
garyschulte Dec 7, 2023
f325331
fix merge snafu
garyschulte Dec 8, 2023
240a3ac
Merge remote-tracking branch 'origin/main' into feature/fleet-mode
garyschulte Dec 8, 2023
1e091d6
re-apply doc and test changes from 033e3c8
garyschulte Dec 8, 2023
08645ab
merge main
matkt Dec 13, 2023
ee0e08b
fixing on selfdestruct
matkt Jan 9, 2024
3297536
spotless
matkt Jan 9, 2024
6b15e3f
add flag to modify pruning limit
matkt Jan 10, 2024
9a9c3d1
Merge branch 'main' into feature/fleet-mode
matkt Jan 10, 2024
f854a08
fix review
matkt Jan 10, 2024
63ab34c
fix build
matkt Jan 10, 2024
09077ad
add missing file
matkt Jan 10, 2024
0a23160
Merge branch 'main' into feature/fleet-mode
matkt Jan 10, 2024
b0a4fa6
merge main
matkt Jan 30, 2024
e55528b
fix build
matkt Jan 30, 2024
6fb28f2
Merge branch 'main' into feature/fleet-mode
matkt Jan 30, 2024
52ba7c1
update plugin hash
matkt Feb 2, 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
10 changes: 10 additions & 0 deletions besu/src/main/java/org/hyperledger/besu/Runner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolEvictionService;
import org.hyperledger.besu.ethereum.p2p.network.NetworkRunner;
import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
import org.hyperledger.besu.ethereum.stratum.StratumServer;
import org.hyperledger.besu.ethstats.EthStatsService;
import org.hyperledger.besu.metrics.MetricsService;
Expand Down Expand Up @@ -422,6 +423,15 @@ Optional<EnodeURL> getLocalEnode() {
return networkRunner.getNetwork().getLocalEnode();
}

/**
* get P2PNetwork service.
*
* @return p2p network service.
*/
public P2PNetwork getP2PNetwork() {
return networkRunner.getNetwork();
}

@FunctionalInterface
private interface SynchronousShutdown {
/**
Expand Down
37 changes: 33 additions & 4 deletions besu/src/main/java/org/hyperledger/besu/cli/BesuCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,30 @@
import org.hyperledger.besu.plugin.services.exception.StorageException;
import org.hyperledger.besu.plugin.services.metrics.MetricCategory;
import org.hyperledger.besu.plugin.services.metrics.MetricCategoryRegistry;
import org.hyperledger.besu.plugin.services.p2p.P2PService;
import org.hyperledger.besu.plugin.services.rlp.RlpConverterService;
import org.hyperledger.besu.plugin.services.securitymodule.SecurityModule;
import org.hyperledger.besu.plugin.services.storage.PrivacyKeyValueStorageFactory;
import org.hyperledger.besu.plugin.services.storage.rocksdb.RocksDBPlugin;
import org.hyperledger.besu.plugin.services.sync.SynchronizationService;
import org.hyperledger.besu.plugin.services.transactionpool.TransactionPoolService;
import org.hyperledger.besu.plugin.services.txselection.PluginTransactionSelectorFactory;
import org.hyperledger.besu.plugin.services.txvalidator.PluginTransactionValidatorFactory;
import org.hyperledger.besu.services.BesuEventsImpl;
import org.hyperledger.besu.services.BesuPluginContextImpl;
import org.hyperledger.besu.services.BlockchainServiceImpl;
import org.hyperledger.besu.services.P2PServiceImpl;
import org.hyperledger.besu.services.PermissioningServiceImpl;
import org.hyperledger.besu.services.PicoCLIOptionsImpl;
import org.hyperledger.besu.services.PluginTransactionValidatorServiceImpl;
import org.hyperledger.besu.services.PrivacyPluginServiceImpl;
import org.hyperledger.besu.services.RlpConverterServiceImpl;
import org.hyperledger.besu.services.RpcEndpointServiceImpl;
import org.hyperledger.besu.services.SecurityModuleServiceImpl;
import org.hyperledger.besu.services.StorageServiceImpl;
import org.hyperledger.besu.services.SynchronizationServiceImpl;
import org.hyperledger.besu.services.TraceServiceImpl;
import org.hyperledger.besu.services.TransactionPoolServiceImpl;
import org.hyperledger.besu.services.TransactionSelectionServiceImpl;
import org.hyperledger.besu.services.kvstore.InMemoryStoragePlugin;
import org.hyperledger.besu.util.InvalidConfigurationException;
Expand Down Expand Up @@ -1467,12 +1475,15 @@ public void run() {
final var runner = buildRunner();
runner.startExternalServices();

startPlugins();
startPlugins(runner);
validatePluginOptions();
setReleaseMetrics();
preSynchronization();

runner.startEthereumMainLoop();

besuPluginContext.afterExternalServicesMainLoop();

runner.awaitStop();

} catch (final Exception e) {
Expand Down Expand Up @@ -1654,7 +1665,7 @@ private Runner buildRunner() {
pidPath);
}

private void startPlugins() {
private void startPlugins(final Runner runner) {
besuPluginContext.addService(
BesuEvents.class,
new BesuEventsImpl(
Expand All @@ -1668,6 +1679,24 @@ private void startPlugins() {
BlockchainService.class,
new BlockchainServiceImpl(besuController.getProtocolContext().getBlockchain()));

besuPluginContext.addService(
SynchronizationService.class,
new SynchronizationServiceImpl(
besuController.getProtocolContext(),
besuController.getProtocolSchedule(),
besuController.getSyncState(),
besuController.getProtocolContext().getWorldStateArchive()));

besuPluginContext.addService(P2PService.class, new P2PServiceImpl(runner.getP2PNetwork()));

besuPluginContext.addService(
TransactionPoolService.class,
new TransactionPoolServiceImpl(besuController.getTransactionPool()));

besuPluginContext.addService(
RlpConverterService.class,
new RlpConverterServiceImpl(besuController.getProtocolSchedule()));

besuPluginContext.addService(
TraceService.class,
new TraceServiceImpl(
Expand Down Expand Up @@ -1989,11 +2018,11 @@ private void validateRpcOptionsParams() {
private void validateChainDataPruningParams() {
if (unstableChainPruningOptions.getChainDataPruningEnabled()
&& unstableChainPruningOptions.getChainDataPruningBlocksRetained()
< ChainPruningOptions.DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED) {
< unstableChainPruningOptions.getChainDataPruningBlocksRetainedLimit()) {
throw new ParameterException(
this.commandLine,
"--Xchain-pruning-blocks-retained must be >= "
+ ChainPruningOptions.DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED);
+ unstableChainPruningOptions.getChainDataPruningBlocksRetainedLimit());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,20 @@ public class ChainPruningOptions implements CLIOptions<ChainPrunerConfiguration>
private static final String CHAIN_PRUNING_ENABLED_FLAG = "--Xchain-pruning-enabled";
private static final String CHAIN_PRUNING_BLOCKS_RETAINED_FLAG =
"--Xchain-pruning-blocks-retained";
private static final String CHAIN_PRUNING_BLOCKS_RETAINED_LIMIT_FLAG =
"--Xchain-pruning-blocks-retained-limit";
private static final String CHAIN_PRUNING_FREQUENCY_FLAG = "--Xchain-pruning-frequency";
/** The constant DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED. */
public static final long DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED = 7200;

/**
* The "CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT" field sets the minimum limit for the
* "DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED" value. For most networks, the default value of
* this limit is the safest. Reducing this value requires careful consideration and understanding
* of the potential implications. Lowering this limit may have unintended side effects.
*/
public static final long CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT = 7200;

/** The constant DEFAULT_CHAIN_DATA_PRUNING_FREQUENCY. */
public static final int DEFAULT_CHAIN_DATA_PRUNING_FREQUENCY = 256;

Expand All @@ -47,11 +58,22 @@ public class ChainPruningOptions implements CLIOptions<ChainPrunerConfiguration>
names = {CHAIN_PRUNING_BLOCKS_RETAINED_FLAG},
description =
"The number of recent blocks for which to keep the chain data. Must be >= "
+ DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED
+ CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT
+ " (default: ${DEFAULT-VALUE})")
private final Long chainDataPruningBlocksRetained =
DEFAULT_CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED;

@CommandLine.Option(
hidden = true,
names = {CHAIN_PRUNING_BLOCKS_RETAINED_LIMIT_FLAG},
description =
"Allows setting the limit below which no more blocks can be pruned. This prevents setting a value lower than this for "
+ CHAIN_PRUNING_BLOCKS_RETAINED_FLAG
+ ". This flag should be used with caution as reducing the limit may have unintended side effects."
+ " (default: ${DEFAULT-VALUE})")
private final Long chainDataPruningBlocksRetainedLimit =
CHAIN_DATA_PRUNING_MIN_BLOCKS_RETAINED_LIMIT;

@CommandLine.Option(
hidden = true,
names = {CHAIN_PRUNING_FREQUENCY_FLAG},
Expand Down Expand Up @@ -87,11 +109,16 @@ public Long getChainDataPruningBlocksRetained() {
return chainDataPruningBlocksRetained;
}

public Long getChainDataPruningBlocksRetainedLimit() {
return chainDataPruningBlocksRetainedLimit;
}

@Override
public ChainPrunerConfiguration toDomainObject() {
return new ChainPrunerConfiguration(
chainDataPruningEnabled,
chainDataPruningBlocksRetained,
chainDataPruningBlocksRetainedLimit,
chainDataPruningBlocksFrequency.getValue());
}

Expand All @@ -102,6 +129,8 @@ public List<String> getCLIOptions() {
chainDataPruningEnabled.toString(),
CHAIN_PRUNING_BLOCKS_RETAINED_FLAG,
chainDataPruningBlocksRetained.toString(),
CHAIN_PRUNING_BLOCKS_RETAINED_LIMIT_FLAG,
chainDataPruningBlocksRetainedLimit.toString(),
CHAIN_PRUNING_FREQUENCY_FLAG,
chainDataPruningBlocksFrequency.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ public class BesuConfigurationImpl implements BesuConfiguration {
private final Path storagePath;
private final Path dataPath;

/**
* BesuConfigurationImpl Constructor.
*
* @param dataPath The Path representing data folder
* @param storagePath The path representing storage folder
*/
public BesuConfigurationImpl(final Path dataPath, final Path storagePath) {
this.dataPath = dataPath;
this.storagePath = storagePath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ public void removeBlockReorgListener(final long listenerIdentifier) {
blockchain.removeObserver(listenerIdentifier);
}

@Override
public long addInitialSyncCompletionListener(final InitialSyncCompletionListener listener) {
return syncState.subscribeCompletionReached(listener);
}

@Override
public long addTransactionAddedListener(final TransactionAddedListener listener) {
return transactionPool.subscribePendingTransactions(listener::onTransactionAdded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,24 @@ public void startPlugins() {
state = Lifecycle.BEFORE_MAIN_LOOP_FINISHED;
}

public void afterExternalServicesMainLoop() {
checkState(
state == Lifecycle.BEFORE_MAIN_LOOP_FINISHED,
"BesuContext should be in state %s but it was in %s",
Lifecycle.BEFORE_MAIN_LOOP_FINISHED,
state);
final Iterator<BesuPlugin> pluginsIterator = plugins.iterator();

while (pluginsIterator.hasNext()) {
final BesuPlugin plugin = pluginsIterator.next();
try {
plugin.afterExternalServicePostMainLoop();
} finally {
pluginsIterator.remove();
}
}
}

/** Stop plugins. */
public void stopPlugins() {
checkState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,33 @@

package org.hyperledger.besu.services;

import org.hyperledger.besu.ethereum.chain.Blockchain;
import org.hyperledger.besu.ethereum.core.BlockBody;
import org.hyperledger.besu.datatypes.Hash;
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.plugin.Unstable;
import org.hyperledger.besu.plugin.data.BlockBody;
import org.hyperledger.besu.plugin.data.BlockContext;
import org.hyperledger.besu.plugin.data.BlockHeader;
import org.hyperledger.besu.plugin.data.TransactionReceipt;
import org.hyperledger.besu.plugin.services.BlockchainService;

import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/** The Blockchain service implementation. */
@Unstable
public class BlockchainServiceImpl implements BlockchainService {

private final Blockchain blockchain;
private final MutableBlockchain blockchain;

/**
* Instantiates a new Blockchain service.
*
* @param blockchain the blockchain
*/
public BlockchainServiceImpl(final Blockchain blockchain) {
public BlockchainServiceImpl(final MutableBlockchain blockchain) {
this.blockchain = blockchain;
}

Expand All @@ -53,6 +58,48 @@ public Optional<BlockContext> getBlockByNumber(final long number) {
.map(block -> blockContext(block::getHeader, block::getBody));
}

@Override
public Optional<List<TransactionReceipt>> getReceiptsByBlockHash(final Hash blockHash) {
return blockchain
.getTxReceipts(blockHash)
.map(
list -> list.stream().map(TransactionReceipt.class::cast).collect(Collectors.toList()));
}

@Override
public void storeBlock(
final BlockHeader blockHeader,
final BlockBody blockBody,
final List<TransactionReceipt> receipts) {
final org.hyperledger.besu.ethereum.core.BlockHeader coreHeader =
(org.hyperledger.besu.ethereum.core.BlockHeader) blockHeader;
final org.hyperledger.besu.ethereum.core.BlockBody coreBody =
(org.hyperledger.besu.ethereum.core.BlockBody) blockBody;
final List<org.hyperledger.besu.ethereum.core.TransactionReceipt> coreReceipts =
receipts.stream()
.map(org.hyperledger.besu.ethereum.core.TransactionReceipt.class::cast)
.toList();
blockchain.unsafeImportBlock(
new Block(coreHeader, coreBody),
coreReceipts,
Optional.ofNullable(blockchain.calculateTotalDifficulty(coreHeader)));
}

@Override
public BlockHeader getChainHead() {
return blockchain.getChainHead().getBlockHeader();
}

@Override
public Optional<Hash> getSafeBlock() {
return blockchain.getSafeBlock();
}

@Override
public Optional<Hash> getFinalizedBlock() {
return blockchain.getFinalized();
}

private static BlockContext blockContext(
final Supplier<BlockHeader> blockHeaderSupplier,
final Supplier<BlockBody> blockBodySupplier) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright Hyperledger Besu Contributors.
*
* 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.services;

import org.hyperledger.besu.ethereum.p2p.network.P2PNetwork;
import org.hyperledger.besu.plugin.services.p2p.P2PService;

public class P2PServiceImpl implements P2PService {

private final P2PNetwork p2PNetwork;

public P2PServiceImpl(final P2PNetwork p2PNetwork) {
this.p2PNetwork = p2PNetwork;
}

@Override
public void enableDiscovery() {
p2PNetwork.start();
}

@Override
public void disableDiscovery() {
p2PNetwork.stop();
}
}
Loading
Loading