Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions eclair-core/src/main/scala/fr/acinq/eclair/Eclair.scala
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ trait Eclair {

def updateRelayFee(nodes: List[PublicKey], feeBase: MilliSatoshi, feeProportionalMillionths: Long)(implicit timeout: Timeout): Future[Map[ApiTypes.ChannelIdentifier, Either[Throwable, CommandResponse[CMD_UPDATE_RELAY_FEE]]]]

def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GETINFO]]
def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GET_CHANNEL_INFO]]

def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GETINFO]]
def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GET_CHANNEL_INFO]]

def peers()(implicit timeout: Timeout): Future[Iterable[PeerInfo]]

Expand Down Expand Up @@ -216,22 +216,22 @@ class EclairImpl(appKit: Kit) extends Eclair with Logging {
.map(_.filter(n => nodeIds_opt.forall(_.contains(n.nodeId))))
}

override def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GETINFO]] = {
override def channelsInfo(toRemoteNode_opt: Option[PublicKey])(implicit timeout: Timeout): Future[Iterable[RES_GET_CHANNEL_INFO]] = {
val futureResponse = toRemoteNode_opt match {
case Some(pk) => (appKit.register ? Symbol("channelsTo")).mapTo[Map[ByteVector32, PublicKey]].map(_.filter(_._2 == pk).keys)
case None => (appKit.register ? Symbol("channels")).mapTo[Map[ByteVector32, ActorRef]].map(_.keys)
}

for {
channelIds <- futureResponse
channels <- Future.sequence(channelIds.map(channelId => sendToChannel[CMD_GETINFO, CommandResponse[CMD_GETINFO]](Left(channelId), CMD_GETINFO(ActorRef.noSender))))
channels <- Future.sequence(channelIds.map(channelId => sendToChannel[CMD_GET_CHANNEL_INFO, CommandResponse[CMD_GET_CHANNEL_INFO]](Left(channelId), CMD_GET_CHANNEL_INFO(ActorRef.noSender))))
} yield channels.collect {
case properResponse: RES_GETINFO => properResponse
case properResponse: RES_GET_CHANNEL_INFO => properResponse
}
}

override def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GETINFO]] = {
sendToChannel[CMD_GETINFO, CommandResponse[CMD_GETINFO]](channel, CMD_GETINFO(ActorRef.noSender))
override def channelInfo(channel: ApiTypes.ChannelIdentifier)(implicit timeout: Timeout): Future[CommandResponse[CMD_GET_CHANNEL_INFO]] = {
sendToChannel[CMD_GET_CHANNEL_INFO, CommandResponse[CMD_GET_CHANNEL_INFO]](channel, CMD_GET_CHANNEL_INFO(ActorRef.noSender))
}

override def allChannels()(implicit timeout: Timeout): Future[Iterable[ChannelDesc]] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import fr.acinq.eclair.balance.CheckBalance.GlobalBalance
import fr.acinq.eclair.balance.Monitoring.{Metrics, Tags}
import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinCoreClient
import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinCoreClient.Utxo
import fr.acinq.eclair.channel.HasCommitments
import fr.acinq.eclair.channel.PersistentChannelData
import fr.acinq.eclair.db.Databases
import grizzled.slf4j.Logger
import org.json4s.JsonAST.JInt
Expand All @@ -25,7 +25,7 @@ object BalanceActor {
// @formatter:off
sealed trait Command
private final case object TickBalance extends Command
final case class GetGlobalBalance(replyTo: ActorRef[Try[GlobalBalance]], channels: Map[ByteVector32, HasCommitments]) extends Command
final case class GetGlobalBalance(replyTo: ActorRef[Try[GlobalBalance]], channels: Map[ByteVector32, PersistentChannelData]) extends Command
private final case class WrappedChannels(wrapped: ChannelsListener.GetChannelsResponse) extends Command
private final case class WrappedGlobalBalanceWithChannels(wrapped: Try[GlobalBalance], channelsCount: Int) extends Command
private final case class WrappedUtxoInfo(wrapped: Try[UtxoInfo]) extends Command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import akka.actor.typed.scaladsl.{ActorContext, Behaviors}
import fr.acinq.bitcoin.scalacompat.ByteVector32
import fr.acinq.eclair.balance.ChannelsListener._
import fr.acinq.eclair.channel.Helpers.Closing
import fr.acinq.eclair.channel.{ChannelPersisted, ChannelRestored, HasCommitments}
import fr.acinq.eclair.channel.{ChannelPersisted, ChannelRestored, PersistentChannelData}

import scala.concurrent.Promise
import scala.concurrent.duration.DurationInt
Expand All @@ -18,14 +18,14 @@ object ChannelsListener {

// @formatter:off
sealed trait Command
private final case class ChannelData(channelId: ByteVector32, channel: akka.actor.ActorRef, data: HasCommitments) extends Command
private final case class ChannelData(channelId: ByteVector32, channel: akka.actor.ActorRef, data: PersistentChannelData) extends Command
private final case class ChannelDied(channelId: ByteVector32) extends Command
final case class GetChannels(replyTo: typed.ActorRef[GetChannelsResponse]) extends Command
final case object SendDummyEvent extends Command
final case object DummyEvent extends Command
// @formatter:on

case class GetChannelsResponse(channels: Map[ByteVector32, HasCommitments])
case class GetChannelsResponse(channels: Map[ByteVector32, PersistentChannelData])

def apply(ready: Promise[Done]): Behavior[Command] =
Behaviors.setup { context =>
Expand Down Expand Up @@ -55,7 +55,7 @@ private class ChannelsListener(context: ActorContext[Command]) {

private val log = context.log

def running(channels: Map[ByteVector32, HasCommitments]): Behavior[Command] =
def running(channels: Map[ByteVector32, PersistentChannelData]): Behavior[Command] =
Behaviors.receiveMessage {
case ChannelData(channelId, channel, data) =>
Closing.isClosed(data, additionalConfirmedTx_opt = None) match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fr.acinq.eclair.balance
import com.softwaremill.quicklens._
import fr.acinq.bitcoin.scalacompat.{Btc, ByteVector32, Satoshi, SatoshiLong}
import fr.acinq.eclair.blockchain.bitcoind.rpc.BitcoinCoreClient
import fr.acinq.eclair.channel.ChannelStateData._
import fr.acinq.eclair.channel.Helpers.Closing
import fr.acinq.eclair.channel.Helpers.Closing.{CurrentRemoteClose, LocalClose, NextRemoteClose, RemoteClose}
import fr.acinq.eclair.channel._
Expand Down Expand Up @@ -186,8 +187,8 @@ object CheckBalance {
*
* Assumptions:
* - If the commitment transaction hasn't been published, we simply take our local amount (and htlc amount in states
* where they may exist, namely [[NORMAL]] and [[SHUTDOWN]]).
* - In [[CLOSING]] state:
* where they may exist, namely [[ChannelState.NORMAL]] and [[ChannelState.SHUTDOWN]]).
* - In [[ChannelState.CLOSING]] state:
* - If we know for sure we are in a mutual close scenario, then we don't count the amount, because the tx will
* already have been published.
* - If we know for sure we are in a local, then we take the amounts based on the outputs of
Expand All @@ -197,7 +198,7 @@ object CheckBalance {
* - In the other cases, we simply take our local amount
* - TODO?: we disregard anchor outputs
*/
def computeOffChainBalance(channels: Iterable[HasCommitments], knownPreimages: Set[(ByteVector32, Long)]): OffChainBalance = {
def computeOffChainBalance(channels: Iterable[PersistentChannelData], knownPreimages: Set[(ByteVector32, Long)]): OffChainBalance = {
channels
.foldLeft(OffChainBalance()) {
case (r, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => r.modify(_.waitForFundingConfirmed).using(updateMainBalance(d.commitments.localCommit))
Expand Down Expand Up @@ -293,7 +294,7 @@ object CheckBalance {
val total: Btc = onChain.total + offChain.total
}

def computeGlobalBalance(channels: Map[ByteVector32, HasCommitments], db: Databases, bitcoinClient: BitcoinCoreClient)(implicit ec: ExecutionContext): Future[GlobalBalance] = for {
def computeGlobalBalance(channels: Map[ByteVector32, PersistentChannelData], db: Databases, bitcoinClient: BitcoinCoreClient)(implicit ec: ExecutionContext): Future[GlobalBalance] = for {
onChain <- CheckBalance.computeOnChainBalance(bitcoinClient)
knownPreimages = db.pendingCommands.listSettlementCommands().collect { case (channelId, cmd: CMD_FULFILL_HTLC) => (channelId, cmd.id) }.toSet
offChainRaw = CheckBalance.computeOffChainBalance(channels.values, knownPreimages)
Expand Down
Loading