-
Notifications
You must be signed in to change notification settings - Fork 235
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
Asynchronous Block Download and Verification #4365
Conversation
dcb1e3d
to
6aac1b1
Compare
This comment was marked as off-topic.
This comment was marked as off-topic.
fe63750
to
5949684
Compare
5949684
to
210ca64
Compare
da0db29
to
426adc0
Compare
} | ||
|
||
// `self.non_contextual_verify` is very fast. | ||
fn asynchronous_process_block(&self, lonely_block: LonelyBlock) { |
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.
seems asynchronous_
is not the best name for this function, which makes me think of async fn in tokio :)
it's more like preprocess_block
, we only do non_contextual_verify
and insert into db.
9a96db5
@chenyukang I have pushed a commit for Please re-add this PR to merge queue. |
9a96db5
to
5b895f2
Compare
…fore exit Signed-off-by: Eval EXEC <execvy@gmail.com>
5b895f2
to
dc5dfb8
Compare
What problem does this PR solve?
In this PR, I have made changes to reduce the synchronization time during CKB's initial block download (IBD) phase. Previously, in the
develop
branch, theSynchronizer
would continuously request blocks within a sliding window from theTip
toTip+BLOCK_DOWNLOAD_WINDOW
. After receiving a block, theSynchronizer
would send it to theChainService
and wait for it to be fully processed before proceeding to the next block. Since theTip
would only update afterChainService
completely verified a block, theSynchronizer
refrained from requesting blocks from other peers during this period. This sequential processing limited the sliding window's progression speed, reducing theSynchronizer's
efficiency in block requests and causing delays in feeding blocks to theChainService
, ultimately prolonging the synchronization time.To address this, this PR aims to decouple the sliding window movement in the
Synchronizer
from the block verification process in theChainService
, making these operations asynchronous. SinceChainService
verifies blocks faster than it inserts them, I've introduced an additionalUnverifiedTip
value inChainService
to represent the continuous stream of blocks waiting for verification. The sliding window in theSynchronizer
is now based on theUnverifiedTip
, allowing it to request blocks from other peers independently.ChainService
will continuously follow theUnverifiedTip
to verify blocks, ensuring that block download is not hindered by the time-consuming block verification process.a sequence diagram to describe the IBD phase
The IBD phase on develop branch (before v0.111.0)
The IBD phase by this PR:
What's Changed:
Related changes
Synchronizer
receive a block from remote peer, transfer it toChainService
.ChainService
performs all validation tasks except forScriptVerify
, and optimistically assumes that the block is valid, storing blocks first in RocksDB, and usingUnverifiedTip
to represent the highest chain that has not been verified.ScriptVerify
task in a a asynchronous thread and updateTipHeader
OrphanBlock
tockb_chain
BlockStatus
andHeaderMap
tockb_shared
, because bothSynchronizer
andChainService
need themCheck List
Tests
Side effects
Release note