@@ -1452,8 +1452,8 @@ func (s *SQLStore) FilterChannelRange(startHeight, endHeight uint32,
1452
1452
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
1453
1453
dbChans , err := db .GetPublicV1ChannelsBySCID (
1454
1454
ctx , sqlc.GetPublicV1ChannelsBySCIDParams {
1455
- StartScid : chanIDStart [:] ,
1456
- EndScid : chanIDEnd [:] ,
1455
+ StartScid : chanIDStart ,
1456
+ EndScid : chanIDEnd ,
1457
1457
},
1458
1458
)
1459
1459
if err != nil {
@@ -1560,7 +1560,7 @@ func (s *SQLStore) MarkEdgeZombie(chanID uint64,
1560
1560
return db .UpsertZombieChannel (
1561
1561
ctx , sqlc.UpsertZombieChannelParams {
1562
1562
Version : int16 (ProtocolV1 ),
1563
- Scid : chanIDB [:] ,
1563
+ Scid : chanIDB ,
1564
1564
NodeKey1 : pubKey1 [:],
1565
1565
NodeKey2 : pubKey2 [:],
1566
1566
},
@@ -1592,7 +1592,7 @@ func (s *SQLStore) MarkEdgeLive(chanID uint64) error {
1592
1592
err := s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
1593
1593
res , err := db .DeleteZombieChannel (
1594
1594
ctx , sqlc.DeleteZombieChannelParams {
1595
- Scid : chanIDB [:] ,
1595
+ Scid : chanIDB ,
1596
1596
Version : int16 (ProtocolV1 ),
1597
1597
},
1598
1598
)
@@ -1644,7 +1644,7 @@ func (s *SQLStore) IsZombieEdge(chanID uint64) (bool, [33]byte, [33]byte,
1644
1644
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
1645
1645
zombie , err := db .GetZombieChannel (
1646
1646
ctx , sqlc.GetZombieChannelParams {
1647
- Scid : chanIDB [:] ,
1647
+ Scid : chanIDB ,
1648
1648
Version : int16 (ProtocolV1 ),
1649
1649
},
1650
1650
)
@@ -1723,7 +1723,7 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
1723
1723
1724
1724
row , err := db .GetChannelBySCIDWithPolicies (
1725
1725
ctx , sqlc.GetChannelBySCIDWithPoliciesParams {
1726
- Scid : chanIDB [:] ,
1726
+ Scid : chanIDB ,
1727
1727
Version : int16 (ProtocolV1 ),
1728
1728
},
1729
1729
)
@@ -1786,7 +1786,7 @@ func (s *SQLStore) DeleteChannelEdges(strictZombiePruning, markZombie bool,
1786
1786
err = db .UpsertZombieChannel (
1787
1787
ctx , sqlc.UpsertZombieChannelParams {
1788
1788
Version : int16 (ProtocolV1 ),
1789
- Scid : chanIDB [:] ,
1789
+ Scid : chanIDB ,
1790
1790
NodeKey1 : nodeKey1 [:],
1791
1791
NodeKey2 : nodeKey2 [:],
1792
1792
},
@@ -1833,14 +1833,12 @@ func (s *SQLStore) FetchChannelEdgesByID(chanID uint64) (
1833
1833
ctx = context .TODO ()
1834
1834
edge * models.ChannelEdgeInfo
1835
1835
policy1 , policy2 * models.ChannelEdgePolicy
1836
+ chanIDB = channelIDToBytes (chanID )
1836
1837
)
1837
1838
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
1838
- var chanIDB [8 ]byte
1839
- byteOrder .PutUint64 (chanIDB [:], chanID )
1840
-
1841
1839
row , err := db .GetChannelBySCIDWithPolicies (
1842
1840
ctx , sqlc.GetChannelBySCIDWithPoliciesParams {
1843
- Scid : chanIDB [:] ,
1841
+ Scid : chanIDB ,
1844
1842
Version : int16 (ProtocolV1 ),
1845
1843
},
1846
1844
)
@@ -1849,7 +1847,7 @@ func (s *SQLStore) FetchChannelEdgesByID(chanID uint64) (
1849
1847
// index.
1850
1848
zombie , err := db .GetZombieChannel (
1851
1849
ctx , sqlc.GetZombieChannelParams {
1852
- Scid : chanIDB [:] ,
1850
+ Scid : chanIDB ,
1853
1851
Version : int16 (ProtocolV1 ),
1854
1852
},
1855
1853
)
@@ -2033,21 +2031,19 @@ func (s *SQLStore) HasChannelEdge(chanID uint64) (time.Time, time.Time, bool,
2033
2031
return node1LastUpdate , node2LastUpdate , exists , isZombie , nil
2034
2032
}
2035
2033
2034
+ chanIDB := channelIDToBytes (chanID )
2036
2035
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2037
- var chanIDB [8 ]byte
2038
- byteOrder .PutUint64 (chanIDB [:], chanID )
2039
-
2040
2036
channel , err := db .GetChannelBySCID (
2041
2037
ctx , sqlc.GetChannelBySCIDParams {
2042
- Scid : chanIDB [:] ,
2038
+ Scid : chanIDB ,
2043
2039
Version : int16 (ProtocolV1 ),
2044
2040
},
2045
2041
)
2046
2042
if errors .Is (err , sql .ErrNoRows ) {
2047
2043
// Check if it is a zombie channel.
2048
2044
isZombie , err = db .IsZombieChannel (
2049
2045
ctx , sqlc.IsZombieChannelParams {
2050
- Scid : chanIDB [:] ,
2046
+ Scid : chanIDB ,
2051
2047
Version : int16 (ProtocolV1 ),
2052
2048
},
2053
2049
)
@@ -2179,15 +2175,14 @@ func (s *SQLStore) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
2179
2175
)
2180
2176
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2181
2177
for _ , chanID := range chanIDs {
2182
- var chanIDB [8 ]byte
2183
- byteOrder .PutUint64 (chanIDB [:], chanID )
2178
+ chanIDB := channelIDToBytes (chanID )
2184
2179
2185
2180
// TODO(elle): potentially optimize this by using
2186
2181
// sqlc.slice() once that works for both SQLite and
2187
2182
// Postgres.
2188
2183
row , err := db .GetChannelBySCIDWithPolicies (
2189
2184
ctx , sqlc.GetChannelBySCIDWithPoliciesParams {
2190
- Scid : chanIDB [:] ,
2185
+ Scid : chanIDB ,
2191
2186
Version : int16 (ProtocolV1 ),
2192
2187
},
2193
2188
)
@@ -2270,16 +2265,15 @@ func (s *SQLStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
2270
2265
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2271
2266
for _ , chanInfo := range chansInfo {
2272
2267
channelID := chanInfo .ShortChannelID .ToUint64 ()
2273
- var chanIDB [8 ]byte
2274
- byteOrder .PutUint64 (chanIDB [:], channelID )
2268
+ chanIDB := channelIDToBytes (channelID )
2275
2269
2276
2270
// TODO(elle): potentially optimize this by using
2277
2271
// sqlc.slice() once that works for both SQLite and
2278
2272
// Postgres.
2279
2273
_ , err := db .GetChannelBySCID (
2280
2274
ctx , sqlc.GetChannelBySCIDParams {
2281
2275
Version : int16 (ProtocolV1 ),
2282
- Scid : chanIDB [:] ,
2276
+ Scid : chanIDB ,
2283
2277
},
2284
2278
)
2285
2279
if err == nil {
@@ -2291,7 +2285,7 @@ func (s *SQLStore) FilterKnownChanIDs(chansInfo []ChannelUpdateInfo) ([]uint64,
2291
2285
2292
2286
isZombie , err := db .IsZombieChannel (
2293
2287
ctx , sqlc.IsZombieChannelParams {
2294
- Scid : chanIDB [:] ,
2288
+ Scid : chanIDB ,
2295
2289
Version : int16 (ProtocolV1 ),
2296
2290
},
2297
2291
)
@@ -2609,18 +2603,16 @@ func (s *SQLStore) DisconnectBlockAtHeight(height uint32) (
2609
2603
endShortChanID = aliasmgr .StartingAlias
2610
2604
2611
2605
removedChans []* models.ChannelEdgeInfo
2612
- )
2613
2606
2614
- var chanIDStart [8 ]byte
2615
- byteOrder .PutUint64 (chanIDStart [:], startShortChanID .ToUint64 ())
2616
- var chanIDEnd [8 ]byte
2617
- byteOrder .PutUint64 (chanIDEnd [:], endShortChanID .ToUint64 ())
2607
+ chanIDStart = channelIDToBytes (startShortChanID .ToUint64 ())
2608
+ chanIDEnd = channelIDToBytes (endShortChanID .ToUint64 ())
2609
+ )
2618
2610
2619
2611
err := s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
2620
2612
rows , err := db .GetChannelsBySCIDRange (
2621
2613
ctx , sqlc.GetChannelsBySCIDRangeParams {
2622
- StartScid : chanIDStart [:] ,
2623
- EndScid : chanIDEnd [:] ,
2614
+ StartScid : chanIDStart ,
2615
+ EndScid : chanIDEnd ,
2624
2616
},
2625
2617
)
2626
2618
if err != nil {
@@ -2688,7 +2680,7 @@ func (s *SQLStore) AddEdgeProof(scid lnwire.ShortChannelID,
2688
2680
err := s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
2689
2681
res , err := db .AddV1ChannelProof (
2690
2682
ctx , sqlc.AddV1ChannelProofParams {
2691
- Scid : scidBytes [:] ,
2683
+ Scid : scidBytes ,
2692
2684
Node1Signature : proof .NodeSig1Bytes ,
2693
2685
Node2Signature : proof .NodeSig2Bytes ,
2694
2686
Bitcoin1Signature : proof .BitcoinSig1Bytes ,
@@ -2734,7 +2726,7 @@ func (s *SQLStore) PutClosedScid(scid lnwire.ShortChannelID) error {
2734
2726
)
2735
2727
2736
2728
return s .db .ExecTx (ctx , sqldb .WriteTxOpt (), func (db SQLQueries ) error {
2737
- return db .InsertClosedChannel (ctx , chanIDB [:] )
2729
+ return db .InsertClosedChannel (ctx , chanIDB )
2738
2730
}, sqldb .NoOpReset )
2739
2731
}
2740
2732
@@ -2750,7 +2742,7 @@ func (s *SQLStore) IsClosedScid(scid lnwire.ShortChannelID) (bool, error) {
2750
2742
)
2751
2743
err := s .db .ExecTx (ctx , sqldb .ReadTxOpt (), func (db SQLQueries ) error {
2752
2744
var err error
2753
- isClosed , err = db .IsClosedChannel (ctx , chanIDB [:] )
2745
+ isClosed , err = db .IsClosedChannel (ctx , chanIDB )
2754
2746
if err != nil {
2755
2747
return fmt .Errorf ("unable to fetch closed channel: %w" ,
2756
2748
err )
@@ -3077,7 +3069,7 @@ func updateChanEdgePolicy(ctx context.Context, tx SQLQueries,
3077
3069
// abort the transaction which would abort the entire batch.
3078
3070
dbChan , err := tx .GetChannelAndNodesBySCID (
3079
3071
ctx , sqlc.GetChannelAndNodesBySCIDParams {
3080
- Scid : chanIDB [:] ,
3072
+ Scid : chanIDB ,
3081
3073
Version : int16 (ProtocolV1 ),
3082
3074
},
3083
3075
)
@@ -3779,7 +3771,7 @@ func insertChannel(ctx context.Context, db SQLQueries,
3779
3771
// batch of transactions.
3780
3772
_ , err := db .GetChannelBySCID (
3781
3773
ctx , sqlc.GetChannelBySCIDParams {
3782
- Scid : chanIDB [:] ,
3774
+ Scid : chanIDB ,
3783
3775
Version : int16 (ProtocolV1 ),
3784
3776
},
3785
3777
)
@@ -3808,7 +3800,7 @@ func insertChannel(ctx context.Context, db SQLQueries,
3808
3800
3809
3801
createParams := sqlc.CreateChannelParams {
3810
3802
Version : int16 (ProtocolV1 ),
3811
- Scid : chanIDB [:] ,
3803
+ Scid : chanIDB ,
3812
3804
NodeID1 : node1DBID ,
3813
3805
NodeID2 : node2DBID ,
3814
3806
Outpoint : edge .ChannelPoint .String (),
@@ -4455,9 +4447,9 @@ func extractChannelPolicies(row any) (*sqlc.ChannelPolicy, *sqlc.ChannelPolicy,
4455
4447
4456
4448
// channelIDToBytes converts a channel ID (SCID) to a byte array
4457
4449
// representation.
4458
- func channelIDToBytes (channelID uint64 ) [8 ]byte {
4450
+ func channelIDToBytes (channelID uint64 ) []byte {
4459
4451
var chanIDB [8 ]byte
4460
4452
byteOrder .PutUint64 (chanIDB [:], channelID )
4461
4453
4462
- return chanIDB
4454
+ return chanIDB [:]
4463
4455
}
0 commit comments