You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Move PackageTemplate merging decisions entirely into package.rs
Currently our package merging logic is strewn about between
`package.rs` (which decides various flags based on the package
type) and `onchaintx.rs` (which does the actual merging based on
the derived flags as well as its own logic), making the logic hard
to follow.
Instead, here we consolidate the package merging logic entirely
into `package.rs` with a new `PackageTemplate::can_merge_with`
method that decides if merging can happen. We also simplify the
merge pass in `update_claims_view_from_requests` to try to
maximally merge by testing each pair of `PackageTemplate`s we're
given to see if they can be merged.
This is overly complicated (and inefficient) for today's merge
logic, but over the coming commits we'll expand when we can merge
and not having to think about the merge pass' behavior makes that
much simpler (and O(N^2) for <1000 elements done only once when a
commitment transaction confirms is fine).
log_info!(logger,"Ignoring second claim for outpoint {}:{}, already registered its claiming request", req.outpoints()[0].txid, req.outpoints()[0].vout);
740
+
// First drop any duplicate claims.
741
+
requests.retain(|req| {
742
+
debug_assert_eq!(
743
+
req.outpoints().len(),
744
+
1,
745
+
"Claims passed to `update_claims_view_from_requests` should not be aggregated"
let package_locktime = req.package_locktime(cur_height);
759
-
if package_locktime > cur_height + 1{
760
-
log_info!(logger,"Delaying claim of package until its timelock at {} (current height {}), the following outpoints are spent:", package_locktime, cur_height);
if requests[i].can_merge_with(&requests[j], cur_height){
774
+
let merge = requests.remove(i);
775
+
requests[j].merge_package(merge);
776
+
break;
766
777
}
778
+
}
779
+
}
767
780
768
-
log_trace!(logger,"Test if outpoint which our counterparty can spend at {} can be aggregated based on aggregation limit {}", req.counterparty_spendable_height(), cur_height + CLTV_SHARED_CLAIM_BUFFER);
769
-
if req.counterparty_spendable_height() <= cur_height + CLTV_SHARED_CLAIM_BUFFER || !req.aggregable(){
let package_locktime = req.package_locktime(cur_height);
785
+
if package_locktime > cur_height + 1{
786
+
log_info!(logger,"Delaying claim of package until its timelock at {} (current height {}), the following outpoints are spent:", package_locktime, cur_height);
0 commit comments