Skip to content

Control Tower: Sender-side checks for duplicate payments #2#1719

Merged
Roasbeef merged 32 commits into
lightningnetwork:masterfrom
cfromknecht:duplicate-payments
Aug 23, 2018
Merged

Control Tower: Sender-side checks for duplicate payments #2#1719
Roasbeef merged 32 commits into
lightningnetwork:masterfrom
cfromknecht:duplicate-payments

Conversation

@cfromknecht
Copy link
Copy Markdown
Contributor

@cfromknecht cfromknecht commented Aug 10, 2018

This PR is an extension of #1070, mostly just touching up documentation. The only thing that is new in the PR is the reordering of logic w/in handleLocalDispatch, which should result in better clean up of circuits and fwd references. This was going to be done in a separate PR, but the changes were overlapping enough that I made them here.

FIxes #973.

@cfromknecht
Copy link
Copy Markdown
Contributor Author

@vapopov rebased w/ split commits

@cfromknecht
Copy link
Copy Markdown
Contributor Author

I've also added a strict flag to the current ControlTower implementation. This is meant to be more tolerant of payments that could already have duplicate payments in flight. The stricter state machine would cause issues if enabled immediately, because there could be db's in such a state with duplicate payments. It also means that we don't need to inspect the circuit map during migration, which would require a bit of a code move to be able to parse and find the payment hashes of already in flight payments.

In the future, we can default to the stricter state machine once we are confident that old payment states have been resolved/cleanedup.

@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour payments Related to invoices/payments htlcswitch P2 should be fixed if one has time bug fix labels Aug 14, 2018
@Roasbeef Roasbeef added this to the 0.5 milestone Aug 15, 2018
@cfromknecht
Copy link
Copy Markdown
Contributor Author

Correcting what I said earlier, I did end up making changes that inspect the circuit map and mark all locally sourced payment hashes as inflight

@cfromknecht cfromknecht force-pushed the duplicate-payments branch 4 times, most recently from 0f00102 to a1619cd Compare August 21, 2018 04:27
@cfromknecht
Copy link
Copy Markdown
Contributor Author

Noticed that the performance hit of doing serial state transitions caused the async_payment_benchmark to timeout. In response, three commits have been added, which:

  • reduces the number of db calls from 2 to 1 for each state transition
  • removes the ControlTower's exclusive lock, so that we can utilize bolt's Batch txns
  • made all handling of local response asynchronous, so that db transactions don't affect the critical path of the switch's primary event loop

Copy link
Copy Markdown
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.

Moving onto testing this as is locally (the latest set of the diff). Will do one final pass over the logic in the switch to ensure things are being updated properly in a few edge cases.

Comment thread channeldb/migrations_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! I forget at times that we have the infra to test the pre and post migration state.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@vapopov's idea :)

Comment thread htlcswitch/control_tower.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could use a comment here explaining what "strict" mode entails.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

@cfromknecht cfromknecht force-pushed the duplicate-payments branch 3 times, most recently from e2d9c36 to c945002 Compare August 22, 2018 02:12
vapopov and others added 20 commits August 21, 2018 19:23
by reading the payment hash from the circuit map.
in the circuit map are marked StatusInFlight. We also
check that hashes contained in forwarded circuits are
not updated.
This commit splits FetchPaymentStatus and
UpdatePaymentStatus, such that they each invoke
helper methods that can be composed into different
db txns. This enables us to improve performance on
send/receive, as we can remove the exclusive lock
from the control tower, and allow concurrent calls
to utilize Batch more effectively.
Composes the new payment status helper methods such that
we only require one db txn per state transition. This
also allows us to remove the exclusive lock from the
control tower, and enable more concurrent requests.
This commit moves the logic handling responses to
locally-initiated payments to be asynchronous. The
reordering of operations into handleLocalDispatch
brings a serious performance burden to the switch's
main event loop. However, the at-most once semantics
of circuit map and idempotency of cleanup methods
allows concurrent operations to run in parallel.

Prior to this commit, the async_payments_benchmark
would timeout due to the forcibly serial nature of
the prior design. With this change, there is no
perceptible difference in the benchmark OMM, even
though we've added two extra db calls.
Copy link
Copy Markdown
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 🎩

Tested on both mainnet and testnet!

Comment thread htlcswitch/switch.go
// If the provided payment is nil, we have discarded the error decryptor
// due to a restart. We'll return a fixed error and signal a temporary
// channel failure to the router.
case payment == nil:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍

@cfromknecht
Copy link
Copy Markdown
Contributor Author

Great work on this @vapopov 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix enhancement Improvements to existing features / behaviour htlcswitch P2 should be fixed if one has time payments Related to invoices/payments

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants