@@ -288,7 +288,7 @@ type InitFundingMsg struct {
288288 // PendingChanID is not all zeroes (the default value), then this will
289289 // be the pending channel ID used for the funding flow within the wire
290290 // protocol.
291- PendingChanID [ 32 ] byte
291+ PendingChanID PendingChanID
292292
293293 // ChannelType allows the caller to use an explicit channel type for the
294294 // funding negotiation. This type will only be observed if BOTH sides
@@ -318,7 +318,7 @@ type fundingMsg struct {
318318// pendingChannels is a map instantiated per-peer which tracks all active
319319// pending single funded channels indexed by their pending channel identifier,
320320// which is a set of 32-bytes generated via a CSPRNG.
321- type pendingChannels map [[ 32 ] byte ]* reservationWithCtx
321+ type pendingChannels map [PendingChanID ]* reservationWithCtx
322322
323323// serializedPubKey is used within the FundingManager's activeReservations list
324324// to identify the nodes with which the FundingManager is actively working to
@@ -590,7 +590,7 @@ type Manager struct {
590590 // required as mid funding flow, we switch to referencing the channel
591591 // by its full channel ID once the commitment transactions have been
592592 // signed by both parties.
593- signedReservations map [lnwire.ChannelID ][ 32 ] byte
593+ signedReservations map [lnwire.ChannelID ]PendingChanID
594594
595595 // resMtx guards both of the maps above to ensure that all access is
596596 // goroutine safe.
@@ -797,9 +797,13 @@ func (f *Manager) rebroadcastFundingTx(c *channeldb.OpenChannel) {
797797 }
798798}
799799
800+ // PendingChanID is a type that represents a pending channel ID. This might be
801+ // selected by the caller, but if not, will be automatically selected.
802+ type PendingChanID = [32 ]byte
803+
800804// nextPendingChanID returns the next free pending channel ID to be used to
801805// identify a particular future channel funding workflow.
802- func (f * Manager ) nextPendingChanID () [ 32 ] byte {
806+ func (f * Manager ) nextPendingChanID () PendingChanID {
803807 // Obtain a fresh nonce. We do this by encoding the current nonce
804808 // counter, then incrementing it by one.
805809 f .nonceMtx .Lock ()
@@ -811,7 +815,7 @@ func (f *Manager) nextPendingChanID() [32]byte {
811815 // We'll generate the next pending channelID by "encrypting" 32-bytes
812816 // of zeroes which'll extract 32 random bytes from our stream cipher.
813817 var (
814- nextChanID [ 32 ] byte
818+ nextChanID PendingChanID
815819 zeroes [32 ]byte
816820 )
817821 salsa20 .XORKeyStream (nextChanID [:], zeroes [:], nonce [:], & f .chanIDKey )
@@ -1044,7 +1048,8 @@ func (f *Manager) reservationCoordinator() {
10441048//
10451049// NOTE: This MUST be run as a goroutine.
10461050func (f * Manager ) advanceFundingState (channel * channeldb.OpenChannel ,
1047- pendingChanID [32 ]byte , updateChan chan <- * lnrpc.OpenStatusUpdate ) {
1051+ pendingChanID PendingChanID ,
1052+ updateChan chan <- * lnrpc.OpenStatusUpdate ) {
10481053
10491054 defer f .wg .Done ()
10501055
@@ -1119,7 +1124,7 @@ func (f *Manager) advanceFundingState(channel *channeldb.OpenChannel,
11191124// updateChan can be set non-nil to get OpenStatusUpdates.
11201125func (f * Manager ) stateStep (channel * channeldb.OpenChannel ,
11211126 lnChannel * lnwallet.LightningChannel ,
1122- shortChanID * lnwire.ShortChannelID , pendingChanID [ 32 ] byte ,
1127+ shortChanID * lnwire.ShortChannelID , pendingChanID PendingChanID ,
11231128 channelState channelOpeningState ,
11241129 updateChan chan <- * lnrpc.OpenStatusUpdate ) error {
11251130
@@ -1243,7 +1248,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
12431248// advancePendingChannelState waits for a pending channel's funding tx to
12441249// confirm, and marks it open in the database when that happens.
12451250func (f * Manager ) advancePendingChannelState (
1246- channel * channeldb.OpenChannel , pendingChanID [ 32 ] byte ) error {
1251+ channel * channeldb.OpenChannel , pendingChanID PendingChanID ) error {
12471252
12481253 if channel .IsZeroConf () {
12491254 // Persist the alias to the alias database.
@@ -2744,7 +2749,7 @@ type confirmedChannel struct {
27442749// channel as closed. The error is only returned for the responder of the
27452750// channel flow.
27462751func (f * Manager ) fundingTimeout (c * channeldb.OpenChannel ,
2747- pendingID [ 32 ] byte ) error {
2752+ pendingID PendingChanID ) error {
27482753
27492754 // We'll get a timeout if the number of blocks mined since the channel
27502755 // was initiated reaches MaxWaitNumBlocksFundingConf and we are not the
@@ -3607,7 +3612,7 @@ func (f *Manager) annAfterSixConfs(completeChan *channeldb.OpenChannel,
36073612// a zero-conf channel. This will wait for the real confirmation, add the
36083613// confirmed SCID to the router graph, and then announce after six confs.
36093614func (f * Manager ) waitForZeroConfChannel (c * channeldb.OpenChannel ,
3610- pendingID [ 32 ] byte ) error {
3615+ pendingID PendingChanID ) error {
36113616
36123617 // First we'll check whether the channel is confirmed on-chain. If it
36133618 // is already confirmed, the chainntnfs subsystem will return with the
@@ -3975,7 +3980,7 @@ func (f *Manager) handleChannelReady(peer lnpeer.Peer, //nolint:funlen
39753980// channel is now active, thus we change its state to `addedToRouterGraph` to
39763981// let the channel start handling routing.
39773982func (f * Manager ) handleChannelReadyReceived (channel * channeldb.OpenChannel ,
3978- scid * lnwire.ShortChannelID , pendingChanID [ 32 ] byte ,
3983+ scid * lnwire.ShortChannelID , pendingChanID PendingChanID ,
39793984 updateChan chan <- * lnrpc.OpenStatusUpdate ) error {
39803985
39813986 chanID := lnwire .NewChanIDFromOutPoint (channel .FundingOutpoint )
@@ -4499,7 +4504,7 @@ func (f *Manager) handleInitFundingMsg(msg *InitFundingMsg) {
44994504 // If the caller specified their own channel ID, then we'll use that.
45004505 // Otherwise we'll generate a fresh one as normal. This will be used
45014506 // to track this reservation throughout its lifetime.
4502- var chanID [ 32 ] byte
4507+ var chanID PendingChanID
45034508 if msg .PendingChanID == zeroID {
45044509 chanID = f .nextPendingChanID ()
45054510 } else {
@@ -4904,7 +4909,8 @@ func (f *Manager) pruneZombieReservations() {
49044909// cancelReservationCtx does all needed work in order to securely cancel the
49054910// reservation.
49064911func (f * Manager ) cancelReservationCtx (peerKey * btcec.PublicKey ,
4907- pendingChanID [32 ]byte , byRemote bool ) (* reservationWithCtx , error ) {
4912+ pendingChanID PendingChanID ,
4913+ byRemote bool ) (* reservationWithCtx , error ) {
49084914
49094915 log .Infof ("Cancelling funding reservation for node_key=%x, " +
49104916 "chan_id=%x" , peerKey .SerializeCompressed (), pendingChanID [:])
@@ -4952,7 +4958,7 @@ func (f *Manager) cancelReservationCtx(peerKey *btcec.PublicKey,
49524958// deleteReservationCtx deletes the reservation uniquely identified by the
49534959// target public key of the peer, and the specified pending channel ID.
49544960func (f * Manager ) deleteReservationCtx (peerKey * btcec.PublicKey ,
4955- pendingChanID [ 32 ] byte ) {
4961+ pendingChanID PendingChanID ) {
49564962
49574963 peerIDKey := newSerializedKey (peerKey )
49584964 f .resMtx .Lock ()
@@ -4975,7 +4981,7 @@ func (f *Manager) deleteReservationCtx(peerKey *btcec.PublicKey,
49754981// getReservationCtx returns the reservation context for a particular pending
49764982// channel ID for a target peer.
49774983func (f * Manager ) getReservationCtx (peerKey * btcec.PublicKey ,
4978- pendingChanID [ 32 ] byte ) (* reservationWithCtx , error ) {
4984+ pendingChanID PendingChanID ) (* reservationWithCtx , error ) {
49794985
49804986 peerIDKey := newSerializedKey (peerKey )
49814987 f .resMtx .RLock ()
@@ -4995,7 +5001,7 @@ func (f *Manager) getReservationCtx(peerKey *btcec.PublicKey,
49955001// of being funded. After the funding transaction has been confirmed, the
49965002// channel will receive a new, permanent channel ID, and will no longer be
49975003// considered pending.
4998- func (f * Manager ) IsPendingChannel (pendingChanID [ 32 ] byte ,
5004+ func (f * Manager ) IsPendingChannel (pendingChanID PendingChanID ,
49995005 peer lnpeer.Peer ) bool {
50005006
50015007 peerIDKey := newSerializedKey (peer .IdentityKey ())
0 commit comments