Skip to content

Perf/parallel block downloader#8255

Merged
asdacap merged 54 commits into
masterfrom
perf/parallel-block-downloader
Apr 30, 2025
Merged

Perf/parallel block downloader#8255
asdacap merged 54 commits into
masterfrom
perf/parallel-block-downloader

Conversation

@asdacap

@asdacap asdacap commented Feb 24, 2025

Copy link
Copy Markdown
Contributor
  • Include 4444-ish: Refactor/forward header provider #8254
  • Currently forward sync only download from a single peer.
  • This is a problem as the upload of a peer is more limited than download therefore the download speed really depends on the peer that the forward sync is being pinned to.
    • Depending on the peer, the download speed of the forward sync can be 0 (hang), 15 blk/s or 150 blks.
    • Since nethermind can consistently process at least 30blk/s a lot of the time when catching up, the node is waiting until it got lucky with a peer with fast upload.
    • This makes it hard to know if something is wrong with it or not.
    • Also makes performance benchmarking inconsistent as most of the time, it waiting for block download.
  • This PR add the ability to dowload blocks and receipts in parallel.
  • This provide a much more consistent forward sync download speed of around 200 block per sec.
  • Works by having a map of hash->(block, receipts) that stores download requests.

Types of changes

What types of changes does your code introduce?

  • Optimization

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

  • Mainnet snap sync
  • Mainnet snap sync with disable pivot updater
  • Energyweb
  • Sync github action
  • Hive test

@asdacap asdacap force-pushed the perf/parallel-block-downloader branch from b3fc46a to 0ff8706 Compare March 19, 2025 23:55
@asdacap asdacap force-pushed the perf/parallel-block-downloader branch from 0ff8706 to c24a4b9 Compare March 20, 2025 00:05
@benaadams benaadams requested a review from Copilot March 29, 2025 16:58
@benaadams

Copy link
Copy Markdown
Member

Needs rebasing

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves forward sync performance by enabling parallel block and receipt downloads. Key changes include:

  • Adding a padded hash conversion method in Hash256.
  • Introducing a new blockchain ID ("Hoodi") and corresponding name mapping.
  • Extending ITxSource implementations with a new SupportsBlobs property and updating related transaction sources.

Reviewed Changes

