Skip to content

Rearchitect bdk_electrum syncing/scanning. #1332

@evanlinjin

Description

@evanlinjin

How does syncing/scanning work now?

Currently, updating bdk_chain structures with bdk_electrum looks like this:

  • The first round of fetching from the Electrum API:

    1. Grab latest blocks atomically from Electrum.
    2. Fetch history of txs from Electrum. Each tx is in form txid + conf_height.
    3. Create anchors for the fetched txs (by anchoring confirmed txids to the lowest-possible block fetched in step 1.).
    4. The update is returned as an ElectrumUpdate which is returned to the bdk_chain structures for processing.
  • The update only contains txids. We determine the missing full transactions from TxGraph.

  • The second round of fetching from the Electrum API: fetch missing full transactions. We then apply this to TxGraph.

Problems with the current implementation

  1. The first round of fetching requires an unwieldy loop. This is required because of the following combination of factors:

    • We fetch histories of different spks in separate calls and we cannot guarantee the consistency between the calls.
    • Each txid is returned with txid + height. We don't have the confirmation blockhash, so we cannot know whether two txs confirmed at the same height can co-exist (they can be in conflicting blocks!).

    We mitigate this problem by fetching the chain tip height+hash before fetching txs, and ensuring the tip still exists in the best chain after. If it is not, we need to fetch tx histories again (hence, the purpose of the loop).

    However, there is a chance (although small) of this logic returning an inconsistent history. If a double-reorg occurs, where a stale-block appears in the best chain again.

  2. TODO: I need to finish this ticket!

Metadata

Metadata

Assignees

Labels

apiA breaking API changebugSomething isn't workingmodule-walletnew featureNew feature or request

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions