Skip to content

Feat/coinbase rotation#230

Open
average-gary wants to merge 3 commits intostratum-mining:mainfrom
average-gary:feat/coinbase-rotation
Open

Feat/coinbase rotation#230
average-gary wants to merge 3 commits intostratum-mining:mainfrom
average-gary:feat/coinbase-rotation

Conversation

@average-gary
Copy link
Contributor

Adds deterministic address derivation for coinbase outputs using HD wallet descriptors via miniscript crate. Each block found gets a fresh address derived from an extended public key.

This is ideal for privacy and QC resistance.

The code checks for /* in the descriptor via has_wildcard(). No wildcard = no rotation

New Config Options

# Only needed if using wildcard descriptor
coinbase_index_file = "/var/lib/pool/coinbase_index.dat"  # Required with wildcard
coinbase_start_index = 0  # Optional, defaults to 0

Existing configs work unchanged. Defaults preserve current behavior and coinbase_index_file = None means no rotation.

Testnet4 Validation

Two blocks mined on testnet4 (Jan 28, 2026):

Many more blocks have been found using this code. Any TN4 block with signature whirly-pool is a result of this rotation feature.

Blog: https://average-gary.github.io/sv2-apps/

@average-gary average-gary force-pushed the feat/coinbase-rotation branch from 35a852a to ebe7773 Compare February 18, 2026 16:38
@average-gary average-gary force-pushed the feat/coinbase-rotation branch 5 times, most recently from d4507b0 to 3684103 Compare March 5, 2026 14:11
@average-gary average-gary force-pushed the feat/coinbase-rotation branch from 3684103 to 0b2ccaa Compare March 11, 2026 17:26
Implements automatic coinbase address rotation using HD wallet derivation.
After each block is found, the pool/JDC derives a fresh address from an
xpub descriptor, ensuring each coinbase output uses a unique address with
an unexposed public key.

Key features:
- Wildcard descriptor support (e.g., wpkh(xpub.../0/*))
- Persistent index file survives restarts
- Thread-safe atomic index management
- Works with wpkh, tr, and sh(wpkh) descriptors

Configuration:
- coinbase_reward_script: descriptor with wildcard (e.g., wpkh(tpub.../0/*))
- coinbase_index_file: path to persist current derivation index
- coinbase_start_index: initial index if no persistence file exists

Validated on testnet4 with 2 blocks mined at indices 4 and 5.

Files changed:
- stratum-apps: XpubDerivator, wildcard detection in CoinbaseRewardScript
- pool: ChannelManager rotation integration
- jd-client: Solo mining rotation support
Document the new coinbase rotation configuration options in testnet4
config examples for both pool and JD-client.
- Add detection for testnet extended key prefixes (tpub, tprv, upub, uprv, vpub, vprv)
- Set ok_for_mainnet=false for descriptors using testnet keys
- Log at info level whether descriptor uses mainnet or testnet keys
- Add tests for testnet key detection and ok_for_mainnet validation
@average-gary average-gary force-pushed the feat/coinbase-rotation branch from 0b2ccaa to b35b5d9 Compare March 17, 2026 13:05
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