lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.57k stars 2.06k forks source link

Accounting for pushed funds after the channel is closed #4490

Open kaipila opened 3 years ago

kaipila commented 3 years ago

Background

It is possible for a remote node to open a channel with my node and assigning some of the balance to my local end of the channel. This increases the total balance in my lightning wallet and some of the lightning faucets actually operate exactly in this manner. This also creates a way for basically anyone to push funds to my wallet just by opening a channel.

From an accounting perspective this kind of a income needs to be accounted for like any other.

If I make a GRPC ListChannels call and look at channels open at the moment I can get this information in the push_amount_sat field and everything is great.

However if the channel has already been closed and I need to use the GRPC ClosedChannels call, I don't see a way to get this information. This causes a situation where I can receive Bitcoins but I have no way for reliably accounting for these funds after the channel is closed.

My environment

lnd version 0.10.0-beta.rc2 commit=v0.10.0-beta.rc2 Darwin 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64 x86_64 Bitcoin Core version v0.19.1 (64-bit)

Steps to reproduce

Perform a GRPC ClosedChannels call and look at the response.

Expected behaviour

I would expect the push_amount_sat field to be available in the ChannelCloseSummary response.

Actual behaviour

It is not.

As a workaround the only way to get to this information that I have found is to parse through the lnd log file.

alexbosworth commented 3 years ago

Did you look at https://github.com/lightningnetwork/lnd/issues/2594 and https://github.com/lightningnetwork/lnd/issues/2594

Maybe these new fields could help if you also review the transactional history?

carlaKC commented 3 years ago

Right now, we are getting the push amount for ListChannels by looking at the balances on our first commitment tx. The problem once the channel is closed is that we clean up all of our old commitments, so this information is no longer available.

Options to address this would be:

In the meantime, if you do not want values pushed to your node, you can run your node with --rejectpush which at least prevents people from pushing to you and messing up accounting.

kaipila commented 3 years ago

Right now, we are getting the push amount for ListChannels by looking at the balances on our first commitment tx. The problem once the channel is closed is that we clean up all of our old commitments, so this information is no longer available.

Options to address this would be:

  • Save the push amount in our open channel (which will then be moved to a historical channels bucket on close, so it will still be available)

This would be a great change and would practically solve this problem.

How the reverse situation is handled should also be considered also. If I open a new channel and push some Bitcoins to remote balance?

ListChannels seems to store the push_amount_sat field in both cases and initiator field can be determined which side the push amount belongs to. According to the documentation.

ClosedChannels GRPC call provides open_initiator information so the same push amount could be accounted for correctly in both cases.

Sounds about right?

In the meantime, if you do not want values pushed to your node, you can run your node with --rejectpush which at least prevents people from pushing to you and messing up accounting.

This is a viable workaround for now. You also have to refrain pushing funds when opening channels your self.

carlaKC commented 3 years ago

How the reverse situation is handled should also be considered also. If I open a new channel and push some Bitcoins to remote balance?

Yes if we have that first commit stored, or just the push amount, that would work for both cases.

You also have to refrain pushing funds when opening channels your self.

Indeed, but more achievable now that most impls have keysend, which can be used to push funds after channel open in a way that is accounted for.