Copilot reviewed 211 out of 213 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Nethermind/Nethermind.Core/Crypto/Hash256.cs Added FromBytesWithPadding method to pad hash bytes for non-32-byte inputs
src/Nethermind/Nethermind.Core/BlockchainIds.cs Added a new blockchain ID (Hoodi) and its name mapping
src/Nethermind/Nethermind.Consensus/Transactions/* Added SupportsBlobs property to various ITxSource implementations
src/Nethermind/Nethermind.Blockchain/Blocks/BlockhashStore.cs Updated to use the new padded hash conversion method
src/Nethermind/Nethermind.Blockchain.Test/BlockhashProviderTests.cs Introduced a new test to validate trimmed hash behavior
scripts/superchain.py Adjusted log file name formatting
Files not reviewed (2)
  • scripts/private-networking/clique-validators.sh: Language not supported
  • scripts/systemd-utils/tail.sh: Language not supported


public static Hash256 FromBytesWithPadding(ReadOnlySpan<byte> bytes)
{
if (bytes.Length != 32)

Copilot AI Mar 29, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The FromBytesWithPadding method does not handle the case when bytes.Length > 32, which may result in a negative slice index. Consider changing the condition to 'if (bytes.Length < 32)' and adding appropriate handling or error reporting for inputs longer than 32 bytes.

Suggested change
if (bytes.Length != 32)
if (bytes.Length < 32)

Copilot uses AI. Check for mistakes.
Comment thread src/Nethermind/Nethermind.Blockchain.Test/BlockhashProviderTests.cs
@asdacap asdacap changed the base branch from refactor/forward-header-provider to master April 1, 2025 00:49
@asdacap asdacap force-pushed the perf/parallel-block-downloader branch from f1c07fa to 8db4564 Compare April 4, 2025 09:04
@asdacap

asdacap commented Apr 4, 2025

Copy link
Copy Markdown
Contributor Author

Request size adjustment is a bit flaky. Need to find a solution first or batch size is going to be limited by the slowest node.

@asdacap asdacap marked this pull request as ready for review April 15, 2025 08:25
@asdacap asdacap requested a review from rubo as a code owner April 15, 2025 08:25
@benaadams benaadams requested a review from Copilot April 18, 2025 18:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves forward synchronization performance by introducing parallel block and receipt downloading while refactoring related tests and dependency registration. Key changes include:

  • Implementation of a MultiBlockDownloader to download blocks and receipts concurrently.
  • Refactoring of synchronization feeds and tests to use a new SyncBatchSize constant.
  • Updates to dependency injection lifetimes in merge-related components.

Reviewed Changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
MultiBlockDownloader.cs Adds parallel download logic for block bodies and receipts.
IForwardSyncController.cs Introduces a shared interface for forward sync handling.
FullSyncFeed.cs and FastSyncFeed.cs Refactors feeds to use the forward sync controller and updates multi-feed status.
BlocksSyncPeerSelectionStrategy.cs Adjusts peer selection logic using a temporary difficulty variable.
BlockDownloadRequest.cs Changes BlocksRequest to implement IDisposable and manage pooled resources.
BlockDownloadContext.cs Removes obsolete download context logic.
SynchronizerTests.cs, OldStyleFullSynchronizerTests.cs, ForwardHeaderProviderTests*.cs, BlockDownloaderTests.Merge.cs Updates tests to use the new SyncBatchSizeMax constant and revised sync methods.
OwnedBlockBodies.cs Revises enumerator implementation for owned block bodies.
MergeSynchronizer.cs Updates dependency lifetimes for BlockDownloader and IForwardHeaderProvider to Singleton.
MergeBlockDownloader.cs, ChainLevelHelper.cs, BlockTreeTests.cs, SyncConfig.cs, ISyncConfig.cs Minor adjustments and additions to support the new sync behavior.
Comments suppressed due to low confidence (1)

src/Nethermind/Nethermind.Merge.Plugin/Synchronization/MergeSynchronizer.cs:84

  • Changing the registration of BlockDownloader (and IForwardHeaderProvider) to Singleton may introduce thread-safety or state management issues if these services are not fully stateless and thread-safe. Please verify that the services are intended for a Singleton lifetime.
.AddSingleton<BlockDownloader, MergeBlockDownloader>()

{
yield return blockBody;
}
return GetEnumerator();

Copilot AI Apr 18, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation of IEnumerable.GetEnumerator() calls GetEnumerator() recursively. Replace it with a call to _rawBodies.GetEnumerator() to correctly iterate over the collection.

Copilot uses AI. Check for mistakes.

@LukaszRozmej LukaszRozmej left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, few things to clarify before merging.

You probably don't want to update submodule!

Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/FullSyncFeed.cs
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs Outdated
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs Outdated
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs Outdated
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs Outdated
Comment thread src/Nethermind/Nethermind.Synchronization/Blocks/BlockDownloader.cs Outdated
asdacap and others added 10 commits April 30, 2025 09:58
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…er.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
…rSelectionStrategy.cs

Co-authored-by: Lukasz Rozmej <lukasz.rozmej@gmail.com>
@asdacap asdacap merged commit 8403a08 into master Apr 30, 2025
80 checks passed
@asdacap asdacap deleted the perf/parallel-block-downloader branch April 30, 2025 13:43
kamilchodola added a commit that referenced this pull request May 1, 2025
kamilchodola added a commit that referenced this pull request May 1, 2025
Revert "Perf/parallel block downloader (#8255)"

This reverts commit 8403a08.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants