Skip to content

Commit 8b4920b

Browse files
committed
Remove virtual amount
1 parent 223762e commit 8b4920b

File tree

22 files changed

+191
-242
lines changed

22 files changed

+191
-242
lines changed

eclair-core/src/main/scala/fr/acinq/eclair/db/DbEventHandler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DbEventHandler(nodeParams: NodeParams) extends Actor with DiagnosticActorL
6868
PaymentMetrics.PaymentFailed.withTag(PaymentTags.Direction, PaymentTags.Directions.Sent).increment()
6969

7070
case e: PaymentReceived =>
71-
PaymentMetrics.PaymentAmount.withTag(PaymentTags.Direction, PaymentTags.Directions.Received).record(e.realAmount.truncateToSatoshi.toLong)
71+
PaymentMetrics.PaymentAmount.withTag(PaymentTags.Direction, PaymentTags.Directions.Received).record(e.amount.truncateToSatoshi.toLong)
7272
PaymentMetrics.PaymentParts.withTag(PaymentTags.Direction, PaymentTags.Directions.Received).record(e.parts.length)
7373
auditDb.add(e)
7474
e.parts.foreach(p => channelsDb.updateChannelMeta(p.fromChannelId, ChannelEvent.EventType.PaymentReceived))

eclair-core/src/main/scala/fr/acinq/eclair/db/DualDatabases.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,14 +319,14 @@ case class DualPaymentsDb(primary: PaymentsDb, secondary: PaymentsDb) extends Pa
319319
primary.addIncomingPayment(pr, preimage, paymentType)
320320
}
321321

