@@ -346,6 +346,8 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
346346 CommitSig (channelId, IndividualSignature (randomBytes64()), Nil ),
347347 )
348348 probe.send(peerConnection, CommitSigBatch (commitSigs))
349+ // We insert a start_batch message.
350+ transport.expectMsg(StartBatch (channelId, batchSize = 3 , TlvStream (StartBatchTlv .MessageType (132 ))))
349351 commitSigs.foreach(commitSig => transport.expectMsg(commitSig))
350352 transport.expectNoMessage(100 millis)
351353 }
@@ -357,8 +359,8 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
357359 // We receive a batch of commit_sig messages from a first channel.
358360 val channelId1 = randomBytes32()
359361 val commitSigs1 = Seq (
360- CommitSig (channelId1, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
361- CommitSig (channelId1, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
362+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
363+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
362364 )
363365 transport.send(peerConnection, commitSigs1.head)
364366 transport.expectMsg(TransportHandler .ReadAck (commitSigs1.head))
@@ -370,9 +372,9 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
370372 // We receive a batch of commit_sig messages from a second channel.
371373 val channelId2 = randomBytes32()
372374 val commitSigs2 = Seq (
373- CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 3 ),
374- CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 3 ),
375- CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 3 ),
375+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 3 )) ),
376+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 3 )) ),
377+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 3 )) ),
376378 )
377379 commitSigs2.dropRight(1 ).foreach(commitSig => {
378380 transport.send(peerConnection, commitSig)
@@ -385,8 +387,8 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
385387
386388 // We receive another batch of commit_sig messages from the first channel, with unrelated messages in the batch.
387389 val commitSigs3 = Seq (
388- CommitSig (channelId1, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
389- CommitSig (channelId1, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
390+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
391+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
390392 )
391393 transport.send(peerConnection, commitSigs3.head)
392394 transport.expectMsg(TransportHandler .ReadAck (commitSigs3.head))
@@ -406,9 +408,9 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
406408 // We start receiving a batch of commit_sig messages from the first channel, interleaved with a batch from the second
407409 // channel, which is not supported.
408410 val commitSigs4 = Seq (
409- CommitSig (channelId1, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
410- CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
411- CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 2 ),
411+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
412+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
413+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 2 )) ),
412414 )
413415 transport.send(peerConnection, commitSigs4.head)
414416 transport.expectMsg(TransportHandler .ReadAck (commitSigs4.head))
@@ -421,14 +423,143 @@ class PeerConnectionSpec extends TestKitBaseClass with FixtureAnyFunSuiteLike wi
421423 peer.expectMsg(CommitSigBatch (commitSigs4.tail))
422424
423425 // We receive a batch that exceeds our threshold: we process them individually.
424- val invalidCommitSigs = (0 until 30 ).map(_ => CommitSig (channelId2, randomTxId(), IndividualSignature (randomBytes64()), Nil , batchSize = 30 ))
426+ val invalidCommitSigs = (0 until 30 ).map(_ => CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream ( CommitSigTlv . ExperimentalBatchTlv ( 30 )) ))
425427 invalidCommitSigs.foreach(commitSig => {
426428 transport.send(peerConnection, commitSig)
427429 transport.expectMsg(TransportHandler .ReadAck (commitSig))
428430 peer.expectMsg(commitSig)
429431 })
430432 }
431433
434+ test(" receive batch of commit_sig messages" ) { f =>
435+ import f ._
436+ connect(nodeParams, remoteNodeId, switchboard, router, connection, transport, peerConnection, peer)
437+
438+ // A first channel has a pending splice.
439+ val channelId1 = randomBytes32()
440+ val startBatch1 = StartBatch (channelId1, batchSize = 2 , TlvStream (StartBatchTlv .MessageType (132 )))
441+ val commitSigs1 = Seq (
442+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
443+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
444+ )
445+ transport.send(peerConnection, startBatch1)
446+ transport.expectMsg(TransportHandler .ReadAck (startBatch1))
447+ transport.send(peerConnection, commitSigs1(0 ))
448+ transport.expectMsg(TransportHandler .ReadAck (commitSigs1(0 )))
449+ peer.expectNoMessage(100 millis)
450+ transport.send(peerConnection, commitSigs1(1 ))
451+ transport.expectMsg(TransportHandler .ReadAck (commitSigs1(1 )))
452+ peer.expectMsg(CommitSigBatch (commitSigs1))
453+
454+ // Another channel has 2 pending splices.
455+ val channelId2 = randomBytes32()
456+ val startBatch2 = StartBatch (channelId2, batchSize = 3 , TlvStream (StartBatchTlv .MessageType (132 )))
457+ val commitSigs2 = Seq (
458+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
459+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
460+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
461+ )
462+ transport.send(peerConnection, startBatch2)
463+ transport.expectMsg(TransportHandler .ReadAck (startBatch2))
464+ transport.send(peerConnection, commitSigs2(0 ))
465+ transport.expectMsg(TransportHandler .ReadAck (commitSigs2(0 )))
466+ transport.send(peerConnection, commitSigs2(1 ))
467+ transport.expectMsg(TransportHandler .ReadAck (commitSigs2(1 )))
468+ peer.expectNoMessage(100 millis)
469+ transport.send(peerConnection, commitSigs2(2 ))
470+ transport.expectMsg(TransportHandler .ReadAck (commitSigs2(2 )))
471+ peer.expectMsg(CommitSigBatch (commitSigs2))
472+
473+ // We receive another batch of commit_sig messages for the first channel.
474+ val startBatch3 = StartBatch (channelId1, batchSize = 3 , TlvStream (StartBatchTlv .MessageType (132 )))
475+ val commitSigs3 = Seq (
476+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
477+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
478+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
479+ )
480+ transport.send(peerConnection, startBatch3)
481+ transport.expectMsg(TransportHandler .ReadAck (startBatch3))
482+ transport.send(peerConnection, commitSigs3(0 ))
483+ transport.expectMsg(TransportHandler .ReadAck (commitSigs3(0 )))
484+ transport.send(peerConnection, commitSigs3(1 ))
485+ transport.expectMsg(TransportHandler .ReadAck (commitSigs3(1 )))
486+ peer.expectNoMessage(100 millis)
487+ transport.send(peerConnection, commitSigs3(2 ))
488+ transport.expectMsg(TransportHandler .ReadAck (commitSigs3(2 )))
489+ peer.expectMsg(CommitSigBatch (commitSigs3))
490+
491+ // We reject batches that mix unrelated channels.
492+ val startBatch4 = StartBatch (channelId1, batchSize = 3 , TlvStream (StartBatchTlv .MessageType (132 )))
493+ val commitSigs4 = Seq (
494+ CommitSig (channelId1, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
495+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
496+ CommitSig (channelId2, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId()))),
497+ )
498+ transport.send(peerConnection, startBatch4)
499+ transport.expectMsg(TransportHandler .ReadAck (startBatch4))
500+ transport.send(peerConnection, commitSigs4(0 ))
501+ transport.expectMsg(TransportHandler .ReadAck (commitSigs4(0 )))
502+ peer.expectNoMessage(100 millis)
503+ transport.send(peerConnection, commitSigs4(1 ))
504+ transport.expectMsg(TransportHandler .ReadAck (commitSigs4(1 )))
505+ peer.expectMsg(CommitSigBatch (commitSigs4.take(1 )))
506+ peer.expectMsg(commitSigs4(1 ))
507+ peer.expectNoMessage(100 millis)
508+ transport.send(peerConnection, commitSigs4(2 ))
509+ transport.expectMsg(TransportHandler .ReadAck (commitSigs4(2 )))
510+ peer.expectMsg(commitSigs4(2 ))
511+ peer.expectNoMessage(100 millis)
512+ }
513+
514+ test(" receive unsupported batch of channel messages" ) { f =>
515+ import f ._
516+ connect(nodeParams, remoteNodeId, switchboard, router, connection, transport, peerConnection, peer)
517+
518+ // We receive a batch of splice_locked messages: we forward them individually.
519+ val channelId = randomBytes32()
520+ val startBatch1 = StartBatch (channelId, batchSize = 2 ) // note that start_batch doesn't indicate the message type
521+ val spliceLocked1 = SpliceLocked (channelId, randomTxId())
522+ val spliceLocked2 = SpliceLocked (channelId, randomTxId())
523+ transport.send(peerConnection, startBatch1)
524+ transport.expectMsg(TransportHandler .ReadAck (startBatch1))
525+ transport.expectMsgType[Warning ]
526+ transport.send(peerConnection, spliceLocked1)
527+ transport.expectMsg(TransportHandler .ReadAck (spliceLocked1))
528+ peer.expectMsg(spliceLocked1)
529+ transport.send(peerConnection, spliceLocked2)
530+ transport.expectMsg(TransportHandler .ReadAck (spliceLocked2))
531+ peer.expectMsg(spliceLocked2)
532+
533+ // We receive a batch containing commit_sig and an unrelated message.
534+ val startBatch2 = StartBatch (channelId, batchSize = 3 , TlvStream (StartBatchTlv .MessageType (132 )))
535+ val commitSig1 = CommitSig (channelId, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId())))
536+ val commitSig2 = CommitSig (channelId, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId())))
537+ val spliceLocked3 = SpliceLocked (channelId, randomTxId())
538+ transport.send(peerConnection, startBatch2)
539+ transport.expectMsg(TransportHandler .ReadAck (startBatch2))
540+ transport.send(peerConnection, commitSig1)
541+ transport.expectMsg(TransportHandler .ReadAck (commitSig1))
542+ transport.send(peerConnection, commitSig2)
543+ transport.expectMsg(TransportHandler .ReadAck (commitSig2))
544+ peer.expectNoMessage(100 millis)
545+ transport.send(peerConnection, spliceLocked3)
546+ transport.expectMsg(TransportHandler .ReadAck (spliceLocked3))
547+ peer.expectMsg(CommitSigBatch (commitSig1 :: commitSig2 :: Nil ))
548+ peer.expectMsg(spliceLocked3)
549+ peer.expectNoMessage(100 millis)
550+
551+ // We receive a batch exceeding 20 elements: we relay messages individually.
552+ val startBatch3 = StartBatch (channelId, batchSize = 21 , TlvStream (StartBatchTlv .MessageType (132 )))
553+ val commitSig3 = CommitSig (channelId, IndividualSignature (randomBytes64()), Nil , TlvStream (CommitSigTlv .FundingTx (randomTxId())))
554+ transport.send(peerConnection, startBatch3)
555+ transport.expectMsg(TransportHandler .ReadAck (startBatch3))
556+ transport.expectMsgType[Warning ]
557+ transport.send(peerConnection, commitSig3)
558+ transport.expectMsg(TransportHandler .ReadAck (commitSig3))
559+ peer.expectMsg(commitSig3)
560+ peer.expectNoMessage(100 millis)
561+ }
562+
432563 test(" react to peer's bad behavior" ) { f =>
433564 import f ._
434565 val probe = TestProbe ()
0 commit comments