-
Notifications
You must be signed in to change notification settings - Fork 2k
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
lnd: compute FundingExpiryBlocks in PendingOpenChannel message #7480
lnd: compute FundingExpiryBlocks in PendingOpenChannel message #7480
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! Please refer to our contribution guidelines on how to create commit messages. Plus the linter needs to be fixed.
5e4499a
to
692654a
Compare
@yyforyongyu thanks for the review! Cleaned up the commit stack. Ran |
7063c3d
to
1a4a978
Compare
Fixing lint. Found this style guide. (y) |
59a87b6
to
ede9514
Compare
When you create a PR, there's a checklist: https://github.com/lightningnetwork/lnd/blob/master/.github/pull_request_template.md |
ede9514
to
e8ad5cc
Compare
e8ad5cc
to
0d51d79
Compare
@guggero @yyforyongyu would love to get a review or feedback on this. I can abandon the PR if it's not relevant, or wrap this up if you want it included. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks good👍 Also like the added itest! The only issue is the format of the commit messages - that we wanna the format of pkg: description
. For instance, the first commit would need to be changed into funding: make MaxWaitNumBlocksFundingConf public to...
, and so do the rest.
0d51d79
to
01562c2
Compare
Made suggested changes. Re-requesting review @guggero @yyforyongyu. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great feature and nice test!
Mostly nits from my side.
lnrpc/lightning.proto
Outdated
// channel should be fee bumped using CPFP (see walletrpc.BumpFee) to | ||
// ensure that the channel confirms in time. Otherwise a force-close | ||
// will be necessary if the channel confirms after the funding | ||
// transaction expires. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "A negative value means the channel responder has very likely canceled the funding and the channel will never become fully operational."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guggero @yyforyongyu : We should be able to test for a negative value of FundExpiryBlocks
. Any tips on how to construct this state? I was considering something like:
- Alice opens a pending channel to Bob
- Alice force closes the channel
- Mine more blocks than what Bob expects for a confirmation
- Verify the negative value of
FundExpiryBlocks
I'll try it out, but it's not clear to me how a "pending" channel might transition after the requisite number of confirmations or a force close. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a ht.MineEmptyBlocks
method you can use, which mines blocks, but not includes any txes from the mempool.
You could try it out locally, and I'm suggesting not adding it to the itest builds here. Unfortunately, we are still trying to find out an efficient way to run itests faster, and mining 2016 blocks will dramatically slow them down.
itest/lnd_misc_test.go
Outdated
// before the funding transaction is confirmed, that the FundingExpiryBlocks | ||
// field of a PendingChannels decreases. | ||
func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) { | ||
// Configure bob to require 5 confs for a channel to be considered open |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: missing fulls top at end of sentence.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this comment just describes what the code does. But it doesn't say why the default confs need to be overwritten (because the default in all integration tests is set to 1).
We should probably also decrease the value to 3 since the more blocks we mine here, the slower subsequent tests become because the nodes need to sync to the extra blocks mined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably also decrease the value to 3 since the more blocks we mine here, the slower subsequent tests become because the nodes need to sync to the extra blocks mined.
Is the test not isolated in this instance? If so, would it make sense to restart the node with the defaults when the test ends (both on success and failure)?
Side note: Do tests need to do their own cleanup here? I did a quick search for test setup, but I didn't see how this was handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is a cleanup in Subtest
. And nope, currently all tests in the same tranche share the same blockchain state, which is something I'm looking into for a change.
Re-requesting review. At your leisure. Thanks @guggero and @yyforyongyu ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, LGTM 🎉
@yyforyongyu: review reminder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice! Could you do a rebase so we can let the build run again? The newly added itest funding_expiry_blocks_on_pending
has failed, and the logs are expired.
2e32ab0
to
7d164dc
Compare
I rebased to master and reran cc @yyforyongyu |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the error from the builds,
harness_assertion.go:972:
Error Trace: /home/runner/work/lnd/lnd/itest/harness_assertion.go:972
/home/runner/work/lnd/lnd/itest/lnd_open_channel_test.go:653
/home/runner/work/lnd/lnd/itest/harness.go:286
/home/runner/work/lnd/lnd/itest/lnd_test.go:136
Error: Received unexpected error:
Alice: assert pending open channels failed: want 0, got: 1, total: 1, previously had: 0
Test: TestLightningNetworkDaemon/tranche00/14-of-133/bitcoind/funding_expiry_blocks_on_pending
Messages: num of pending open channels not match
harness.go:339: finished test: funding_expiry_blocks_on_pending, start height=974, end height=978, mined blocks=4
harness.go:345: test failed, skipped cleanup
Can take a deeper look tomorrow.
itest/lnd_open_channel_test.go
Outdated
ht.MineBlocks(1) | ||
ht.AssertNumPendingOpenChannels(alice, 0) | ||
ht.AssertNumPendingOpenChannels(bob, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyforyongyu , the build failure seems strange. This test passes when run locally and in isolation. I'm testing if the complete make itest
passes locally. Maybe it's a test isolation issue. That being said though, is there some difference between the local run and the build run? The failure seems to be after mining a single block and checking for the number of pending open channels (the lines above). On a local run, mining one block moves the channel from pending to open. In the build environment, is this still the case?
In any event, the intention of the test is to check the decreasing value of FundingExpiryBlocks
and not that channels transition from pending to open after mining a block. I'll check if the test still passes locally without these lines, and I think it should be fine to remove them altogether. Thoughts?
7d164dc
to
de9f778
Compare
ht.MineBlocksAndAssertNumTxes(1, 1) | ||
chanPoint := lntest.ChanPointFromPendingUpdate(update) | ||
ht.CloseChannel(alice, chanPoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyforyongyu, I went for a slightly different approach. Still need to mine a block to gracefully close the channel, but I don't think we need to check that it transitions to open. This works on an isolated local run, and I'm testing if the complete make itest
passes locally. Let me know if you have any thoughts. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can always refer to the build results below to see the errors. And you can test it against different backend nodes as documented here. Our build runs against btcd
, neutrino
and multiple modes of bitcoind
mixed with different database options.
As for why the previous test was flaky, it was because the method ht.MineBlocks(1)
is used instead of ht.MineBlocksAndAssertNumTxes(1)
. Because we use regtest, mining blocks can be very fast, thus the funding tx may have not entered the mempool yet but the block is already mined, which explains why the test failed for some of the backends.
The current approach works because ht.MineBlocksAndAssertNumTxes
is used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yyforyongyu thanks for the explanation. Good to know about ht.MineBlocksAndAssertNumTxes
. I rebased this against the latest master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM🎉
ht.MineBlocksAndAssertNumTxes(1, 1) | ||
chanPoint := lntest.ChanPointFromPendingUpdate(update) | ||
ht.CloseChannel(alice, chanPoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can always refer to the build results below to see the errors. And you can test it against different backend nodes as documented here. Our build runs against btcd
, neutrino
and multiple modes of bitcoind
mixed with different database options.
As for why the previous test was flaky, it was because the method ht.MineBlocks(1)
is used instead of ht.MineBlocksAndAssertNumTxes(1)
. Because we use regtest, mining blocks can be very fast, thus the funding tx may have not entered the mempool yet but the block is already mined, which explains why the test failed for some of the backends.
The current approach works because ht.MineBlocksAndAssertNumTxes
is used.
Needs a rebase. cc @saubyk |
`FundingExpiryBlocks`.
pending channels that are waiting for funding confirmation.
`PendingOpenChannel`.
de9f778
to
987b54f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@maxwellsayles does this pr covers the change to REST API response as well?
@saubyk this is the first of heard of the REST API. I would have to investigate to answer your question. Any pointers or documentation on the REST API? |
You can see the REST API for the pending channels rpc: https://lightning.engineering/api-docs/api/lnd/lightning/pending-channels My guess is it's covered as I see the changes made to the lightning.swagger.json as well, but wanted to be sure. |
@saubyk the REST API is always automatically updated from changes to any of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🕐
Congrats @maxwellsayles on getting your first pr merged in LND! 🎉 |
@guggero any recommended followup 'issues' that might be a continuation of this PR? I'll have a look at the open issues and see if anything jumps out. Thanks everyone for the help throughout! |
Not really related to this issue, just a thought. I should probably write this into an actual issue, but one thing I was thinking today that would be very helpful is an RPC that returns a certain number of lines from the current log file. So basically a |
Change Description
This adds the
FundingExpiryBlocks
field to thePendingOpenChannel
message. TheFundingExpiryBlocks
field is computed from the broadcast height of the funding transaction, the current height of the chain andMaxWaitNumBlocksFundingConf
. This is visible via the RPC andlncli pendingchannels
.Resolves #7434
Steps to Test
Added an integration test (
testFundingExpiryBlocksOnPending
) that opens a channel between Alice and Bob, invokes the RPC "pendingchannels", checks for theFundingExpiryBlocks
field in the result message, mines a block, and then loops checking that the value decreases as expected until the funding transaction is completed.Also manually tested the results of
lncli pendingchannels
:lncli openchannel
.lncli pendingchannels
has"funding_expiry_blocks": 2016
.btcd generate 1
.lncli pendingchannels
has"funding_expiry_blocks": 2015
. The value decreased by one as expected.lncli pendingchannels
, but rather does show up withlncli listchannels
.Pull Request Checklist
Testing
Code Style and Documentation
[skip ci]
in the commit message for small changes.📝 Please see our Contribution Guidelines for further guidance.