Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(chart.ts): pending channel display bug #703

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

amovfx
Copy link
Contributor

@amovfx amovfx commented Apr 3, 2023

Channel info now displays proper source and dest names
for pending channels

Closes #699

Description

Channel links are proccessed twice resulting in data being clobbered.

Steps to Test

  1. Launch terminal for alice
  2. Run lncli openchannel <bob-pubkey> 100000
  3. Check channel details

Screenshots

[Only if applicable]

@amovfx
Copy link
Contributor Author

amovfx commented Apr 3, 2023

@jamaljsr
You might want to take a look at this a bit more closely, it was subtle. I'm also curious if taro is going to need this. I don't think so because the links can't really be changed after the network starts.

ALso, out of scope. Maybe a pending channel link could use the functionality to quickly confirm the channel with mining 6 blocks and refreshing the chart? WDT?

@codecov-commenter
Copy link

codecov-commenter commented Apr 3, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (bd93e13) 100.00% compared to head (162f1e5) 100.00%.

Additional details and impacted files
@@            Coverage Diff            @@
##            master      #703   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          116       116           
  Lines         3435      3437    +2     
  Branches       619       647   +28     
=========================================
+ Hits          3435      3437    +2     
Impacted Files Coverage Δ
src/lib/lightning/lnd/lndService.ts 100.00% <100.00%> (ø)

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 in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@jamaljsr
Copy link
Owner

jamaljsr commented Apr 3, 2023

Thanks for investigating and submitting this PR.

While this solution does work in this specific scenario, it's not addressing the root cause of the problem. If you look at LndService.getChannels(), you'll see that for open channels it's only returning the channels that were opened by the supplied node, whereas for the other pending channels it's not filtering out the channels initiated by other nodes.

return [
...open.filter(c => c.initiator).map(mapOpenChannel),
...opening.map(pluckChan).map(mapPendingChannel('Opening')),
...closing.map(pluckChan).map(mapPendingChannel('Closing')),
...forceClosing.map(pluckChan).map(mapPendingChannel('Force Closing')),
...waitingClose.map(pluckChan).map(mapPendingChannel('Waiting to Close')),
];

So when the chart links are being created, the same pending channel is present for both nodes. This causes the link created for alice to be overwritten by the link created for bob. Your fix does work because it prevents bob's channel from overwriting alice's, but now the inverse situation becomes a bug. Currently if you open the channel from bob to alice, the pending channel will show the correct source and destination. When using your fix, the bug returns as it now shows the source as alice, since bob's channel is being filtered out.

The better solution here would be to address the root cause of the problem, which is that LndService.getChannels() is returning channels that were not initiated by the node provided when they are pending. The LND.PendingChannel type does have an initiator field which it can inspect to see if the value is LND.Initiator.INITIATOR_LOCAL.

@amovfx
Copy link
Contributor Author

amovfx commented Apr 3, 2023

Thanks for the guidance, I was looking at this function for a period of time as a root cause but couldn't identify the solution you pointed out, I'll update this asap.

...closing.map(pluckChan).map(mapPendingChannel('Closing')),
...forceClosing.map(pluckChan).map(mapPendingChannel('Force Closing')),
...waitingClose.map(pluckChan).map(mapPendingChannel('Waiting to Close')),
...open.filter(isChanInitiatorLocal).map(mapOpenChannel),
Copy link
Owner

@jamaljsr jamaljsr Apr 3, 2023

Choose a reason for hiding this comment

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

This won't work because LND.Channel.initiator is a boolean, but the isChanInitiatorLocal function is comparing it to an enum/number. That function looks good for all of the pending arrays below, but the open channels array has a different type so it should be filtered differently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ty!

@amovfx amovfx requested a review from jamaljsr April 8, 2023 17:14
@jamaljsr
Copy link
Owner

jamaljsr commented Apr 8, 2023

The code looks good. I'll test it when I get a chance.

Can you squash your commits into one and use a proper message prefix fix(lnd): ...

@jamaljsr
Copy link
Owner

jamaljsr commented Apr 8, 2023

Tested and confirmed this resolves the issue. Just needs a squash then this can be merged.

@amovfx
Copy link
Contributor Author

amovfx commented Apr 9, 2023

Fantastic, thanks for the guidance and feedback once again.

filters by local initiator
@amovfx amovfx force-pushed the lnd-pending-channel-bug branch from f8cfac0 to 162f1e5 Compare April 9, 2023 17:30
@jamaljsr jamaljsr merged commit c8aee78 into jamaljsr:master Apr 10, 2023
Sign up for free to 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.

Bug: Source and destination of unconfirmed channel is shown reverse
3 participants