-
Notifications
You must be signed in to change notification settings - Fork 712
Await db blocks sync inside ReviewBlockTree #9196
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
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7e61dde
Stop after 256 blocks
deffrian 1bef72d
Run until BestKnownNumber
deffrian 4790116
Split InitializeNetwork
deffrian b568e4e
Remove comment
deffrian 4e613be
Merge branch 'master' into fix/9032
deffrian a3ff997
Await processing in ReviewBlockTree
deffrian caa9daf
Revert InitializeNetwork
deffrian f39726a
Fix formatting
deffrian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Nethermind.Api; | ||
| using Nethermind.Api.Steps; | ||
| using Nethermind.Blockchain.Synchronization; | ||
| using Nethermind.Core; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Network; | ||
| using Nethermind.Synchronization; | ||
| using Nethermind.Synchronization.Peers; | ||
|
|
||
| namespace Nethermind.Init.Steps; | ||
|
|
||
| [RunnerStepDependencies(typeof(RegisterPluginRpcModules))] | ||
| public class StartNetwork( | ||
| INethermindApi api, | ||
| ISyncPeerPool syncPeerPool, | ||
| ISynchronizer synchronizer, | ||
| IDiscoveryApp discoveryApp, | ||
| Lazy<IPeerPool> peerPool, | ||
| ISyncConfig syncConfig, | ||
| IInitConfig initConfig, | ||
| ILogManager logManager) : IStep | ||
| { | ||
|
|
||
| ILogger _logger = logManager.GetClassLogger(); | ||
|
|
||
| public async Task Execute(CancellationToken cancellationToken) | ||
| { | ||
| await StartSync().ContinueWith(initNetTask => | ||
| { | ||
| if (initNetTask.IsFaulted) | ||
| { | ||
| _logger.Error("Unable to start the synchronizer.", initNetTask.Exception); | ||
| } | ||
| }); | ||
|
|
||
| if (cancellationToken.IsCancellationRequested) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| await StartDiscovery().ContinueWith(initDiscoveryTask => | ||
| { | ||
| if (initDiscoveryTask.IsFaulted) | ||
| { | ||
| _logger.Error("Unable to start the discovery protocol.", initDiscoveryTask.Exception); | ||
| } | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| if (cancellationToken.IsCancellationRequested) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| StartPeer(); | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| _logger.Error("Unable to start the peer manager.", e); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| private Task StartDiscovery() | ||
| { | ||
| if (!initConfig.DiscoveryEnabled) | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"Skipping discovery init due to {nameof(IInitConfig.DiscoveryEnabled)} set to false"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| if (_logger.IsDebug) _logger.Debug("Starting discovery process."); | ||
| _ = discoveryApp.StartAsync(); | ||
| if (_logger.IsDebug) _logger.Debug("Discovery process started."); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private void StartPeer() | ||
| { | ||
| if (api.PeerManager is null) throw new StepDependencyException(nameof(api.PeerManager)); | ||
| if (api.SessionMonitor is null) throw new StepDependencyException(nameof(api.SessionMonitor)); | ||
|
|
||
| if (!api.Config<IInitConfig>().PeerManagerEnabled) | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"Skipping peer manager init due to {nameof(IInitConfig.PeerManagerEnabled)} set to false"); | ||
| } | ||
|
|
||
| if (_logger.IsDebug) _logger.Debug("Initializing peer manager"); | ||
| peerPool.Value.Start(); | ||
| api.PeerManager.Start(); | ||
| api.SessionMonitor.Start(); | ||
| if (_logger.IsDebug) _logger.Debug("Peer manager initialization completed"); | ||
| } | ||
|
|
||
| private Task StartSync() | ||
| { | ||
| if (api.BlockTree is null) throw new StepDependencyException(nameof(api.BlockTree)); | ||
|
|
||
| if (syncConfig.NetworkingEnabled) | ||
| { | ||
| syncPeerPool.Start(); | ||
|
|
||
| if (syncConfig.SynchronizationEnabled) | ||
| { | ||
| if (_logger.IsDebug) _logger.Debug($"Starting synchronization from block {api.BlockTree.Head?.Header.ToString(BlockHeader.Format.Short)}."); | ||
| synchronizer.Start(); | ||
| } | ||
| else | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"Skipping blockchain synchronization init due to {nameof(ISyncConfig.SynchronizationEnabled)} set to false"); | ||
| } | ||
| } | ||
| else if (_logger.IsWarn) _logger.Warn($"Skipping connecting to peers due to {nameof(ISyncConfig.NetworkingEnabled)} set to false"); | ||
|
|
||
|
|
||
| return Task.CompletedTask; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't still need
Initialize? AsStartis separated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RegisterRpcModulesdepends inInitializeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok so it is there implicitly, could be left explicitly but whatever.