Skip to content

Add SPV inclusion check that returns block heights#140

Open
olga24912 wants to merge 7 commits into
mainfrom
feat/tx_validation_and_block_number
Open

Add SPV inclusion check that returns block heights#140
olga24912 wants to merge 7 commits into
mainfrom
feat/tx_validation_and_block_number

Conversation

@olga24912

Copy link
Copy Markdown
Collaborator

Summary

  • New view method verify_transaction_inclusion_with_heights(TxInclusionProof) -> Option<TxInclusionInfo> returning the tx's block height and the current mainchain tip height in one call.
  • Existing verify_transaction_inclusion (bool, with confirmations) preserved — now delegates to the new method and applies the confirmations check on top.
  • New types in btc-types::contract_args: TxInclusionProof, TxInclusionInfo, TxBlockMeta. Existing ProofArgs is unchanged, no protocol break.

Motivation

btc-connector needs to aggregate transferred amounts per block, so it needs the tx's block height alongside the inclusion proof. It also wants to apply the confirmation-depth policy adaptively on its side rather than committing to a single threshold at call time. The new method returns both heights in a single call and avoids a follow-up query just to get the height.

@frolvanya frolvanya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a couple of tests to test_basics.rs

Comment thread contract/src/lib.rs Outdated
>= args.confirmations,
"Not enough blocks confirmed"
);
match self.verify_transaction_inclusion_with_heights(proof) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to change v1 if it's deprecated?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just to reduce the amount of copy-paste code. But may be you are right in the point of view, to always check the coinbase tx in verify_transaction_inclusion_with_heights...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return back verify_tx_inclusion. Now removed Some in coinbase_tx_id in the arguments of verify_tx_inclusion_with_heights. Decided to add a check for now that these values are defaults.

After some time we'll remove this part and will always perform the check.

566c36c

Comment thread contract/src/lib.rs
@olga24912

Copy link
Copy Markdown
Collaborator Author

Let's add a couple of tests to test_basics.rs

added: 7ecc6da

@olga24912 olga24912 requested a review from frolvanya June 24, 2026 12:19

@frolvanya frolvanya left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

2 participants