diff --git a/tapchannel/aux_traffic_shaper.go b/tapchannel/aux_traffic_shaper.go index 361a9835d9..e687ae4e85 100644 --- a/tapchannel/aux_traffic_shaper.go +++ b/tapchannel/aux_traffic_shaper.go @@ -1,6 +1,7 @@ package tapchannel import ( + "context" "fmt" "sync" @@ -228,7 +229,7 @@ func (s *AuxTrafficShaper) PaymentBandwidth(fundingBlob, htlcBlob, // Otherwise, we derive the available bandwidth from the HTLC's RFQ and // the asset units in our local balance. return s.paymentBandwidth( - htlc, computedLocal, linkBandwidth, minHtlcAmt, + htlc, computedLocal, linkBandwidth, minHtlcAmt, fundingChan, ) } @@ -279,8 +280,8 @@ func paymentBandwidthAssetUnits(htlcAssetAmount, computedLocal uint64, // on the asset rate of the RFQ quote that is included in the HTLC and the asset // units of the local balance. func (s *AuxTrafficShaper) paymentBandwidth(htlc *rfqmsg.Htlc, - localBalance uint64, linkBandwidth, - minHtlcAmt lnwire.MilliSatoshi) (lnwire.MilliSatoshi, error) { + localBalance uint64, linkBandwidth, minHtlcAmt lnwire.MilliSatoshi, + fundingChan *cmsg.OpenChannel) (lnwire.MilliSatoshi, error) { // If the HTLC doesn't have an RFQ ID, it's incomplete, and we cannot // determine the bandwidth. @@ -301,19 +302,54 @@ func (s *AuxTrafficShaper) paymentBandwidth(htlc *rfqmsg.Htlc, sellQuote, isSellQuote := acceptedSellQuotes[rfqID.Scid()] buyQuote, isBuyQuote := acceptedBuyQuotes[rfqID.Scid()] - var rate rfqmsg.AssetRate + var ( + rate rfqmsg.AssetRate + specifier asset.Specifier + ) switch { case isSellQuote: rate = sellQuote.AssetRate + specifier = sellQuote.Request.AssetSpecifier case isBuyQuote: rate = buyQuote.AssetRate + specifier = buyQuote.Request.AssetSpecifier default: return 0, fmt.Errorf("no accepted quote found for RFQ ID "+ "%x (SCID %d)", rfqID[:], rfqID.Scid()) } + // Now that we found the quote, we can determine if this quote is even + // compatible with this channel. If not, we cannot forward the HTLC + // and should return 0 bandwidth. + for _, b := range fundingChan.FundedAssets.Val.Outputs { + // We define compatibility by making sure that each asset in the + // channel matches the specifier of the RFQ quote. This means + // if the quote was created for a single asset in a grouped + // asset channel with multiple tranches, then the check will + // return false, because the group key needs to be used in that + // case. But this matches the behavior in other areas, where we + // also use AssetMatchesSpecifier. + match, err := s.cfg.RfqManager.AssetMatchesSpecifier( + context.Background(), specifier, b.AssetID.Val, + ) + if err != nil { + return 0, fmt.Errorf("error checking if asset ID %x "+ + "matches specifier %s: %w", b.AssetID.Val[:], + specifier.String(), err) + } + + // One of the asset IDs in the channel does not match the quote, + // we don't want to route this HTLC over this channel. + if !match { + log.Tracef("Quote with ID %x (SCID %d) not compatible "+ + "with channel assets, returning 0 bandwidth", + rfqID[:], rfqID.Scid()) + return 0, nil + } + } + // Calculate the local available balance in the local asset unit, // expressed in milli-satoshis. localBalanceFp := rfqmath.NewBigIntFixedPoint(localBalance, 0) diff --git a/tapchannelmsg/testdata/commitment-blob.hexdump b/tapchannelmsg/testdata/commitment-blob.hexdump new file mode 100644 index 0000000000..ed393d3f98 --- /dev/null +++ b/tapchannelmsg/testdata/commitment-blob.hexdump @@ -0,0 +1,228 @@ + 00000000 00 fd 06 25 01 fd 06 21 00 20 5b bc bd f0 0f 8e |...%...!. [.....| + 00000010 10 65 38 4e fe f9 28 66 46 ca 3b 97 65 45 8d f9 |.e8N..(fF.;.eE..| + 00000020 a2 2b aa 1b 1b d3 bb 75 bf 71 01 08 00 00 00 0d |.+.....u.q......| + 00000030 33 95 a9 4c 02 fd 05 f1 54 41 50 50 00 04 00 00 |3..L....TAPP....| + 00000040 00 00 02 24 9a f2 43 8f e5 6d a2 6a 02 7d 32 7b |...$..C..m.j.}2{| + 00000050 af 7c 46 bf 62 77 95 b4 d3 e3 3e c3 e9 8e 54 b8 |.|F.bw....>...T.| + 00000060 46 cf 62 b4 00 00 00 00 04 50 00 00 00 00 00 00 |F.b......P......| + 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 |................| + 000000b0 6e 88 00 00 00 00 00 00 00 00 06 df 02 00 00 00 |n...............| + 000000c0 01 9a f2 43 8f e5 6d a2 6a 02 7d 32 7b af 7c 46 |...C..m.j.}2{.|F| + 000000d0 bf 62 77 95 b4 d3 e3 3e c3 e9 8e 54 b8 46 cf 62 |.bw....>...T.F.b| + 000000e0 b4 00 00 00 00 00 00 00 00 00 04 4a 01 00 00 00 |...........J....| + 000000f0 00 00 00 22 51 20 3a 99 3f 75 7a df 8e 6f ba 90 |..."Q :.?uz..o..| + 00000100 2e 6a 7e d0 73 19 59 0b da cc f2 64 6f 6d 61 b7 |.j~.s.Y....doma.| + 00000110 fe bb dd 63 ce 83 4a 01 00 00 00 00 00 00 22 51 |...c..J......."Q| + 00000120 20 c8 e6 cd 25 59 05 1e 66 84 26 f0 d9 38 9f 54 | ...%Y..f.&..8.T| + 00000130 ef e1 55 70 56 0f 57 a3 60 b5 a9 7b 72 e9 36 c7 |..UpV.W.`..{r.6.| + 00000140 e0 ac 37 00 00 00 00 00 00 22 51 20 eb 42 61 b7 |..7......"Q .Ba.| + 00000150 24 ac 8a 69 97 98 de 51 10 5e 9e dc 49 2e 51 1c |$..i...Q.^..I.Q.| + 00000160 26 53 4b c7 28 cf 33 df 28 f6 a0 57 5f 4c 01 00 |&SK.(.3.(..W_L..| + 00000170 00 00 00 00 22 51 20 d2 d6 9d 0b 55 2f 37 94 d2 |...."Q ....U/7..| + 00000180 88 37 8d 0f 69 88 6d 6f b8 63 d6 38 97 91 2a 87 |.7..i.mo.c.8..*.| + 00000190 61 35 ef 48 26 c3 03 00 00 00 00 08 01 00 0a fd |a5.H&...........| + 000001a0 01 46 00 01 01 02 50 fe c0 b8 1d 9e 96 c2 27 56 |.F....P.......'V| + 000001b0 af 3d db 25 34 fc 44 2a b3 1d 74 1e 3e f6 98 cf |.=.%4.D*..t.>...| + 000001c0 02 df aa 74 d7 32 56 00 00 00 00 06 55 53 44 54 |...t.2V.....USDT| + 000001d0 4c 54 98 51 a1 7b 59 f7 6b 6a 64 c6 43 92 09 f6 |LT.Q.{Y.kjd.C...| + 000001e0 18 bf ce 05 9b e6 fb f4 ee e4 07 c3 a4 8b fc 91 |................| + 000001f0 f7 a1 00 00 00 00 00 04 01 00 06 09 ff 00 00 00 |................| + 00000200 0d 33 95 a9 4c 0b 90 01 8e 01 65 9a f2 43 8f e5 |.3..L.....e..C..| + 00000210 6d a2 6a 02 7d 32 7b af 7c 46 bf 62 77 95 b4 d3 |m.j.}2{.|F.bw...| + 00000220 e3 3e c3 e9 8e 54 b8 46 cf 62 b4 00 00 00 00 5b |.>...T.F.b.....[| + 00000230 bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 46 ca 3b |......e8N..(fF.;| + 00000240 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf 71 02 |.eE...+.....u.q.| + 00000250 50 aa eb 16 6f 42 34 65 0d 84 a2 d8 a1 30 98 7a |P...oB4e.....0.z| + 00000260 ea f6 95 02 06 e0 90 54 01 ee 74 ff 3f 8d 18 e6 |.......T..t.?...| + 00000270 03 25 02 01 51 21 c1 dc a0 94 75 11 09 d0 bd 05 |.%..Q!....u.....| + 00000280 5d 03 56 58 74 e8 27 6d d5 3e 92 6b 44 e3 bd 1b |].VXt.'m.>.kD...| + 00000290 b6 bf 4b c1 30 a2 79 0d 28 f1 d3 fa 25 90 dd 39 |..K.0.y.(...%..9| + 000002a0 80 33 7c d4 32 bc 0b ab 25 ee 23 95 a1 ec bc 6e |.3|.2...%.#....n| + 000002b0 57 be e8 47 c9 e9 d3 41 b2 00 00 00 17 48 76 e8 |W..G...A.....Hv.| + 000002c0 00 0e 02 00 00 10 21 02 fa 23 85 30 b2 ae b0 c6 |......!..#.0....| + 000002d0 83 7e 2d 64 4d eb d1 0f 9c f0 31 f7 e2 87 4a 37 |.~-dM.....1...J7| + 000002e0 5c 13 fa 15 e8 27 60 64 0c fd 01 5a 00 04 00 00 |\....'`d...Z....| + 000002f0 00 02 02 21 02 dc a0 94 75 11 09 d0 bd 05 5d 03 |...!....u.....].| + 00000300 56 58 74 e8 27 6d d5 3e 92 6b 44 e3 bd 1b b6 bf |VXt.'m.>.kD.....| + 00000310 4b c1 30 a2 79 03 fd 01 2d 01 49 00 01 01 02 20 |K.0.y...-.I.... | + 00000320 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 46 ca |[......e8N..(fF.| + 00000330 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf 71 |;.eE...+.....u.q| + 00000340 04 22 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |."..............| + 00000350 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000360 ff ff ff ff 02 27 00 01 02 02 22 00 00 ff ff ff |.....'....".....| + 00000370 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000380 ff ff ff ff ff ff ff ff ff ff ff ff ff 05 41 01 |..............A.| + 00000390 7c 82 be fe 07 d1 f4 c1 08 ac 93 04 bb c3 73 36 ||.............s6| + 000003a0 c5 e1 cf 1e 4d d9 46 db 3c 59 c6 93 ba 84 8c 1d |....M.F..kD...| + 00000470 b6 bf 4b c1 30 a2 79 03 fd 01 3c 01 71 00 01 01 |..K.0.y...<.q...| + 00000480 02 20 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 |. [......e8N..(f| + 00000490 46 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 |F.;.eE...+.....u| + 000004a0 bf 71 04 4a 00 01 04 04 89 78 6d 57 7b c5 2a 7d |.q.J.....xmW{.*}| + 000004b0 b6 32 d8 ca 0f 86 b2 5b a6 00 ce ce 0a 10 6b 60 |.2.....[......k`| + 000004c0 47 3c 35 b7 ea 08 00 00 00 0a 14 e1 3e b4 ff ff |G<5.........>...| + 000004d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000004e0 ff ff ff ff ff ff ff ff ff ff ff ff ff 7f 02 27 |...............'| + 000004f0 00 01 02 02 22 00 00 ff ff ff ff ff ff ff ff ff |...."...........| + 00000500 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000510 ff ff ff ff ff ff ff 05 28 00 c0 25 20 93 af 6e |........(..% ..n| + 00000520 53 19 00 ed 21 76 57 b7 86 66 d3 70 d4 e1 6c 23 |S...!vW..f.p..l#| + 00000530 d4 25 71 9a f6 f8 82 2d e1 9e 38 2c 6a ac 51 b2 |.%q....-..8,j.Q.| + 00000540 75 07 74 01 02 20 93 aa 53 e2 42 66 eb cd 05 09 |u.t.. ..S.Bf....| + 00000550 ad 1b 54 0b f1 c8 ec 68 15 a4 89 99 e0 2f 03 81 |..T....h...../..| + 00000560 cf d6 f0 6b 75 51 02 4f 00 01 02 02 4a 00 01 d5 |...kuQ.O....J...| + 00000570 05 88 b0 24 04 b9 80 52 2f e1 09 56 2a 0d 3c 81 |...$...R/..V*.<.| + 00000580 ec ab 3a 8e 3b ee 64 72 13 9f 55 87 22 44 50 00 |..:.;.dr..U."DP.| + 00000590 00 00 0a 14 e1 3e b4 ff ff ff ff ff ff ff ff ff |.....>..........| + 000005a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000005b0 ff ff ff ff ff ff 7f 35 00 04 00 00 00 00 02 21 |.......5.......!| + 000005c0 03 f3 7c 4f 1d 80 4f e3 16 a4 7b 85 41 d2 a4 ae |..|O..O...{.A...| + 000005d0 3d dc ba ec f8 3a 2b c9 d4 a7 ec f2 02 e4 c4 11 |=....:+.........| + 000005e0 e7 05 0a 01 05 00 c0 02 60 b2 04 01 00 35 00 04 |........`....5..| + 000005f0 00 00 00 01 02 21 02 93 af 6e 53 19 00 ed 21 76 |.....!...nS...!v| + 00000600 57 b7 86 66 d3 70 d4 e1 6c 23 d4 25 71 9a f6 f8 |W..f.p..l#.%q...| + 00000610 82 2d e1 9e 38 2c 6a 05 0a 01 05 00 c0 02 60 b2 |.-..8,j.......`.| + 00000620 04 01 00 16 04 00 00 00 00 01 fd 07 62 01 fd 07 |............b...| + 00000630 5e 00 20 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 |^. [......e8N..(| + 00000640 66 46 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb |fF.;.eE...+.....| + 00000650 75 bf 71 01 08 00 00 00 0a 14 e1 3e b4 02 fd 07 |u.q........>....| + 00000660 2e 54 41 50 50 00 04 00 00 00 00 02 24 9a f2 43 |.TAPP.......$..C| + 00000670 8f e5 6d a2 6a 02 7d 32 7b af 7c 46 bf 62 77 95 |..m.j.}2{.|F.bw.| + 00000680 b4 d3 e3 3e c3 e9 8e 54 b8 46 cf 62 b4 00 00 00 |...>...T.F.b....| + 00000690 00 04 50 00 00 00 00 00 00 00 00 00 00 00 00 00 |..P.............| + 000006a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000006b0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000006c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000006d0 00 00 00 00 00 00 00 00 09 6e 88 00 00 00 00 00 |.........n......| + 000006e0 00 00 00 06 df 02 00 00 00 01 9a f2 43 8f e5 6d |............C..m| + 000006f0 a2 6a 02 7d 32 7b af 7c 46 bf 62 77 95 b4 d3 e3 |.j.}2{.|F.bw....| + 00000700 3e c3 e9 8e 54 b8 46 cf 62 b4 00 00 00 00 00 00 |>...T.F.b.......| + 00000710 00 00 00 04 4a 01 00 00 00 00 00 00 22 51 20 3a |....J......."Q :| + 00000720 99 3f 75 7a df 8e 6f ba 90 2e 6a 7e d0 73 19 59 |.?uz..o...j~.s.Y| + 00000730 0b da cc f2 64 6f 6d 61 b7 fe bb dd 63 ce 83 4a |....doma....c..J| + 00000740 01 00 00 00 00 00 00 22 51 20 c8 e6 cd 25 59 05 |......."Q ...%Y.| + 00000750 1e 66 84 26 f0 d9 38 9f 54 ef e1 55 70 56 0f 57 |.f.&..8.T..UpV.W| + 00000760 a3 60 b5 a9 7b 72 e9 36 c7 e0 ac 37 00 00 00 00 |.`..{r.6...7....| + 00000770 00 00 22 51 20 eb 42 61 b7 24 ac 8a 69 97 98 de |.."Q .Ba.$..i...| + 00000780 51 10 5e 9e dc 49 2e 51 1c 26 53 4b c7 28 cf 33 |Q.^..I.Q.&SK.(.3| + 00000790 df 28 f6 a0 57 5f 4c 01 00 00 00 00 00 22 51 20 |.(..W_L......"Q | + 000007a0 d2 d6 9d 0b 55 2f 37 94 d2 88 37 8d 0f 69 88 6d |....U/7...7..i.m| + 000007b0 6f b8 63 d6 38 97 91 2a 87 61 35 ef 48 26 c3 03 |o.c.8..*.a5.H&..| + 000007c0 00 00 00 00 08 01 00 0a fd 02 91 00 01 01 02 50 |...............P| + 000007d0 fe c0 b8 1d 9e 96 c2 27 56 af 3d db 25 34 fc 44 |.......'V.=.%4.D| + 000007e0 2a b3 1d 74 1e 3e f6 98 cf 02 df aa 74 d7 32 56 |*..t.>......t.2V| + 000007f0 00 00 00 00 06 55 53 44 54 4c 54 98 51 a1 7b 59 |.....USDTLT.Q.{Y| + 00000800 f7 6b 6a 64 c6 43 92 09 f6 18 bf ce 05 9b e6 fb |.kjd.C..........| + 00000810 f4 ee e4 07 c3 a4 8b fc 91 f7 a1 00 00 00 00 00 |................| + 00000820 04 01 00 06 09 ff 00 00 00 0a 14 e1 3e b4 0b fd |............>...| + 00000830 02 03 01 fd 01 ff 01 65 00 00 00 00 00 00 00 00 |.......e........| + 00000840 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000850 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000860 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000870 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000880 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000890 00 00 00 00 00 00 00 00 00 00 00 00 00 05 fd 01 |................| + 000008a0 94 4a 00 01 84 41 dd 42 55 79 73 07 4f ee 88 d5 |.J...A.BUys.O...| + 000008b0 3e 6c 4d ba b9 6f 2a 01 8a b4 6b 83 39 d9 fa c3 |>lM..o*...k.9...| + 000008c0 9a 31 31 50 00 00 00 0d 33 95 a9 4c ff ff ff ff |.11P....3..L....| + 000008d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000008e0 ff ff ff ff ff ff ff ff ff ff ff 7f fd 01 46 00 |..............F.| + 000008f0 01 01 02 50 fe c0 b8 1d 9e 96 c2 27 56 af 3d db |...P.......'V.=.| + 00000900 25 34 fc 44 2a b3 1d 74 1e 3e f6 98 cf 02 df aa |%4.D*..t.>......| + 00000910 74 d7 32 56 00 00 00 00 06 55 53 44 54 4c 54 98 |t.2V.....USDTLT.| + 00000920 51 a1 7b 59 f7 6b 6a 64 c6 43 92 09 f6 18 bf ce |Q.{Y.kjd.C......| + 00000930 05 9b e6 fb f4 ee e4 07 c3 a4 8b fc 91 f7 a1 00 |................| + 00000940 00 00 00 00 04 01 00 06 09 ff 00 00 00 0d 33 95 |..............3.| + 00000950 a9 4c 0b 90 01 8e 01 65 9a f2 43 8f e5 6d a2 6a |.L.....e..C..m.j| + 00000960 02 7d 32 7b af 7c 46 bf 62 77 95 b4 d3 e3 3e c3 |.}2{.|F.bw....>.| + 00000970 e9 8e 54 b8 46 cf 62 b4 00 00 00 00 5b bc bd f0 |..T.F.b.....[...| + 00000980 0f 8e 10 65 38 4e fe f9 28 66 46 ca 3b 97 65 45 |...e8N..(fF.;.eE| + 00000990 8d f9 a2 2b aa 1b 1b d3 bb 75 bf 71 02 50 aa eb |...+.....u.q.P..| + 000009a0 16 6f 42 34 65 0d 84 a2 d8 a1 30 98 7a ea f6 95 |.oB4e.....0.z...| + 000009b0 02 06 e0 90 54 01 ee 74 ff 3f 8d 18 e6 03 25 02 |....T..t.?....%.| + 000009c0 01 51 21 c1 dc a0 94 75 11 09 d0 bd 05 5d 03 56 |.Q!....u.....].V| + 000009d0 58 74 e8 27 6d d5 3e 92 6b 44 e3 bd 1b b6 bf 4b |Xt.'m.>.kD.....K| + 000009e0 c1 30 a2 79 0d 28 f1 d3 fa 25 90 dd 39 80 33 7c |.0.y.(...%..9.3|| + 000009f0 d4 32 bc 0b ab 25 ee 23 95 a1 ec bc 6e 57 be e8 |.2...%.#....nW..| + 00000a00 47 c9 e9 d3 41 b2 00 00 00 17 48 76 e8 00 0e 02 |G...A.....Hv....| + 00000a10 00 00 10 21 02 fa 23 85 30 b2 ae b0 c6 83 7e 2d |...!..#.0.....~-| + 00000a20 64 4d eb d1 0f 9c f0 31 f7 e2 87 4a 37 5c 13 fa |dM.....1...J7\..| + 00000a30 15 e8 27 60 64 0e 02 00 00 10 21 02 56 4f 68 4c |..'`d.....!.VOhL| + 00000a40 f8 73 85 f4 55 1d c9 32 73 1b 03 83 fe 12 9a 3b |.s..U..2s......;| + 00000a50 a2 06 3f aa 17 ed bf 85 71 3a e8 05 0c c9 00 04 |..?.....q:......| + 00000a60 00 00 00 03 02 21 02 dc a0 94 75 11 09 d0 bd 05 |.....!....u.....| + 00000a70 5d 03 56 58 74 e8 27 6d d5 3e 92 6b 44 e3 bd 1b |].VXt.'m.>.kD...| + 00000a80 b6 bf 4b c1 30 a2 79 03 9e 01 49 00 01 01 02 20 |..K.0.y...I.... | + 00000a90 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 46 ca |[......e8N..(fF.| + 00000aa0 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf 71 |;.eE...+.....u.q| + 00000ab0 04 22 00 00 ff ff ff ff ff ff ff ff ff ff ff ff |."..............| + 00000ac0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000ad0 ff ff ff ff 02 27 00 01 02 02 22 00 00 ff ff ff |.....'....".....| + 00000ae0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000af0 ff ff ff ff ff ff ff ff ff ff ff ff ff 05 28 00 |..............(.| + 00000b00 c0 25 20 93 af 6e 53 19 00 ed 21 76 57 b7 86 66 |.% ..nS...!vW..f| + 00000b10 d3 70 d4 e1 6c 23 d4 25 71 9a f6 f8 82 2d e1 9e |.p..l#.%q....-..| + 00000b20 38 2c 6a ac 51 b2 75 0d fd 01 7a 03 fd 01 0a 00 |8,j.Q.u...z.....| + 00000b30 04 00 00 00 02 02 21 02 dc a0 94 75 11 09 d0 bd |......!....u....| + 00000b40 05 5d 03 56 58 74 e8 27 6d d5 3e 92 6b 44 e3 bd |.].VXt.'m.>.kD..| + 00000b50 1b b6 bf 4b c1 30 a2 79 03 df 01 71 00 01 01 02 |...K.0.y...q....| + 00000b60 20 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 46 | [......e8N..(fF| + 00000b70 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf |.;.eE...+.....u.| + 00000b80 71 04 4a 00 01 26 cb e8 54 b3 3c de 72 fc 6f 34 |q.J..&..T.<.r.o4| + 00000b90 80 03 d4 80 23 62 7d a9 a4 84 79 2e 1a bf 3c e0 |....#b}...y...<.| + 00000ba0 9c 39 54 01 05 00 00 00 0d 33 95 a9 4c ff ff ff |.9T......3..L...| + 00000bb0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000bc0 ff ff ff ff ff ff ff ff ff ff ff ff 7f 02 27 00 |..............'.| + 00000bd0 01 02 02 22 00 00 ff ff ff ff ff ff ff ff ff ff |..."............| + 00000be0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000bf0 ff ff ff ff ff ff 05 41 01 7c 82 be fe 07 d1 f4 |.......A.|......| + 00000c00 c1 08 ac 93 04 bb c3 73 36 c5 e1 cf 1e 4d d9 46 |.......s6....M.F| + 00000c10 db 3c 59 c6 93 ba 84 8c 1d c3 a2 ed 89 67 e0 51 |..kD.....K.0.y| + 00000cd0 03 b7 01 49 00 01 01 02 20 5b bc bd f0 0f 8e 10 |...I.... [......| + 00000ce0 65 38 4e fe f9 28 66 46 ca 3b 97 65 45 8d f9 a2 |e8N..(fF.;.eE...| + 00000cf0 2b aa 1b 1b d3 bb 75 bf 71 04 22 00 00 ff ff ff |+.....u.q.".....| + 00000d00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000d10 ff ff ff ff ff ff ff ff ff ff ff ff ff 02 27 00 |..............'.| + 00000d20 01 02 02 22 00 00 ff ff ff ff ff ff ff ff ff ff |..."............| + 00000d30 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000d40 ff ff ff ff ff ff 05 41 01 7c 82 be fe 07 d1 f4 |.......A.|......| + 00000d50 c1 08 ac 93 04 bb c3 73 36 c5 e1 cf 1e 4d d9 46 |.......s6....M.F| + 00000d60 db 3c 59 c6 93 ba 84 8c 1d c3 a2 ed 89 67 e0 51 |.T...| + 00000db0 05 6c 52 16 4c 6b 8b bf 59 7b 6d db 28 02 1d 4d |.lR.Lk..Y{m.(..M| + 00000dc0 df 91 5e 60 36 3e 27 36 bd b1 ee 38 e2 6c 13 d3 |..^`6>'6...8.l..| + 00000dd0 54 60 66 36 09 aa b8 3b a1 7a cb 30 c4 c3 00 00 |T`f6...;.z.0....| + 00000de0 00 0d 33 95 a9 4c 01 4c c0 49 49 6a 47 e8 54 3f |..3..L.L.IIjG.T?| + 00000df0 2a b1 63 fa f6 93 97 1a 65 3e 54 ef e3 d8 05 6c |*.c.....e>T....l| + 00000e00 52 16 4c 6b 8b bf 59 7b 6d db 28 02 5c 7a ea 28 |R.Lk..Y{m.(.\z.(| + 00000e10 5e f7 aa 4a d4 31 55 d1 0c 19 dc 5f b6 fe 46 c7 |^..J.1U...._..F.| + 00000e20 9f 05 b0 fc a0 d1 99 4f 95 6d fc 70 00 00 00 0a |.......O.m.p....| + 00000e30 14 e1 3e b4 02 01 00 03 01 00 |..>.......| \ No newline at end of file diff --git a/tapchannelmsg/testdata/funding-blob.hexdump b/tapchannelmsg/testdata/funding-blob.hexdump new file mode 100644 index 0000000000..3572c2681c --- /dev/null +++ b/tapchannelmsg/testdata/funding-blob.hexdump @@ -0,0 +1,106 @@ + 00000000 00 fd 06 8c 01 fd 06 88 00 20 5b bc bd f0 0f 8e |......... [.....| + 00000010 10 65 38 4e fe f9 28 66 46 ca 3b 97 65 45 8d f9 |.e8N..(fF.;.eE..| + 00000020 a2 2b aa 1b 1b d3 bb 75 bf 71 01 08 00 00 00 17 |.+.....u.q......| + 00000030 48 76 e8 00 02 fd 06 58 54 41 50 50 00 04 00 00 |Hv.....XTAPP....| + 00000040 00 00 02 24 e3 b3 18 bb 44 96 eb 00 47 b9 da af |...$....D...G...| + 00000050 9e d0 cd 1f e3 4e fd 40 40 d1 ac a0 bd 48 4a b7 |.....N.@@....HJ.| + 00000060 9f 95 d8 da 00 00 00 00 04 50 00 00 00 00 00 00 |.........P......| + 00000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 000000a0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 09 |................| + 000000b0 6e 88 00 00 00 00 00 00 00 00 06 dd 02 00 00 00 |n...............| + 000000c0 02 e3 b3 18 bb 44 96 eb 00 47 b9 da af 9e d0 cd |.....D...G......| + 000000d0 1f e3 4e fd 40 40 d1 ac a0 bd 48 4a b7 9f 95 d8 |..N.@@....HJ....| + 000000e0 da 00 00 00 00 00 00 00 00 00 e3 b3 18 bb 44 96 |..............D.| + 000000f0 eb 00 47 b9 da af 9e d0 cd 1f e3 4e fd 40 40 d1 |..G........N.@@.| + 00000100 ac a0 bd 48 4a b7 9f 95 d8 da 02 00 00 00 00 00 |...HJ...........| + 00000110 00 00 00 03 a0 86 01 00 00 00 00 00 22 51 20 36 |............"Q 6| + 00000120 e0 66 44 e2 1f 95 43 4b 22 09 3b 99 d1 3d 7f b3 |.fD...CK".;..=..| + 00000130 74 16 a8 20 40 bb ac 6e 2b 3c da 92 df 2f 44 e8 |t.. @..n+<.../D.| + 00000140 03 00 00 00 00 00 00 22 51 20 78 c9 df a4 61 c9 |......."Q x...a.| + 00000150 63 5a 54 30 3c 45 20 bb c6 f7 78 c7 f7 54 ab ce |cZT0.....| + 000001c0 aa 74 d7 32 56 00 00 00 00 06 55 53 44 54 4c 54 |.t.2V.....USDTLT| + 000001d0 98 51 a1 7b 59 f7 6b 6a 64 c6 43 92 09 f6 18 bf |.Q.{Y.kjd.C.....| + 000001e0 ce 05 9b e6 fb f4 ee e4 07 c3 a4 8b fc 91 f7 a1 |................| + 000001f0 00 00 00 00 00 04 01 00 06 09 ff 00 00 00 17 48 |...............H| + 00000200 76 e8 00 0b fd 02 20 01 fd 02 1c 01 65 00 00 00 |v..... .....e...| + 00000210 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000220 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000230 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000240 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000250 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000260 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| + 00000270 00 00 05 fd 01 b1 4a 00 01 9d 62 8a 09 da 78 fd |......J...b...x.| + 00000280 55 2f 80 de 81 92 f9 3f b3 b5 d0 1d e8 b1 b8 7b |U/.....?.......{| + 00000290 5e 1b 94 e4 12 48 1a 50 25 00 00 00 8b b2 c9 70 |^....H.P%......p| + 000002a0 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000002b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000002c0 bf fd 01 63 00 01 00 02 50 fe c0 b8 1d 9e 96 c2 |...c....P.......| + 000002d0 27 56 af 3d db 25 34 fc 44 2a b3 1d 74 1e 3e f6 |'V.=.%4.D*..t.>.| + 000002e0 98 cf 02 df aa 74 d7 32 56 00 00 00 00 06 55 53 |.....t.2V.....US| + 000002f0 44 54 4c 54 98 51 a1 7b 59 f7 6b 6a 64 c6 43 92 |DTLT.Q.{Y.kjd.C.| + 00000300 09 f6 18 bf ce 05 9b e6 fb f4 ee e4 07 c3 a4 8b |................| + 00000310 fc 91 f7 a1 00 00 00 00 00 04 01 00 06 09 ff 00 |................| + 00000320 00 00 8b b2 c9 70 00 0b ad 01 ab 01 65 e3 b3 18 |.....p......e...| + 00000330 bb 44 96 eb 00 47 b9 da af 9e d0 cd 1f e3 4e fd |.D...G........N.| + 00000340 40 40 d1 ac a0 bd 48 4a b7 9f 95 d8 da 00 00 00 |@@....HJ........| + 00000350 00 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 46 |.[......e8N..(fF| + 00000360 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf |.;.eE...+.....u.| + 00000370 71 02 c4 c1 0f 4b 66 6d 6c 65 04 94 86 e7 63 d1 |q....Kfmle....c.| + 00000380 fd 9c 58 50 c3 42 6e 98 95 a7 c2 76 5f d2 c9 a0 |..XP.Bn....v_...| + 00000390 e9 31 03 42 01 40 fb d6 b7 66 c5 44 90 21 f6 b4 |.1.B.@...f.D.!..| + 000003a0 01 4b 58 a9 92 af d3 85 47 52 18 4e 8d 8c d2 bf |.KX.....GR.N....| + 000003b0 ea fe 1d c1 1a ba bc c0 f1 2b 9a c9 aa d5 12 43 |.........+.....C| + 000003c0 49 ad e8 9e 04 2f ac 32 ae 0e c8 04 af 20 d3 b9 |I..../.2..... ..| + 000003d0 b2 cb bc 52 cf 20 0d 28 86 28 09 8b 45 4a 14 d6 |...R. .(.(..EJ..| + 000003e0 fb fd 14 d9 be fe 3b 69 99 eb be 1e 75 f5 a4 6b |......;i....u..k| + 000003f0 f8 61 64 dc 51 78 b9 80 00 00 00 a2 fb 40 58 00 |.ad.Qx.......@X.| + 00000400 0e 02 00 00 10 21 02 a8 21 5e 24 a9 c7 25 96 33 |.....!..!^$..%.3| + 00000410 1b f5 95 a0 35 f2 f5 18 86 18 b4 fb 62 72 49 37 |....5.......brI7| + 00000420 ed d4 77 f9 3a ea 47 0e 02 00 00 10 21 02 50 aa |..w.:.G.....!.P.| + 00000430 eb 16 6f 42 34 65 0d 84 a2 d8 a1 30 98 7a ea f6 |..oB4e.....0.z..| + 00000440 95 02 06 e0 90 54 01 ee 74 ff 3f 8d 18 e6 0c 9f |.....T..t.?.....| + 00000450 00 04 00 00 00 00 02 21 02 25 73 85 a5 39 6c 24 |.......!.%s..9l$| + 00000460 e0 6e 13 2c 58 cd 68 06 7b de bc 61 4d af d1 c7 |.n.,X.h.{..aM...| + 00000470 24 bc 7c 1d 80 8f 56 d3 1d 03 74 01 49 00 01 01 |$.|...V...t.I...| + 00000480 02 20 5b bc bd f0 0f 8e 10 65 38 4e fe f9 28 66 |. [......e8N..(f| + 00000490 46 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b d3 bb 75 |F.;.eE...+.....u| + 000004a0 bf 71 04 22 00 00 ff ff ff ff ff ff ff ff ff ff |.q."............| + 000004b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000004c0 ff ff ff ff ff ff 02 27 00 01 02 02 22 00 00 ff |.......'...."...| + 000004d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000004e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 0d |................| + 000004f0 f8 02 c7 00 04 00 00 00 01 02 21 02 24 12 a4 0a |..........!.$...| + 00000500 95 f1 15 6b cc 4a 6f 4c 8e cf 9b 93 f2 6f 83 57 |...k.JoL.....o.W| + 00000510 37 47 7b 1c da 80 61 ac 72 43 d6 ae 03 9c 01 71 |7G{...a.rC.....q| + 00000520 00 01 00 02 20 5b bc bd f0 0f 8e 10 65 38 4e fe |.... [......e8N.| + 00000530 f9 28 66 46 ca 3b 97 65 45 8d f9 a2 2b aa 1b 1b |.(fF.;.eE...+...| + 00000540 d3 bb 75 bf 71 04 4a 00 01 19 fe fa af 0e 61 b3 |..u.q.J.......a.| + 00000550 9b 16 91 93 29 06 39 79 e0 c7 8c 88 56 48 51 6d |....).9y....VHQm| + 00000560 d5 9e 02 97 94 87 89 b3 8e 00 00 00 8b b2 c9 70 |...............p| + 00000570 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000580 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000590 7f 02 27 00 01 02 02 22 00 00 ff ff ff ff ff ff |..'...."........| + 000005a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 000005b0 ff ff ff ff ff ff ff ff ff ff 2e 00 04 00 00 00 |................| + 000005c0 02 02 21 02 01 d1 0b 6b 42 84 5c a8 63 b7 f9 fb |..!....kB.\.c...| + 000005d0 aa f0 b6 3d 7b ce f5 5d 6f d7 da 78 36 47 29 8e |...={..]o..x6G).| + 000005e0 ef a5 08 19 05 03 04 01 01 0f 9f 00 04 00 00 00 |................| + 000005f0 01 02 21 02 24 12 a4 0a 95 f1 15 6b cc 4a 6f 4c |..!.$......k.JoL| + 00000600 8e cf 9b 93 f2 6f 83 57 37 47 7b 1c da 80 61 ac |.....o.W7G{...a.| + 00000610 72 43 d6 ae 03 74 01 49 00 01 00 02 20 5b bc bd |rC...t.I.... [..| + 00000620 f0 0f 8e 10 65 38 4e fe f9 28 66 46 ca 3b 97 65 |....e8N..(fF.;.e| + 00000630 45 8d f9 a2 2b aa 1b 1b d3 bb 75 bf 71 04 22 00 |E...+.....u.q.".| + 00000640 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000650 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000660 ff 02 27 00 01 02 02 22 00 00 ff ff ff ff ff ff |..'...."........| + 00000670 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff |................| + 00000680 ff ff ff ff ff ff ff ff ff ff 16 04 00 00 00 00 |................| + 00000690 01 01 06 |...| \ No newline at end of file diff --git a/tapchannelmsg/testdata/htlc-blob.hexdump b/tapchannelmsg/testdata/htlc-blob.hexdump new file mode 100644 index 0000000000..ee3c6e0168 --- /dev/null +++ b/tapchannelmsg/testdata/htlc-blob.hexdump @@ -0,0 +1,3 @@ + 00000000 fe 00 01 00 02 20 cb e4 1e 5c 1b be 71 1d 9e df |..... ...\..q...| + 00000010 32 45 c6 d8 48 4c c5 a3 39 fa 30 82 a4 00 f5 50 |2E..HL..9.0....P| + 00000020 eb e8 46 37 3a 3d fe 00 01 a1 47 01 00 |..F7:=....G..| \ No newline at end of file diff --git a/tapchannelmsg/wire_msgs_test.go b/tapchannelmsg/wire_msgs_test.go index 29e59154dd..4e2f5f3508 100644 --- a/tapchannelmsg/wire_msgs_test.go +++ b/tapchannelmsg/wire_msgs_test.go @@ -4,7 +4,11 @@ import ( "bytes" "crypto/sha256" "encoding/hex" + "encoding/json" + "fmt" "os" + "path/filepath" + "regexp" "strings" "testing" @@ -12,6 +16,7 @@ import ( "github.com/lightninglabs/taproot-assets/asset" "github.com/lightninglabs/taproot-assets/internal/test" "github.com/lightninglabs/taproot-assets/proof" + "github.com/lightninglabs/taproot-assets/rfqmsg" "github.com/stretchr/testify/require" "pgregory.net/rapid" ) @@ -258,3 +263,135 @@ func TestProofChunkErrorCases(t *testing.T) { ) }) } + +// ExtractHexDump extracts the hex bytes from a hex dump string, saved from a +// log file that contains the spew.Sdump format of a byte blob. +func ExtractHexDump(input string) ([]byte, error) { + lines := strings.Split(input, "\n") + + // Regex to match the hex byte part between the offset and ASCII + // section. + re := regexp.MustCompile(`^[\da-fA-F]+\s+((?:[\da-fA-F]{2} ? ?){1,16})`) + + var result bytes.Buffer + for _, line := range lines { + line = strings.TrimSpace(line) + if line == "" { + continue + } + + match := re.FindStringSubmatch(line) + if len(match) < 2 { + continue + } + + hexPart := strings.ReplaceAll(match[1], " ", "") + extractedBytes, err := hex.DecodeString(hexPart) + if err != nil { + return nil, fmt.Errorf("error decoding hex on line: "+ + "%s, err: %v", line, err) + } + + _, _ = result.Write(extractedBytes) + } + + return result.Bytes(), nil +} + +// TestDecodeFundingBlobHexDump tests decoding a funding blob from a hex dump +// file, saved from a log file that contains the spew.Sdump format of a +// byte blob. The hex dump is expected to contain the funding blob in a specific +// format, which is then decoded into a ChannelCustomData structure. +func TestDecodeFundingBlobHexDump(t *testing.T) { + fileName := filepath.Join("testdata", "funding-blob.hexdump") + fundingBlobBytes, err := os.ReadFile(fileName) + require.NoError(t, err) + + // Extract the hex bytes from the hex dump. + hexBytes, err := ExtractHexDump(string(fundingBlobBytes)) + require.NoError(t, err) + + // Decode the funding blob from the extracted hex bytes. + fundingChan, err := DecodeOpenChannel(hexBytes) + require.NoError(t, err) + + customChan := &ChannelCustomData{ + OpenChan: *fundingChan, + } + + customChanJSON, err := customChan.AsJson() + require.NoError(t, err) + + var formatted bytes.Buffer + err = json.Indent(&formatted, customChanJSON, "", " ") + require.NoError(t, err) + + t.Logf("Decoded funding channel: %s", formatted.String()) +} + +// TestDecodeHtlcBlobHexDump tests decoding a HTLC blob from a hex dump +// file, saved from a log file that contains the spew.Sdump format of a +// byte blob. The hex dump is expected to contain the funding blob in a specific +// format, which is then decoded into a Htlc structure. +func TestDecodeHtlcBlobHexDump(t *testing.T) { + fileName := filepath.Join("testdata", "htlc-blob.hexdump") + htlcBlobBytes, err := os.ReadFile(fileName) + require.NoError(t, err) + + // Extract the hex bytes from the hex dump. + hexBytes, err := ExtractHexDump(string(htlcBlobBytes)) + require.NoError(t, err) + + // Decode the HTLC blob from the extracted hex bytes. + htlc, err := rfqmsg.DecodeHtlc(hexBytes) + require.NoError(t, err) + + htlcJSON, err := htlc.AsJson() + require.NoError(t, err) + + var formatted bytes.Buffer + err = json.Indent(&formatted, htlcJSON, "", " ") + require.NoError(t, err) + + t.Logf("Decoded HTLC blob: %s", formatted.String()) +} + +// TestDecodeCommitmentBlobHexDump tests decoding a commitment blob from a hex +// dump file, saved from a log file that contains the spew.Sdump format of a +// byte blob. The hex dump is expected to contain the funding blob in a specific +// format, which is then decoded into a Commitment structure. +func TestDecodeCommitmentBlobHexDump(t *testing.T) { + fileName := filepath.Join("testdata", "commitment-blob.hexdump") + commitmentBlobBytes, err := os.ReadFile(fileName) + require.NoError(t, err) + + // Extract the hex bytes from the hex dump. + hexBytes, err := ExtractHexDump(string(commitmentBlobBytes)) + require.NoError(t, err) + + // Decode the commitment blob from the extracted hex bytes. + commit, err := DecodeCommitment(hexBytes) + require.NoError(t, err) + + resp := &rfqmsg.JsonAssetChannel{ + LocalBalance: commit.LocalAssets.Val.Sum(), + RemoteBalance: commit.RemoteAssets.Val.Sum(), + OutgoingHtlcBalance: commit.OutgoingHtlcAssets.Val.Sum(), + IncomingHtlcBalance: commit.IncomingHtlcAssets.Val.Sum(), + } + resp.LocalAssets = outputsToJsonTranches(commit.LocalAssets.Val.Outputs) + resp.RemoteAssets = outputsToJsonTranches( + commit.RemoteAssets.Val.Outputs, + ) + resp.OutgoingHtlcs = outputsToJsonTranches( + commit.OutgoingHtlcAssets.Val.Outputs(), + ) + resp.IncomingHtlcs = outputsToJsonTranches( + commit.IncomingHtlcAssets.Val.Outputs(), + ) + + formatted, err := json.MarshalIndent(resp, "", " ") + require.NoError(t, err) + + t.Logf("Decoded commitment: %s", string(formatted)) +}