Skip to content

Conversation

@uncomputable
Copy link
Contributor

This PR implements and tests all (connector) outputs that are used in the Glock transaction graph.

I have used AI for autocompletion.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature/Enhancement (non-breaking change which adds functionality or enhances an existing one)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor
  • New or updated tests
  • Dependency Update

Notes to Reviewers

The Connector and Signer traits turned out very useful for implementing and testing transaction outputs. While Connector is made for Taproot outputs, I was able to implement CpfpConnector which uses a custom script pubkey. I also implemented ContestCounterproofOutput, which is not a connector but just a normal output. We may want to rename Connector to just Output or something like that.

Checklist

  • I have performed a self-review of my code.
  • I have commented my code where necessary.
  • I have updated the documentation if needed.
  • My changes do not introduce new warnings.
  • I have added (where necessary) tests that prove my changes are effective or that my feature works.
  • New and existing tests pass with my changes.
  • I have disclosed my use of AI in the body of this PR.

Related Issues

Depends on #296

@uncomputable uncomputable force-pushed the glock-tx-graph-connectors branch from ed566d2 to 5fe9111 Compare December 9, 2025 04:18
@uncomputable uncomputable marked this pull request as ready for review December 9, 2025 04:22
@codecov
Copy link

codecov bot commented Dec 9, 2025

Codecov Report

❌ Patch coverage is 83.35234% with 146 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.78%. Comparing base (e0416ed) to head (22d5f47).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ates/tx-graph2/src/connectors/timelocked_n_of_n.rs 50.64% 76 Missing ⚠️
crates/tx-graph2/src/connectors/claim_contest.rs 84.95% 17 Missing ⚠️
...s/tx-graph2/src/connectors/contest_counterproof.rs 87.50% 16 Missing ⚠️
crates/tx-graph2/src/connectors/cpfp.rs 77.04% 14 Missing ⚠️
crates/tx-graph2/src/transactions/claim.rs 0.00% 12 Missing ⚠️
crates/tx-graph2/src/connectors/n_of_n.rs 85.71% 7 Missing ⚠️
crates/tx-graph2/src/connectors/test_utils.rs 97.93% 3 Missing ⚠️
crates/tx-graph2/src/connectors/claim_payout.rs 99.03% 1 Missing ⚠️
@@            Coverage Diff             @@
##             main     #298      +/-   ##
==========================================
+ Coverage   52.10%   52.78%   +0.68%     
==========================================
  Files         148      155       +7     
  Lines       22063    22680     +617     
==========================================
+ Hits        11495    11971     +476     
- Misses      10568    10709     +141     
Files with missing lines Coverage Δ
crates/tx-graph2/src/connectors/mod.rs 100.00% <100.00%> (ø)
crates/tx-graph2/src/connectors/claim_payout.rs 99.03% <99.03%> (ø)
crates/tx-graph2/src/connectors/test_utils.rs 97.93% <97.93%> (ø)
crates/tx-graph2/src/connectors/n_of_n.rs 85.71% <85.71%> (ø)
crates/tx-graph2/src/transactions/claim.rs 0.00% <0.00%> (ø)
crates/tx-graph2/src/connectors/cpfp.rs 77.04% <77.04%> (ø)
...s/tx-graph2/src/connectors/contest_counterproof.rs 87.50% <87.50%> (ø)
crates/tx-graph2/src/connectors/claim_contest.rs 84.95% <84.95%> (ø)
...ates/tx-graph2/src/connectors/timelocked_n_of_n.rs 50.64% <50.64%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Collaborator

@Rajil1213 Rajil1213 left a comment

Choose a reason for hiding this comment

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

Amazing work -- especially with generalizing the connectors and creating "one-test-to-rule-them-all". It does come at the cost of a more convoluted test design but I think the tradeoffs are acceptable. I also like the new TaprootWitness type and I'm okay removing the older type once the old tx-graph crate has been replaced.

Most of my review comments are about some non-obvious/new things and some general housekeeping stuff.

Comment on lines 58 to 61
.push_opcode(opcodes::all::OP_SIZE)
.push_int(0x20)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a note in the constructor that the preimage must be a 32-byte value? At the same time, I don't really see the value in enforcing this since the spec does not specify the size of the preimage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked at the stake chain implementation and it used 32-byte preimages. I think it's good to consistently use 32 bytes.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't have the hashlocked (stake) chain anymore so there is nothing to be consistent with. To be clear, I don't mind having this in. However, this should not be abstracted away in the implementation -- it should be documented.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's documented now in the constructor. Should we update the spec?

Copy link
Collaborator

@Rajil1213 Rajil1213 left a comment

Choose a reason for hiding this comment

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

I did a second pass of this PR, specifically the OP_CODESEPARATOR stuff and the test. I think we can make the spending transaction in the test more like what we expect to see in the final transaction graph. For the CPFP connector, it'd be useful to have a separate test that actually demonstrates the CPFP behavior. A test like this already exists in the older CPFP connector module which you might want to borrow.

@Rajil1213 Rajil1213 mentioned this pull request Dec 9, 2025
14 tasks
All connector outputs implement this trait. Most of the taproot internals are automatically implemented.

The TaprootWitness struct represents a generic Taproot witness. I realize that this clashes with the TaprootWitness from primitives/scripts/taproot.rs. I feel the latter is ill-named or should be removed, since the "witness" doesn't contain any signature data. I plan to make a follow-up PR that revises the struct and that updates the affected Musig2 signing machinery. Let's discuss this.
This commit moves the connector testing code to test_utils.rs.
The code is generic, using the new Signer trait.
Stop using old connectors crate as a dependency.
It turns out that half of the Glock connectors follow the same pattern:
- some internal key
- a single tap leaf: N/N + some timelock
This commit extends the connector testing functionality to support leaf scripts that contain OP_CODESEPARATOR.
Because this output is only spent in one place of the transaction graph, it is strictly speaking not a connector. However, it is convenient to implement the Connector trait regardless.
@uncomputable uncomputable force-pushed the glock-tx-graph-connectors branch from 5fe9111 to aeda373 Compare December 9, 2025 21:01
@uncomputable
Copy link
Contributor Author

Rebased onto main and addressed the easy comments. Still working on improving the test utils.

Copy link
Collaborator

@Rajil1213 Rajil1213 left a comment

Choose a reason for hiding this comment

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

Did another pass of this PR after the recent changes.

These methods will be useful to make signartures for testing and for
production. Splitting the normal method from the code separator one
keeps the code simple. In the following commit, I will refactor the
testing infrastructure of connectors.
This struct makes it easy to play transactions on Bitcoin Core. The RPC
calls are abstracted away, to reduce code duplication. The coinbase
outpoints are an easy way to fund transactions. The wallet automatically
signs its inputs.

This commit temporarily disables the code separator and cpfp tests. I
will refactor these tests in the following commits.
Instead of using assert_connector_is_spendable, we use custom code to
test the connector. Separately handling code separators keeps the code
simple.
@uncomputable
Copy link
Contributor Author

I refactored the testing infrastructure. It should be much simpler and more useful now. Connectors have a method to compute the sighash of their transaction input. Code separators are handled separately from the rest of the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants