Skip to content

refactor(tbtc): split node into per-concern files#4193

Open
piotr-roslaniec wants to merge 1 commit into
mainfrom
refactor/split-tbtc-node
Open

refactor(tbtc): split node into per-concern files#4193
piotr-roslaniec wants to merge 1 commit into
mainfrom
refactor/split-tbtc-node

Conversation

@piotr-roslaniec

@piotr-roslaniec piotr-roslaniec commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What

Splits the ~1450-LOC pkg/tbtc/node.go monolith into per-concern files within the same package:

File Responsibility
node.go core node struct, newNode, accessors, DKG entry (joinDKGIfEligible, validateDKG)
node_executors.go signing / coordination / inactivity-claim executors
node_proposals.go wallet-action proposal handlers (heartbeat, deposit sweep, redemption, moving funds, moved-funds sweep)
node_coordination.go coordination-layer loop (runCoordinationLayer, executeCoordinationProcedure, processCoordinationResult)
node_wallet_closure.go closed-wallet archival and closure
node_block.go block-height wait helpers

node.go drops from ~1450 to ~300 LOC.

Why

node.go was one of the two largest monoliths in the package and mixed several unrelated concerns, making it hard to navigate. This is the companion to the tBTC chain-adapter split.

Safety

Pure relocation, no behavioral change. Declarations are moved verbatim; every top-level declaration body was hashed before and after the split and confirmed byte-for-byte identical. Per-file imports were pruned with goimports. go build, go vet, gofmt -l, and the full pkg/tbtc test suite all pass.

Since everything stays in package tbtc, cross-file references resolve unchanged.

Summary by CodeRabbit

  • New Features
    • Added coordination processing for heartbeat, deposit sweep, redemption, moving funds, and moved-funds sweep actions.
    • Added wallet-specific executor management to support signing, coordination, and inactivity claims.
    • Added block-height waiting and context cancellation utilities.
    • Added wallet closure verification and automatic archiving for wallets no longer registered on-chain.

The pkg/tbtc/node.go file had grown to ~1450 LOC covering the node
struct plus signing/coordination/inactivity executors, wallet-action
proposal handlers, the coordination layer, wallet closure, and block
helpers. Split it into per-concern files within the same package:

- node.go              core struct, constructor, accessors, DKG entry
- node_executors.go    signing/coordination/inactivity executors
- node_proposals.go    wallet-action proposal handlers
- node_coordination.go coordination layer loop
- node_wallet_closure.go closed-wallet archival and closure
- node_block.go        block-height wait helpers

Pure relocation: declarations are moved verbatim, no behavioral change.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a53b0f6f-ad84-49dd-b381-3171086faea8

📥 Commits

Reviewing files that changed from the base of the PR and between 5245f66 and f1a0994.

📒 Files selected for processing (6)
  • pkg/tbtc/node.go
  • pkg/tbtc/node_block.go
  • pkg/tbtc/node_coordination.go
  • pkg/tbtc/node_executors.go
  • pkg/tbtc/node_proposals.go
  • pkg/tbtc/node_wallet_closure.go
💤 Files with no reviewable changes (1)
  • pkg/tbtc/node.go

📝 Walkthrough

Walkthrough

TBTC node orchestration was split from node.go into dedicated files covering executor caching, coordination processing, proposal dispatch, block waiting, and wallet closure archival.

Changes

TBTC node orchestration

Layer / File(s) Summary
Separate node orchestration components
pkg/tbtc/node.go
node.go removes the relocated orchestration implementations and their unused imports.
Cache wallet-specific executors
pkg/tbtc/node_executors.go
Signing, coordination, and inactivity-claim executors are created, filtered, instrumented, cached, and returned according to wallet signer control.
Run coordination windows
pkg/tbtc/node_coordination.go
Coordination windows trigger per-wallet execution, metric tracking, asynchronous result processing, and proposal routing.
Dispatch wallet proposals
pkg/tbtc/node_proposals.go
Proposal handlers validate signer control, construct wallet actions, and dispatch them with block ranges and optional metrics.
Wait for blocks and archive closed wallets
pkg/tbtc/node_block.go, pkg/tbtc/node_wallet_closure.go
Block-waiting helpers provide cancellable contexts, while closure handling confirms on-chain removal before archiving controlled wallets.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant BlockCounter
  participant Node
  participant CoordinationExecutor
  participant WalletDispatcher
  BlockCounter->>Node: detect coordination window
  Node->>CoordinationExecutor: coordinate wallet window
  CoordinationExecutor-->>Node: return coordination result
  Node->>WalletDispatcher: dispatch corresponding wallet action
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: splitting pkg/tbtc/node.go into per-concern files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/split-tbtc-node

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant