-
Notifications
You must be signed in to change notification settings - Fork 38.8k
kernel: Expose CheckTransaction consensus validation function
#33796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33796. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
| #define btck_TxValidationResult_MEMPOOL_POLICY ((btck_TxValidationResult)(9)) | ||
| #define btck_TxValidationResult_NO_MEMPOOL ((btck_TxValidationResult)(10)) | ||
| #define btck_TxValidationResult_RECONSIDERABLE ((btck_TxValidationResult)(11)) | ||
| #define btck_TxValidationResult_UNKNOWN ((btck_TxValidationResult)(12)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be bigger than 12 (or could maybe be 0) so that new values can be added in the future?
|
Concept ACK on adding more checks. I am not sure how useful this check by itself is though, since it lacks finality, inputs, sigops, amount + fee, and script checks. Are you planning on adding these too and if not, what is the purpose served from surfacing the context-free checks, but not the others? I think the unit tests are going a bit too far. We don't have to verify again that our validation logic works internally and should instead just verify that the function's contract is correct. If you want to check that the mapping for each of the result enums is correct maybe pass in a few hard-coded transactions instead? We do the same in our unit tests too so maybe just reuse a few of the vectors from test/data/tx_invalid.json? |
The new API intentionally exposes only the context‑free consensus predicate ( This gives library users (indexers, gateways, alternative mempool layers, etc.) a cheap pre‑filter to catch structural rule violations like empty vin/vout, out‑of‑range amounts, coinbase scriptSig length bounds, duplicate inputs, or null prevouts in non‑coinbase txs—before doing any stateful or expensive work. Script checks are already available via
Agreed. This can be simplified. |
CheckTransaction consensus validation functionCheckTransaction consensus validation function
yuvicc
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approach ACK
Great addition exposing CheckTransaction to the kernel API. This will be useful to external users needing context-free transaction validation.
| /** | ||
| * @brief Run consensus/tx_check::CheckTransaction on a tx and return the filled state. | ||
| * @return 1 if valid, 0 if invalid. | ||
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /** | |
| * @brief Run consensus/tx_check::CheckTransaction on a tx and return the filled state. | |
| * @return 1 if valid, 0 if invalid. | |
| */ | |
| /** | |
| * @brief Run consensus/tx_check::CheckTransaction on a transaction. | |
| * | |
| * Performs context-free consensus validation on a transaction without | |
| * requiring blockchain state. | |
| * | |
| * @param[in] tx The transaction to validate | |
| * @param[out] out_state Pointer to receive the validation state (always set, | |
| * caller must destroy with btck_tx_validation_state_destroy) | |
| * @return 1 if valid, 0 if invalid | |
| */ |
janb84
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK a262282
PR extends bitcoin kernel library with the checkTransaction consensus validation function.
Added a suggestion NIT (non-blocking) and I agree with the NIT from yuvicc
Steps taken:
- Build & tested
- Code review
- Create a implementation PR for BitcoinKernel.Net
|
|
||
| // ----------------------------------------------------------------------------- | ||
| // CheckTransaction tests | ||
| // ----------------------------------------------------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: (non-blocking) maybe add a note why only the 2 (possible) states are tested ? For a non-bitcoin-core dev this is maybe a bit unclear given all the TxValidationResults and the Check_Transaction that these are the 2 outcomes.
It's for me not logical to add this as a comment on the function because it returns a pointer to the results.
| // ----------------------------------------------------------------------------- | |
| // ----------------------------------------------------------------------------- | |
| // Note: CheckTransaction performs only basic consensus checks and returns either: | |
| // - VALID (ValidationMode::VALID, TxValidationResult::UNSET) for valid transactions | |
| // - INVALID (ValidationMode::INVALID, TxValidationResult::CONSENSUS) for violations | |
| // | |
| // Other TxValidationResult values are set by higher-level validation functions and | |
| // not exposed through btck_check_transaction. | |
| // ----------------------------------------------------------------------------- |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
This PR exposes the consensus-level
CheckTransactionfunction through the libbitcoinkernel C API and adds a corresponding C++ wrapper.Currently, libkernel only provided script-level validation via
btck_script_pubkey_verifyandScriptPubkeyApi<>::Verify.AFAIK there was no way to perform context-free consensus checks on a transaction’s structure (e.g., coinbase rules, money-range, duplicate inputs).
This change introduces a new API:
and a C++ convenience wrapper:
Both follow the ownership and error-handling conventions established in
bitcoinkernel.h.The test suite is extended with cases covering: