← 输入框|github.com|刷新
Skip to content

net: Hand blocks to the kernel as they arrive - #119

Merged
rustaceanrob merged 3 commits into
kernel-node:masterfrom
pzafonte:process-on-arrival
Nov 11, 2026
Merged

rustaceanrob merged 3 commits into
kernel-node:masterfrom
pzafonte:process-on-arrival

Conversation

@pzafonte

@pzafonte pzafonte commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

This fixes something that confused me initially. I had mixed up the node handing blocks over in order with the kernel needing them that way.

Blocks wait in memory until their parent connects, with no limit. If one peer holds the block the tip needs, everything the other peers download after it sits in RAM.

process_block sets force_processing, which stores a block whose parent is missing and connects it when it can. This hands each block over as it arrives, through a one-block channel, and drops the buffer. When the channel is full the peer thread stops reading, like Core does for a peer past 5 MB.

With waiting blocks on disk, a download window can be Core's 1024 blocks instead of whatever fits in memory, and the window and stall handling can follow Core's behavior directly.

Because blocks arriving ahead of a missing one would keep resetting the stale check, it resets only when the tip moves. The new test forces a block to arrive before its parent. It passes before and after the change.

Blocks already handed over aren't requested again, except after a restart, because the kernel API can't say which blocks it has.

Nothing in the suite forces a block to arrive before its parent. A
scripted peer answers each getdata in reverse. It does its own
handshake because the p2p crate sends verack only after receiving one.
Any block handed to the kernel reset the check, even one that left the
tip stuck. Core's TipMayBeStale also measures from the last tip change.
Blocks waited in memory until their parent connected, with no limit.
The kernel stores a block whose parent is missing and switches branches
on its own. When the one-block channel is full, the peer thread stops
reading its socket, as Core does for a peer past 5 MB. After a restart,
stored blocks that haven't connected are fetched again because the
kernel API can't say which it has.

@rustaceanrob rustaceanrob 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.

Looks good. Did IBD before and after this change with no observable difference in behavior. We do have some stuttering behavior where the logs look like they look up and then proceed in bursts. Perhaps we could add some more network level logging when we receive blocks

@rustaceanrob
rustaceanrob merged commit 2ba6f0f into kernel-node:master Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants