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

htlcswitch: interceptor watchdog #6831

Merged
merged 6 commits into from
Oct 18, 2022

Conversation

joostjager
Copy link
Contributor

Fixes a left-over of the htlc interception api implementation that prevents channels from force-closing if a connected interceptor client does not resolve or resume an htlc in time.

Original mention: #6212 (review)

@joostjager joostjager force-pushed the interceptor-watchdog branch 3 times, most recently from 65b783c to 58317fe Compare August 16, 2022 12:35
@joostjager joostjager marked this pull request as ready for review August 16, 2022 12:35
Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

looks good, have one comment

lncfg/config.go Outdated Show resolved Hide resolved
@Roasbeef Roasbeef added this to the v0.16.0 milestone Aug 16, 2022
@Roasbeef Roasbeef added the enhancement Improvements to existing features / behaviour label Aug 16, 2022
@joostjager joostjager force-pushed the interceptor-watchdog branch 3 times, most recently from 7547a6f to 1361a5b Compare August 17, 2022 12:12
Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Nice to see this change come in! I think it would be a nice addition to surface the height that htlcs will be auto-released on the interceptor api so that calling code can be mindful of that height.

htlcswitch/interceptable_switch.go Outdated Show resolved Hide resolved
htlcswitch/interceptable_switch.go Show resolved Hide resolved
htlcswitch/held_htlc_set.go Outdated Show resolved Hide resolved
@joostjager joostjager force-pushed the interceptor-watchdog branch 2 times, most recently from 979c782 to 4c39d78 Compare August 30, 2022 07:44
@joostjager
Copy link
Contributor Author

@Crypt-iQ do you want to assign a second Lightning Labs reviewer to this?

Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Sorry for the delay on looking a this, looks good now.

I do still think that we should surface the "release height" on the interceptor rpc so that callers know when their htlcs are going to be dropped. Otherwise you need to configure your code with something like --lnd.interceptordelta=x, which will be incorrect if LND changes its defaults/the value is made configurable. Can be done in a follow up, but I think it's important to make this feature more user-friendly.

htlcswitch/held_htlc_set.go Outdated Show resolved Hide resolved
@joostjager
Copy link
Contributor Author

Yes, agreed that adding a height to the interceptor request rpc message is useful. Even just during development. Added.

Copy link
Collaborator

@Crypt-iQ Crypt-iQ left a comment

Choose a reason for hiding this comment

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

I think we could use another reviewer, not because we need LL reviewers, but because we're dealing with switch-related code and it can be tricky

@Roasbeef
Copy link
Member

Roasbeef commented Oct 7, 2022

I think this just needs a rebase then it can land.

@joostjager
Copy link
Contributor Author

Rebased

@lightninglabs-deploy
Copy link

@yyforyongyu: review reminder

Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

Overall looks good. Left several nits and a question about using panic. I think one day we'll need to unify block consumption in one place.

htlcswitch/interceptable_switch.go Show resolved Hide resolved
htlcswitch/interceptable_switch.go Outdated Show resolved Hide resolved
htlcswitch/switch_test.go Outdated Show resolved Hide resolved
htlcswitch/switch_test.go Outdated Show resolved Hide resolved
@@ -3754,9 +3754,22 @@ func assertOutgoingLinkReceiveIntercepted(t *testing.T,
}
}

func TestSwitchHoldForward(t *testing.T) {
t.Parallel()
type interceptableSwitchTestContext struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't quite get the idea behind this test context, looks like in the end it will hold everything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The goal is to make the test context and methods operating within the context re-usable for the unit test that is added in the next commit.

htlcswitch/held_htlc_set.go Show resolved Hide resolved
htlcswitch/held_htlc_set.go Show resolved Hide resolved
// be greater than CltvRejectDelta, because we don't want to offer htlcs
// to the interceptor client for which there is no time left to resolve
// them anymore.
DefaultCltvInterceptDelta = DefaultFinalCltvRejectDelta + 3
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the reason behind 3?

Copy link
Contributor Author

@joostjager joostjager Oct 14, 2022

Choose a reason for hiding this comment

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

Looked like a reasonable interval for an htlc interceptor application to respond. Suppose there would be three blocks in quick succession - 10 sec/block - the application still has 30 seconds to process the intercept.

@joostjager joostjager force-pushed the interceptor-watchdog branch 6 times, most recently from d17f1d0 to c1007cc Compare October 14, 2022 14:14
Copy link
Collaborator

@yyforyongyu yyforyongyu left a comment

Choose a reason for hiding this comment

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

LGTM🎉 Thanks for adding the tests!

htlcswitch/held_htlc_set_test.go Show resolved Hide resolved
htlcswitch/switch_test.go Outdated Show resolved Hide resolved
@guggero
Copy link
Collaborator

guggero commented Oct 18, 2022

GitHub shows a conflict, but doesn't say in which file... Can you try rebasing please?

Preparation for adding more config options.
Preparation for making the interceptable switch aware of expiring htlcs.
Isolation of the set logic so that it will be easier to add watchdog functionality later.
Refactor to prepare for adding more tests.
@joostjager
Copy link
Contributor Author

Done. Problem was the release notes.

Make the interceptable switch aware of htlc expiry and fail back htlcs in-time
to prevent the counterparty from force-closing the channel.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour interceptors
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

8 participants