Skip to content

Commit

Permalink
Improving backwards sync (#3638)
Browse files Browse the repository at this point in the history
Refactor Backwards sync to use a rocks db.

Signed-off-by: Jiri Peinlich <[email protected]>
  • Loading branch information
gezero committed Apr 14, 2022
1 parent 6c8602d commit 998ea64
Show file tree
Hide file tree
Showing 25 changed files with 760 additions and 1,298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.peervalidation.PeerValidator;
import org.hyperledger.besu.ethereum.eth.peervalidation.RequiredBlocksPeerValidator;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardChain;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncLookupService;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.worldstate.WorldStateArchive;

import java.util.List;
Expand Down Expand Up @@ -68,9 +69,8 @@ protected MiningCoordinator createMiningCoordinator(
metricsSystem,
ethProtocolManager.ethContext(),
syncState,
new BackwardSyncLookupService(
protocolSchedule, ethProtocolManager.ethContext(), metricsSystem, protocolContext),
storageProvider));
BackwardChain.from(
storageProvider, ScheduleBasedBlockHeaderFunctions.create(protocolSchedule))));
}

protected MiningCoordinator createTransitionMiningCoordinator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.sync.SynchronizerConfiguration;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncLookupService;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPoolConfiguration;
Expand Down Expand Up @@ -98,11 +97,6 @@ protected MiningCoordinator createMiningCoordinator(
metricsSystem,
ethProtocolManager.ethContext(),
syncState,
new BackwardSyncLookupService(
transitionProtocolSchedule,
ethProtocolManager.ethContext(),
metricsSystem,
protocolContext),
storageProvider);

final TransitionCoordinator composedCoordinator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@
import org.hyperledger.besu.ethereum.chain.MutableBlockchain;
import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture;
import org.hyperledger.besu.ethereum.core.Difficulty;
import org.hyperledger.besu.ethereum.core.InMemoryKeyValueStorageProvider;
import org.hyperledger.besu.ethereum.core.MiningParameters;
import org.hyperledger.besu.ethereum.eth.manager.EthProtocolManager;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.eth.transactions.TransactionPool;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec;
import org.hyperledger.besu.ethereum.storage.StorageProvider;

import java.util.Optional;

Expand All @@ -61,6 +63,7 @@ public class TransitionControllerBuilderTest {
@Mock SyncState syncState;
@Mock EthProtocolManager ethProtocolManager;
@Mock PostMergeContext mergeContext;
StorageProvider storageProvider = new InMemoryKeyValueStorageProvider();

@Spy CliqueBesuControllerBuilder cliqueBuilder = new CliqueBesuControllerBuilder();
@Spy BesuControllerBuilder powBuilder = new MainnetBesuControllerBuilder();
Expand All @@ -76,6 +79,7 @@ public void setup() {
new TransitionProtocolSchedule(
preMergeProtocolSchedule, postMergeProtocolSchedule, mergeContext));
cliqueBuilder.nodeKey(NodeKeyUtils.generate());
postMergeBuilder.storageProvider(storageProvider);
when(protocolContext.getBlockchain()).thenReturn(mockBlockchain);
when(transitionProtocolSchedule.getPostMergeSchedule()).thenReturn(postMergeProtocolSchedule);
when(transitionProtocolSchedule.getPreMergeSchedule()).thenReturn(preMergeProtocolSchedule);
Expand Down Expand Up @@ -152,6 +156,7 @@ public void assertPreMergeScheduleForBelowTerminalBlockWhenPostMergeIfNotFinaliz
TransitionCoordinator buildTransitionCoordinator(
final BesuControllerBuilder preMerge, final MergeBesuControllerBuilder postMerge) {
var builder = new TransitionBesuControllerBuilder(preMerge, postMerge);
builder.storageProvider(storageProvider);
var coordinator =
builder.createMiningCoordinator(
transitionProtocolSchedule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
import org.hyperledger.besu.ethereum.ProtocolContext;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.eth.manager.EthContext;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardChain;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncContext;
import org.hyperledger.besu.ethereum.eth.sync.backwardsync.BackwardSyncLookupService;
import org.hyperledger.besu.ethereum.eth.sync.state.SyncState;
import org.hyperledger.besu.ethereum.mainnet.ScheduleBasedBlockHeaderFunctions;
import org.hyperledger.besu.ethereum.storage.StorageProvider;
import org.hyperledger.besu.plugin.services.MetricsSystem;

Expand All @@ -34,16 +35,15 @@ public TransitionBackwardSyncContext(
final MetricsSystem metricsSystem,
final EthContext ethContext,
final SyncState syncState,
final BackwardSyncLookupService backwardSyncLookupService,
final StorageProvider storageProvider) {
super(
protocolContext,
transitionProtocolSchedule,
metricsSystem,
ethContext,
syncState,
backwardSyncLookupService,
storageProvider);
BackwardChain.from(
storageProvider, ScheduleBasedBlockHeaderFunctions.create(transitionProtocolSchedule)));
this.transitionProtocolSchedule = transitionProtocolSchedule;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static org.hyperledger.besu.consensus.merge.TransitionUtils.isTerminalProofOfWorkBlock;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.debugLambda;
import static org.hyperledger.besu.util.Slf4jLambdaHelper.infoLambda;

import org.hyperledger.besu.consensus.merge.MergeContext;
import org.hyperledger.besu.datatypes.Address;
Expand Down Expand Up @@ -215,7 +214,7 @@ public Optional<BlockHeader> getOrSyncHeaderByHash(final Hash blockhash) {
if (optHeader.isPresent()) {
debugLambda(LOG, "BlockHeader {} is already present", () -> optHeader.get().toLogString());
} else {
infoLambda(LOG, "appending block hash {} to backward sync", blockhash::toHexString);
debugLambda(LOG, "appending block hash {} to backward sync", blockhash::toHexString);
backwardSyncContext.syncBackwardsUntil(blockhash);
}
return optHeader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public enum KeyValueSegmentIdentifier implements SegmentIdentifier {
GOQUORUM_PRIVATE_WORLD_STATE(new byte[] {11}),
GOQUORUM_PRIVATE_STORAGE(new byte[] {12}),
BACKWARD_SYNC_HEADERS(new byte[] {13}),
BACKWARD_SYNC_BLOCKS(new byte[] {14});
BACKWARD_SYNC_BLOCKS(new byte[] {14}),
BACKWARD_SYNC_CHAIN(new byte[] {15});

private final byte[] id;
private final int[] versionList;
Expand Down
Loading

0 comments on commit 998ea64

Please sign in to comment.