Skip to content

BIP drafts: SwiftSync Specification#2152

Draft
rustaceanrob wants to merge 3 commits intobitcoin:masterfrom
rustaceanrob:swiftsync-bips
Draft

BIP drafts: SwiftSync Specification#2152
rustaceanrob wants to merge 3 commits intobitcoin:masterfrom
rustaceanrob:swiftsync-bips

Conversation

@rustaceanrob
Copy link
Copy Markdown

SwiftSync is a protocol for clients to parallelize initial block download, based on the original writeup.

Copy link
Copy Markdown
Member

@murchandamus murchandamus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a quick first glance, but could you please break your text into shorter lines? That makes it easier to leave review and track what changed between commits. Either 100 or 120 characters per line seems to work well enough.

Comment thread bip-xxxx-swiftsync.md
Status: Draft
Type: Specification
Assigned: ?
License: BSD-3-Clause
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add links to the relevant discussions on the mailing list and Delving on this document and the others?

Suggested change
License: BSD-3-Clause
License: BSD-3-Clause
Discussion: https://groups.google.com/g/bitcoindev/c/FpSWUxItXQs/m/pnfjP6rFCgAJ

Comment thread bip-xxxx-swiftsync.md
License: BSD-3-Clause
Requires: BIP ?, BIP ?
```
# Abstract
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, Markdown only allows a single first-level header per document, so you probably want to bump all of the headers up one level.

Suggested change
# Abstract
## Abstract

@murchandamus murchandamus added New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author labels May 6, 2026
@jonatack jonatack changed the title SwiftSync Specification BIP drafts: SwiftSync Specification May 6, 2026
@jonatack
Copy link
Copy Markdown
Member

jonatack commented May 6, 2026

FWIW, I don't mind the unbroken lines and even prefer them. Avoids rejigging line lengths to keep them consistent when updating or having lines with very different lengths.

Copy link
Copy Markdown
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did an initial pass and left some comments. I read the BIPs in the commit order (block undo -> histfile -> swiftsync) and it was pretty easy to follow.

Comment thread bip-xxxx-block-undo.md
# Abstract

Inputs of a Bitcoin block are referenced by the outpoint data structure. This poses a limitation during initial block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over the peer-to-peer network. Namely, the creation height, coinbase flag, input script, and amount for each spent coin must be accessible to fully validate a block in a state-less manner. This data cannot be trusted by a peer under usual conditions, however SwiftSync allows a client performing IBD to validate the correctness of this data.
# Motivation
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation is a bit repetitive with what's in the abstract, and there are a lot of technical details. I would reshape this a little in order to give a stronger motivation ("IBD is slow because it must be done sequentially, SwiftSync speeds this up by removing this limitation")

Comment thread bip-xxxx-block-undo.md

# Abstract

Inputs of a Bitcoin block are referenced by the outpoint data structure. This poses a limitation during initial block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over the peer-to-peer network. Namely, the creation height, coinbase flag, input script, and amount for each spent coin must be accessible to fully validate a block in a state-less manner. This data cannot be trusted by a peer under usual conditions, however SwiftSync allows a client performing IBD to validate the correctness of this data.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While reading the spec we notice that the bip is about sharing undo data, but that was not clear from the abstract.

I would add a sentence along the lines of "This document describes how to share [this additional data] over the peer to peer network"

Comment thread bip-xxxx-block-undo.md
## Data structures
#### Height Code

The height and coinbase flag are encoded as a 32 bit integer. To encode the height and flag, binary left shift the height one bit, treat the boolean as a bit, insert it into the newly opened bit position. To decode the height, binary right shift the code. To decode the coinbase flag, mask the first bit position of the header code and interpret the bit as a boolean.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"To encode the height and flag, binary left shift the height one bit, treat the boolean as a bit, insert it into the newly opened bit position."

I would be slightly more explicit and say "the coinbase flag" instead of "the boolean"

Comment thread bip-xxxx-block-undo.md
| `len` | `CompactSize(Len(vector<Coins>))` | The length of the coins vector |
| `coins` | `vector<Coin>` | Coins that were spent, after filtering on the request `cutoff` |

A client supporting the `bspent` MUST include coins created _before_ the `cutoff` field in `getbspent` requests. A client receiving a `bspent` message with un-requested or missing coins MUST disconnect from the serving peer. A client supporting `bspent` MUST adhere to the format of `Coin` specified in the `verion` of the request.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: verion -> version

Comment thread bip-xxxx-block-undo.md
Comment on lines +28 to +30
- `[]byte`: arbitrary byte vector
- `<N bytes>`: size `N` byte vector
- `vector<Foo>`: arbitrary sized vector of `Foo`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I was a bit confused at first, I would reshape this a little to make it clearer:

  • []byte: arbitrary sequence of bytes with no fixed length
  • <N bytes>: byte vector of size N, where N is specified inline (e.g. <32 bytes>)
  • vector<Foo>: vector of arbitrary length of elements of type Foo

Comment thread bip-xxxx-block-undo.md
- `<N bytes>`: size `N` byte vector
- `vector<Foo>`: arbitrary sized vector of `Foo`
- `CompactSize`: encoding of unsigned integers defined in peer-to-peer messages
- `CompressAmount`: defined in the Function Appendix section
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would be a bit more explicit here:

  • CompressAmount: compression function for integer amounts, as defined in the Function Appendix section

Comment thread bip-xxxx-block-undo.md
| `0x07` | `P2WPKH` | `<20 bytes>` | `OP_0 20 <20 bytes>` |
| `0x08` | `P2TR` | `<32 byte X-only public key>` | `OP_1 32 <32 bytes>` |

Scripts are serialized in this format by concatenating the `Prefix` and `Format` fields.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this above the table, I kept wondering how to encode until I read this :)

Comment thread bip-xxxx-block-undo.md
| Field | Type | Serialization | Description |
| :----------------------- | :---------------------------- | ------------- | ----------------------------------------------------------------------------------------------------------------- |
| Input index | 32 bit unsigned integer | Little endian | The index in the block inputs for which this coin corresponds. The coinbase inputs are _excluded_ from this index |
| Height and coinbase flag | Height code | Little endian | |
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should have "Defined above" in "Serialization"

Comment thread bip-xxxx-block-undo.md
A current limitation of IBD is that it must be done sequentially. This is a result of the height, coinbase flag, input script, and amount of the block inputs being omitted from the data committed to by proof of work in the current block, and, thus, this data cannot be trusted if received over the wire naively. Using the SwiftSync protocol, a client is able to verify the correctness of this data, even if served by a potentially untrusted party. This is a property of the SwiftSync hash aggregate, which commits to the height, coinbase flag, script, and amount when creating and deleting coins.
# Specification

In Bitcoin Core, to roll-back the chain state in the event of a block reorganization, the height, coinbase flag, script and amount metadata for each input of a block are stored in a data structure known colloquially as "undo data". This terminology stems from its use to "undo" the effect of a block by repopulating the UTXO set with the coins that were spent by the reorganized block. To remain general in language, this data will be referred as "spent coins."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it took me a while to figure out that the coinbase flag is needed in order to check that a transaction is not spending an immature coinbase... It would be nice to have this specified somewhere to avoid confusion, but I'm not sure if it really fits here, so, as you wish

Copy link
Copy Markdown

@jurraca jurraca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some writing nits but overall the concept is clear enough.

Comment thread bip-xxxx-block-undo.md

# Abstract

Inputs of a Bitcoin block are referenced by the outpoint data structure. This poses a limitation during initial block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over the peer-to-peer network. Namely, the creation height, coinbase flag, input script, and amount for each spent coin must be accessible to fully validate a block in a state-less manner. This data cannot be trusted by a peer under usual conditions, however SwiftSync allows a client performing IBD to validate the correctness of this data.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

however additional data is required that must be served over the peer-to-peer network

I would combine this and the next sentence so it's clear what the data is required for at the end of this sentence, e.g. "... in order to validate the blocks, namely the creation height, coinbase flag...".

This data cannot be trusted by a peer under usual conditions

"under usual conditions" doesn't provide much value here, imo it's either trusted or validated, in this case it can't be trusted when served by a peer.

Comment thread bip-xxxx-block-undo.md
# Abstract

Inputs of a Bitcoin block are referenced by the outpoint data structure. This poses a limitation during initial block download (IBD), such that a client must process blocks sequentially to validate the chain history. The SwiftSync protocol allows blocks to be evaluated in arbitrary order, however additional data is required that must be served over the peer-to-peer network. Namely, the creation height, coinbase flag, input script, and amount for each spent coin must be accessible to fully validate a block in a state-less manner. This data cannot be trusted by a peer under usual conditions, however SwiftSync allows a client performing IBD to validate the correctness of this data.
# Motivation
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Abstract and Motivation repeat similar ideas. imo the Abstract part should focus more on what this proposal provides, instead of the reasoning and context that led to it. Could also merge them into one section if you want.

Comment thread bip-xxxx-block-undo.md

In Bitcoin Core, to roll-back the chain state in the event of a block reorganization, the height, coinbase flag, script and amount metadata for each input of a block are stored in a data structure known colloquially as "undo data". This terminology stems from its use to "undo" the effect of a block by repopulating the UTXO set with the coins that were spent by the reorganized block. To remain general in language, this data will be referred as "spent coins."

Bitcoin Core full archival nodes store spent coins for all blocks. This is useful in the context of SwiftSync, as no additional index must be created or maintained to serve this data to peers. There are, however, some discrepancies between how this data is serialized on disk in Bitcoin core and how this proposal seeks to serialize this data over the peer-to-peer protocol, which are detailed in the rationale section.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bitcoin core / Core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New BIP PR Author action required Needs updates, has unaddressed review comments, or is otherwise waiting for PR author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants