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: Isolate conf notifications during historical scans #1787

Merged
merged 27 commits into from
Oct 27, 2018

Conversation

cfromknecht
Copy link
Contributor

@cfromknecht cfromknecht commented Aug 25, 2018

In this PR, we modify the TxConfNotifier to isolate confirmation notifications while a historical dispatch is being processed. The purpose of this is to segment which notifications should have their height hints updated in the cache. During a historical rescan, we don't yet know if the txn is in the chain, so we shouldn't continue to update its height hint until after finishing the rescan. Once the rescan finishes, the notification is grouped along with all other notifications at tip so that their height hints can progress as blocks are added.

This PR also introduces:

  • a reorg safety delta to height hints, currently 144 blocks
    • with the recent LRU cache added to neutrino, this shouldn't result too much unnecessary network I/O
    • the height hint is still clamped to whatever the client initial prescribes, so initial registration doesn't take a hit either
  • moves querying of confirmation height hints into the TxConfNotifier
  • reorders the persistence/spend-notification dispatch to improve external consistency

In a follow PR, we will do the same for spend notifications.

This PR depends on #1951, which contains the first four commits

@cfromknecht cfromknecht force-pushed the isolate-scanning-ntfns branch 2 times, most recently from 02f825f to 63213cd Compare August 25, 2018 03:47
@cfromknecht cfromknecht added this to the 0.5 milestone Aug 25, 2018
@Roasbeef Roasbeef modified the milestones: 0.5, 0.5.1 Aug 26, 2018
@Roasbeef Roasbeef added notifications P2 should be fixed if one has time bug fix labels Sep 9, 2018
@halseth
Copy link
Contributor

halseth commented Sep 20, 2018

Is this needed for initial height hint cache enabling?

@cfromknecht
Copy link
Contributor Author

@halseth yes, and similar work needs to be done for spends

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.

Did initial review pass.

chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
confSet.ntfns[ntfn.ConfID] = ntfn

switch {
case ntfn.HeightHint > tcn.currentHeight:
Copy link
Contributor

Choose a reason for hiding this comment

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

Also comments on what is happening here.

chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Outdated Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
@cfromknecht cfromknecht force-pushed the isolate-scanning-ntfns branch 5 times, most recently from e3b585b to 141c5e2 Compare October 1, 2018 10:53
chainntnfs/txconfnotifier_test.go Show resolved Hide resolved
@@ -139,6 +143,11 @@ func TestTxConfFutureDispatch(t *testing.T) {
t.Fatalf("unable to register ntfn: %v", err)
}

err = tcn.UpdateConfDetails(*ntfn2.TxID, 0, nil)
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this added/not here from before?

@@ -124,35 +135,35 @@ func NewTxConfNotifier(startHeight uint32, reorgSafetyLimit uint32,
// the confirmation details must be provided with the UpdateConfDetails method,
// otherwise we will wait for the transaction to confirm even though it already
// has.
func (tcn *TxConfNotifier) Register(ntfn *ConfNtfn) error {
func (tcn *TxConfNotifier) Register(ntfn *ConfNtfn) (bool, uint32, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

return values should be explained.

@halseth
Copy link
Contributor

halseth commented Oct 4, 2018

Needs a rebase! (I think?)

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.

These changes are starting to look good IMO now :)

It will need a rebase, and some commits can be squashed together, as now it is a bit hard to review going in Github commit order (maybe an --ignore-date is needed?).

}

ntfn, ok := ntfns[clientID]
ntfn, ok := confSet.ntfns[clientID]
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like this check could be removed in favor of the loop below now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, otherwise we will dereference a nil confSet

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh nvm, misread. this is done in a later commit

chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/bitcoindnotify/bitcoind.go Show resolved Hide resolved
chainntnfs/bitcoindnotify/bitcoind.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
chainntnfs/txconfnotifier.go Show resolved Hide resolved
lnd_test.go Outdated Show resolved Hide resolved
cfromknecht and others added 25 commits October 26, 2018 18:32
This commit ensures that a confSet's details
are assigned in the confNotifications index
after discovering the transaction at tip. The
recent changes allow a later notification to
be dispatched on registration if an earlier one
has already discovered the confirmation details.

Before this change, it was observed that a later
registration would attempt an immediate delivery,
but fail to do so because the confset's details
were nil. This commit remedies that dispatch path,
allowing the integration tests to pass again.
…irmed at tip

In this commit, we mark the rescan status for a transaction as complete
if we happen to detect it has confirmed within a new block that extends
the chain. We do this as otherwise, it's possible for us to not
immediately dispatch the notification upon a subsequent registration due
to the rescan state machine.
…n block inclusion

In this commit, we'll attempt to consume a reorg notification for a
transaction that was previously reorged out of the chain upon block
inclusion to ensure that it is not lingering due to a client not
handling it the first time.
In this commit, we address a small bug where it's possible to deliver a
confirmation notification with stale confirmation details upon
registration. This can happen if a transaction has confirmed but was
reorged out of the chain later on, and a subsequent notification is
registered.
Removes details field from conf notifications, in favor
of using the details on the confSet. We also bound the
requested conf depth to the reorg saftey limit, as the
behavior of state tracking within the notifier is
undefined otherwise.
@cfromknecht
Copy link
Contributor Author

Rebased

Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

LGTM 💡

@Roasbeef Roasbeef merged commit eaba39d into lightningnetwork:master Oct 27, 2018
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.

None yet

4 participants