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?
57e5d47 to
ec259f8
Compare
|
Thanks for the review. I addressed everything in the latest commit except the |
I lean towards |
ec259f8 to
60e9bf6
Compare
There was a problem hiding this comment.
I lean towards Block::check_context_free() because it's self-documenting and there could plausibly be a contextual block check down the road.
Thanks for this. I do think there is merit to the check_context_free, but I doubt that a contextual block check would be called "check". The current proposals lean towards "connect" (bitcoin/bitcoin#32317) or "validate" (bitcoin/bitcoin#35187) and would be on the chainstate manager.
Either way, I wanted to hear your opinion on this.
I think check is more idiomatic Rust - discoverability is better addressed by the doc comments you've already added and the flags parameter, which signal what kind of check this is at the call site.
|
@pzafonte this will require a rebase and probably a change to the bindings now. |
60e9bf6 to
b1632cd
Compare
|
Makes sense, if other contextual variants use Rebased on current master. Addressed the remaining feedback. |
b1632cd to
fa474d3
Compare
alexanderwiederin
left a comment
There was a problem hiding this comment.
Almost there - thanks for pushing through!
| pub type BlockCheckFlags = btck_BlockCheckFlags; | ||
|
|
||
| /// Run only base context-free block checks (no PoW, no Merkle root). | ||
| pub const BLOCK_CHECK_BASE: btck_BlockCheckFlags = btck_BlockCheckFlags_BASE; | ||
| pub const BLOCK_CHECK_BASE: BlockCheckFlags = btck_BlockCheckFlags_BASE; | ||
|
|
||
| /// Enable Proof-of-Work verification via the block header. | ||
| pub const BLOCK_CHECK_POW: btck_BlockCheckFlags = btck_BlockCheckFlags_POW; | ||
| pub const BLOCK_CHECK_POW: BlockCheckFlags = btck_BlockCheckFlags_POW; | ||
|
|
||
| /// Enable Merkle-root verification (and mutation detection). | ||
| pub const BLOCK_CHECK_MERKLE: btck_BlockCheckFlags = btck_BlockCheckFlags_MERKLE; | ||
| pub const BLOCK_CHECK_MERKLE: BlockCheckFlags = btck_BlockCheckFlags_MERKLE; | ||
|
|
||
| /// Enable all available context-free block checks (PoW + Merkle root). | ||
| pub const BLOCK_CHECK_ALL: btck_BlockCheckFlags = btck_BlockCheckFlags_ALL; | ||
| pub const BLOCK_CHECK_ALL: BlockCheckFlags = btck_BlockCheckFlags_ALL; |
There was a problem hiding this comment.
This should be in the previous commit.
| state::context::ChainParams, | ||
| KernelError, | ||
| }; | ||
|
|
There was a problem hiding this comment.
| /// Bitmask of flags controlling which checks [`Block::check`] performs. |
I think a doc comment would make sense here.
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. Raw btck_BlockCheckFlags_* constants are added to the sys crate's hand-rolled bindings. Adds an AsPtr<btck_ChainParameters> impl for ChainParams. Tests are split per scenario in src/core/block.rs: 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.
fa474d3 to
4b6e6a4
Compare
Wraps btck_block_check from bitcoin/bitcoin#33908. The function 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_BASE / _POW / _MERKLE / _ALL flags.
Exposed as Block::check returning BlockCheckResult { Valid, Invalid(BlockValidationState) }. Raw btck_BlockCheckFlags_* constants are added to the sys crate's hand-rolled bindings; user-facing BLOCK_CHECK_* aliases in src/core/block.rs are re-exported via a block_check_flags submodule.
Tests are split per scenario as unit tests in src/core/block.rs (valid block, mutated merkle root, invalid PoW, tampered coinbase). A follow-up commit reuses MAINNET_BLOCK_1_HEX in test_block_hash_display and test_block_hash_ref_display since they validate the same block.
Closes #155.