1
0
Fork 0
mirror of https://github.com/ACINQ/eclair.git synced 2025-02-23 14:40:34 +01:00

do not sent htlcs after you've sent a close_clearing message

This commit is contained in:
sstone 2016-08-01 18:49:25 +02:00
parent 5036f8118f
commit a01b98022a
3 changed files with 19 additions and 1 deletions

View file

@ -284,6 +284,10 @@ class Channel(val them: ActorRef, val blockchain: ActorRef, val params: OurChann
*/
when(NORMAL) {
case Event(c:CMD_ADD_HTLC, d: DATA_NORMAL) if d.ourClearing.isDefined =>
handleCommandError(sender, new RuntimeException("Cannot sent an update_add_htlc after a close_clearing message"))
stay
case Event(c@CMD_ADD_HTLC(amount, rHash, expiry, nodeIds, origin, id_opt), d@DATA_NORMAL(commitments, _)) =>
Try(Commitments.sendAdd(commitments, c)) match {
case Success((commitments1, add)) => handleCommandSuccess(sender, add, d.copy(commitments = commitments1))

View file

@ -41,7 +41,7 @@ case class TheirCommit(index: Long, spec: CommitmentSpec, txid: BinaryData, thei
/**
* about theirNextCommitInfo:
* we either:
* - have built and sign their next commit tx with their next revocation hash which can now be discarded
* - have built and signed their next commit tx with their next revocation hash which can now be discarded
* - have their next revocation hash
* So, when we've signed and sent a commit message and are waiting for their revocation message,
* theirNextCommitInfo is their next commit tx. The rest of the time, it is their next revocation hash

View file

@ -521,6 +521,20 @@ class NormalStateSpec extends TestKit(ActorSystem("test")) with fixture.FunSuite
}
}
test("do not send htlcs after you've sent a close_clearing message") { case (alice, _, alice2bob, _, alice2blockchain, _) =>
within(30 seconds) {
val sender = TestProbe()
sender.send(alice, CMD_CLOSE(None))
alice2bob.expectMsgType[close_clearing]
val rand = new Random()
val R = rval(rand.nextInt(), rand.nextInt(), rand.nextInt(), rand.nextInt())
val H: sha256_hash = Crypto.sha256(R)
sender.send(alice, CMD_ADD_HTLC(1000000, H, locktime(Blocks(3))))
alice2bob.expectNoMsg(500 milliseconds)
awaitCond(alice.stateName == NORMAL)
}
}
ignore("recv close_clearing (with unacked received htlcs)") { case (alice, bob, alice2bob, bob2alice, alice2blockchain, _) =>
within(30 seconds) {
val sender = TestProbe()