Skip to content

Commit

Permalink
Make frequency of storage DB clean-up configurable
Browse files Browse the repository at this point in the history
Added to the peer storage configuration section of `eclair.conf`.
  • Loading branch information
t-bast authored and thomash-acinq committed Dec 10, 2024
1 parent 797ec8e commit f708e10
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
2 changes: 2 additions & 0 deletions eclair-core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,8 @@ eclair {
// A long delay here guarantees that peers who are offline while their channels are closed will be able to get their funds
// back if they restore from seed on a different device after the channels have been closed.
removal-delay = 30 days
// Frequency at which we clean our DB to remove peer storage from nodes with whom we don't have channels anymore.
cleanup-frequency = 1 day
}
}

Expand Down
8 changes: 5 additions & 3 deletions eclair-core/src/main/scala/fr/acinq/eclair/NodeParams.scala
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ case class PaymentFinalExpiryConf(min: CltvExpiryDelta, max: CltvExpiryDelta) {
}

/**
* @param writeDelay delay before writing the peer's data to disk, which avoids doing multiple writes during bursts of storage updates.
* @param removalDelay we keep our peer's data in our DB even after closing all of our channels with them, up to this duration.
* @param writeDelay delay before writing the peer's data to disk, which avoids doing multiple writes during bursts of storage updates.
* @param removalDelay we keep our peer's data in our DB even after closing all of our channels with them, up to this duration.
* @param cleanUpFrequency frequency at which we go through the DB to remove unused storage.
*/
case class PeerStorageConfig(writeDelay: FiniteDuration, removalDelay: FiniteDuration)
case class PeerStorageConfig(writeDelay: FiniteDuration, removalDelay: FiniteDuration, cleanUpFrequency: FiniteDuration)

object NodeParams extends Logging {

Expand Down Expand Up @@ -690,6 +691,7 @@ object NodeParams extends Logging {
peerStorageConfig = PeerStorageConfig(
writeDelay = FiniteDuration(config.getDuration("peer-storage.write-delay").getSeconds, TimeUnit.SECONDS),
removalDelay = FiniteDuration(config.getDuration("peer-storage.removal-delay").getSeconds, TimeUnit.SECONDS),
cleanUpFrequency = FiniteDuration(config.getDuration("peer-storage.cleanup-frequency").getSeconds, TimeUnit.SECONDS),
)
)
}
Expand Down
2 changes: 1 addition & 1 deletion eclair-core/src/main/scala/fr/acinq/eclair/Setup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ class Setup(val datadir: File,
system.deadLetters
}
_ = if (nodeParams.features.hasFeature(Features.ProvideStorage)) {
system.spawn(Behaviors.supervise(PeerStorageCleaner(nodeParams.db.peers, nodeParams.peerStorageConfig.removalDelay)).onFailure(typed.SupervisorStrategy.restart), name = "peer-storage-cleaner")
system.spawn(Behaviors.supervise(PeerStorageCleaner(nodeParams.db.peers, nodeParams.peerStorageConfig)).onFailure(typed.SupervisorStrategy.restart), name = "peer-storage-cleaner")
}
dbEventHandler = system.actorOf(SimpleSupervisor.props(DbEventHandler.props(nodeParams), "db-event-handler", SupervisorStrategy.Resume))
register = system.actorOf(SimpleSupervisor.props(Register.props(), "register", SupervisorStrategy.Resume))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,27 @@ package fr.acinq.eclair.db

import akka.actor.typed.Behavior
import akka.actor.typed.scaladsl.Behaviors
import fr.acinq.eclair.TimestampSecond

import scala.concurrent.duration.{DurationInt, FiniteDuration}
import fr.acinq.eclair.{PeerStorageConfig, TimestampSecond}

/**
* This actor frequently deletes from our DB peer storage from nodes with whom we don't have channels anymore, after a
* grace period.
*/
object PeerStorageCleaner {
// @formatter:off
sealed trait Command
private case object CleanPeerStorage extends Command
// @formatter:on

def apply(db: PeersDb, removalDelay: FiniteDuration): Behavior[Command] = {
Behaviors.withTimers { timers =>
timers.startTimerWithFixedDelay(CleanPeerStorage, 1 day)
Behaviors.receiveMessage {
case CleanPeerStorage =>
db.removePeerStorage(TimestampSecond.now() - removalDelay)
Behaviors.same
}
def apply(db: PeersDb, config: PeerStorageConfig): Behavior[Command] = {
Behaviors.withTimers { timers =>
timers.startTimerWithFixedDelay(CleanPeerStorage, config.cleanUpFrequency)
Behaviors.receiveMessage {
case CleanPeerStorage =>
db.removePeerStorage(TimestampSecond.now() - config.removalDelay)
Behaviors.same
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ object TestConstants {
willFundRates_opt = Some(defaultLiquidityRates),
peerWakeUpConfig = PeerReadyNotifier.WakeUpConfig(enabled = false, timeout = 30 seconds),
onTheFlyFundingConfig = OnTheFlyFunding.Config(proposalTimeout = 90 seconds),
peerStorageConfig = PeerStorageConfig(writeDelay = 5 seconds, removalDelay = 10 seconds)
peerStorageConfig = PeerStorageConfig(writeDelay = 5 seconds, removalDelay = 10 seconds, cleanUpFrequency = 1 hour)
)

def channelParams: LocalParams = OpenChannelInterceptor.makeChannelParams(
Expand Down Expand Up @@ -418,7 +418,7 @@ object TestConstants {
willFundRates_opt = Some(defaultLiquidityRates),
peerWakeUpConfig = PeerReadyNotifier.WakeUpConfig(enabled = false, timeout = 30 seconds),
onTheFlyFundingConfig = OnTheFlyFunding.Config(proposalTimeout = 90 seconds),
peerStorageConfig = PeerStorageConfig(writeDelay = 5 seconds, removalDelay = 10 seconds)
peerStorageConfig = PeerStorageConfig(writeDelay = 5 seconds, removalDelay = 10 seconds, cleanUpFrequency = 1 hour)
)

def channelParams: LocalParams = OpenChannelInterceptor.makeChannelParams(
Expand Down

0 comments on commit f708e10

Please sign in to comment.