Add fee info to GetSentInfo#1070
Add fee info to GetSentInfo#1070akumaigorodski wants to merge 10 commits intoACINQ:masterfrom akumaigorodski:getsentinfo-fees
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1070 +/- ##
==========================================
- Coverage 82.5% 82.45% -0.06%
==========================================
Files 99 99
Lines 7587 7610 +23
Branches 298 288 -10
==========================================
+ Hits 6260 6275 +15
- Misses 1327 1335 +8
|
eclair-core/src/main/scala/fr/acinq/eclair/db/sqlite/SqlitePaymentsDb.scala
Outdated
Show resolved
Hide resolved
| // 1 -> 2 was backwards compatible so this method is used to migrate both 1 and 2 to 3 | ||
| statement.executeUpdate("CREATE TABLE IF NOT EXISTS received_payments (payment_hash BLOB NOT NULL PRIMARY KEY, preimage BLOB NOT NULL, payment_request TEXT NOT NULL, received_msat INTEGER, created_at INTEGER NOT NULL, expire_at INTEGER, received_at INTEGER)") | ||
| statement.executeUpdate("CREATE TABLE IF NOT EXISTS sent_payments (id TEXT NOT NULL PRIMARY KEY, payment_hash BLOB NOT NULL, preimage BLOB, amount_msat INTEGER NOT NULL, created_at INTEGER NOT NULL, completed_at INTEGER, status VARCHAR NOT NULL)") | ||
| statement.executeUpdate("ALTER TABLE sent_payments ADD COLUMN fee_msat INTEGER DEFAULT 0 NOT NULL") |
There was a problem hiding this comment.
Why not using a nullable field here?
There was a problem hiding this comment.
And use feeMsat: Option[Long] instead of 0 by default in OutgoingPayment?
There was a problem hiding this comment.
Right, having feeMsat: Option[Long] may be a stretch, the alternative would be to do the conversion in the db layer (keeping feeMsat: Long and nullable in the table) but that's even worse. I think we can keep it NOT NULL and use 0 as default value, after all if the payment wasn't successful we spent exactly 0 msat in fees.
There was a problem hiding this comment.
So no changes here then?
There was a problem hiding this comment.
I don't understand what made you change your mind @araspitzu, a nullable field seems to indeed be better here.
There was a problem hiding this comment.
I don't have strong feelings about this but having it nullable forces the use of Option[Long] which is very correct but will lead to (IMHO) less elegant code where we need to check for the presence of the feeMsat on a finalized outgoing payment. On the other hand one could argue that using a default value of 0 is logically correct because a non finalized payment pays exactly 0 msat in fees.
There was a problem hiding this comment.
FWIW on a client side I'm working on using 0 is bit more comfortable as I can just value + fee instead of value + feeOpt.getOrElse(0).
| // 1 -> 2 was backwards compatible so this method is used to migrate both 1 and 2 to 3 | ||
| statement.executeUpdate("CREATE TABLE IF NOT EXISTS received_payments (payment_hash BLOB NOT NULL PRIMARY KEY, preimage BLOB NOT NULL, payment_request TEXT NOT NULL, received_msat INTEGER, created_at INTEGER NOT NULL, expire_at INTEGER, received_at INTEGER)") | ||
| statement.executeUpdate("CREATE TABLE IF NOT EXISTS sent_payments (id TEXT NOT NULL PRIMARY KEY, payment_hash BLOB NOT NULL, preimage BLOB, amount_msat INTEGER NOT NULL, created_at INTEGER NOT NULL, completed_at INTEGER, status VARCHAR NOT NULL)") | ||
| statement.executeUpdate("ALTER TABLE sent_payments ADD COLUMN fee_msat INTEGER DEFAULT 0 NOT NULL") |
There was a problem hiding this comment.
I don't understand what made you change your mind @araspitzu, a nullable field seems to indeed be better here.
|
|
||
| using(sqlite.createStatement()) { statement => | ||
| require(getVersion(statement, DB_NAME, CURRENT_VERSION) <= CURRENT_VERSION, s"incompatible version of $DB_NAME DB found") // version 2 is "backward compatible" in the sense that it uses separate tables from version 1. There is no migration though | ||
| def migration123(statement: Statement): Unit = { |
There was a problem hiding this comment.
migaration123 doesn't mean anything, I'd prefer taking inspiration from SqliteAuditDb (with migration12 and migration23, maybe one of them being noop).
| // 1 -> 2 was backwards compatible so this method is noop | ||
| def migration12(statement: Statement): Unit = () | ||
|
|
||
| def migration23(statement: Statement): Unit = { |
There was a problem hiding this comment.
That doesn't seem right: if we are in version 2 then we already have those tables.
That should be:
def migration23(statement: Statement): Unit = {
statement.executeUpdate("ALTER TABLE sent_payments ADD COLUMN fee_msat INTEGER DEFAULT 0 NOT NULL")
}Right?
There was a problem hiding this comment.
Also the original comment for version 2 was much more informative
There was a problem hiding this comment.
All CREATE TABLE/INDEX has IF NOT EXISTS which neutralizes them.
There was a problem hiding this comment.
Sure, that's how the case CURRENT_VERSION => works (because starting from nothing or being up to date is the same from a migration point of view) but there is no need to use that in the 2->3 scenario.
|
Needs rebase on master and the new field |
# Conflicts: # eclair-core/src/main/scala/fr/acinq/eclair/db/PaymentsDb.scala # eclair-core/src/main/scala/fr/acinq/eclair/db/sqlite/SqlitePaymentsDb.scala # eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala # eclair-core/src/test/scala/fr/acinq/eclair/db/SqlitePaymentsDbSpec.scala
# Conflicts: # eclair-core/src/main/scala/fr/acinq/eclair/payment/PaymentLifecycle.scala # eclair-core/src/test/scala/fr/acinq/eclair/db/SqlitePaymentsDbSpec.scala
|
This change has been included in #1130 🎉 |
A
feeMsatfield has been added toOutgoingPayment, it is set to0for all states exceptSUCCEDDED.