322-
override def receiveIncomingPayment(paymentHash: ByteVector32, virtualAmount: MilliSatoshi, realAmount: MilliSatoshi, receivedAt: TimestampMilli): Boolean = {
323-
runAsync(secondary.receiveIncomingPayment(paymentHash, virtualAmount, realAmount, receivedAt))
324-
primary.receiveIncomingPayment(paymentHash, virtualAmount, realAmount, receivedAt)
322+
override def receiveIncomingPayment(paymentHash: ByteVector32, amount: MilliSatoshi, receivedAt: TimestampMilli): Boolean = {
323+
runAsync(secondary.receiveIncomingPayment(paymentHash, amount, receivedAt))
324+
primary.receiveIncomingPayment(paymentHash, amount, receivedAt)
325325
}
326326

327-
override def receiveIncomingOfferPayment(pr: MinimalBolt12Invoice, preimage: ByteVector32, virtualAmount: MilliSatoshi, realAmount: MilliSatoshi, receivedAt: TimestampMilli, paymentType: String): Unit = {
328-
runAsync(secondary.receiveIncomingOfferPayment(pr, preimage, virtualAmount, realAmount, receivedAt, paymentType))
329-
primary.receiveIncomingOfferPayment(pr, preimage, virtualAmount, realAmount, receivedAt, paymentType)
327+
override def receiveIncomingOfferPayment(pr: MinimalBolt12Invoice, preimage: ByteVector32, amount: MilliSatoshi, receivedAt: TimestampMilli, paymentType: String): Unit = {
328+
runAsync(secondary.receiveIncomingOfferPayment(pr, preimage, amount, receivedAt, paymentType))
329+
primary.receiveIncomingOfferPayment(pr, preimage, amount, receivedAt, paymentType)
330330
}
331331

332332
override def getIncomingPayment(paymentHash: ByteVector32): Option[IncomingPayment] = {

eclair-core/src/main/scala/fr/acinq/eclair/db/PaymentsDb.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ trait IncomingPaymentsDb {
3636
* Mark an incoming payment as received (paid). The received amount may exceed the invoice amount.
3737
* If there was no matching invoice in the DB, this will return false.
3838
*/
39-
def receiveIncomingPayment(paymentHash: ByteVector32, virtualAmount: MilliSatoshi, realAmount: MilliSatoshi, receivedAt: TimestampMilli = TimestampMilli.now()): Boolean
39+
def receiveIncomingPayment(paymentHash: ByteVector32, amount: MilliSatoshi, receivedAt: TimestampMilli = TimestampMilli.now()): Boolean
4040

4141
/**
4242
* Add a new incoming offer payment as received.
4343
* If the invoice is already paid, adds `amount` to the amount paid.
4444
*/
45-
def receiveIncomingOfferPayment(pr: MinimalBolt12Invoice, preimage: ByteVector32, virtualAmount: MilliSatoshi, realAmount: MilliSatoshi, receivedAt: TimestampMilli = TimestampMilli.now(), paymentType: String = PaymentType.Blinded): Unit
45+
def receiveIncomingOfferPayment(pr: MinimalBolt12Invoice, preimage: ByteVector32, amount: MilliSatoshi, receivedAt: TimestampMilli = TimestampMilli.now(), paymentType: String = PaymentType.Blinded): Unit
4646

4747
/** Get information about the incoming payment (paid or not) for the given payment hash, if any. */
4848
def getIncomingPayment(paymentHash: ByteVector32): Option[IncomingPayment]
@@ -150,11 +150,10 @@ object IncomingPaymentStatus {
150150
/**
151151
* Payment has been successfully received.
152152
*
153-
* @param virtualAmount amount of the payment received, in milli-satoshis (may exceed the invoice amount).
154-
* @param realAmount amount of the payment received, in milli-satoshis (may be less or more than the invoice amount).
155-
* @param receivedAt absolute time in milli-seconds since UNIX epoch when the payment was received.
153+
* @param amount amount of the payment received, in milli-satoshis (may exceed the invoice amount).
154+
* @param receivedAt absolute time in milli-seconds since UNIX epoch when the payment was received.
156155
*/
157-
case class Received(virtualAmount: MilliSatoshi, realAmount: MilliSatoshi, receivedAt: TimestampMilli) extends IncomingPaymentStatus
156+
case class Received(amount: MilliSatoshi, receivedAt: TimestampMilli) extends IncomingPaymentStatus
158157

159158
}
160159

eclair-core/src/main/scala/fr/acinq/eclair/db/pg/PgAuditDb.scala

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import javax.sql.DataSource
3636

3737
object PgAuditDb {
3838
val DB_NAME = "audit"
39-
val CURRENT_VERSION = 13
39+
val CURRENT_VERSION = 12
4040
}
4141

4242
class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
@@ -114,20 +114,12 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
114114
statement.executeUpdate("CREATE INDEX transactions_published_channel_id_idx ON audit.transactions_published(channel_id)")
115115
}
116116

117-
def migration1213(statement: Statement): Unit = {
118-
statement.executeUpdate("ALTER TABLE audit.received RENAME TO received_old")
119-
statement.executeUpdate("CREATE TABLE audit.received (virtual_amount_msat BIGINT NOT NULL, real_amount_msat BIGINT NOT NULL, payment_hash TEXT NOT NULL, from_channel_id TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
120-
statement.executeUpdate("INSERT INTO audit.received SELECT amount_msat, amount_msat, payment_hash, from_channel_id, timestamp FROM audit.received_old")
121-
statement.executeUpdate("DROP TABLE audit.received_old")
122-
statement.executeUpdate("CREATE INDEX received_timestamp_idx ON audit.received(timestamp)")
123-
}
124-
125117
getVersion(statement, DB_NAME) match {
126118
case None =>
127119
statement.executeUpdate("CREATE SCHEMA audit")
128120

129121
statement.executeUpdate("CREATE TABLE audit.sent (amount_msat BIGINT NOT NULL, fees_msat BIGINT NOT NULL, recipient_amount_msat BIGINT NOT NULL, payment_id TEXT NOT NULL, parent_payment_id TEXT NOT NULL, payment_hash TEXT NOT NULL, payment_preimage TEXT NOT NULL, recipient_node_id TEXT NOT NULL, to_channel_id TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
130-
statement.executeUpdate("CREATE TABLE audit.received (virtual_amount_msat BIGINT NOT NULL, real_amount_msat BIGINT NOT NULL, payment_hash TEXT NOT NULL, from_channel_id TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
122+
statement.executeUpdate("CREATE TABLE audit.received (amount_msat BIGINT NOT NULL, payment_hash TEXT NOT NULL, from_channel_id TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
131123
statement.executeUpdate("CREATE TABLE audit.relayed (payment_hash TEXT NOT NULL, amount_msat BIGINT NOT NULL, channel_id TEXT NOT NULL, direction TEXT NOT NULL, relay_type TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
132124
statement.executeUpdate("CREATE TABLE audit.relayed_trampoline (payment_hash TEXT NOT NULL, amount_msat BIGINT NOT NULL, next_node_id TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
133125
statement.executeUpdate("CREATE TABLE audit.channel_events (channel_id TEXT NOT NULL, node_id TEXT NOT NULL, capacity_sat BIGINT NOT NULL, is_funder BOOLEAN NOT NULL, is_private BOOLEAN NOT NULL, event TEXT NOT NULL, timestamp TIMESTAMP WITH TIME ZONE NOT NULL)")
@@ -157,7 +149,7 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
157149
statement.executeUpdate("CREATE INDEX transactions_published_channel_id_idx ON audit.transactions_published(channel_id)")
158150
statement.executeUpdate("CREATE INDEX transactions_published_timestamp_idx ON audit.transactions_published(timestamp)")
159151
statement.executeUpdate("CREATE INDEX transactions_confirmed_timestamp_idx ON audit.transactions_confirmed(timestamp)")
160-
case Some(v@(4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12)) =>
152+
case Some(v@(4 | 5 | 6 | 7 | 8 | 9 | 10 | 11)) =>
161153
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
162154
if (v < 5) {
163155
migration45(statement)
@@ -183,9 +175,6 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
183175
if (v < 12) {
184176
migration1112(statement)
185177
}
186-
if (v < 13) {
187-
migration1213(statement)
188-
}
189178
case Some(CURRENT_VERSION) => () // table is up-to-date, nothing to do
190179
case Some(unknownVersion) => throw new RuntimeException(s"Unknown version of DB $DB_NAME found, version=$unknownVersion")
191180
}
@@ -231,13 +220,12 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
231220

232221
override def add(e: PaymentReceived): Unit = withMetrics("audit/add-payment-received", DbBackends.Postgres) {
233222
inTransaction { pg =>
234-
using(pg.prepareStatement("INSERT INTO audit.received VALUES (?, ?, ?, ?, ?)")) { statement =>
223+
using(pg.prepareStatement("INSERT INTO audit.received VALUES (?, ?, ?, ?)")) { statement =>
235224
e.parts.foreach(p => {
236-
statement.setLong(1, p.virtualAmount.toLong)
237-
statement.setLong(2, p.realAmount.toLong)
238-
statement.setString(3, e.paymentHash.toHex)
239-
statement.setString(4, p.fromChannelId.toHex)
240-
statement.setTimestamp(5, p.timestamp.toSqlTimestamp)
225+
statement.setLong(1, p.amount.toLong)
226+
statement.setString(2, e.paymentHash.toHex)
227+
statement.setString(3, p.fromChannelId.toHex)
228+
statement.setTimestamp(4, p.timestamp.toSqlTimestamp)
241229
statement.addBatch()
242230
})
243231
statement.executeBatch()
@@ -416,8 +404,7 @@ class PgAuditDb(implicit ds: DataSource) extends AuditDb with Logging {
416404
.foldLeft(Map.empty[ByteVector32, PaymentReceived]) { (receivedByHash, rs) =>
417405
val paymentHash = rs.getByteVector32FromHex("payment_hash")
418406
val part = PaymentReceived.PartialPayment(
419-
MilliSatoshi(rs.getLong("virtual_amount_msat")),
420-
MilliSatoshi(rs.getLong("real_amount_msat")),
407+
MilliSatoshi(rs.getLong("amount_msat")),
421408
rs.getByteVector32FromHex("from_channel_id"),
422409
TimestampMilli.fromSqlTimestamp(rs.getTimestamp("timestamp")))
423410
val received = receivedByHash.get(paymentHash) match {

0 commit comments

Comments
 (0)