-
Notifications
You must be signed in to change notification settings - Fork 411
feat(chain): add new list_ordered_canonical_txs method
#2027
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
feat(chain): add new list_ordered_canonical_txs method
#2027
Conversation
6b76092 to
a28cfdf
Compare
|
Nice diagrams |
08e4ce8 to
70ee41b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
6239c8f to
0aab769
Compare
d57a580 to
3b79cba
Compare
evanlinjin
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.
The internals have completely changed. I don't think a point release would make any sense (we also have already merged other breaking changes). I recommend to just break the API.
Get rid of CanonicalIter. Just have a single function that returns impl Iterator<Item = ...>.
0a17091 to
71c3744
Compare
Thanks, I've removed the deprecation in 9664402. It's valid to note that before merging the |
|
ACK 9c4da10 Tested locally, and I agree with the test expectations. No real opinion on deprecating |
ValuedMammal
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.
9c4da10 to
6fd0de9
Compare
b1294f5 to
37920a2
Compare
|
@evanlinjin I've addressed all the comments/nits, and it's ready for a final round of review. Let me know if you see anything else. I improved the docs, commit messages, and also squashed some of them. --
@ValuedMammal I fixed these through the rebase, but now I'll need to drop the new one d9a7c2c, but it depends on #2075 landing in |
ValuedMammal
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.
I'll give this another review.
- Add a new `test_list_ordered_canonical_txs`, to assert the topological spending order when yielding the list of canonical txs, it also adds a new helper `Scenario` structure, and `is_txs_in_topological_order`.
Adds a new `list_ordered_canonical_txs` method which uses the new `TopologicalIterator` on top of the result of `list_canonical_txs` method, yielding the canonical txs in topological spending order. The new `list_ordered_canonical_txs` guarantees that spending transactions appears after their inputs, in topological "spending order". - Introduce the new `TopologicalIterator` for level-based topological sorting, based on Kahn's Algorithm, it uses the `ChainPosition` for sorting within the same graph level, and it takes an `Iterator<Item = CanonicalTx<'a, Arc<Transaction>, A>> of canonical txs. - Introduce the new `list_ordered_canonical_txs` method to `TxGraph`. - Update the existing tests under `test_tx_graph.rs` to verify the topological ordering correctness. - Update the existing `canonicalization` benchmark to also use the new `topological_ordered_txs` method. NOTE: - I've squashed the previous commits into a single one, as they're changing the same files and applies to the same scope. - Also, I've partially used Claude to help with the Kahn's Algorithm. Co-Authored-By: Claude <noreply@anthropic.com>
37920a2 to
12c1076
Compare
ValuedMammal
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.
ACK 12c1076
1a77475
into
bitcoindevkit:release/chain-0.23.x
Description
It introduces a new method for topological ordering canonical transactions,
list_ordered_canonical_txs. It now ensures the dependency-based transaction processing, guaranteeing that parent transactions always appears before their children transaction.The existing
list_canonical_txsandtry_list_canonical_txsmethods have been deprecated in favor of the new ordered version.Notes to the reviewers
"[...] For those reviewing, and wondering why we don't have a fallible try version of this method, it's because we don't have a fallible ChainOracle implementation - we will get rid of ChainOracle trait soon anyway."
This PR is intended for a point release so that bdk_wallet 2.x users can get a topologically sorted list of transactions (we need a point release on bdk_wallet 2.x as well).
It might be useful to take a look at the new test scenarios that I've added, it shows some specific scenarios where the current implementation and output of
canonical_txsdidn't output the transactions in topological order.Let me know if you think the TopologicalIter algorithm and/or API could be improved.
Changelog notice
Checklists
All Submissions:
New Features: