Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Expose new BumpChannelClose event for channels with anchor outputs by wpaulino · Pull Request #1689 · lightningdevkit/rust-lightning · GitHub
Skip to content

Expose new BumpChannelClose event for channels with anchor outputs - #1689

Merged
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event
Oct 19, 2022
Merged

Expose new BumpChannelClose event for channels with anchor outputs#1689
TheBlueMatt merged 10 commits into
lightningdevkit:mainfrom
wpaulino:anchors-bump-channel-close-event

Conversation

@wpaulino

@wpaulinowpaulino commented Aug 31, 2022

Copy link
Copy Markdown
Contributor

This PR introduces a new BumpChannelClose event to be consumed by users indicating that they should craft a proper child anchor transaction with a sufficient feerate to increase the commitment transaction's (its parent) feerate and help get it confirmed.

Future work will also feature a similar event to bump the fees of HTLC success and timeout transactions.

@codecov-commenter

codecov-commenter commented Aug 31, 2022

Copy link
Copy Markdown

Codecov Report

Base: 90.79% // Head: 90.49% // Decreases project coverage by -0.29%⚠️

Coverage data is based on head (5478ef6) compared to base (6738fd5).
Patch coverage: 58.70% of modified lines in pull request are covered.

❗ Current head 5478ef6 differs from pull request most recent head e159214. Consider uploading reports for the commit e159214 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #1689 +/- ##
==========================================
- Coverage 90.79% 90.49% -0.30% 
==========================================
Files 87 87 Lines 46969 46863 -106 Branches 46969 46863 -106 ==========================================
- Hits 42646 42410 -236 - Misses 4323 4453 +130 
Impacted FilesCoverage Δ
lightning/src/chain/keysinterface.rs90.89% <0.00%> (-1.65%)⬇️
lightning/src/util/events.rs36.95% <0.00%> (-1.19%)⬇️
lightning/src/ln/chan_utils.rs93.99% <14.28%> (-0.56%)⬇️
lightning/src/chain/channelmonitor.rs89.77% <52.08%> (-1.44%)⬇️
lightning/src/chain/onchaintx.rs88.16% <54.16%> (-7.47%)⬇️
lightning/src/chain/package.rs91.59% <80.80%> (-1.46%)⬇️
lightning/src/util/wakers.rs86.70% <0.00%> (-4.86%)⬇️
lightning/src/chain/mod.rs63.63% <0.00%> (-4.55%)⬇️
lightning/src/routing/gossip.rs91.44% <0.00%> (-0.72%)⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/chain/onchaintx.rs

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Didn't really dig into anything, just looking at the high-level.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 0e079cd to 937017eCompareSeptember 14, 2022 23:23
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Rebased on latest main and addressed pending comments.

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm Approach ACK on both the BumpTransaction enum, the data scope returned back to the user and the event itself. To be looked more, the callsites where we're triggering the event, to see if there is way to simplify or clean paths.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/channelmonitor.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs
log_debug!(logger, "Finalized transaction {} ready to broadcast", bumped_tx.txid());
Some(bumped_tx)
}
pub(crate) fn finalize_untractable_package<L: Deref, Signer: Sign>(

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.

I think "intractable" is the more common form

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

"untractable" is already used quite a bit across the codebase, I'd prefer having a separate PR to only do the rename.

Comment threadlightning/src/chain/package.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 937017e to 21ad8f4CompareSeptember 19, 2022 23:24

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some quick comments, will take a further look later.

Comment threadlightning/src/ln/chan_utils.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
let package_feerate = Self::compute_feerate(previous_package_feerate, fee_estimator, conf_target);
// With the new package feerate obtained, compute the feerate the child transaction must
// meet such that the package feerate is met.
(package_feerate as u64).checked_mul(2).map(|f| f.checked_sub(parent_feerate)).flatten()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmmmm, how do we handle the 1-sat/vb initial fee requirement? If our target ends up being, eg, 1sat/vb can we end up returning something lower here? Also, can we just subtract here? Don't we have to weigh it by the weight of the two transactions?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

The issue here is that we don't know the weight of the child transaction yet as it will be created by the event consumer.

After dwelling on #1689 (comment), it may be better to expose a ConfirmationTarget instead of a feerate to indicate the confirmation urgency. The yet to be developed middleware can then handle mapping it to an appropriate feerate as it will have all the context required to do so properly.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hmm, yea....somehow the consumer has to be able to track the specific transaction, though. We generally try to avoid assuming the fee estimator is correct, or that it responds quickly if the mempool is actively filling up (because some explicitly don't). Thus, we really need to make sure it's easy to track what feerate was used on the previous transaction not just what the target is.

I guess we could just expose the target feerate and let the user do the averaging?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah that should work. We can then expose a helper method that does the averaging for the user.

@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 4aff3e2 to 974c96fCompareSeptember 23, 2022 21:51
Comment threadlightning/src/chain/onchaintx.rs Outdated
#[derive(PartialEq, Eq, PartialOrd, Ord)]
pub(crate) enum ClaimEvent {
BumpCommitment {
target_feerate_sat_per_1000_weight: u32,

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.

nit: Just grepping around and see we have this identifier but with plural sats.

Suggested change
target_feerate_sat_per_1000_weight:u32,
target_feerate_sats_per_1000_weight:u32,

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Looks like we just use both interchangeably across the codebase. Would prefer deferring a consistent rename change to a distinct PR.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/package.rs

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still have to review some of the changes in package.rs, looks good overall.

Thanks for dealing with the rather murky package API, my apologies for the lack of documentation there.

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/package.rs
Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/src/chain/onchaintx.rs
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 974c96f to 5748ec9CompareSeptember 29, 2022 19:27

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Basically LGTM.

Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/util/events.rs Outdated
Comment threadlightning/src/util/events.rs
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 3 times, most recently from 0a0216b to 5478ef6CompareOctober 6, 2022 19:38

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we're good though I'm blocking a bit as using #[cfg(test)] TODO: remove-on-anchors-release to feature gate anchor output support. I can't remember we have gradually release sophisticated feature in the past, so sounds a first time. While I think it's worthy to do so in the present case I don't know if it's the best approach, see comment.

let commitment_package = PackageTemplate::build_package(
self.funding_info.0.txid.clone(), self.funding_info.0.index as u32,
PackageSolvingData::HolderFundingOutput(funding_output),
best_block_height, false, best_block_height,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For builders/helpers in safety-critical parts, we could start to document the boolean argument at the caller call-site, i.e "/* aggregable */ false". It sounds a code style sophistication, though we already do that on the Core-side. As the codebase keeps growing I think this could be a good practice as a argument misusage could introduce a logical bug. E.g, aggregating a PackageMalleability::Untractable and a PackageMalleability::Malleable together triggering a panic!(). Already seen that type of bug sticking for years in Core.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Will address this as a separate PR.

Comment threadlightning/src/chain/keysinterface.rs Outdated
// attempt to broadcast the transaction with its current fee rate and hope
// it confirms. This is essentially the same behavior as a commitment
// transaction without anchor outputs.
None => Some((None, 0, OnchainClaim::Tx(tx.clone()))),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

IIRC, the case where we don't find a second anchor output for the channel is when we have no fund at stakes in the channel (no-htlc, no-balance) output. We could consider the channel early closed and return a OnchainEvent::ChannelClosed, to allow consumer to react in consequence.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I like the idea, but seems out of scope for this PR.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
@@ -2299,6 +2321,39 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
pub fn get_and_clear_pending_events(&mut self) -> Vec<Event> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we should update ChainMonitor::process_pending_events in consequence, noticing the user that this call is from now on important for the funds safety and call frequence should at least match every block ?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Done. I wonder if the ChainMonitor should just do this itself if any anchor channels are present. Would it be considered a violation of the events API?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yeah we can do in a follow-up.

Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/channelmonitor.rs Outdated
Comment threadlightning/src/chain/keysinterface.rs Outdated
Comment threadlightning/src/chain/onchaintx.rs Outdated
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch 2 times, most recently from 004aedf to 46f35c0CompareOctober 11, 2022 20:22
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from 46f35c0 to e159214CompareOctober 11, 2022 20:25
@wpaulino

Copy link
Copy Markdown
ContributorAuthor

Had to rebase on main to address a conflict. The previous push includes changes addressing latest round of feedback.

arik-so
arik-so previously approved these changes Oct 11, 2022

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment threadlightning/src/chain/onchaintx.rs
Comment threadlightning/Cargo.toml Outdated

@ariardariard left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

TheBlueMatt
TheBlueMatt previously approved these changes Oct 17, 2022

@TheBlueMattTheBlueMatt left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. There's a few followups but ideally let's just land this and we can do them later.

Comment threadlightning/src/chain/onchaintx.rs Outdated
Some((idx, _)) => {
// Our target feerate will depend on whether we have any HTLCs present
// within our commitment.
let conf_target = if self.holder_commitment.trust().htlcs().is_empty() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We may have a unrevoked counterparty commitment that does contain HTLCs, I think, so we should check for that or just always use highpriority. Happy to see it as a followup so we can land this.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Since the counterparty commitment isn't exposed to the OnchainTxHandler, I reverted to always using HighPriority and added a todo.

Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/chain/package.rs Outdated
Comment threadlightning/src/util/events.rs
&Event::BumpTransaction(ref event)=> {
27u8.write(writer)?;
match event {
// We never write the ChannelClose events as they'll be replayed upon restarting

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm a little dubious of the never-write here. While we should generate a new bump eventually, we may take a few blocks to do so, and dropping the event may waste a few blocks' time, which seems bad?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I was thinking it would be fine as long as we always use a soonest_conf_deadline of our best known height (which is currently the case). get_height_timer will then force a retry at the next block.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yea, we should reconsider that at some point, though, IIUC that will do an RBF bump at every block, which may mean bumping the fee by 25% every block, which seems like a lot? Not something for this PR, though.

@TheBlueMatt

Copy link
Copy Markdown
Collaborator

Oops, needs rebase now, sorry about that. Feel free to tackle some of the above when you do so.

arik-so
arik-so previously approved these changes Oct 18, 2022
As we integrate the support of anchor outputs, we'll want to know if
each input we're working with came from an anchor outputs channel.
Instead of threading through a `opt_anchors` boolean across several
methods on `PackageSolvingData` and `PackageTemplate`, we decide to
store a reference in each `PackageSolvingData` variant instead that
features a change in behavior between channels with and without anchor
outputs.
This will be useful later on when determining the appropriate fee rate
to use on the anchor transaction to bump its commitment transaction.
@wpaulino
wpaulino dismissed stale reviews from arik-so and TheBlueMatt via abe85a1October 18, 2022 19:27
@wpaulino
wpaulinoforce-pushed the anchors-bump-channel-close-event branch from c963d3a to abe85a1CompareOctober 18, 2022 19:27
@TheBlueMatt
TheBlueMatt merged commit 95bb27a into lightningdevkit:mainOct 19, 2022
@wpaulino
wpaulino deleted the anchors-bump-channel-close-event branch October 19, 2022 00:33
Sign up for freeto 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.

6 participants

@wpaulino@codecov-commenter@TheBlueMatt@arik-so@dunxen@ariard