@@ -287,7 +287,7 @@ type InitFundingMsg struct {
287287 // PendingChanID is not all zeroes (the default value), then this will
288288 // be the pending channel ID used for the funding flow within the wire
289289 // protocol.
290- PendingChanID [ 32 ] byte
290+ PendingChanID PendingChanID
291291
292292 // ChannelType allows the caller to use an explicit channel type for the
293293 // funding negotiation. This type will only be observed if BOTH sides
@@ -317,7 +317,7 @@ type fundingMsg struct {
317317// pendingChannels is a map instantiated per-peer which tracks all active
318318// pending single funded channels indexed by their pending channel identifier,
319319// which is a set of 32-bytes generated via a CSPRNG.
320- type pendingChannels map [[ 32 ] byte ]* reservationWithCtx
320+ type pendingChannels map [PendingChanID ]* reservationWithCtx
321321
322322// serializedPubKey is used within the FundingManager's activeReservations list
323323// to identify the nodes with which the FundingManager is actively working to
@@ -591,7 +591,7 @@ type Manager struct {
591591 // required as mid funding flow, we switch to referencing the channel
592592 // by its full channel ID once the commitment transactions have been
593593 // signed by both parties.
594- signedReservations map [lnwire.ChannelID ][ 32 ] byte
594+ signedReservations map [lnwire.ChannelID ]PendingChanID
595595
596596 // resMtx guards both of the maps above to ensure that all access is
597597 // goroutine safe.
@@ -798,9 +798,13 @@ func (f *Manager) rebroadcastFundingTx(c *channeldb.OpenChannel) {
798798 }
799799}
800800
801+ // PendingChanID is a type that represents a pending channel ID. This might be
802+ // selected by the caller, but if not, will be automatically selected.
803+ type PendingChanID = [32 ]byte
804+
801805// nextPendingChanID returns the next free pending channel ID to be used to
802806// identify a particular future channel funding workflow.
803- func (f * Manager ) nextPendingChanID () [ 32 ] byte {
807+ func (f * Manager ) nextPendingChanID () PendingChanID {
804808 // Obtain a fresh nonce. We do this by encoding the current nonce
805809 // counter, then incrementing it by one.
806810 f .nonceMtx .Lock ()
@@ -812,7 +816,7 @@ func (f *Manager) nextPendingChanID() [32]byte {
812816 // We'll generate the next pending channelID by "encrypting" 32-bytes
813817 // of zeroes which'll extract 32 random bytes from our stream cipher.
814818 var (
815- nextChanID [ 32 ] byte
819+ nextChanID PendingChanID
816820 zeroes [32 ]byte
817821 )
818822 salsa20 .XORKeyStream (nextChanID [:], zeroes [:], nonce [:], & f .chanIDKey )
@@ -1045,7 +1049,8 @@ func (f *Manager) reservationCoordinator() {
10451049//
10461050// NOTE: This MUST be run as a goroutine.
10471051func (f * Manager ) advanceFundingState (channel * channeldb.OpenChannel ,
1048- pendingChanID [32 ]byte , updateChan chan <- * lnrpc.OpenStatusUpdate ) {
1052+ pendingChanID PendingChanID ,
1053+ updateChan chan <- * lnrpc.OpenStatusUpdate ) {
10491054
10501055 defer f .wg .Done ()
10511056
@@ -1115,7 +1120,7 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
11151120// updateChan can be set non-nil to get OpenStatusUpdates.
11161121func (f * Manager ) stateStep (channel * channeldb.OpenChannel ,
11171122 lnChannel * lnwallet.LightningChannel ,
1118- shortChanID * lnwire.ShortChannelID , pendingChanID [ 32 ] byte ,
1123+ shortChanID * lnwire.ShortChannelID , pendingChanID PendingChanID ,
11191124 channelState channelOpeningState ,
11201125 updateChan chan <- * lnrpc.OpenStatusUpdate ) error {
11211126
@@ -1239,7 +1244,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
12391244// advancePendingChannelState waits for a pending channel's funding tx to
12401245// confirm, and marks it open in the database when that happens.
12411246func (f * Manager ) advancePendingChannelState (
1242- channel * channeldb.OpenChannel , pendingChanID [ 32 ] byte ) error {
1247+ channel * channeldb.OpenChannel , pendingChanID PendingChanID ) error {
12431248
12441249 if channel .IsZeroConf () {
12451250 // Persist the alias to the alias database.
@@ -2770,7 +2775,7 @@ type confirmedChannel struct {
27702775// channel as closed. The error is only returned for the responder of the
27712776// channel flow.
27722777func (f * Manager ) fundingTimeout (c * channeldb.OpenChannel ,
2773- pendingID [ 32 ] byte ) error {
2778+ pendingID PendingChanID ) error {
27742779
27752780 // We'll get a timeout if the number of blocks mined since the channel
27762781 // was initiated reaches MaxWaitNumBlocksFundingConf and we are not the
@@ -3995,7 +4000,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, //nolint:funlen
39954000// channel is now active, thus we change its state to `addedToGraph` to
39964001// let the channel start handling routing.
39974002func (f * Manager ) handleChannelReadyReceived (channel * channeldb.OpenChannel ,
3998- scid * lnwire.ShortChannelID , pendingChanID [ 32 ] byte ,
4003+ scid * lnwire.ShortChannelID , pendingChanID PendingChanID ,
39994004 updateChan chan <- * lnrpc.OpenStatusUpdate ) error {
40004005
40014006 chanID := lnwire .NewChanIDFromOutPoint (channel .FundingOutpoint )
@@ -4519,7 +4524,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
45194524 // If the caller specified their own channel ID, then we'll use that.
45204525 // Otherwise we'll generate a fresh one as normal. This will be used
45214526 // to track this reservation throughout its lifetime.
4522- var chanID [ 32 ] byte
4527+ var chanID PendingChanID
45234528 if msg .PendingChanID == zeroID {
45244529 chanID = f .nextPendingChanID ()
45254530 } else {
@@ -4942,7 +4947,8 @@ func (f *Manager) pruneZombieReservations() {
49424947// cancelReservationCtx does all needed work in order to securely cancel the
49434948// reservation.
49444949func (f * Manager ) cancelReservationCtx (peerKey * btcec.PublicKey ,
4945- pendingChanID [32 ]byte , byRemote bool ) (* reservationWithCtx , error ) {
4950+ pendingChanID PendingChanID ,
4951+ byRemote bool ) (* reservationWithCtx , error ) {
49464952
49474953 log .Infof ("Cancelling funding reservation for node_key=%x, " +
49484954 "chan_id=%x" , peerKey .SerializeCompressed (), pendingChanID [:])
@@ -4990,7 +4996,7 @@ func (f *Manager) cancelReservationCtx(peerKey *btcec.PublicKey,
49904996// deleteReservationCtx deletes the reservation uniquely identified by the
49914997// target public key of the peer, and the specified pending channel ID.
49924998func (f * Manager ) deleteReservationCtx (peerKey * btcec.PublicKey ,
4993- pendingChanID [ 32 ] byte ) {
4999+ pendingChanID PendingChanID ) {
49945000
49955001 peerIDKey := newSerializedKey (peerKey )
49965002 f .resMtx .Lock ()
@@ -5013,7 +5019,7 @@ func (f *Manager) deleteReservationCtx(peerKey *btcec.PublicKey,
50135019// getReservationCtx returns the reservation context for a particular pending
50145020// channel ID for a target peer.
50155021func (f * Manager ) getReservationCtx (peerKey * btcec.PublicKey ,
5016- pendingChanID [ 32 ] byte ) (* reservationWithCtx , error ) {
5022+ pendingChanID PendingChanID ) (* reservationWithCtx , error ) {
50175023
50185024 peerIDKey := newSerializedKey (peerKey )
50195025 f .resMtx .RLock ()
@@ -5033,7 +5039,7 @@ func (f *Manager) getReservationCtx(peerKey *btcec.PublicKey,
50335039// of being funded. After the funding transaction has been confirmed, the
50345040// channel will receive a new, permanent channel ID, and will no longer be
50355041// considered pending.
5036- func (f * Manager ) IsPendingChannel (pendingChanID [ 32 ] byte ,
5042+ func (f * Manager ) IsPendingChannel (pendingChanID PendingChanID ,
50375043 peer lnpeer.Peer ) bool {
50385044
50395045 peerIDKey := newSerializedKey (peer .IdentityKey ())
0 commit comments