Skip to content

Drop 353 resolution and fix block updating in OffersMessageFlow#4543

Merged
tnull merged 3 commits intolightningdevkit:mainfrom
TheBlueMatt:2026-04-flow-opts
Apr 7, 2026
Merged

Drop 353 resolution and fix block updating in OffersMessageFlow#4543
tnull merged 3 commits intolightningdevkit:mainfrom
TheBlueMatt:2026-04-flow-opts

Conversation

@TheBlueMatt
Copy link
Copy Markdown
Collaborator

The second commit should be backported.

In 884158d we dropped built-in
BIP 353 resolution logic in favor of the
`bitcoin-payment-instructions` crate but forgot to do so in the
`OffersMessageFlow`. Here we do so.
It seems we forgot to ensure `OffersMessageHandler::best_block` is
consistently updated, leading to us building invalid blinded
payment paths for short-lived payment paths after two weeks without
restart.
@ldk-reviews-bot
Copy link
Copy Markdown

ldk-reviews-bot commented Apr 7, 2026

👋 I see @wpaulino was un-assigned.
If you'd like another reviewer assignment, please click here.

@TheBlueMatt TheBlueMatt added this to the 0.3 milestone Apr 7, 2026
@github-advanced-security
Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

let timestamp = &self.highest_seen_timestamp;
let block_time = header.time as usize;

*self.best_block.write().unwrap() = BestBlock::new(header.block_hash(), height);
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.

Nit: BestBlock::new always wipes previous_blocks history. ChannelManager::best_block_updated uses update_for_new_tip instead, which preserves the block-hash history on single-block advances. While OffersMessageFlow doesn't currently use previous_blocks, using update_for_new_tip would be more consistent and future-proof:

Suggested change
*self.best_block.write().unwrap() = BestBlock::new(header.block_hash(), height);
self.best_block.write().unwrap().update_for_new_tip(header.block_hash(), height);

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.

This might be a valid nit?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yea, I'd avoided it to make it easier to backport and because the history isn't used but you're right I should just do it in a separate commit.

@ldk-claude-review-bot
Copy link
Copy Markdown
Collaborator

ldk-claude-review-bot commented Apr 7, 2026

Review Summary

One new minor issue found beyond prior review comments.

Inline comments posted

  • lightning/src/offers/flow.rs:190-191 — Typo ("dont" → "don't") and missing comma in the new comment explaining the BestBlock::new usage.

Prior issues (not re-posted)

  • blocks_disconnected in ChannelManager still does not propagate to OffersMessageFlow.best_block — the newly added comment acknowledges the design choice but the reorg staleness window remains.
  • DNSSec removal is clean with no dangling references.

@ldk-reviews-bot ldk-reviews-bot requested a review from wpaulino April 7, 2026 01:31
@tnull tnull removed the request for review from wpaulino April 7, 2026 07:23
tnull
tnull previously approved these changes Apr 7, 2026
Copy link
Copy Markdown
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Ah, whoops, took the leftovers as somewhat intentional in the first PR.

LGTM, might want to address Claude's nit?

Comment on lines +186 to +190
pub fn best_block_updated(&self, header: &Header, height: u32) {
let timestamp = &self.highest_seen_timestamp;
let block_time = header.time as usize;

self.best_block.write().unwrap().update_for_new_tip(header.block_hash(), height);
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.

Bug: ChannelManager::blocks_disconnected (the Listen impl, line ~15765 of channelmanager.rs) updates its own self.best_block to the fork point but does not propagate the height decrease to self.flow. This means after a reorg, OffersMessageFlow.best_block.height remains at the old (higher) value, causing max_cltv_expiry at line 335 to be too permissive.

You'd need either:

  • A blocks_disconnected (or more general set_best_block) method on OffersMessageFlow, called from ChannelManager::blocks_disconnected, or
  • ChannelManager::blocks_disconnected calling self.flow.best_block_updated(...) with the fork-point header/height (though the current signature expects a Header, not just a hash+height).

Since this commit is flagged for backport, it's worth getting the reorg path right too.

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.

That also seems like a valid concern? @TheBlueMatt

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Not really - if our best block tip is too low during a reorg that's fine - we'll be reconnecting new blocks immediately to catch up to the new tip anyway, so we actually would rather leave the value high than reset and jump ahead again. It is wrong, however, to use update_for_new_tip here as we'll have bunk history. I reset to not using that and left a comment as to why we aren't in its place.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.99%. Comparing base (2adb690) to head (5704e8e).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4543      +/-   ##
==========================================
- Coverage   87.09%   86.99%   -0.10%     
==========================================
  Files         163      163              
  Lines      108856   108635     -221     
  Branches   108856   108635     -221     
==========================================
- Hits        94808    94511     -297     
- Misses      11563    11647      +84     
+ Partials     2485     2477       -8     
Flag Coverage Δ
fuzzing 40.30% <100.00%> (+0.10%) ⬆️
tests 86.09% <100.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@tnull tnull merged commit 4ac8a76 into lightningdevkit:main Apr 7, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants