@@ -19,13 +19,14 @@ package fr.acinq.eclair.db.pg
19
19
import fr .acinq .bitcoin .{ByteVector32 , Crypto , Satoshi }
20
20
import fr .acinq .eclair .ShortChannelId
21
21
import fr .acinq .eclair .db .Monitoring .Metrics .withMetrics
22
+ import fr .acinq .eclair .db .Monitoring .Tags .DbBackends
22
23
import fr .acinq .eclair .db .NetworkDb
23
24
import fr .acinq .eclair .router .Router .PublicChannel
24
25
import fr .acinq .eclair .wire .protocol .LightningMessageCodecs .{channelAnnouncementCodec , channelUpdateCodec , nodeAnnouncementCodec }
25
26
import fr .acinq .eclair .wire .protocol .{ChannelAnnouncement , ChannelUpdate , NodeAnnouncement }
26
27
import grizzled .slf4j .Logging
27
- import javax .sql .DataSource
28
28
29
+ import javax .sql .DataSource
29
30
import scala .collection .immutable .SortedMap
30
31
31
32
class PgNetworkDb (implicit ds : DataSource ) extends NetworkDb with Logging {
@@ -48,7 +49,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
48
49
}
49
50
}
50
51
51
- override def addNode (n : NodeAnnouncement ): Unit = withMetrics(" network/add-node" ) {
52
+ override def addNode (n : NodeAnnouncement ): Unit = withMetrics(" network/add-node" , DbBackends . Postgres ) {
52
53
inTransaction { pg =>
53
54
using(pg.prepareStatement(" INSERT INTO nodes VALUES (?, ?) ON CONFLICT DO NOTHING" )) { statement =>
54
55
statement.setString(1 , n.nodeId.value.toHex)
@@ -58,7 +59,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
58
59
}
59
60
}
60
61
61
- override def updateNode (n : NodeAnnouncement ): Unit = withMetrics(" network/update-node" ) {
62
+ override def updateNode (n : NodeAnnouncement ): Unit = withMetrics(" network/update-node" , DbBackends . Postgres ) {
62
63
inTransaction { pg =>
63
64
using(pg.prepareStatement(" UPDATE nodes SET data=? WHERE node_id=?" )) { statement =>
64
65
statement.setBytes(1 , nodeAnnouncementCodec.encode(n).require.toByteArray)
@@ -68,7 +69,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
68
69
}
69
70
}
70
71
71
- override def getNode (nodeId : Crypto .PublicKey ): Option [NodeAnnouncement ] = withMetrics(" network/get-node" ) {
72
+ override def getNode (nodeId : Crypto .PublicKey ): Option [NodeAnnouncement ] = withMetrics(" network/get-node" , DbBackends . Postgres ) {
72
73
inTransaction { pg =>
73
74
using(pg.prepareStatement(" SELECT data FROM nodes WHERE node_id=?" )) { statement =>
74
75
statement.setString(1 , nodeId.value.toHex)
@@ -78,7 +79,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
78
79
}
79
80
}
80
81
81
- override def removeNode (nodeId : Crypto .PublicKey ): Unit = withMetrics(" network/remove-node" ) {
82
+ override def removeNode (nodeId : Crypto .PublicKey ): Unit = withMetrics(" network/remove-node" , DbBackends . Postgres ) {
82
83
inTransaction { pg =>
83
84
using(pg.prepareStatement(" DELETE FROM nodes WHERE node_id=?" )) { statement =>
84
85
statement.setString(1 , nodeId.value.toHex)
@@ -87,7 +88,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
87
88
}
88
89
}
89
90
90
- override def listNodes (): Seq [NodeAnnouncement ] = withMetrics(" network/list-nodes" ) {
91
+ override def listNodes (): Seq [NodeAnnouncement ] = withMetrics(" network/list-nodes" , DbBackends . Postgres ) {
91
92
inTransaction { pg =>
92
93
using(pg.createStatement()) { statement =>
93
94
val rs = statement.executeQuery(" SELECT data FROM nodes" )
@@ -96,7 +97,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
96
97
}
97
98
}
98
99
99
- override def addChannel (c : ChannelAnnouncement , txid : ByteVector32 , capacity : Satoshi ): Unit = withMetrics(" network/add-channel" ) {
100
+ override def addChannel (c : ChannelAnnouncement , txid : ByteVector32 , capacity : Satoshi ): Unit = withMetrics(" network/add-channel" , DbBackends . Postgres ) {
100
101
inTransaction { pg =>
101
102
using(pg.prepareStatement(" INSERT INTO channels VALUES (?, ?, ?, ?) ON CONFLICT DO NOTHING" )) { statement =>
102
103
statement.setLong(1 , c.shortChannelId.toLong)
@@ -108,7 +109,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
108
109
}
109
110
}
110
111
111
- override def updateChannel (u : ChannelUpdate ): Unit = withMetrics(" network/update-channel" ) {
112
+ override def updateChannel (u : ChannelUpdate ): Unit = withMetrics(" network/update-channel" , DbBackends . Postgres ) {
112
113
val column = if (u.isNode1) " channel_update_1" else " channel_update_2"
113
114
inTransaction { pg =>
114
115
using(pg.prepareStatement(s " UPDATE channels SET $column=? WHERE short_channel_id=? " )) { statement =>
@@ -119,7 +120,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
119
120
}
120
121
}
121
122
122
- override def listChannels (): SortedMap [ShortChannelId , PublicChannel ] = withMetrics(" network/list-channels" ) {
123
+ override def listChannels (): SortedMap [ShortChannelId , PublicChannel ] = withMetrics(" network/list-channels" , DbBackends . Postgres ) {
123
124
inTransaction { pg =>
124
125
using(pg.createStatement()) { statement =>
125
126
val rs = statement.executeQuery(" SELECT channel_announcement, txid, capacity_sat, channel_update_1, channel_update_2 FROM channels" )
@@ -137,7 +138,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
137
138
}
138
139
}
139
140
140
- override def removeChannels (shortChannelIds : Iterable [ShortChannelId ]): Unit = withMetrics(" network/remove-channels" ) {
141
+ override def removeChannels (shortChannelIds : Iterable [ShortChannelId ]): Unit = withMetrics(" network/remove-channels" , DbBackends . Postgres ) {
141
142
inTransaction { pg =>
142
143
using(pg.createStatement) { statement =>
143
144
shortChannelIds
@@ -150,7 +151,7 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
150
151
}
151
152
}
152
153
153
- override def addToPruned (shortChannelIds : Iterable [ShortChannelId ]): Unit = withMetrics(" network/add-to-pruned" ) {
154
+ override def addToPruned (shortChannelIds : Iterable [ShortChannelId ]): Unit = withMetrics(" network/add-to-pruned" , DbBackends . Postgres ) {
154
155
inTransaction { pg =>
155
156
using(pg.prepareStatement(" INSERT INTO pruned VALUES (?) ON CONFLICT DO NOTHING" )) { statement =>
156
157
shortChannelIds.foreach(shortChannelId => {
@@ -162,15 +163,15 @@ class PgNetworkDb(implicit ds: DataSource) extends NetworkDb with Logging {
162
163
}
163
164
}
164
165
165
- override def removeFromPruned (shortChannelId : ShortChannelId ): Unit = withMetrics(" network/remove-from-pruned" ) {
166
+ override def removeFromPruned (shortChannelId : ShortChannelId ): Unit = withMetrics(" network/remove-from-pruned" , DbBackends . Postgres ) {
166
167
inTransaction { pg =>
167
168
using(pg.createStatement) { statement =>
168
169
statement.executeUpdate(s " DELETE FROM pruned WHERE short_channel_id= ${shortChannelId.toLong}" )
169
170
}
170
171
}
171
172
}
172
173
173
- override def isPruned (shortChannelId : ShortChannelId ): Boolean = withMetrics(" network/is-pruned" ) {
174
+ override def isPruned (shortChannelId : ShortChannelId ): Boolean = withMetrics(" network/is-pruned" , DbBackends . Postgres ) {
174
175
inTransaction { pg =>
175
176
using(pg.prepareStatement(" SELECT short_channel_id from pruned WHERE short_channel_id=?" )) { statement =>
176
177
statement.setLong(1 , shortChannelId.toLong)
0 commit comments