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
88
+
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
89
}
89
90
90
91
when(DISCONNECTED) {
@@ -93,7 +94,7 @@ class Peer(val nodeParams: NodeParams,
caseEvent(Terminated(actor), d: DisconnectedData) if d.channels.values.toSet.contains(actor) =>
99
100
// we have at most 2 ids: a TemporaryChannelId and a FinalChannelId
@@ -465,7 +466,7 @@ class Peer(val nodeParams: NodeParams,
465
466
stopPeer()
466
467
} else {
467
468
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)
468
-
goto(DISCONNECTED) using DisconnectedData(d.channels.collect { case (k: FinalChannelId, v) => (k, v) })
469
+
goto(DISCONNECTED) using DisconnectedData(d.channels.collect { case (k: FinalChannelId, v) => (k, v) }, d.peerStorage)
469
470
}
470
471
471
472
caseEvent(Terminated(actor), d: ConnectedData) if d.channels.values.toSet.contains(actor) =>
@@ -484,7 +485,7 @@ class Peer(val nodeParams: NodeParams,
484
485
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)
763
782
@@ -775,7 +794,7 @@ class Peer(val nodeParams: NodeParams,
0 commit comments