-
Notifications
You must be signed in to change notification settings - Fork 267
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
deleteinvoice
method
#1984
deleteinvoice
method
#1984
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1984 +/- ##
==========================================
- Coverage 87.68% 87.61% -0.08%
==========================================
Files 160 160
Lines 12533 12559 +26
Branches 530 550 +20
==========================================
+ Hits 10990 11003 +13
- Misses 1543 1556 +13
|
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 doing this!
Can you add this to the release notes?
eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgPaymentsDb.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgPaymentsDb.scala
Outdated
Show resolved
Hide resolved
eclair-core/src/main/scala/fr/acinq/eclair/db/sqlite/SqlitePaymentsDb.scala
Outdated
Show resolved
Hide resolved
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, we're getting closer!
My last pending issue is that this introduces a race condition in MultiPartHandler.scala
.
We previously never removed an invoice from the DB, so we assumed we could do db,getIncomingPayment
and if it returned something, we could process the payment and then call db.receiveIncomingPayment
and it would always succeed.
Unfortunately the call to db.receiveIncomingPayment
may now fail if the invoice is deleted concurrently. We should change the signature from:
/**
* Mark an incoming payment as received (paid). The received amount may exceed the payment request amount.
* Note that this function assumes that there is a matching payment request in the DB.
*/
def receiveIncomingPayment(paymentHash: ByteVector32, amount: MilliSatoshi, receivedAt: Long = System.currentTimeMillis): Unit
to:
/**
* Mark an incoming payment as received (paid). The received amount may exceed the payment request amount.
* If there was no matching payment request in the DB, this will return false.
*/
def receiveIncomingPayment(paymentHash: ByteVector32, amount: MilliSatoshi, receivedAt: Long = System.currentTimeMillis): Boolean
Then in MultiPartHandler.scala
, we should check the result of db.receiveIncomingPayment
and only release the preimage if it was true
.
Please also add tests for this last change.
eclair-core/src/test/scala/fr/acinq/eclair/db/PaymentsDbSpec.scala
Outdated
Show resolved
Hide resolved
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!
I applied some refactoring and fixed the failing test on top of your work in 8d49fc1, can you cherry-pick this commit? After that we should be good to go.
One thing I wanted to highlight that may not be obvious: using a Try[T]
is very different from throwing. It is purely functional and doesn't capture an expensive stack trace, which is why it should always be preferred to actually throwing (and why I'm such a pita when it comes to throwing exceptions).
This is needed for automated rebalancing too.