@@ -319,10 +319,15 @@ class RouterSpec extends BaseRouterSpec {
319319 probe.expectMsg(PublicNode (node_b, 2 , publicChannelCapacity * 2 ))
320320 }
321321
322+ def fundingTx (node1 : PublicKey , node2 : PublicKey , capacity : Satoshi = publicChannelCapacity): Transaction = {
323+ val fundingScript = write(pay2wsh(Scripts .multiSig2of2(node1, node2)))
324+ val fundingTx = Transaction (version = 0 , txIn = Nil , txOut = TxOut (capacity, fundingScript) :: Nil , lockTime = 0 )
325+ fundingTx
326+ }
327+
322328 def spendingTx (node1 : PublicKey , node2 : PublicKey , capacity : Satoshi = publicChannelCapacity): Transaction = {
323329 val fundingScript = write(pay2wsh(Scripts .multiSig2of2(node1, node2)))
324- val previousFundingTx = Transaction (version = 2 , txIn = Nil , txOut = TxOut (capacity, fundingScript) :: Nil , lockTime = 0 )
325- val nextFundingTx = Transaction (version = 0 , txIn = TxIn (OutPoint (previousFundingTx, 0 ), fundingScript, 0 ) :: Nil , txOut = TxOut (capacity, fundingScript) :: Nil , lockTime = 0 )
330+ val nextFundingTx = Transaction (version = 0 , txIn = TxIn (OutPoint (fundingTx(node1, node2, capacity), 0 ), fundingScript, 0 ) :: Nil , txOut = TxOut (capacity, fundingScript) :: Nil , lockTime = 0 )
326331 nextFundingTx
327332 }
328333
@@ -335,6 +340,7 @@ class RouterSpec extends BaseRouterSpec {
335340 watcher.expectMsgType[WatchTxConfirmed ]
336341 router ! WatchTxConfirmedTriggered (BlockHeight (0 ), 0 , spendingTx(funding_a, funding_b))
337342 eventListener.expectMsg(ChannelLost (scid_ab))
343+ assert(watcher.expectMsgType[UnwatchExternalChannelSpent ].txId == fundingTx(funding_a, funding_b).txid)
338344 assert(nodeParams.db.network.getChannel(scid_ab).isEmpty)
339345 // a doesn't have any channels, b still has one with c
340346 eventListener.expectMsg(NodeLost (a))
@@ -345,6 +351,7 @@ class RouterSpec extends BaseRouterSpec {
345351 router ! WatchExternalChannelSpentTriggered (scid_cd, spendingTx(funding_c, funding_d))
346352 watcher.expectMsgType[WatchTxConfirmed ]
347353 router ! WatchTxConfirmedTriggered (BlockHeight (0 ), 0 , spendingTx(funding_c, funding_d))
354+ assert(watcher.expectMsgType[UnwatchExternalChannelSpent ].txId == fundingTx(funding_c, funding_d).txid)
348355 eventListener.expectMsg(ChannelLost (scid_cd))
349356 assert(nodeParams.db.network.getChannel(scid_cd).isEmpty)
350357 // d doesn't have any channels, c still has one with b
@@ -356,6 +363,7 @@ class RouterSpec extends BaseRouterSpec {
356363 router ! WatchExternalChannelSpentTriggered (scid_bc, spendingTx(funding_b, funding_c))
357364 watcher.expectMsgType[WatchTxConfirmed ]
358365 router ! WatchTxConfirmedTriggered (BlockHeight (0 ), 0 , spendingTx(funding_b, funding_c))
366+ assert(watcher.expectMsgType[UnwatchExternalChannelSpent ].txId == fundingTx(funding_b, funding_c).txid)
359367 eventListener.expectMsg(ChannelLost (scid_bc))
360368 assert(nodeParams.db.network.getChannel(scid_bc).isEmpty)
361369 // now b and c do not have any channels
@@ -374,10 +382,10 @@ class RouterSpec extends BaseRouterSpec {
374382 val priv_funding_u = randomKey()
375383 val scid_au = RealShortChannelId (fixture.nodeParams.currentBlockHeight - 5000 , 5 , 0 )
376384 val ann = channelAnnouncement(scid_au, priv_a, priv_u, priv_funding_a, priv_funding_u)
377- val fundingTx = Transaction ( 2 , Nil , Seq ( TxOut ( 500_000 sat, write(pay2wsh( Scripts .multiSig2of2( funding_a, priv_funding_u.publicKey))))), 0 )
385+ val fundingTx_au = fundingTx( funding_a, priv_funding_u.publicKey, 500_000 sat )
378386 router ! PeerRoutingMessage (TestProbe ().ref, remoteNodeId, ann)
379387 watcher.expectMsgType[ValidateRequest ]
380- watcher.send(router, ValidateResult (ann, Right ((fundingTx , UtxoStatus .Unspent ))))
388+ watcher.send(router, ValidateResult (ann, Right ((fundingTx_au , UtxoStatus .Unspent ))))
381389 watcher.expectMsgType[WatchExternalChannelSpent ]
382390 eventListener.expectMsg(ChannelsDiscovered (SingleChannelDiscovered (ann, 500_000 sat, None , None ) :: Nil ))
383391 awaitAssert(assert(nodeParams.db.network.getChannel(scid_au).nonEmpty))
@@ -392,6 +400,7 @@ class RouterSpec extends BaseRouterSpec {
392400 router ! WatchExternalChannelSpentTriggered (scid_au, spendingTx(funding_a, priv_funding_u.publicKey))
393401 assert(watcher.expectMsgType[WatchTxConfirmed ].txId == spendingTx(funding_a, priv_funding_u.publicKey).txid)
394402 router ! WatchTxConfirmedTriggered (BlockHeight (0 ), 0 , spendingTx(funding_a, priv_funding_u.publicKey))
403+ assert(watcher.expectMsgType[UnwatchExternalChannelSpent ].txId == fundingTx_au.txid)
395404 eventListener.expectMsg(ChannelLost (scid_au))
396405 eventListener.expectMsg(NodeLost (priv_u.publicKey))
397406 awaitAssert(assert(nodeParams.db.network.getChannel(scid_au).isEmpty))
@@ -905,12 +914,12 @@ class RouterSpec extends BaseRouterSpec {
905914 val scid = RealShortChannelId (fixture.nodeParams.currentBlockHeight - 5000 , 5 , 0 )
906915 val capacity = 1_000_000 .sat
907916 val ann = channelAnnouncement(scid, priv_a, priv_c, priv_funding_a, priv_funding_c)
908- val fundingTx = Transaction (2 , Nil , Seq (TxOut (capacity, write(pay2wsh(Scripts .multiSig2of2(funding_a, funding_c))))), 0 )
909917 val peerConnection = TestProbe ()
918+ val fundingTx_ac = fundingTx(funding_a, funding_c, capacity)
910919 peerConnection.ignoreMsg { case _ : TransportHandler .ReadAck => true }
911920 peerConnection.send(router, PeerRoutingMessage (peerConnection.ref, remoteNodeId, ann))
912921 watcher.expectMsgType[ValidateRequest ]
913- watcher.send(router, ValidateResult (ann, Right ((fundingTx , UtxoStatus .Unspent ))))
922+ watcher.send(router, ValidateResult (ann, Right ((fundingTx_ac , UtxoStatus .Unspent ))))
914923 peerConnection.expectMsg(GossipDecision .Accepted (ann))
915924 probe.send(router, GetChannels )
916925 assert(probe.expectMsgType[Iterable [ChannelAnnouncement ]].exists(_.shortChannelId == scid))
@@ -928,17 +937,17 @@ class RouterSpec extends BaseRouterSpec {
928937 val staleUpdate = makeChannelUpdate(Block .RegtestGenesisBlock .hash, priv_a, c, scid, CltvExpiryDelta (72 ), 1 msat, 10 msat, 100 , htlcMaximum, timestamp = staleTimestamp)
929938 peerConnection.send(router, PeerRoutingMessage (peerConnection.ref, remoteNodeId, staleUpdate))
930939 peerConnection.expectMsg(GossipDecision .Stale (staleUpdate))
931- assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, None , None , None )))
940+ assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, None , None , None )))
932941
933942 // We receive a non-stale channel update for one side of the channel.
934943 val update_ac_1 = makeChannelUpdate(Block .RegtestGenesisBlock .hash, priv_a, c, scid, CltvExpiryDelta (72 ), 1 msat, 10 msat, 100 , htlcMaximum, timestamp = TimestampSecond .now() - 3 .days)
935944 peerConnection.send(router, PeerRoutingMessage (peerConnection.ref, remoteNodeId, update_ac_1))
936945 peerConnection.expectMsg(GossipDecision .RelatedChannelPruned (update_ac_1))
937946 peerConnection.expectNoMessage(100 millis)
938947 if (update_ac_1.channelFlags.isNode1) {
939- assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, Some (update_ac_1), None , None )))
948+ assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, Some (update_ac_1), None , None )))
940949 } else {
941- assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, None , Some (update_ac_1), None )))
950+ assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, None , Some (update_ac_1), None )))
942951 }
943952 probe.send(router, GetRouterData )
944953 val routerData1 = probe.expectMsgType[Data ]
@@ -953,9 +962,9 @@ class RouterSpec extends BaseRouterSpec {
953962 peerConnection.expectMsg(GossipDecision .RelatedChannelPruned (update_ac_2))
954963 peerConnection.expectNoMessage(100 millis)
955964 if (update_ac_2.channelFlags.isNode1) {
956- assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, Some (update_ac_2), None , None )))
965+ assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, Some (update_ac_2), None , None )))
957966 } else {
958- assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, None , Some (update_ac_2), None )))
967+ assert(nodeParams.db.network.getChannel(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, None , Some (update_ac_2), None )))
959968 }
960969 probe.send(router, GetRouterData )
961970 val routerData2 = probe.expectMsgType[Data ]
@@ -972,9 +981,9 @@ class RouterSpec extends BaseRouterSpec {
972981 assert(routerData3.channels.contains(scid))
973982 assert(! routerData3.prunedChannels.contains(scid))
974983 if (update_ac_2.channelFlags.isNode1) {
975- assert(routerData3.channels.get(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, Some (update_ac_2), Some (update_ca), None )))
984+ assert(routerData3.channels.get(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, Some (update_ac_2), Some (update_ca), None )))
976985 } else {
977- assert(routerData3.channels.get(scid).contains(PublicChannel (ann, fundingTx .txid, capacity, Some (update_ca), Some (update_ac_2), None )))
986+ assert(routerData3.channels.get(scid).contains(PublicChannel (ann, fundingTx_ac .txid, capacity, Some (update_ca), Some (update_ac_2), None )))
978987 }
979988 assert(routerData3.graphWithBalances.graph.containsEdge(ChannelDesc (update_ac_2, ann)))
980989 assert(routerData3.graphWithBalances.graph.containsEdge(ChannelDesc (update_ca, ann)))
0 commit comments