Skip to content

Conversation

@kcalvinalvin
Copy link
Collaborator

@kcalvinalvin kcalvinalvin commented Jan 19, 2026

Change Description

This is a first implementation of SwiftSync for btcd. SwiftSync enables fast UTXO set bootstrapping during initial block download by using a precomputed bitmap that indicates which transaction outputs have been spent.

Instead of replaying and validating all historical transactions from genesis, nodes can use the bitmap to directly construct the UTXO set:

  • Bit 0 = output is unspent (add to UTXO cache)
  • Bit 1 = output was spent (skip)

The main benefit is performance improvement during ibd. On this PR when testing on signet, it was 3.3x faster than on master.

Without SwiftSync on master to block height 285,205 took 22m 59s.

Ran with command:

./btcd --datadir=. --logdir=. --signet --cpuprofile=cpuprof-without-ss --memprofile=memprof-without-ss --connect=127.0.0.1 --addcheckpoint=285205:00000004b1cc694c48295fc56c2d78b88abdd648ee60a21548feba259e6dedf1

pprof:
IMG_0571

With SwiftSync on this PR to block height 285,205 took 6m 56s.

Ran with command:

./btcd --datadir=. --logdir=. --signet --cpuprofile=cpuprof-with-ss --memprofile=memprof-with-ss --connect=127.0.0.1

IMG_0572

One caveat is that we can't generate the SpendJournals for the blocks that are processed with SwiftSync.
Note that the aggregator part of SwiftSync is not yet implemented which makes this not safe to run for production uses.

This is a first pass at the implementation and is not final. Feedback welcome.

Steps to Test

Steps for reviewers to follow to test the change.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

for clients

In order for the clients to take advantage of swiftsync, we need provide
the bitmap to the clients. This tool generates the bitmap and writes it
in the data directory of the given network (mainnet, signet, etc).
Add the SwiftSyncData structure which contains precomputed bitmap data
for fast UTXO set bootstrapping. The bitmap indicates which transaction
outputs have been spent up to a certain block height, allowing nodes to
skip transaction replay during initial sync.

Include embedded bitmap data for signet covering blocks 1 through
285205. The bitmap is stored in chaincfg/data/ and embedded at compile
time using go:embed.
Implement swift sync which uses precomputed bitmap data to rapidly
construct the UTXO set during initial block download. Instead of
replaying all historical transactions, swift sync checks each output
against the bitmap: bit 0 means unspent (add to UTXO cache), bit 1
means spent (skip).

Key features:
- Skip all transaction validation during swift sync range
- Persist bitmap bit index for resumability across restarts
- Verify block hash at swift sync boundary to ensure chain correctness
- Safety check prevents enabling swift sync on existing chain data

Swift sync is automatically enabled when checkpoints are enabled and
SwiftSyncData is available in chain parameters.
Add a checkpoint at the swift sync boundary height (285205) for signet.
Swift sync requires at least one checkpoint to be enabled as a security
measure to validate the chain before trusting the precomputed bitmap.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 21129009243

Details

  • 217 of 717 (30.26%) changed or added relevant lines in 8 files are covered.
  • 87 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.2%) to 54.714%

Changes Missing Coverage Covered Lines Changed/Added Lines %
blockchain/swiftsync.go 13 32 40.63%
blockchain/chainio.go 0 21 0.0%
blockchain/chain.go 15 41 36.59%
cmd/genswiftsyncbitmap/config.go 0 70 0.0%
cmd/genswiftsyncbitmap/genswiftsyncbitmap.go 165 529 31.19%
Files with Coverage Reduction New Missed Lines %
btcutil/gcs/gcs.go 1 80.95%
btcec/schnorr/musig2/sign.go 2 90.44%
database/ffldb/blockio.go 4 88.81%
wire/msgaddrv2.go 13 55.36%
wire/netaddressv2.go 20 75.08%
blockchain/chainio.go 47 71.1%
Totals Coverage Status
Change from base Build 20942501138: -0.2%
Covered Lines: 31375
Relevant Lines: 57344

💛 - Coveralls

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