Skip to content

Commit

Permalink
Add more fixes suggested by @t-bast
Browse files Browse the repository at this point in the history
  • Loading branch information
remyers committed Feb 5, 2025
1 parent dcfde3a commit 790ffb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,39 +232,41 @@ abstract class BaseRouterSpec extends TestKitBaseClass with FixtureAnyFunSuiteLi
}

def addChannel(router: ActorRef, watcher: TestProbe, scid: RealShortChannelId, priv1: PrivateKey, priv2: PrivateKey, priv_funding1: PrivateKey, priv_funding2: PrivateKey): (ChannelAnnouncement, ChannelUpdate, ChannelUpdate) = {
val channelAnnoucement = channelAnnouncement(scid, priv1, priv2, priv_funding1, priv_funding2)
val ann = channelAnnouncement(scid, priv1, priv2, priv_funding1, priv_funding2)
val pub1 = priv1.publicKey
val pub2 = priv2.publicKey
val update1 = makeChannelUpdate(Block.RegtestGenesisBlock.hash, priv1, pub2, scid, CltvExpiryDelta(7), htlcMinimumMsat = 0 msat, feeBaseMsat = 10 msat, feeProportionalMillionths = 10, htlcMaximumMsat = htlcMaximum)
val update2 = makeChannelUpdate(Block.RegtestGenesisBlock.hash, priv2, pub1, scid, CltvExpiryDelta(7), htlcMinimumMsat = 0 msat, feeBaseMsat = 10 msat, feeProportionalMillionths = 10, htlcMaximumMsat = htlcMaximum)
val pub_funding1 = priv_funding1.publicKey
val pub_funding2 = priv_funding2.publicKey
assert(ChannelDesc(update1, channelAnnoucement) == ChannelDesc(channelAnnoucement.shortChannelId, pub1, pub2))
assert(ChannelDesc(update1, ann) == ChannelDesc(ann.shortChannelId, pub1, pub2))
val sender1 = TestProbe()
val peerConnection = TestProbe()
peerConnection.ignoreMsg { case _: TransportHandler.ReadAck => true }
peerConnection.send(router, PeerRoutingMessage(peerConnection.ref, remoteNodeId, channelAnnoucement))
peerConnection.send(router, PeerRoutingMessage(peerConnection.ref, remoteNodeId, ann))
peerConnection.send(router, PeerRoutingMessage(peerConnection.ref, remoteNodeId, update1))
peerConnection.send(router, PeerRoutingMessage(peerConnection.ref, remoteNodeId, update2))
assert(watcher.expectMsgType[ValidateRequest].ann == channelAnnoucement)
watcher.send(router, ValidateResult(channelAnnoucement, Right((Transaction(version = 0, txIn = Nil, txOut = TxOut(publicChannelCapacity, write(pay2wsh(Scripts.multiSig2of2(pub_funding1, pub_funding2)))) :: Nil, lockTime = 0), UtxoStatus.Unspent))))
assert(watcher.expectMsgType[ValidateRequest].ann == ann)
watcher.send(router, ValidateResult(ann, Right((Transaction(version = 2, txIn = Nil, txOut = TxOut(publicChannelCapacity, write(pay2wsh(Scripts.multiSig2of2(pub_funding1, pub_funding2)))) :: Nil, lockTime = 0), UtxoStatus.Unspent))))
assert(watcher.expectMsgType[WatchExternalChannelSpent].shortChannelId == scid)
peerConnection.expectMsgAllOf(
GossipDecision.Accepted(channelAnnoucement),
GossipDecision.Accepted(ann),
GossipDecision.Accepted(update1),
GossipDecision.Accepted(update2)
)
peerConnection.expectNoMessage()
peerConnection.expectNoMessage(100 millis)
awaitCond({
sender1.send(router, GetNodes)
val nodes = sender1.expectMsgType[Iterable[NodeAnnouncement]]
sender1.send(router, GetChannels)
val channels = sender1.expectMsgType[Iterable[ChannelAnnouncement]]
val channels = sender1.expectMsgType[Iterable[ChannelAnnouncement]].toSeq
sender1.send(router, GetChannelUpdates)
val updates = sender1.expectMsgType[Iterable[ChannelUpdate]]
nodes.size == 8 && channels.size == 6 && updates.size == 14
val updates = sender1.expectMsgType[Iterable[ChannelUpdate]].toSeq
nodes.exists(_.nodeId == pub1) && nodes.exists(_.nodeId == pub2) &&
channels.contains(ann) &&
updates.contains(update1) && updates.contains(update2)
}, max = 10 seconds, interval = 1 second)
(channelAnnoucement, update1, update2)
(ann, update1, update2)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1345,8 +1345,7 @@ class RouterSpec extends BaseRouterSpec {
assert(routerData.spentChannels(spliceTx_bc.txid) == Set(scid_bc))
assert(routerData.spentChannels(batchSpliceTx.txid) == Set(scid_bc))
assert(routerData.spentChannels(batchSpliceTx_RBF.txid) == Set(scid_bc))
}
else {
} else {
assert(routerData.spentChannels.contains(spliceTx_bc2.txid))
assert(routerData.spentChannels(spliceTx_bc2.txid) == Set(scid_bc2))
assert(routerData.spentChannels(batchSpliceTx.txid) == Set(scid_bc2))
Expand All @@ -1370,7 +1369,11 @@ class RouterSpec extends BaseRouterSpec {
eventListener.expectNoMessage(100 millis)

// Alternative spending transactions in the mempool are now unspendable and need not be watched.
assert((1 to 2).map(_ => watcher.expectMsgType[UnwatchTxConfirmed].txId).toSet == Set(spliceTx_bc2.txid, batchSpliceTx.txid))
val unwatchedTxs = Set(
watcher.expectMsgType[UnwatchTxConfirmed].txId,
watcher.expectMsgType[UnwatchTxConfirmed].txId,
)
assert(unwatchedTxs == Set(spliceTx_bc2.txid, batchSpliceTx.txid))
watcher.expectNoMessage(100 millis)

// The router no longer tracks the parent scids.
Expand Down

0 comments on commit 790ffb5

Please sign in to comment.