mirror of
https://github.com/ACINQ/eclair.git
synced 2025-02-22 14:22:39 +01:00
moved extractOutgoingMessages to Helpers
This commit is contained in:
parent
c017a9a217
commit
f3db1ea15c
3 changed files with 44 additions and 54 deletions
|
@ -834,11 +834,11 @@ class Channel(nodeParams: NodeParams, remoteNodeId: PublicKey, blockchain: Actor
|
|||
}
|
||||
|
||||
onTransition {
|
||||
case previousState -> currentState =>
|
||||
if (currentState != previousState) {
|
||||
context.system.eventStream.publish(ChannelStateChanged(self, context.parent, remoteNodeId, previousState, currentState, nextStateData))
|
||||
case state -> nextState =>
|
||||
if (nextState != state) {
|
||||
context.system.eventStream.publish(ChannelStateChanged(self, context.parent, remoteNodeId, state, nextState, nextStateData))
|
||||
}
|
||||
forwarder ! StoreAndForward(previousState, currentState, stateData, nextStateData)
|
||||
forwarder ! StoreAndForward(nextStateData, Helpers.extractOutgoingMessages(state, nextState, stateData, nextStateData))
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -2,20 +2,19 @@ package fr.acinq.eclair.channel
|
|||
|
||||
import akka.actor.{Actor, ActorLogging, ActorRef}
|
||||
import fr.acinq.eclair.NodeParams
|
||||
import fr.acinq.eclair.db.Dbs
|
||||
import fr.acinq.eclair.wire.{LightningMessage, Error}
|
||||
import fr.acinq.eclair.wire.{Error, LightningMessage}
|
||||
|
||||
/**
|
||||
* Created by fabrice on 27/02/17.
|
||||
*/
|
||||
|
||||
case class StoreAndForward(previousState: State, nextState: State, previousData: Data, currentData: Data)
|
||||
case class StoreAndForward(stateData: Data, outgoing: Seq[LightningMessage])
|
||||
|
||||
class Forwarder(nodeParams: NodeParams) extends Actor with ActorLogging {
|
||||
|
||||
def receive = {
|
||||
case destination: ActorRef => context become main(destination)
|
||||
}
|
||||
// caller is responsible for sending the destination before anything else
|
||||
// the general case is that destination can die anytime and it is managed by the caller
|
||||
def receive = main(context.system.deadLetters)
|
||||
|
||||
def main(destination: ActorRef): Receive = {
|
||||
|
||||
|
@ -23,48 +22,11 @@ class Forwarder(nodeParams: NodeParams) extends Actor with ActorLogging {
|
|||
|
||||
case error: Error => destination ! error
|
||||
|
||||
case StoreAndForward(previousState, nextState, previousData, nextData) =>
|
||||
val outgoing = Forwarder.extractOutgoingMessages(previousState, nextState, previousData, nextData)
|
||||
if (outgoing.size > 0) {
|
||||
log.debug(s"sending ${outgoing.map(_.getClass.getSimpleName).mkString(" ")}")
|
||||
case StoreAndForward(stateData: HasCommitments, outgoing) =>
|
||||
nodeParams.channelsDb.put(stateData.channelId, stateData)
|
||||
outgoing.foreach(destination forward _)
|
||||
|
||||
case StoreAndForward(_, outgoing) =>
|
||||
outgoing.foreach(destination forward _)
|
||||
}
|
||||
val (previousId, nextId) = (Helpers.getChannelId(previousData), Helpers.getChannelId(nextData))
|
||||
nodeParams.channelsDb.put(nextId, nextData)
|
||||
if (previousId != nextId) {
|
||||
nodeParams.channelsDb.delete(previousId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Forwarder {
|
||||
|
||||
def extractOutgoingMessages(previousState: State, nextState: State, previousData: Data, currentData: Data): Seq[LightningMessage] = {
|
||||
previousState match {
|
||||
case OFFLINE =>
|
||||
(previousData, currentData) match {
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.lastSent.right.toSeq // NB: if we re-send the message and the other party didn't receive it they will return an error (see #120)
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_LOCKED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_ANN_SIGNATURES) => d.lastSent :: Nil
|
||||
case (_: HasCommitments, d2: HasCommitments)=> d2.commitments.unackedMessages
|
||||
case _ => Nil
|
||||
}
|
||||
case _ =>
|
||||
(previousData, currentData) match {
|
||||
case (_, Nothing) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_OPEN_CHANNEL) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_ACCEPT_CHANNEL) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_INTERNAL) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CREATED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_SIGNED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.lastSent.right.toOption.map(_ :: Nil).getOrElse(Nil)
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_LOCKED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_ANN_SIGNATURES) => d.lastSent :: Nil
|
||||
case (_, d: DATA_CLOSING) => Nil
|
||||
case (d1: HasCommitments, d2: HasCommitments) => d2.commitments.unackedMessages diff d1.commitments.unackedMessages
|
||||
case (_, _: HasCommitments) => ??? // eg: goto(CLOSING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ import fr.acinq.eclair.crypto.Generators
|
|||
import fr.acinq.eclair.transactions.Scripts._
|
||||
import fr.acinq.eclair.transactions.Transactions._
|
||||
import fr.acinq.eclair.transactions._
|
||||
import fr.acinq.eclair.wire.{ClosingSigned, UpdateAddHtlc, UpdateFulfillHtlc}
|
||||
import fr.acinq.eclair.wire.{ClosingSigned, LightningMessage, UpdateAddHtlc, UpdateFulfillHtlc}
|
||||
import grizzled.slf4j.Logging
|
||||
|
||||
import scala.util.{Failure, Success, Try}
|
||||
|
@ -40,6 +40,34 @@ object Helpers {
|
|||
require(reserveToFundingRatio <= nodeParams.maxReserveToFundingRatio, s"channelReserveSatoshis too high: ratio=$reserveToFundingRatio max=${nodeParams.maxReserveToFundingRatio}")
|
||||
}
|
||||
|
||||
def extractOutgoingMessages(currentState: State, nextState: State, currentData: Data, nextData: Data): Seq[LightningMessage] = {
|
||||
currentState match {
|
||||
case OFFLINE =>
|
||||
(currentData, nextData) match {
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.lastSent.right.toSeq // NB: if we re-send the message and the other party didn't receive it they will return an error (see #120)
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_LOCKED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_ANN_SIGNATURES) => d.lastSent :: Nil
|
||||
case (_: HasCommitments, d2: HasCommitments)=> d2.commitments.unackedMessages
|
||||
case _ => Nil
|
||||
}
|
||||
case _ =>
|
||||
(currentData, nextData) match {
|
||||
case (_, Nothing) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_OPEN_CHANNEL) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_ACCEPT_CHANNEL) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_INTERNAL) => Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CREATED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_SIGNED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_CONFIRMED) => d.lastSent.right.toOption.map(_ :: Nil).getOrElse(Nil)
|
||||
case (_, d: DATA_WAIT_FOR_FUNDING_LOCKED) => d.lastSent :: Nil
|
||||
case (_, d: DATA_WAIT_FOR_ANN_SIGNATURES) => d.lastSent :: Nil
|
||||
case (_, d: DATA_CLOSING) => Nil
|
||||
case (d1: HasCommitments, d2: HasCommitments) => d2.commitments.unackedMessages diff d1.commitments.unackedMessages
|
||||
case (_, _: HasCommitments) => ??? // eg: goto(CLOSING)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
object Funding {
|
||||
|
||||
def makeFundingInputInfo(fundingTxId: BinaryData, fundingTxOutputIndex: Int, fundingSatoshis: Satoshi, fundingPubkey1: PublicKey, fundingPubkey2: PublicKey): InputInfo = {
|
||||
|
|
Loading…
Add table
Reference in a new issue