Skip to content

refactor(ethereum): split tBTC chain adapter into per-concern files#4191

Open
piotr-roslaniec wants to merge 1 commit into
refactor/named-chain-param-gettersfrom
refactor/split-ethereum-tbtc-adapter
Open

refactor(ethereum): split tBTC chain adapter into per-concern files#4191
piotr-roslaniec wants to merge 1 commit into
refactor/named-chain-param-gettersfrom
refactor/split-ethereum-tbtc-adapter

Conversation

@piotr-roslaniec

Copy link
Copy Markdown
Collaborator

TL;DR for reviewers

This is a pure, AST-verified relocation — no declaration body changed. pkg/chain/ethereum/tbtc.go (~2400 lines, ~90 methods on TbtcChain) is split into per-concern files within the same package. Every top-level declaration was moved verbatim; a tool compared the AST of all 96 declarations before and after the split and confirmed each is byte-identical. Build, go vet, and the ethereum test suite all pass. It should review in minutes, not hours: check the file assignments, not the bodies.

Why

The adapter had become a monolith spanning every tBTC concern (sortition, DKG, inactivity, deposit, redemption, wallet, moving funds) in one file, making it hard to navigate. Same-package split ⇒ no visibility or interface-satisfaction changes.

New file layout

File Concern
tbtc.go TbtcChain struct, constructor, shared constants, TxProofDifficultyFactor
tbtc_sortition.go sortition pool, operator status, rewards, group selection
tbtc_dkg.go DKG lifecycle, result assembly and validation
tbtc_inactivity.go inactivity claims
tbtc_deposit.go deposit reveal, sweep proposals and proofs
tbtc_redemption.go redemption requests, proposals and proofs
tbtc_wallet.go wallet registration/state, heartbeat proposals
tbtc_moving_funds.go moving funds + moved funds sweep

Notes / deviations

  • 8 files, not the originally-scoped 4 (deposit/redemption/wallet/moving-funds): DKG + sortition + inactivity are ~40% of the file (~900 lines), so the 4-file version would have left tbtc.go at ~1200 lines — still a monolith. Splitting those out too is what actually de-monoliths the adapter.
  • Heartbeat has a single method (ValidateHeartbeatProposal); folded into tbtc_wallet.go (wallet liveness) rather than given its own file.
  • Imports were carried verbatim into each file and pruned per-file with goimports (preserves the custom aliases ecdsaabi/tbtcabi/tbtccontract/ecdsacontract).

Base / stacking

Based on refactor/named-chain-param-getters (#4188), not main: #4188 also edits tbtc.go (the Get*Parameters getters), so splitting on top of it avoids a conflict. Once #4188 merges, this branch should be rebased --onto main.

pkg/chain/ethereum/tbtc.go had grown to ~2400 lines and ~90 methods
spanning every tBTC concern. Split it into per-concern files within the
same package so the adapter is navigable:

- tbtc.go: TbtcChain struct, constructor, shared constants
- tbtc_sortition.go: sortition pool, operator status, group selection
- tbtc_dkg.go: DKG lifecycle, result assembly and validation
- tbtc_inactivity.go: inactivity claims
- tbtc_deposit.go: deposit reveal, sweep proposals and proofs
- tbtc_redemption.go: redemption requests, proposals and proofs
- tbtc_wallet.go: wallet registration/state, heartbeat proposals
- tbtc_moving_funds.go: moving funds and moved funds sweep

Pure relocation: no declaration bodies changed. Verified by comparing
the AST of every top-level declaration before and after the split - all
96 declarations are byte-identical.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2375853b-80dd-40b5-a409-2d55d997318f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/split-ethereum-tbtc-adapter

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