-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[feature]: Include last state in close summary and exportchanbackup #7658
Comments
I researched this issue. It is work in progress and I want to share intermediate results. We can put LocalForceCloseSummary or OpenChannel to such a backup. I explored both directions. LocalForceCloseSummaryLocalForceCloseSummary is produced by lnwallet.LightningChannel.ForceClose method, which also force-closes the channel. I factored out the code to a separate public method GetLocalForceCloseSummary(). How to produce LocalForceCloseSummary in my dev branch. // get one channel
channel, err := r.server.chanStateDB.FetchChannel(nil, chanPoint)
if err != nil {
return nil, err
}
// get all channels
channels, err := r.server.chanStateDB.FetchAllOpenChannels()
if err != nil {
return nil, err
}
chanMachine, err := lnwallet.NewLightningChannel(
r.server.cc.Signer, channel, nil,
)
if err != nil {
return nil, err
}
closeSummary, err := chanMachine.GetLocalForceCloseSummary()
if err != nil {
return nil, err
} Then, during recovery, the following code generates the commitment transaction: var txBuf bytes.Buffer
if err := closeSummary.CloseTx.Serialize(&txBuf); err != nil {
panic(err)
}
fmt.Println("CloseTx", hex.EncodeToString(txBuf.Bytes())) Then, another transaction is needed to sweep the funds from the output of the commitment transaction. I found the code to generate inputs for that transaction in commit_sweep_resolver.go. There also 3 pieces of information missing in LocalForceCloseSummary needed to produce sweep tx: LeaseExpiry, IsInitiator and ChanType. They are passed to commit_sweep_resolver in method SupplementState. In my dev branch I added them to CommitOutputResolution as well as the code needed to generate the input of sweep transaction. Using this method, the following code generated commit sweep transaction. inp, err := closeSummary.CommitResolution.MakeCommitSweepInput(uint32(bestHeight))
if err != nil {
panic(err)
}
sweepTx, err := r.server.sweeper.CreateSweepTx(
[]input.Input{inp},
sweep.FeePreference{
ConfTarget: 6,
},
0,
)
if err != nil {
return nil, err
}
var sweepTxBuf bytes.Buffer
if err := sweepTx.Serialize(&sweepTxBuf); err != nil {
panic(err)
}
fmt.Println("SweepTx", hex.EncodeToString(sweepTxBuf.Bytes())) I tested it on testnet - both transactions work! The remaining part is recovery of HTLC funds. I haven't looked into that yet. OpenChannelThen I discovered that To get OpenChannel's, FetchChannel or FetchAllOpenChannels can be used. The structure was not originally JSON-friendly for encoding and decoding, but I managed to encode it in LND in my another branch. I used the value of OpenChannel in Unfortunately it produced an invalid transaction. When I tried to broadcast it, I got the following error: "non-mandatory-script-verify-flag (Witness program hash mismatch)". I'm debugging this. RevocationStoreOpenChannel also includes RevocationStore which can be used to punish another node if it broadcasts an old commitment transaction during channel recovery process. LND does not have a protection against that at the moment, so it makes sense for the remote node to try to play the system, if its balance in the latest channel state is small (e.g. 1%). Size of RevocationStore is below 2 kilobytes thanks to O(log N) storage solution. I think, this is an argument in favor of including whole OpenChannel into the backup. Open questions
|
Thanks for taking a closer look at this. Just a few general points before I get to your questions:
To your questions:
Again, just the commitment transaction should be added. This can be done with a new version based encoding here: Line 245 in 5f1e0bf
If you've only got the |
@guggero Thank you for feedback! I have a working implementation storing close tx inside SCB: #8183 I tested it on testnet. The channel is in Could you check that I'm moving the right direction, please? |
Hey. I was away for a bit but will take a look at your PRs soon. |
As described in issue #7426 (comment) there are situations where it would be very helpful if the last state was included in the data of the close summary and/or in
exportchanbackup
.Ofcourse this extra data must be totally ignored by all existing commands like
restorechanbackup
. But in cases were you are 100 percent certain the channel state did not change, you would at least be able to manually extract the state from this data using an external tool likechantools
.I made a very expensive mistake with
abandonchannel
by assumingexportchanbackup
would allow me to restore the state. If the state had been stored in the close summary or in that backup, it would have allowed me to recover my funds.I cannot think of any downsides by implementing this feature, except for the close summary and the returnvalue of
exportchanbackup
growing a few bytes in size. Which seems a small tradeoff compared to the advantage it brings.The text was updated successfully, but these errors were encountered: