Skip to content

feat(state): add ChainstateManager::validate_block() (callback) - #218

Draft
alexanderwiederin wants to merge 8 commits into
sedited:masterfrom
alexanderwiederin:callback-utxo-free
Draft

feat(state): add ChainstateManager::validate_block() (callback)#218
alexanderwiederin wants to merge 8 commits into
sedited:masterfrom
alexanderwiederin:callback-utxo-free

Conversation

@alexanderwiederin

Copy link
Copy Markdown
Collaborator

To be compared with #205

depends on bitcoin/bitcoin#35187

…65fc94a39

5c65fc94a39 kernel: Add sans utxo set block validation
b369e88ad40 kernel: Add outpoint equals operator
e65476d050f kernel: Add outpoint creation to C header
d54e309d00d kernel: Add coin creation to C header
644f73541f2 kernel: Add transaction is coinbase to C header
REVERT: 70d9ec7f3d4 Merge bitcoin/bitcoin#34538: net: advertise -externalip addresses
REVERT: 7bff765d514 Merge bitcoin/bitcoin#35639: external_signer: validate fingerprint from enumerate response
REVERT: 773b1c9aa58 Merge bitcoin/bitcoin#35572: coins: make cursor iteration DB-only
REVERT: dab7f2c984b test: cover -externalip/onlynet interaction in functional test
REVERT: 657a5aa3f3d test: cover -externalip bypassing -onlynet
REVERT: 8c87e32bd39 net: let -externalip bypass -onlynet
REVERT: f4af02e827b net: add an add_even_if_unreachable argument to AddLocal
REVERT: 4c9de7d5b32 external_signer: validate fingerprint from enumerate response
REVERT: 72db4accbf5 coins: drop stale cursor null checks
REVERT: 3d2f2d8de09 coins: pass UTXO stats view by reference
REVERT: 35aedb28236 coins: drop cursor from base view
REVERT: c6fbe2f66cf coins: pass DB view to cursor users

git-subtree-dir: libbitcoinkernel-sys/bitcoin
git-subtree-split: 5c65fc94a3997356374568783045e465f3cae706
Add FFI declaration for btck_transaction_is_coinbase, and expose it via
TransactionExt::is_coinbase in the Rust API.
Add FFI declaration for btck_coin_create, and expose it via Coin::new()
in the Rust API.
TxOut::new()

Add FFI declaration for btck_transaction_out_point_create, and expose it
via TxOut::new() in the Rust API.
Validate a block against caller-supplied coins instead of the
chainstate's UTXO state, running CheckBlock through ConnectBlock with
fJustCheck = true so the chainstate is read but never mutated.

Coins are requested through the new FetchCoinCallback trait,
blanket-implemented for Fn(TxOutPointRef<'_>) -> Option<Coin>. The
callback is scoped to a single call, so it needs neither 'static nor
Send + Sync. Panics are caught at the FFI boundary and resumed after the
kernel returns.

Outputs created and spent within the same block never reach the
callback, so BIP-30 violations cannot be detected here.
Extract TestLog, setup_logging, create_context, testing_setup and
read_block_data from tests/test.rs into tests/common so upcoming
integration tests can reuse them. No behaviour change.
Pass the temp directory name in rather than hardcoding
"test_chainman_regtest", so tests in other files can user their own
directories. Existing call sites keep the old name.
Add tests/validate_block.rs with a UtxoSet implementing
FetchCoinCallback, built up block by block from the headers-only chain.
One test walks the chain validating each block against the coins
accumulated so far and asserts the callback is consulted and the active
chain never advances.
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.

1 participant