Skip to content

net: dedicated tip-accept thread for tip connect - #313

Merged
reardencode merged 7 commits into
masterfrom
net/tip-accept-thread
Sep 2, 2026
Merged

net: dedicated tip-accept thread for tip connect#313
reardencode merged 7 commits into
masterfrom
net/tip-accept-thread

Conversation

@rearden-grok

@rearden-grok rearden-grok Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Story

P2P/RPC tip connect never runs on a tokio worker. Confirm stays lookup → load → rbtc-scripts-* steal → write + ibd-confirm-head drain, one block at a time (or a short queued run). Same per-block work as IBD — without the IBD body-queue / densify / lookup-wave machine.

Mainnet freeze (~6h after IBD): all tokio-rt-workers + main in userspace futex; SIGINT/tip:perf dead. Tip follow was calling accept_received_blockconnect_atconfirm_wire_run_preverified on the peer task.

What

  • Process-wide tip-accept OS thread (lazy OnceLock, queue depth 8).
  • ChainHub::{accept_block,accept_branch,accept_received_block,generate_to_script,invalidate,reconsider,precious,rewind,ensure_genesis} hop onto that thread (re-entrant / inline if already there).
  • Peer handle_peer_frame awaits accept_received_block_async (oneshot). Other tokio workers stay free, including signalfd.
  • connect_at debug_asserts it is not on tokio-rt-worker.
  • Scripts: still confirm_scripts_phasestart_for_each_ownedrbtc-scripts-*. No new interpreter path. Queue-depth script/write overlap skipped this PR (connect_lock vs reorg).

Tests

  • Lane unit: named thread, re-entrant, survives job panic, async job is not a tokio worker.
  • generate_to_script / accept_received_block_async from a spawned multi-thread worker (debug_assert pin).
  • Tip block with two script jobs publishes to rbtc-scripts-*.
  • Existing chain / tip_burst / submitblock still pass.

Non-goals

  • IBD body-queue reuse
  • Flattening io_uring machines
  • Stall watchdog / process abort
  • Compact reconstruct still on the session; only connect moved

rbitcoin-grok added 2 commits September 2, 2026 09:50
P2P reconstruct and RPC generate/submitblock were calling
confirm_wire_run_preverified on tokio-rt-worker (connect_lock, TLS uring,
ibd-confirm-head join). That can park every runtime worker, including
signalfd.

A process-wide tip-accept OS thread (queue depth 8) owns connect. Peer
sessions await a oneshot. Scripts still publish via start_for_each_owned
onto rbtc-scripts-* steal. Not the IBD body-queue pipeline.
Peer sessions reconstruct only. connect_lock / confirm_wire_run_preverified
run on tip-accept. Scripts stay on rbtc-scripts-* steal.
@rearden-grok rearden-grok Bot added core-functional Run Core functional nightly.sh on this PR (inventory + release-pin warn) and removed core-functional Run Core functional nightly.sh on this PR (inventory + release-pin warn) labels Sep 2, 2026
rbitcoin-grok added 5 commits September 2, 2026 10:09
tokio mpsc/oneshot blocking_send/recv panic inside a current-thread
runtime, which is how most #[tokio::test] peer tests generate and
accept. Drop of an aborted peer future then left a job running against
a freed ChainHub (SIGSEGV).

Job queue is std sync_channel. Async wait is a waker + condvar so
cancellation still joins without parking a tokio blocking primitive.
CI failed this assign test with issued=[] after tip-accept started
owning ensure_genesis. Assert the hub tip is 0 before densify so a
missed genesis hop fails loudly.
Parallel assign tests mutate RBITCOIN_BLOCK_QUEUE_BYTES. Without the
shared lock, over-free-floor densify sees a tiny assign-stop, clamps
to fetched_hi, and issues nothing. Tip-accept serializes genesis so
the race showed up on CI.
Public accept/generate/rewind methods hop onto tip-accept
unconditionally. Nested work calls inner methods so the lane never
re-enters. Removed the on-thread / block_in_place forks that still
ran confirm on the caller.
is_tokio_runtime_worker was production code gated to silence unused
after connect_at started asserting the tip-accept thread name. Tests
inline the worker-name check.
@rearden-grok rearden-grok Bot added core-functional Run Core functional nightly.sh on this PR (inventory + release-pin warn) and removed core-functional Run Core functional nightly.sh on this PR (inventory + release-pin warn) labels Sep 2, 2026
@reardencode
reardencode merged commit e8ef6fd into master Sep 2, 2026
14 of 15 checks passed
@rearden-grok
rearden-grok Bot deleted the net/tip-accept-thread branch September 4, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core-functional Run Core functional nightly.sh on this PR (inventory + release-pin warn)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant