Skip to content

Proposed protocol extension

Levon Oganyan edited this page Jul 11, 2021 · 5 revisions

Motivation

We extend the protocol to enable indexers to store and provide access to the BTC's mempool.

Changes

We add following messages.

Message types:

Message ID Name
15 FullFilterInv
16 GetFullFilter
17 FullFilter
18 GetMemFilters
19 MemFilters
20 GetMempool
21 MempoolChunk

The three stage Notification-Request-Response scheme for full filters was chosen since a full mempool filter might get about 1Mb in size and it is not the best idea to include it in every notification.

FullFilterInv

When the indexer computes a new set of filters, it notifies all clients with FullFilterInv message.

This message carries no payload.

GetFullFilter

When the client wants to download the new full filter it sends GetFullFilter. It is not required that GetFullFilter is sent after FullFilterInv. The client might keep track of the mempool itself and ignore FullFilterInv. Or it might decide to download filters tree directly. The server must answer with FullFilter message.

This message carries no payload.

FullFilter

This message is sent by the server in response to GetFullFilter message. The whole payload is a single filter.

Payload

Field Type Size Description
Length uint32 VarInt Length of the filter
Filter ubyte[] Length GZIP encoded bytes of Filters

GetMemFilters

If the client spots, via the full filter, that there is a client's transaction in the mempool, it sends a request to get all filters for mempool branches. The server must respond with MemFilters.

This message carries no payload.

MemFilters

Sent in response to GetMemFilters. The payload contains a list (a map) of filters with corresponding prefixes. Filters are compressed with GZIP.

Payload

Field Type Size Description
FiltersLen uint32 VarInt Amount of filter-prefix pairs
FilterPrefPairs FilterPrefPair[] ? Array of pairs

FilterPrefPair

Field Type Size Description
TxPrefix ubyte[] 2 TxPrefix for the filter
Length uint32 VarInt Length of the filter
Filter ubyte[] Length GZIP encoded bytes of Filters

GetMempool

If the client wants to get parts (or all) of the mempool, it has to send GetMempool with specific TxPrefixes. The indexer must respond with Mempool message.

Zero prefixes shall by convention mean "Send all chunks in response"

Payload

Field Type Size Description
Amount uint32 VarInt Amount of prefixes
Prefixes TxPrefix[] Amount*sizeof(TxPrefix) TxPrefixes

sizeof(TxPrefix) = 2 bytes

MempoolChunk

This message contains transactions from mempool chunks requested via GetMempool. In response the indexer sends as many MempoolChunks messages as requested.

To save traffic, each chunk is compressed with GZIP

Payload

Field Type Size Description
Prefix TxPrefix 2 The TxPrefix of the chunk
Amount uint32 VarInt Amount of transactions in the chunk
Length uint32 VarInt Length of the data
Data ubyte[] ? GZIP encoded bytes of chunk data

The data in MempoolChunk is constructed as follows:

  • All transactions in a chunk are encoded as per Bitcoin protocol
  • Resulting bytes are concatenated
  • Resulting bytearray is compressed/encoded with GZIP