feat(core): expose Block::check#177
Conversation
|
Can you rebase and undraft this? |
0533bfd to
f3f404f
Compare
alexanderwiederin
left a comment
There was a problem hiding this comment.
Cool!
Could you also please add the change to the CHANGELOG?
| /// # Ok(()) | ||
| /// # } | ||
| /// ``` | ||
| pub fn check_context_free( |
There was a problem hiding this comment.
I think we can call the method check(). What do you think?
| self.inner, | ||
| consensus_params, | ||
| flags, | ||
| validation_state.as_ptr() as *mut btck_BlockValidationState, |
There was a problem hiding this comment.
The .as_ptr() as *mut is a bit of a faux pas. Added PR to remove the implicit cast, which can be used here.
57e5d47 to
ec259f8
Compare
|
Thanks for the review. I addressed everything in the latest commit except the |
I lean towards |
Wraps btck_block_check from bitcoin/bitcoin#33908, which performs context-free validation of a block (size, weight, coinbase, transactions, sigops) without chainstate or block index access. Proof-of-work and merkle-root checks are optional via the BLOCK_CHECK_* flags. Block::check returns a BlockCheckResult enum carrying the validation state on failure. Adds an AsPtr<btck_ChainParameters> impl for ChainParams. Raw BTCK_BLOCK_CHECK_FLAGS_* constants live in src/ffi/constants.rs with user-facing BLOCK_CHECK_* aliases, mirroring the VERIFY_* pattern and exposed via a block_check_flags submodule. Tests live as unit tests in src/core/block.rs, split per scenario: valid block, mutated merkle root, invalid PoW, tampered coinbase.
Reuses the constant introduced for the Block::check tests, removing the duplicated inline hex from test_block_hash_display and test_block_hash_ref_display.
ec259f8 to
60e9bf6
Compare
Wraps btck_block_check from bitcoin/bitcoin#33908. The function performs context-free validation of a block (size, weight, coinbase, transactions, sigops), with optional proof-of-work and merkle-root checks toggled via the BLOCK_CHECK_BASE / _POW / _MERKLE / _ALL flags. Useful for early rejection of invalid blocks before any chainstate-dependent validation runs.
The Rust signature mirrors the C contract: validation_state is filled in-place and the function returns a bool. Adds an AsPtr<btck_ChainParameters> impl on ChainParams and re-exports the owned BlockValidationState type since callers now need to construct one. The flag constants follow the existing VERIFY_* pattern and are also exposed via a block_check_flags submodule mirroring verify_flags.
Test mirrors upstream's btck_check_block_context_free case-by-case (valid block, mutated merkle, bad PoW, tampered coinbase, truncated bytes), reusing a single state to verify the documented reset-on-entry behavior.
Draft until subtree is synced, but tested locally on updated subree.
Closes #155.