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

chainntnfs: fix nil pointer on address reuse #3569

Merged
merged 2 commits into from
Oct 23, 2019

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Oct 2, 2019

When a confirmation notification for a script hash is registered, the notifier panics with a nil pointer dereference in case two transactions send funds to this script and are confirmed at different block heights.

The test that triggers the panic is added in the first commit with a fix for it in the second commit.

@Roasbeef Roasbeef added bug fix notifications P2 should be fixed if one has time labels Oct 3, 2019
chainntnfs/txnotifier_test.go Show resolved Hide resolved
chainntnfs/txnotifier_test.go Outdated Show resolved Hide resolved
@guggero guggero force-pushed the chainntfs-addr-reuse branch 2 times, most recently from 865505b to f6ded12 Compare October 3, 2019 09:41
Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

Perhaps the better fix here is to ignore the reuse when detecting it within a transaction? This currently prevents the panic, but a notification won't be dispatched for the reuse anyway.

@guggero guggero force-pushed the chainntfs-addr-reuse branch 2 times, most recently from 5fbd2d6 to ac754ab Compare October 4, 2019 08:46
@guggero
Copy link
Collaborator Author

guggero commented Oct 4, 2019

I now implemented the version that will not notify again on reuse.
Turns out, it's also less code.
Tested it with my regtest setup and was unable to reproduce it after the fix.

The unit test setup is still a bit peculiar with the event listener in the goroutine since we still get multiple messages on the Event.Update channel.
The reason for this is that because both confRequests are identical, there are two ntfns created for the same request and they both get notified. And since the request is referenced from two block heights, we get a total of 4 Update messages (two per TX).
And because the chan buffer is only 1, the test would block if we didn't read in a goroutine.

Not sure if this can still cause problems on the receiver end?

@wpaulino
Copy link
Contributor

wpaulino commented Oct 4, 2019

The reason for this is that because both confRequests are identical, there are two ntfns created for the same request and they both get notified. And since the request is referenced from two block heights, we get a total of 4 Update messages (two per TX).

I think we can get around this by adding an additional check to ensure no details exist for the notification before notifying the transaction at:

if _, ok := n.confNotifications[confRequest]; ok {

@guggero
Copy link
Collaborator Author

guggero commented Oct 7, 2019

I was able to get around the problem by not notifying ntfns that have already been marked as dispatched. Now the test is simpler too.

chainntnfs/txnotifier.go Outdated Show resolved Hide resolved
@joostjager joostjager added this to the 0.9 milestone Oct 8, 2019
@guggero guggero requested a review from wpaulino October 9, 2019 12:25
@guggero
Copy link
Collaborator Author

guggero commented Oct 9, 2019

Ok, I think I was finally able to fix it the way you suggested, @wpaulino.

chainntnfs/txnotifier.go Outdated Show resolved Hide resolved
@wpaulino wpaulino removed their request for review October 9, 2019 17:09
@guggero guggero force-pushed the chainntfs-addr-reuse branch 2 times, most recently from 9f1a905 to f39df06 Compare October 10, 2019 07:38
chainntnfs/txnotifier_test.go Outdated Show resolved Hide resolved
chainntnfs/txnotifier.go Show resolved Hide resolved
@wpaulino
Copy link
Contributor

Travis is reporting a linter failure: chainntnfs/txnotifier.go:1510: File is not goimports-ed (goimports)

chainntnfs/txnotifier.go Show resolved Hide resolved
chainntnfs/txnotifier_test.go Show resolved Hide resolved
chainntnfs/txnotifier_test.go Show resolved Hide resolved
chainntnfs/txnotifier.go Outdated Show resolved Hide resolved
@wpaulino wpaulino requested a review from halseth October 16, 2019 11:45
Copy link
Contributor

@halseth halseth left a comment

Choose a reason for hiding this comment

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

LGTM ✅

@halseth halseth merged commit fd90647 into lightningnetwork:master Oct 23, 2019
@guggero guggero deleted the chainntfs-addr-reuse branch October 23, 2019 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug fix notifications P2 should be fixed if one has time
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants