Repository navigation
Conversation
bitcoind writes blocks to blk*.dat in download order, so a block can sit in an earlier file than the block that funds one of its inputs. Since adding and indexing happen in one pass per file, indexing such a block failed the prevout lookup and panicked with MissingTxo (Blockstream#214). With the blk*.dat fetcher, a batch that hits MissingTxo is now indexed block by block. Blocks whose prevouts are missing are left added but unindexed, and the import returns an error at the end, so the existing RPC fallback indexes only those blocks, in height order. Indexer::index now returns the lookup error instead of unwrapping it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #214.
bitcoind writes blocks to
blk*.datin download order, not height order. Since f66e7fb adds and indexes each file's blocks in one pass, a block stored in an earlier file than the block that funds one of its inputs fails the prevout lookup, and_indexpanics on theunwrap()withMissingTxo. @nikicat traced this in #214. The fetcher sends one batch per file, so blocks within a file are fine, and the bug only shows when the funding block is in a later file.Change
MissingTxois retried block by block. Blocks whose prevouts are not added yet stay added but unindexed, and the other blocks in the file are indexed as before.Indexer::index/_indexnow return the lookup error instead of unwrapping it. On the RPC path aMissingTxois now a returned error rather than a panic. The RPC path delivers blocks in order, so it should not hit this.This keeps the single-pass add+index (and its write-buffer locality) for every block except the deferred ones. It does not touch the RPC or REST paths, so it should not conflict with #217.
Tests
tests/index.rs::file_import_defers_blocks_that_spend_outputs_stored_later: two blk files,[0, 1, 2, 4]and[3], where block 4 spends block 3's coinbase. Onnew-indexit panics with the sameMissingTxoatschema.rs:744as in the issue. With this change the import reaches tip 4, fetches only block 4 over RPC, andlookup_spendand the script stats find the spend.write_filenow goes through a smallwrite_fileshelper.cargo fmt --checkandcargo check --all-targetsare clean (plus--features liquid). The lib,index,query,rest,config,scan_limits,rpc_max_connectionsandelectrum_response_limitstests pass, and so do theelectrumtests apart from the three wallet ones (balance,history,payment). Those hang in my container becauseelectrumddoesn't start there, which looks like what test(electrum): replace electrumd with an in-process BDK wallet #267 addresses, so CI will be the check for them.Real run, testnet4
This was a fresh index from Bitcoin Core 32.1's own blk files (94 files, tip 161,336), using
--blocks-dirwith defaults otherwise.new-index(4e8e6fe): panics about 30 s in, atprocessing blocks 28237/161323, withMissingTxo("5ddd9284…611c01:0").blk-file import incomplete, fetching remaining='3687' of total='161336' blocks over RPC, and the sync reaches the same tip hash as Core in about 20 minutes.GET /tx/5ddd9284…611c01/outspend/0returns the spend in block 42,519, and Core confirms its input. The funding tx is in block 42,518, so the two blocks are adjacent in height but stored in different files.