mirror of
https://github.com/ACINQ/eclair.git
synced 2024-11-20 10:39:19 +01:00
only forward cross-signed htlcs
This commit is contained in:
parent
3b65269c9a
commit
f061f59803
@ -240,7 +240,7 @@ class Channel(val remote: ActorRef, val blockchain: ActorRef, router: ActorRef,
|
||||
|
||||
val commitments = Commitments(params.localParams, params.remoteParams,
|
||||
LocalCommit(0, localSpec, PublishableTxs(signedLocalCommitTx, Nil)), RemoteCommit(0, remoteSpec, remoteCommitTx.tx.txid, remoteFirstPerCommitmentPoint),
|
||||
LocalChanges(Nil, Nil, Nil), RemoteChanges(Nil, Nil),
|
||||
LocalChanges(Nil, Nil, Nil), RemoteChanges(Nil, Nil, Nil),
|
||||
localNextHtlcId = 0L, remoteNextHtlcId = 0L,
|
||||
remoteNextCommitInfo = Right(null), // TODO: we will receive their next per-commitment point in the next message, so we temporarily put an empty byte array
|
||||
commitInput, ShaChain.init, channelId = 0) // TODO: we will compute the channelId at the next step, so we temporarily put 0
|
||||
@ -272,7 +272,7 @@ class Channel(val remote: ActorRef, val blockchain: ActorRef, router: ActorRef,
|
||||
|
||||
val commitments = Commitments(params.localParams, params.remoteParams,
|
||||
LocalCommit(0, localSpec, PublishableTxs(signedLocalCommitTx, Nil)), remoteCommit,
|
||||
LocalChanges(Nil, Nil, Nil), RemoteChanges(Nil, Nil),
|
||||
LocalChanges(Nil, Nil, Nil), RemoteChanges(Nil, Nil, Nil),
|
||||
localNextHtlcId = 0L, remoteNextHtlcId = 0L,
|
||||
remoteNextCommitInfo = Right(null), // TODO: we will receive their next per-commitment point in the next message, so we temporarily put an empty byte array
|
||||
commitInput, ShaChain.init, channelId = 0)
|
||||
@ -456,10 +456,6 @@ class Channel(val remote: ActorRef, val blockchain: ActorRef, router: ActorRef,
|
||||
Try(Commitments.receiveCommit(d.commitments, msg)) match {
|
||||
case Success((commitments1, revocation)) =>
|
||||
remote ! revocation
|
||||
// now that we have their sig, we should propagate the htlcs newly received
|
||||
(commitments1.localCommit.spec.htlcs -- d.commitments.localCommit.spec.htlcs)
|
||||
.filter(_.direction == IN)
|
||||
.foreach(htlc => relayer ! htlc.add)
|
||||
context.system.eventStream.publish(ChannelSignatureReceived(self, commitments1))
|
||||
stay using d.copy(commitments = commitments1)
|
||||
case Failure(cause) => handleLocalError(cause, d)
|
||||
@ -470,6 +466,9 @@ class Channel(val remote: ActorRef, val blockchain: ActorRef, router: ActorRef,
|
||||
// => all our changes have been acked
|
||||
Try(Commitments.receiveRevocation(d.commitments, msg)) match {
|
||||
case Success(commitments1) =>
|
||||
// we forward HTLCs only when they have been committed by both sides
|
||||
// it always happen when we receive a revocation, because, we always sign our changes before they sign them
|
||||
val newlySignedHtlcs = d.commitments.remoteChanges.signed.collect { case htlc: UpdateAddHtlc => relayer ! htlc}
|
||||
stay using d.copy(commitments = commitments1)
|
||||
case Failure(cause) => handleLocalError(cause, d)
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ import grizzled.slf4j.Logging
|
||||
case class LocalChanges(proposed: List[UpdateMessage], signed: List[UpdateMessage], acked: List[UpdateMessage]) {
|
||||
def all: List[UpdateMessage] = proposed ++ signed ++ acked
|
||||
}
|
||||
case class RemoteChanges(proposed: List[UpdateMessage], acked: List[UpdateMessage])
|
||||
case class RemoteChanges(proposed: List[UpdateMessage], acked: List[UpdateMessage], signed: List[UpdateMessage])
|
||||
case class Changes(ourChanges: LocalChanges, theirChanges: RemoteChanges)
|
||||
case class HtlcTxAndSigs(txinfo: TransactionWithInputInfo, localSig: BinaryData, remoteSig: BinaryData)
|
||||
case class PublishableTxs(commitTx: CommitTx, htlcTxsAndSigs: Seq[HtlcTxAndSigs])
|
||||
@ -207,7 +207,7 @@ object Commitments extends Logging {
|
||||
val commitments1 = commitments.copy(
|
||||
remoteNextCommitInfo = Left(RemoteCommit(remoteCommit.index + 1, spec, remoteCommitTx.tx.txid, remoteNextPerCommitmentPoint)),
|
||||
localChanges = localChanges.copy(proposed = Nil, signed = localChanges.proposed),
|
||||
remoteChanges = remoteChanges.copy(acked = Nil))
|
||||
remoteChanges = remoteChanges.copy(acked = Nil, signed = remoteChanges.acked))
|
||||
(commitments1, commitSig)
|
||||
case Left(_) =>
|
||||
throw new RuntimeException("cannot sign until next revocation hash is received")
|
||||
@ -314,6 +314,7 @@ object Commitments extends Logging {
|
||||
|
||||
commitments.copy(
|
||||
localChanges = localChanges.copy(signed = Nil, acked = localChanges.acked ++ localChanges.signed),
|
||||
remoteChanges = remoteChanges.copy(signed = Nil),
|
||||
remoteCommit = theirNextCommit,
|
||||
remoteNextCommitInfo = Right(revocation.nextPerCommitmentPoint),
|
||||
remotePerCommitmentSecrets = commitments.remotePerCommitmentSecrets.addHash(revocation.perCommitmentSecret, 0xFFFFFFFFFFFFL - commitments.remoteCommit.index))
|
||||
|
@ -34,15 +34,11 @@ class LocalPaymentHandler extends Actor with ActorLogging {
|
||||
|
||||
case htlc: UpdateAddHtlc if h2r.contains(htlc.paymentHash) =>
|
||||
val r = h2r(htlc.paymentHash)
|
||||
sender ! CMD_SIGN
|
||||
sender ! CMD_FULFILL_HTLC(htlc.id, r)
|
||||
sender ! CMD_SIGN
|
||||
sender ! CMD_FULFILL_HTLC(htlc.id, r, commit = true)
|
||||
context.become(run(h2r - htlc.paymentHash))
|
||||
|
||||
case htlc: UpdateAddHtlc =>
|
||||
sender ! CMD_SIGN
|
||||
sender ! CMD_FAIL_HTLC(htlc.id, "unkown H")
|
||||
sender ! CMD_SIGN
|
||||
sender ! CMD_FAIL_HTLC(htlc.id, "unkown H", commit = true)
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user