1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-03-13 03:14:26 +01:00

Add logs and exception for checkDBCompatibility

This commit is contained in:
Dominique Padiou 2024-10-16 17:10:28 +02:00
parent 33a352e4a0
commit 83dd1b96ac
No known key found for this signature in database
GPG key ID: 574C8C6A1673E987
4 changed files with 12 additions and 5 deletions

View file

@ -30,7 +30,7 @@ object DBCompatChecker extends Logging {
def checkDBCompatibility(nodeParams: NodeParams): Unit = def checkDBCompatibility(nodeParams: NodeParams): Unit =
Try(nodeParams.db.channels.listLocalChannels()) match { Try(nodeParams.db.channels.listLocalChannels()) match {
case Success(_) => {} case Success(_) => {}
case Failure(_) => throw IncompatibleDBException case Failure(exception) => throw IncompatibleDBException(exception)
} }
/** /**

View file

@ -303,6 +303,6 @@ case object BitcoinWalletDisabledException extends RuntimeException("bitcoind mu
case object EmptyAPIPasswordException extends RuntimeException("must set a password for the json-rpc api") case object EmptyAPIPasswordException extends RuntimeException("must set a password for the json-rpc api")
case object IncompatibleDBException extends RuntimeException("database is not compatible with this version of eclair") case class IncompatibleDBException(cause: Throwable) extends RuntimeException("database is not compatible with this version of eclair", cause)
case object IncompatibleNetworkDBException extends RuntimeException("network database is not compatible with this version of eclair") case object IncompatibleNetworkDBException extends RuntimeException("network database is not compatible with this version of eclair")

View file

@ -65,10 +65,17 @@ trait JdbcUtils {
* *
* TODO: we should use an scala.Iterator instead * TODO: we should use an scala.Iterator instead
*/ */
def codecSequence[T](rs: ResultSet, codec: Codec[T]): Seq[T] = { def codecSequence[T](rs: ResultSet, codec: Codec[T], onError: String => Unit = { _ => Unit }): Seq[T] = {
var q: Queue[T] = Queue() var q: Queue[T] = Queue()
while (rs.next()) { while (rs.next()) {
q = q :+ codec.decode(BitVector(rs.getBytes("data"))).require.value val data = BitVector(rs.getBytes("data"))
try {
q = q :+ codec.decode(data).require.value
} catch {
case t: Throwable =>
onError(s"unreadable data=${data.toHex}")
throw t
}
} }
q q
} }

View file

@ -98,7 +98,7 @@ class SqliteChannelsDb(sqlite: Connection) extends ChannelsDb with Logging {
override def listLocalChannels(): Seq[HasCommitments] = withMetrics("channels/list-local-channels") { override def listLocalChannels(): Seq[HasCommitments] = withMetrics("channels/list-local-channels") {
using(sqlite.createStatement) { statement => using(sqlite.createStatement) { statement =>
val rs = statement.executeQuery("SELECT data FROM local_channels WHERE is_closed=0") val rs = statement.executeQuery("SELECT data FROM local_channels WHERE is_closed=0")
codecSequence(rs, stateDataCodec) codecSequence(rs, stateDataCodec, onError = { message => logger.error(message) })
} }
} }