Skip to content

Commit

Permalink
core: reaload offers from db if any
Browse files Browse the repository at this point in the history
When we store offers, we should also restore the status of the
offer manager when we are restarting the node implementation.

Signed-off-by: Vincenzo Palazzo <[email protected]>
  • Loading branch information
vincenzopalazzo committed Jan 6, 2025
1 parent bdb5677 commit 623d8ba
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions modules/core/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ class Peer(
previousState = it
}
}

launch {
reloadOffersFromPersistance()
}
}

data class ConnectionJob(val job: Job, val socket: TcpSocket) {
Expand Down Expand Up @@ -752,6 +756,16 @@ class Peer(
return offer
}

/**
* Reload the offers from the database to allow to reuse custom offers across restarts.
*/
suspend fun reloadOffersFromPersistance() {
val offers = db.offers.listOffers()
offers.forEach { (pathId, offer) ->
offerManager.registerOffer(offer, pathId.value)
}
}

// The (node_id, fcm_token) tuple only needs to be registered once.
// And after that, only if the tuple changes (e.g. different fcm_token).
fun registerFcmToken(token: String?) {
Expand Down

0 comments on commit 623d8ba

Please sign in to comment.