You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -54,20 +54,28 @@ class PgPeersDb(implicit ds: DataSource, lock: PgLock) extends PeersDb with Logg
54
54
statement.executeUpdate("CREATE TABLE local.relay_fees (node_id TEXT NOT NULL PRIMARY KEY, fee_base_msat BIGINT NOT NULL, fee_proportional_millionths BIGINT NOT NULL)")
55
55
}
56
56
57
+
defmigration34(statement: Statement):Unit= {
58
+
statement.executeUpdate("CREATE TABLE local.peer_storage (node_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL)")
59
+
}
60
+
57
61
using(pg.createStatement()) { statement =>
58
62
getVersion(statement, DB_NAME) match {
59
63
caseNone=>
60
64
statement.executeUpdate("CREATE SCHEMA IF NOT EXISTS local")
61
-
statement.executeUpdate("CREATE TABLE local.peers (node_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL)")
65
+
statement.executeUpdate("CREATE TABLE local.peers (node_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL, storage BYTEA)")
62
66
statement.executeUpdate("CREATE TABLE local.relay_fees (node_id TEXT NOT NULL PRIMARY KEY, fee_base_msat BIGINT NOT NULL, fee_proportional_millionths BIGINT NOT NULL)")
63
-
caseSome(v@(1|2)) =>
67
+
statement.executeUpdate("CREATE TABLE local.peer_storage (node_id TEXT NOT NULL PRIMARY KEY, data BYTEA NOT NULL)")
68
+
caseSome(v@(1|2|3)) =>
64
69
logger.warn(s"migrating db $DB_NAME, found version=$v current=$CURRENT_VERSION")
65
70
if (v <2) {
66
71
migration12(statement)
67
72
}
68
73
if (v <3) {
69
74
migration23(statement)
70
75
}
76
+
if (v <4) {
77
+
migration34(statement)
78
+
}
71
79
caseSome(CURRENT_VERSION) => () // table is up-to-date, nothing to do
72
80
caseSome(unknownVersion) =>thrownewRuntimeException(s"Unknown version of DB $DB_NAME found, version=$unknownVersion")
73
81
}
@@ -98,6 +106,10 @@ class PgPeersDb(implicit ds: DataSource, lock: PgLock) extends PeersDb with Logg
98
106
statement.setString(1, nodeId.value.toHex)
99
107
statement.executeUpdate()
100
108
}
109
+
using(pg.prepareStatement("DELETE FROM local.peer_storage WHERE node_id = ?")) { statement =>
110
+
statement.setString(1, nodeId.value.toHex)
111
+
statement.executeUpdate()
112
+
}
101
113
}
102
114
}
103
115
@@ -155,4 +167,31 @@ class PgPeersDb(implicit ds: DataSource, lock: PgLock) extends PeersDb with Logg
goto(DISCONNECTED) using DisconnectedData(channels) // when we restart, we will attempt to reconnect right away, but then we'll wait
89
+
goto(DISCONNECTED) using DisconnectedData(channels, PeerStorage(nodeParams.db.peers.getStorage(remoteNodeId), written =true, TimestampMilli.min)) // when we restart, we will attempt to reconnect right away, but then we'll wait
88
90
}
89
91
90
92
when(DISCONNECTED) {
@@ -93,7 +95,7 @@ class Peer(val nodeParams: NodeParams,
caseEvent(Terminated(actor), d: DisconnectedData) if d.channels.values.toSet.contains(actor) =>
99
101
// we have at most 2 ids: a TemporaryChannelId and a FinalChannelId
@@ -461,7 +463,7 @@ class Peer(val nodeParams: NodeParams,
461
463
stopPeer()
462
464
} else {
463
465
d.channels.values.toSet[ActorRef].foreach(_ !INPUT_DISCONNECTED) // we deduplicate with toSet because there might be two entries per channel (tmp id and final id)
464
-
goto(DISCONNECTED) using DisconnectedData(d.channels.collect { case (k: FinalChannelId, v) => (k, v) })
466
+
goto(DISCONNECTED) using DisconnectedData(d.channels.collect { case (k: FinalChannelId, v) => (k, v) }, d.peerStorage)
465
467
}
466
468
467
469
caseEvent(Terminated(actor), d: ConnectedData) if d.channels.values.toSet.contains(actor) =>
@@ -480,7 +482,7 @@ class Peer(val nodeParams: NodeParams,
480
482
log.debug(s"got new connection, killing current one and switching")
d.channels.values.toSet[ActorRef].foreach(_ !INPUT_DISCONNECTED) // we deduplicate with toSet because there might be two entries per channel (tmp id and final id)
channels.values.toSet[ActorRef].foreach(_ !INPUT_RECONNECTED(connectionReady.peerConnection, connectionReady.localInit, connectionReady.remoteInit)) // we deduplicate with toSet because there might be two entries per channel (tmp id and final id)
759
779
@@ -771,7 +791,7 @@ class Peer(val nodeParams: NodeParams,
0 commit comments