Merge pull request #7517 from yyforyongyu/fix-funding-locked

Replace `FundingLocked` with `ChannelReady`
This commit is contained in:
Oliver Gugger authored and GitHub committed 2023-03-30 17:22:17 +02:00
commit ec5b95c9a9
22 files changed
+364 -324

No files matched your search

+3 -3
View File
@@ -38,7 +38,7 @@ var (
lastAliasKey = []byte("last-alias-key") lastAliasKey = []byte("last-alias-key")
// invoiceAliasBucket is a root-level bucket that stores the alias // invoiceAliasBucket is a root-level bucket that stores the alias
// SCIDs that our peers send us in the funding_locked TLV. The keys are // SCIDs that our peers send us in the channel_ready TLV. The keys are
// the ChannelID generated from the FundingOutpoint and the values are // the ChannelID generated from the FundingOutpoint and the values are
// the remote peer's alias SCID. // the remote peer's alias SCID.
invoiceAliasBucket = []byte("invoice-alias-bucket") invoiceAliasBucket = []byte("invoice-alias-bucket")
@@ -88,7 +88,7 @@ type Manager struct {
aliasToBase map[lnwire.ShortChannelID]lnwire.ShortChannelID aliasToBase map[lnwire.ShortChannelID]lnwire.ShortChannelID
// peerAlias is a cache for the alias SCIDs that our peers send us in // peerAlias is a cache for the alias SCIDs that our peers send us in
// the funding_locked TLV. The keys are the ChannelID generated from // the channel_ready TLV. The keys are the ChannelID generated from
// the FundingOutpoint and the values are the remote peer's alias SCID. // the FundingOutpoint and the values are the remote peer's alias SCID.
// The values should match the ones stored in the "invoice-alias-bucket" // The values should match the ones stored in the "invoice-alias-bucket"
// bucket. // bucket.
@@ -341,7 +341,7 @@ func (m *Manager) DeleteSixConfs(baseScid lnwire.ShortChannelID) error {
} }
// PutPeerAlias stores the peer's alias SCID once we learn of it in the // PutPeerAlias stores the peer's alias SCID once we learn of it in the
// funding_locked message. // channel_ready message.
func (m *Manager) PutPeerAlias(chanID lnwire.ChannelID, func (m *Manager) PutPeerAlias(chanID lnwire.ChannelID,
alias lnwire.ShortChannelID) error { alias lnwire.ShortChannelID) error {
+2 -2
View File
@@ -1345,7 +1345,7 @@ func (c *OpenChannel) MarkBorked() error {
} }
// SecondCommitmentPoint returns the second per-commitment-point for use in the // SecondCommitmentPoint returns the second per-commitment-point for use in the
// funding_locked message. // channel_ready message.
func (c *OpenChannel) SecondCommitmentPoint() (*btcec.PublicKey, error) { func (c *OpenChannel) SecondCommitmentPoint() (*btcec.PublicKey, error) {
c.RLock() c.RLock()
defer c.RUnlock() defer c.RUnlock()
@@ -3770,7 +3770,7 @@ func putChanRevocationState(chanBucket kvdb.RwBucket, channel *OpenChannel) erro
// TODO(roasbeef): don't keep producer on disk // TODO(roasbeef): don't keep producer on disk
// If the next revocation is present, which is only the case after the // If the next revocation is present, which is only the case after the
// FundingLocked message has been sent, then we'll write it to disk. // ChannelReady message has been sent, then we'll write it to disk.
if channel.RemoteNextRevocation != nil { if channel.RemoteNextRevocation != nil {
err = WriteElements(&b, channel.RemoteNextRevocation) err = WriteElements(&b, channel.RemoteNextRevocation)
if err != nil { if err != nil {
@@ -42,6 +42,13 @@
added to `lnrpc` so the node operator can know whether a certain request has added to `lnrpc` so the node operator can know whether a certain request has
happened or not. happened or not.
* Message `funding_locked` [has been
renamed](https://github.com/lightningnetwork/lnd/pull/7517) to
`channel_ready` internally to match the specs update. This should not change
anything for the users since the message type(36) stays unchanged, except in
the logging all the appearance of `funding_locked` replated experssion is
replaced with `channel_ready`.
# Contributors (Alphabetical Order) # Contributors (Alphabetical Order)
* ardevd * ardevd
+1 -1
View File
@@ -7,5 +7,5 @@ import "time"
func init() { func init() {
// For itest, we will use a much shorter checking interval here as // For itest, we will use a much shorter checking interval here as
// local communications are very fast. // local communications are very fast.
checkPeerFundingLockInterval = 10 * time.Millisecond checkPeerChannelReadyInterval = 10 * time.Millisecond
} }
+3 -3
View File
@@ -23,15 +23,15 @@ type Controller interface {
// aliasHandler is an interface that abstracts the managing of aliases. // aliasHandler is an interface that abstracts the managing of aliases.
type aliasHandler interface { type aliasHandler interface {
// RequestAlias lets the funding manager request a unique SCID alias to // RequestAlias lets the funding manager request a unique SCID alias to
// use in the funding_locked message. // use in the channel_ready message.
RequestAlias() (lnwire.ShortChannelID, error) RequestAlias() (lnwire.ShortChannelID, error)
// PutPeerAlias lets the funding manager store the received alias SCID // PutPeerAlias lets the funding manager store the received alias SCID
// in the funding_locked message. // in the channel_ready message.
PutPeerAlias(lnwire.ChannelID, lnwire.ShortChannelID) error PutPeerAlias(lnwire.ChannelID, lnwire.ShortChannelID) error
// GetPeerAlias lets the funding manager lookup the received alias SCID // GetPeerAlias lets the funding manager lookup the received alias SCID
// from the funding_locked message. This is not the same as GetAliases // from the channel_ready message. This is not the same as GetAliases
// which retrieves OUR aliases for a given channel. // which retrieves OUR aliases for a given channel.
GetPeerAlias(lnwire.ChannelID) (lnwire.ShortChannelID, error) GetPeerAlias(lnwire.ChannelID) (lnwire.ShortChannelID, error)
+99 -85
View File
@@ -40,12 +40,12 @@ var (
// buffers. // buffers.
byteOrder = binary.BigEndian byteOrder = binary.BigEndian
// checkPeerFundingLockInterval is used when we are waiting for the // checkPeerChannelReadyInterval is used when we are waiting for the
// peer to send us FundingLocked. We will check every 1 second to see // peer to send us ChannelReady. We will check every 1 second to see
// if the message is received. // if the message is received.
// //
// NOTE: for itest, this value is changed to 10ms. // NOTE: for itest, this value is changed to 10ms.
checkPeerFundingLockInterval = 1 * time.Second checkPeerChannelReadyInterval = 1 * time.Second
) )
// WriteOutpoint writes an outpoint to an io.Writer. This is not the same as // WriteOutpoint writes an outpoint to an io.Writer. This is not the same as
@@ -377,7 +377,7 @@ type Config struct {
// NotifyWhenOnline allows the FundingManager to register with a // NotifyWhenOnline allows the FundingManager to register with a
// subsystem that will notify it when the peer comes online. This is // subsystem that will notify it when the peer comes online. This is
// used when sending the fundingLocked message, since it MUST be // used when sending the channelReady message, since it MUST be
// delivered after the funding transaction is confirmed. // delivered after the funding transaction is confirmed.
// //
// NOTE: The peerChan channel must be buffered. // NOTE: The peerChan channel must be buffered.
@@ -570,8 +570,8 @@ type Manager struct {
localDiscoveryMtx sync.Mutex localDiscoveryMtx sync.Mutex
localDiscoverySignals map[lnwire.ChannelID]chan struct{} localDiscoverySignals map[lnwire.ChannelID]chan struct{}
handleFundingLockedMtx sync.RWMutex handleChannelReadyMtx sync.RWMutex
handleFundingLockedBarriers map[lnwire.ChannelID]struct{} handleChannelReadyBarriers map[lnwire.ChannelID]struct{}
quit chan struct{} quit chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
@@ -584,18 +584,18 @@ type channelOpeningState uint8
const ( const (
// markedOpen is the opening state of a channel if the funding // markedOpen is the opening state of a channel if the funding
// transaction is confirmed on-chain, but fundingLocked is not yet // transaction is confirmed on-chain, but channelReady is not yet
// successfully sent to the other peer. // successfully sent to the other peer.
markedOpen channelOpeningState = iota markedOpen channelOpeningState = iota
// fundingLockedSent is the opening state of a channel if the // channelReadySent is the opening state of a channel if the
// fundingLocked message has successfully been sent to the other peer, // channelReady message has successfully been sent to the other peer,
// but we still haven't announced the channel to the network. // but we still haven't announced the channel to the network.
fundingLockedSent channelReadySent
// addedToRouterGraph is the opening state of a channel if the // addedToRouterGraph is the opening state of a channel if the
// channel has been successfully added to the router graph // channel has been successfully added to the router graph
// immediately after the fundingLocked message has been sent, but // immediately after the channelReady message has been sent, but
// we still haven't announced the channel to the network. // we still haven't announced the channel to the network.
addedToRouterGraph addedToRouterGraph
) )
@@ -604,8 +604,8 @@ func (c channelOpeningState) String() string {
switch c { switch c {
case markedOpen: case markedOpen:
return "markedOpen" return "markedOpen"
case fundingLockedSent: case channelReadySent:
return "fundingLocked" return "channelReady"
case addedToRouterGraph: case addedToRouterGraph:
return "addedToRouterGraph" return "addedToRouterGraph"
default: default:
@@ -617,16 +617,30 @@ func (c channelOpeningState) String() string {
// fundingManager. // fundingManager.
func NewFundingManager(cfg Config) (*Manager, error) { func NewFundingManager(cfg Config) (*Manager, error) {
return &Manager{ return &Manager{
cfg: &cfg, cfg: &cfg,
chanIDKey: cfg.TempChanIDSeed, chanIDKey: cfg.TempChanIDSeed,
activeReservations: make(map[serializedPubKey]pendingChannels), activeReservations: make(
signedReservations: make(map[lnwire.ChannelID][32]byte), map[serializedPubKey]pendingChannels,
newChanBarriers: make(map[lnwire.ChannelID]chan struct{}), ),
fundingMsgs: make(chan *fundingMsg, msgBufferSize), signedReservations: make(
fundingRequests: make(chan *InitFundingMsg, msgBufferSize), map[lnwire.ChannelID][32]byte,
localDiscoverySignals: make(map[lnwire.ChannelID]chan struct{}), ),
handleFundingLockedBarriers: make(map[lnwire.ChannelID]struct{}), newChanBarriers: make(
quit: make(chan struct{}), map[lnwire.ChannelID]chan struct{},
),
fundingMsgs: make(
chan *fundingMsg, msgBufferSize,
),
fundingRequests: make(
chan *InitFundingMsg, msgBufferSize,
),
localDiscoverySignals: make(
map[lnwire.ChannelID]chan struct{},
),
handleChannelReadyBarriers: make(
map[lnwire.ChannelID]struct{},
),
quit: make(chan struct{}),
}, nil }, nil
} }
@@ -889,9 +903,9 @@ func (f *Manager) reservationCoordinator() {
case *lnwire.FundingSigned: case *lnwire.FundingSigned:
f.handleFundingSigned(fmsg.peer, msg) f.handleFundingSigned(fmsg.peer, msg)
case *lnwire.FundingLocked: case *lnwire.ChannelReady:
f.wg.Add(1) f.wg.Add(1)
go f.handleFundingLocked(fmsg.peer, msg) go f.handleChannelReady(fmsg.peer, msg)
case *lnwire.Warning: case *lnwire.Warning:
f.handleWarningMsg(fmsg.peer, msg) f.handleWarningMsg(fmsg.peer, msg)
@@ -1000,38 +1014,38 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
switch channelState { switch channelState {
// The funding transaction was confirmed, but we did not successfully // The funding transaction was confirmed, but we did not successfully
// send the fundingLocked message to the peer, so let's do that now. // send the channelReady message to the peer, so let's do that now.
case markedOpen: case markedOpen:
err := f.sendFundingLocked(channel, lnChannel) err := f.sendChannelReady(channel, lnChannel)
if err != nil { if err != nil {
return fmt.Errorf("failed sending fundingLocked: %v", return fmt.Errorf("failed sending channelReady: %v",
err) err)
} }
// As the fundingLocked message is now sent to the peer, the // As the channelReady message is now sent to the peer, the
// channel is moved to the next state of the state machine. It // channel is moved to the next state of the state machine. It
// will be moved to the last state (actually deleted from the // will be moved to the last state (actually deleted from the
// database) after the channel is finally announced. // database) after the channel is finally announced.
err = f.saveChannelOpeningState( err = f.saveChannelOpeningState(
&channel.FundingOutpoint, fundingLockedSent, &channel.FundingOutpoint, channelReadySent,
shortChanID, shortChanID,
) )
if err != nil { if err != nil {
return fmt.Errorf("error setting channel state to"+ return fmt.Errorf("error setting channel state to"+
" fundingLockedSent: %v", err) " channelReadySent: %v", err)
} }
log.Debugf("Channel(%v) with ShortChanID %v: successfully "+ log.Debugf("Channel(%v) with ShortChanID %v: successfully "+
"sent FundingLocked", chanID, shortChanID) "sent ChannelReady", chanID, shortChanID)
return nil return nil
// fundingLocked was sent to peer, but the channel was not added to the // channelReady was sent to peer, but the channel was not added to the
// router graph and the channel announcement was not sent. // router graph and the channel announcement was not sent.
case fundingLockedSent: case channelReadySent:
// We must wait until we've received the peer's funding locked // We must wait until we've received the peer's funding locked
// before sending a channel_update according to BOLT#07. // before sending a channel_update according to BOLT#07.
received, err := f.receivedFundingLocked( received, err := f.receivedChannelReady(
channel.IdentityPub, chanID, channel.IdentityPub, chanID,
) )
if err != nil { if err != nil {
@@ -1040,11 +1054,11 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
} }
if !received { if !received {
// We haven't received FundingLocked, so we'll continue // We haven't received ChannelReady, so we'll continue
// to the next iteration of the loop after sleeping for // to the next iteration of the loop after sleeping for
// checkPeerFundingLockInterval. // checkPeerChannelReadyInterval.
select { select {
case <-time.After(checkPeerFundingLockInterval): case <-time.After(checkPeerChannelReadyInterval):
case <-f.quit: case <-f.quit:
return ErrFundingManagerShuttingDown return ErrFundingManagerShuttingDown
} }
@@ -1054,7 +1068,7 @@ func (f *Manager) stateStep(channel *channeldb.OpenChannel,
var peerAlias *lnwire.ShortChannelID var peerAlias *lnwire.ShortChannelID
if channel.IsZeroConf() { if channel.IsZeroConf() {
// We'll need to wait until funding_locked has been // We'll need to wait until channel_ready has been
// received and the peer lets us know the alias they // received and the peer lets us know the alias they
// want to use for the channel. With this information, // want to use for the channel. With this information,
// we can then construct a ChannelUpdate for them. // we can then construct a ChannelUpdate for them.
@@ -1213,7 +1227,7 @@ func (f *Manager) advancePendingChannelState(
f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint) f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint)
// Find and close the discoverySignal for this channel such // Find and close the discoverySignal for this channel such
// that FundingLocked messages will be processed. // that ChannelReady messages will be processed.
chanID := lnwire.NewChanIDFromOutPoint( chanID := lnwire.NewChanIDFromOutPoint(
&channel.FundingOutpoint, &channel.FundingOutpoint,
) )
@@ -2890,10 +2904,10 @@ func (f *Manager) handleFundingConfirmation(
return nil return nil
} }
// sendFundingLocked creates and sends the fundingLocked message. // sendChannelReady creates and sends the channelReady message.
// This should be called after the funding transaction has been confirmed, // This should be called after the funding transaction has been confirmed,
// and the channelState is 'markedOpen'. // and the channelState is 'markedOpen'.
func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel, func (f *Manager) sendChannelReady(completeChan *channeldb.OpenChannel,
channel *lnwallet.LightningChannel) error { channel *lnwallet.LightningChannel) error {
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint) chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
@@ -2909,7 +2923,7 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
if err != nil { if err != nil {
return fmt.Errorf("unable to create next revocation: %v", err) return fmt.Errorf("unable to create next revocation: %v", err)
} }
fundingLockedMsg := lnwire.NewFundingLocked(chanID, nextRevocation) channelReadyMsg := lnwire.NewChannelReady(chanID, nextRevocation)
// If the channel negotiated the option-scid-alias feature bit, we'll // If the channel negotiated the option-scid-alias feature bit, we'll
// send a TLV segment that includes an alias the peer can use in their // send a TLV segment that includes an alias the peer can use in their
@@ -2926,19 +2940,19 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
// We can use a pointer to aliases since GetAliases returns a // We can use a pointer to aliases since GetAliases returns a
// copy of the alias slice. // copy of the alias slice.
fundingLockedMsg.AliasScid = &aliases[0] channelReadyMsg.AliasScid = &aliases[0]
} }
// If the peer has disconnected before we reach this point, we will need // If the peer has disconnected before we reach this point, we will need
// to wait for him to come back online before sending the fundingLocked // to wait for him to come back online before sending the channelReady
// message. This is special for fundingLocked, since failing to send any // message. This is special for channelReady, since failing to send any
// of the previous messages in the funding flow just cancels the flow. // of the previous messages in the funding flow just cancels the flow.
// But now the funding transaction is confirmed, the channel is open // But now the funding transaction is confirmed, the channel is open
// and we have to make sure the peer gets the fundingLocked message when // and we have to make sure the peer gets the channelReady message when
// it comes back online. This is also crucial during restart of lnd, // it comes back online. This is also crucial during restart of lnd,
// where we might try to resend the fundingLocked message before the // where we might try to resend the channelReady message before the
// server has had the time to connect to the peer. We keep trying to // server has had the time to connect to the peer. We keep trying to
// send fundingLocked until we succeed, or the fundingManager is shut // send channelReady until we succeed, or the fundingManager is shut
// down. // down.
for { for {
peer, err := f.waitForPeerOnline(completeChan.IdentityPub) peer, err := f.waitForPeerOnline(completeChan.IdentityPub)
@@ -2956,14 +2970,14 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
// We could also refresh the channel state instead of checking // We could also refresh the channel state instead of checking
// whether the feature was negotiated, but this saves us a // whether the feature was negotiated, but this saves us a
// database read. // database read.
if fundingLockedMsg.AliasScid == nil && localAlias && if channelReadyMsg.AliasScid == nil && localAlias &&
remoteAlias { remoteAlias {
// If an alias was not assigned above and the scid // If an alias was not assigned above and the scid
// alias feature was negotiated, check if we already // alias feature was negotiated, check if we already
// have an alias stored in case handleFundingLocked was // have an alias stored in case handleChannelReady was
// called before this. If an alias exists, use that in // called before this. If an alias exists, use that in
// funding_locked. Otherwise, request and store an // channel_ready. Otherwise, request and store an
// alias and use that. // alias and use that.
aliases := f.cfg.AliasManager.GetAliases( aliases := f.cfg.AliasManager.GetAliases(
completeChan.ShortChannelID, completeChan.ShortChannelID,
@@ -2983,31 +2997,31 @@ func (f *Manager) sendFundingLocked(completeChan *channeldb.OpenChannel,
return err return err
} }
fundingLockedMsg.AliasScid = &alias channelReadyMsg.AliasScid = &alias
} else { } else {
fundingLockedMsg.AliasScid = &aliases[0] channelReadyMsg.AliasScid = &aliases[0]
} }
} }
log.Infof("Peer(%x) is online, sending FundingLocked "+ log.Infof("Peer(%x) is online, sending ChannelReady "+
"for ChannelID(%v)", peerKey, chanID) "for ChannelID(%v)", peerKey, chanID)
if err := peer.SendMessage(true, fundingLockedMsg); err == nil { if err := peer.SendMessage(true, channelReadyMsg); err == nil {
// Sending succeeded, we can break out and continue the // Sending succeeded, we can break out and continue the
// funding flow. // funding flow.
break break
} }
log.Warnf("Unable to send fundingLocked to peer %x: %v. "+ log.Warnf("Unable to send channelReady to peer %x: %v. "+
"Will retry when online", peerKey, err) "Will retry when online", peerKey, err)
} }
return nil return nil
} }
// receivedFundingLocked checks whether or not we've received a FundingLocked // receivedChannelReady checks whether or not we've received a ChannelReady
// from the remote peer. If we have, RemoteNextRevocation will be set. // from the remote peer. If we have, RemoteNextRevocation will be set.
func (f *Manager) receivedFundingLocked(node *btcec.PublicKey, func (f *Manager) receivedChannelReady(node *btcec.PublicKey,
chanID lnwire.ChannelID) (bool, error) { chanID lnwire.ChannelID) (bool, error) {
// If the funding manager has exited, return an error to stop looping. // If the funding manager has exited, return an error to stop looping.
@@ -3028,7 +3042,7 @@ func (f *Manager) receivedFundingLocked(node *btcec.PublicKey,
channel, err := f.cfg.FindChannel(node, chanID) channel, err := f.cfg.FindChannel(node, chanID)
if err != nil { if err != nil {
log.Errorf("Unable to locate ChannelID(%v) to determine if "+ log.Errorf("Unable to locate ChannelID(%v) to determine if "+
"FundingLocked was received", chanID) "ChannelReady was received", chanID)
return false, err return false, err
} }
@@ -3140,7 +3154,7 @@ func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
} }
// annAfterSixConfs broadcasts the necessary channel announcement messages to // annAfterSixConfs broadcasts the necessary channel announcement messages to
// the network after 6 confs. Should be called after the fundingLocked message // the network after 6 confs. Should be called after the channelReady message
// is sent and the channel is added to the router graph (channelState is // is sent and the channel is added to the router graph (channelState is
// 'addedToRouterGraph') and the channel is ready to be used. This is the last // 'addedToRouterGraph') and the channel is ready to be used. This is the last
// step in the channel opening process, and the opening state will be deleted // step in the channel opening process, and the opening state will be deleted
@@ -3391,36 +3405,36 @@ func (f *Manager) waitForZeroConfChannel(c *channeldb.OpenChannel,
return nil return nil
} }
// handleFundingLocked finalizes the channel funding process and enables the // handleChannelReady finalizes the channel funding process and enables the
// channel to enter normal operating mode. // channel to enter normal operating mode.
func (f *Manager) handleFundingLocked(peer lnpeer.Peer, func (f *Manager) handleChannelReady(peer lnpeer.Peer,
msg *lnwire.FundingLocked) { msg *lnwire.ChannelReady) {
defer f.wg.Done() defer f.wg.Done()
log.Debugf("Received FundingLocked for ChannelID(%v) from "+ log.Debugf("Received ChannelReady for ChannelID(%v) from "+
"peer %x", msg.ChanID, "peer %x", msg.ChanID,
peer.IdentityKey().SerializeCompressed()) peer.IdentityKey().SerializeCompressed())
// If we are currently in the process of handling a funding locked // If we are currently in the process of handling a funding locked
// message for this channel, ignore. // message for this channel, ignore.
f.handleFundingLockedMtx.Lock() f.handleChannelReadyMtx.Lock()
_, ok := f.handleFundingLockedBarriers[msg.ChanID] _, ok := f.handleChannelReadyBarriers[msg.ChanID]
if ok { if ok {
log.Infof("Already handling fundingLocked for "+ log.Infof("Already handling channelReady for "+
"ChannelID(%v), ignoring.", msg.ChanID) "ChannelID(%v), ignoring.", msg.ChanID)
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
return return
} }
// If not already handling fundingLocked for this channel, set up // If not already handling channelReady for this channel, set up
// barrier, and move on. // barrier, and move on.
f.handleFundingLockedBarriers[msg.ChanID] = struct{}{} f.handleChannelReadyBarriers[msg.ChanID] = struct{}{}
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
defer func() { defer func() {
f.handleFundingLockedMtx.Lock() f.handleChannelReadyMtx.Lock()
delete(f.handleFundingLockedBarriers, msg.ChanID) delete(f.handleChannelReadyBarriers, msg.ChanID)
f.handleFundingLockedMtx.Unlock() f.handleChannelReadyMtx.Unlock()
}() }()
f.localDiscoveryMtx.Lock() f.localDiscoveryMtx.Lock()
@@ -3464,7 +3478,7 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
// during invoice creation. In the zero-conf case, it is also used to // during invoice creation. In the zero-conf case, it is also used to
// provide a ChannelUpdate to the remote peer. This is done before the // provide a ChannelUpdate to the remote peer. This is done before the
// call to InsertNextRevocation in case the call to PutPeerAlias fails. // call to InsertNextRevocation in case the call to PutPeerAlias fails.
// If it were to fail on the first call to handleFundingLocked, we // If it were to fail on the first call to handleChannelReady, we
// wouldn't want the channel to be usable yet. // wouldn't want the channel to be usable yet.
if channel.NegotiatedAliasFeature() { if channel.NegotiatedAliasFeature() {
// If the AliasScid field is nil, we must fail out. We will // If the AliasScid field is nil, we must fail out. We will
@@ -3487,14 +3501,14 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
// If we do not have an alias stored, we'll create one now. // If we do not have an alias stored, we'll create one now.
// This is only used in the upgrade case where a user toggles // This is only used in the upgrade case where a user toggles
// the option-scid-alias feature-bit to on. We'll also send the // the option-scid-alias feature-bit to on. We'll also send the
// funding_locked message here in case the link is created // channel_ready message here in case the link is created
// before sendFundingLocked is called. // before sendChannelReady is called.
aliases := f.cfg.AliasManager.GetAliases( aliases := f.cfg.AliasManager.GetAliases(
channel.ShortChannelID, channel.ShortChannelID,
) )
if len(aliases) == 0 { if len(aliases) == 0 {
// No aliases were found so we'll request and store an // No aliases were found so we'll request and store an
// alias and use it in the funding_locked message. // alias and use it in the channel_ready message.
alias, err := f.cfg.AliasManager.RequestAlias() alias, err := f.cfg.AliasManager.RequestAlias()
if err != nil { if err != nil {
log.Errorf("unable to request alias: %v", err) log.Errorf("unable to request alias: %v", err)
@@ -3517,12 +3531,12 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
return return
} }
fundingLockedMsg := lnwire.NewFundingLocked( channelReadyMsg := lnwire.NewChannelReady(
chanID, secondPoint, chanID, secondPoint,
) )
fundingLockedMsg.AliasScid = &alias channelReadyMsg.AliasScid = &alias
err = peer.SendMessage(true, fundingLockedMsg) err = peer.SendMessage(true, channelReadyMsg)
if err != nil { if err != nil {
log.Errorf("unable to send funding locked: %v", log.Errorf("unable to send funding locked: %v",
err) err)
@@ -3532,16 +3546,16 @@ func (f *Manager) handleFundingLocked(peer lnpeer.Peer,
} }
// If the RemoteNextRevocation is non-nil, it means that we have // If the RemoteNextRevocation is non-nil, it means that we have
// already processed fundingLocked for this channel, so ignore. This // already processed channelReady for this channel, so ignore. This
// check is after the alias logic so we store the peer's most recent // check is after the alias logic so we store the peer's most recent
// alias. The spec requires us to validate that subsequent // alias. The spec requires us to validate that subsequent
// funding_locked messages use the same per commitment point (the // channel_ready messages use the same per commitment point (the
// second), but it is not actually necessary since we'll just end up // second), but it is not actually necessary since we'll just end up
// ignoring it. We are, however, required to *send* the same per // ignoring it. We are, however, required to *send* the same per
// commitment point, since another pedantic implementation might // commitment point, since another pedantic implementation might
// verify it. // verify it.
if channel.RemoteNextRevocation != nil { if channel.RemoteNextRevocation != nil {
log.Infof("Received duplicate fundingLocked for "+ log.Infof("Received duplicate channelReady for "+
"ChannelID(%v), ignoring.", chanID) "ChannelID(%v), ignoring.", chanID)
return return
} }
+180 -160
View File
@@ -900,8 +900,8 @@ func assertFundingMsgSent(t *testing.T, msgChan chan lnwire.Message,
sentMsg, ok = msg.(*lnwire.FundingCreated) sentMsg, ok = msg.(*lnwire.FundingCreated)
case "FundingSigned": case "FundingSigned":
sentMsg, ok = msg.(*lnwire.FundingSigned) sentMsg, ok = msg.(*lnwire.FundingSigned)
case "FundingLocked": case "ChannelReady":
sentMsg, ok = msg.(*lnwire.FundingLocked) sentMsg, ok = msg.(*lnwire.ChannelReady)
case "Error": case "Error":
sentMsg, ok = msg.(*lnwire.Error) sentMsg, ok = msg.(*lnwire.Error)
default: default:
@@ -1050,13 +1050,13 @@ func assertMarkedOpen(t *testing.T, alice, bob *testNode,
assertDatabaseState(t, bob, fundingOutPoint, markedOpen) assertDatabaseState(t, bob, fundingOutPoint, markedOpen)
} }
func assertFundingLockedSent(t *testing.T, alice, bob *testNode, func assertChannelReadySent(t *testing.T, alice, bob *testNode,
fundingOutPoint *wire.OutPoint) { fundingOutPoint *wire.OutPoint) {
t.Helper() t.Helper()
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
} }
func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode, func assertAddedToRouterGraph(t *testing.T, alice, bob *testNode,
@@ -1082,7 +1082,7 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
t.Helper() t.Helper()
// After the FundingLocked message is sent, Alice and Bob will each send // After the ChannelReady message is sent, Alice and Bob will each send
// the following messages to their gossiper: // the following messages to their gossiper:
// 1) ChannelAnnouncement // 1) ChannelAnnouncement
// 2) ChannelUpdate // 2) ChannelUpdate
@@ -1222,7 +1222,7 @@ func assertChannelAnnouncements(t *testing.T, alice, bob *testNode,
func assertAnnouncementSignatures(t *testing.T, alice, bob *testNode) { func assertAnnouncementSignatures(t *testing.T, alice, bob *testNode) {
t.Helper() t.Helper()
// After the FundingLocked message is sent and six confirmations have // After the ChannelReady message is sent and six confirmations have
// been reached, the channel will be announced to the greater network // been reached, the channel will be announced to the greater network
// by having the nodes exchange announcement signatures. // by having the nodes exchange announcement signatures.
// Two distinct messages will be sent: // Two distinct messages will be sent:
@@ -1347,7 +1347,7 @@ func assertInitialFwdingPolicyNotFound(t *testing.T, node *testNode,
fwdingPolicy) fwdingPolicy)
} }
func assertHandleFundingLocked(t *testing.T, alice, bob *testNode) { func assertHandleChannelReady(t *testing.T, alice, bob *testNode) {
t.Helper() t.Helper()
// They should both send the new channel state to their peer. // They should both send the new channel state to their peer.
@@ -1405,26 +1405,28 @@ func TestFundingManagerNormalWorkflow(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -1635,7 +1637,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
) )
// After the funding transaction gets mined, both nodes will send the // After the funding transaction gets mined, both nodes will send the
// fundingLocked message to the other peer. If the funding node fails // channelReady message to the other peer. If the funding node fails
// before this message has been successfully sent, it should retry // before this message has been successfully sent, it should retry
// sending it on restart. We mimic this behavior by letting the // sending it on restart. We mimic this behavior by letting the
// SendToPeer method return an error, as if the message was not // SendToPeer method return an error, as if the message was not
@@ -1666,7 +1668,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction was mined, Bob should have successfully // After the funding transaction was mined, Bob should have successfully
// sent the fundingLocked message, while Alice failed sending it. In // sent the channelReady message, while Alice failed sending it. In
// Alice's case this means that there should be no messages for Bob, and // Alice's case this means that there should be no messages for Bob, and
// the channel should still be in state 'markedOpen' // the channel should still be in state 'markedOpen'
select { select {
@@ -1677,18 +1679,19 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
} }
// Bob will send funding locked to Alice. // Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Alice should still be markedOpen // Alice should still be markedOpen
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// While Bob successfully sent fundingLocked. // While Bob successfully sent channelReady.
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
// We now recreate Alice's fundingManager with the correct sendMessage // We now recreate Alice's fundingManager with the correct sendMessage
// implementation, and expect it to retry sending the fundingLocked // implementation, and expect it to retry sending the channelReady
// message. We'll explicitly shut down Alice's funding manager to // message. We'll explicitly shut down Alice's funding manager to
// prevent a race when overriding the sendMessage implementation. // prevent a race when overriding the sendMessage implementation.
if err := alice.fundingMgr.Stop(); err != nil { if err := alice.fundingMgr.Stop(); err != nil {
@@ -1706,12 +1709,13 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
return errChan return errChan
} }
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// The state should now be fundingLockedSent // The state should now be channelReadySent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Check that the channel announcements were never sent // Check that the channel announcements were never sent
select { select {
@@ -1722,13 +1726,13 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
// Expected // Expected
} }
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Next up, we check that Alice rebroadcasts the announcement // Next up, we check that Alice rebroadcasts the announcement
// messages on restart. Bob should as expected send announcements. // messages on restart. Bob should as expected send announcements.
@@ -1771,7 +1775,7 @@ func TestFundingManagerRestartBehavior(t *testing.T) {
// TestFundingManagerOfflinePeer checks that the fundingManager waits for the // TestFundingManagerOfflinePeer checks that the fundingManager waits for the
// server to notify when the peer comes online, in case sending the // server to notify when the peer comes online, in case sending the
// fundingLocked message fails the first time. // channelReady message fails the first time.
func TestFundingManagerOfflinePeer(t *testing.T) { func TestFundingManagerOfflinePeer(t *testing.T) {
t.Parallel() t.Parallel()
@@ -1791,8 +1795,8 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
) )
// After the funding transaction gets mined, both nodes will send the // After the funding transaction gets mined, both nodes will send the
// fundingLocked message to the other peer. If the funding node fails // channelReady message to the other peer. If the funding node fails
// to send the fundingLocked message to the peer, it should wait for // to send the channelReady message to the peer, it should wait for
// the server to notify it that the peer is back online, and try again. // the server to notify it that the peer is back online, and try again.
// We'll save the current implementation of sendMessage to restore the // We'll save the current implementation of sendMessage to restore the
// original behavior later on. // original behavior later on.
@@ -1823,7 +1827,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction was mined, Bob should have successfully // After the funding transaction was mined, Bob should have successfully
// sent the fundingLocked message, while Alice failed sending it. In // sent the channelReady message, while Alice failed sending it. In
// Alice's case this means that there should be no messages for Bob, and // Alice's case this means that there should be no messages for Bob, and
// the channel should still be in state 'markedOpen' // the channel should still be in state 'markedOpen'
select { select {
@@ -1834,15 +1838,16 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
} }
// Bob will send funding locked to Alice // Bob will send funding locked to Alice
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Alice should still be markedOpen // Alice should still be markedOpen
assertDatabaseState(t, alice, fundingOutPoint, markedOpen) assertDatabaseState(t, alice, fundingOutPoint, markedOpen)
// While Bob successfully sent fundingLocked. // While Bob successfully sent channelReady.
assertDatabaseState(t, bob, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, bob, fundingOutPoint, channelReadySent)
// Alice should be waiting for the server to notify when Bob comes back // Alice should be waiting for the server to notify when Bob comes back
// online. // online.
@@ -1868,7 +1873,7 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
} }
// Before sending on the con chan, update Alice's NotifyWhenOnline // Before sending on the con chan, update Alice's NotifyWhenOnline
// function so that the next invocation in receivedFundingLocked will // function so that the next invocation in receivedChannelReady will
// use this new function. // use this new function.
alice.fundingMgr.cfg.NotifyWhenOnline = func(peer [33]byte, alice.fundingMgr.cfg.NotifyWhenOnline = func(peer [33]byte,
connected chan<- lnpeer.Peer) { connected chan<- lnpeer.Peer) {
@@ -1881,21 +1886,22 @@ func TestFundingManagerOfflinePeer(t *testing.T) {
bob.sendMessage = workingSendMessage bob.sendMessage = workingSendMessage
con <- bob con <- bob
// This should make Alice send the fundingLocked. // This should make Alice send the channelReady.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// The state should now be fundingLockedSent // The state should now be channelReadySent
assertDatabaseState(t, alice, fundingOutPoint, fundingLockedSent) assertDatabaseState(t, alice, fundingOutPoint, channelReadySent)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -2272,10 +2278,10 @@ func TestFundingManagerFundingNotTimeoutInitiator(t *testing.T) {
assertNumPendingChannelsBecomes(t, bob, 0) assertNumPendingChannelsBecomes(t, bob, 0)
} }
// TestFundingManagerReceiveFundingLockedTwice checks that the fundingManager // TestFundingManagerReceiveChannelReadyTwice checks that the fundingManager
// continues to operate as expected in case we receive a duplicate fundingLocked // continues to operate as expected in case we receive a duplicate channelReady
// message. // message.
func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) { func TestFundingManagerReceiveChannelReadyTwice(t *testing.T) {
t.Parallel() t.Parallel()
alice, bob := setupFundingManagers(t) alice, bob := setupFundingManagers(t)
@@ -2310,27 +2316,29 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Send the fundingLocked message twice to Alice, and once to Bob. // Send the channelReady message twice to Alice, and once to Bob.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Alice should not send the channel state the second time, as the // Alice should not send the channel state the second time, as the
// second funding locked should just be ignored. // second funding locked should just be ignored.
@@ -2341,9 +2349,9 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
// Expected // Expected
} }
// Another fundingLocked should also be ignored, since Alice should // Another channelReady should also be ignored, since Alice should
// have updated her database at this point. // have updated her database at this point.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
select { select {
case <-alice.newChannels: case <-alice.newChannels:
t.Fatalf("alice sent new channel to peer a second time") t.Fatalf("alice sent new channel to peer a second time")
@@ -2384,7 +2392,7 @@ func TestFundingManagerReceiveFundingLockedTwice(t *testing.T) {
} }
// TestFundingManagerRestartAfterChanAnn checks that the fundingManager properly // TestFundingManagerRestartAfterChanAnn checks that the fundingManager properly
// handles receiving a fundingLocked after the its own fundingLocked and channel // handles receiving a channelReady after the its own channelReady and channel
// announcement is sent and gets restarted. // announcement is sent and gets restarted.
func TestFundingManagerRestartAfterChanAnn(t *testing.T) { func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
t.Parallel() t.Parallel()
@@ -2421,26 +2429,28 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -2454,7 +2464,7 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
waitForOpenUpdate(t, updateChan) waitForOpenUpdate(t, updateChan)
// At this point we restart Alice's fundingManager, before she receives // At this point we restart Alice's fundingManager, before she receives
// the fundingLocked message. After restart, she will receive it, and // the channelReady message. After restart, she will receive it, and
// we expect her to be able to handle it correctly. // we expect her to be able to handle it correctly.
recreateAliceFundingManager(t, alice) recreateAliceFundingManager(t, alice)
@@ -2480,10 +2490,10 @@ func TestFundingManagerRestartAfterChanAnn(t *testing.T) {
assertNoFwdingPolicy(t, alice, bob, fundingOutPoint) assertNoFwdingPolicy(t, alice, bob, fundingOutPoint)
} }
// TestFundingManagerRestartAfterReceivingFundingLocked checks that the // TestFundingManagerRestartAfterReceivingChannelReady checks that the
// fundingManager continues to operate as expected after it has received // fundingManager continues to operate as expected after it has received
// fundingLocked and then gets restarted. // channelReady and then gets restarted.
func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) { func TestFundingManagerRestartAfterReceivingChannelReady(t *testing.T) {
t.Parallel() t.Parallel()
alice, bob := setupFundingManagers(t) alice, bob := setupFundingManagers(t)
@@ -2518,28 +2528,30 @@ func TestFundingManagerRestartAfterReceivingFundingLocked(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Let Alice immediately get the fundingLocked message. // Let Alice immediately get the channelReady message.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
// Also let Bob get the fundingLocked message. // Also let Bob get the channelReady message.
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// At this point we restart Alice's fundingManager. // At this point we restart Alice's fundingManager.
recreateAliceFundingManager(t, alice) recreateAliceFundingManager(t, alice)
@@ -2611,26 +2623,28 @@ func TestFundingManagerPrivateChannel(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -2734,26 +2748,28 @@ func TestFundingManagerPrivateRestart(t *testing.T) {
assertMarkedOpen(t, alice, bob, fundingOutPoint) assertMarkedOpen(t, alice, bob, fundingOutPoint)
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Check that the state machine is updated accordingly // Check that the state machine is updated accordingly
assertFundingLockedSent(t, alice, bob, fundingOutPoint) assertChannelReadySent(t, alice, bob, fundingOutPoint)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -3169,23 +3185,25 @@ func TestFundingManagerCustomChannelParameters(t *testing.T) {
} }
// After the funding transaction is mined, Alice will send // After the funding transaction is mined, Alice will send
// fundingLocked to Bob. // channelReady to Bob.
fundingLockedAlice := assertFundingMsgSent( channelReadyAlice, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// And similarly Bob will send funding locked to Alice. // And similarly Bob will send funding locked to Alice.
fundingLockedBob := assertFundingMsgSent( channelReadyBob, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.True(t, ok)
// Exchange the fundingLocked messages. // Exchange the channelReady messages.
alice.fundingMgr.ProcessFundingMsg(fundingLockedBob, bob) alice.fundingMgr.ProcessFundingMsg(channelReadyBob, bob)
bob.fundingMgr.ProcessFundingMsg(fundingLockedAlice, alice) bob.fundingMgr.ProcessFundingMsg(channelReadyAlice, alice)
// Check that they notify the breach arbiter and peer about the new // Check that they notify the breach arbiter and peer about the new
// channel. // channel.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// Make sure both fundingManagers send the expected channel // Make sure both fundingManagers send the expected channel
// announcements. // announcements.
@@ -3486,14 +3504,14 @@ func TestFundingManagerMaxPendingChannels(t *testing.T) {
Tx: txs[i], Tx: txs[i],
} }
// Expect both to be sending FundingLocked. // Expect both to be sending ChannelReady.
_ = assertFundingMsgSent( _ = assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
_ = assertFundingMsgSent( _ = assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
} }
@@ -4202,26 +4220,28 @@ func TestFundingManagerZeroConf(t *testing.T) {
Index: 0, Index: 0,
} }
// Assert that Bob's funding_locked message has an AliasScid. // Assert that Bob's channel_ready message has an AliasScid.
bobFundingLocked := assertFundingMsgSent( bobChannelReady, ok := assertFundingMsgSent(
t, bob.msgChan, "FundingLocked", t, bob.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.NotNil(t, bobFundingLocked.AliasScid) require.True(t, ok)
require.Equal(t, *bobFundingLocked.AliasScid, alias) require.NotNil(t, bobChannelReady.AliasScid)
require.Equal(t, *bobChannelReady.AliasScid, alias)
// Do the same for Alice as well. // Do the same for Alice as well.
aliceFundingLocked := assertFundingMsgSent( aliceChannelReady, ok := assertFundingMsgSent(
t, alice.msgChan, "FundingLocked", t, alice.msgChan, "ChannelReady",
).(*lnwire.FundingLocked) ).(*lnwire.ChannelReady)
require.NotNil(t, aliceFundingLocked.AliasScid) require.True(t, ok)
require.Equal(t, *aliceFundingLocked.AliasScid, alias) require.NotNil(t, aliceChannelReady.AliasScid)
require.Equal(t, *aliceChannelReady.AliasScid, alias)
// Exchange the funding_locked messages. // Exchange the channel_ready messages.
alice.fundingMgr.ProcessFundingMsg(bobFundingLocked, bob) alice.fundingMgr.ProcessFundingMsg(bobChannelReady, bob)
bob.fundingMgr.ProcessFundingMsg(aliceFundingLocked, alice) bob.fundingMgr.ProcessFundingMsg(aliceChannelReady, alice)
// We'll assert that they both create new links. // We'll assert that they both create new links.
assertHandleFundingLocked(t, alice, bob) assertHandleChannelReady(t, alice, bob)
// We'll now assert that both sides send ChannelAnnouncement and // We'll now assert that both sides send ChannelAnnouncement and
// ChannelUpdate messages. // ChannelUpdate messages.
+7 -7
View File
@@ -724,12 +724,12 @@ func (l *channelLink) syncChanStates() error {
// done any state updates yet, then we'll retransmit the // done any state updates yet, then we'll retransmit the
// funding locked message first. We do this, as at this point // funding locked message first. We do this, as at this point
// we can't be sure if they've really received the // we can't be sure if they've really received the
// FundingLocked message. // ChannelReady message.
if remoteChanSyncMsg.NextLocalCommitHeight == 1 && if remoteChanSyncMsg.NextLocalCommitHeight == 1 &&
localChanSyncMsg.NextLocalCommitHeight == 1 && localChanSyncMsg.NextLocalCommitHeight == 1 &&
!l.channel.IsPending() { !l.channel.IsPending() {
l.log.Infof("resending FundingLocked message to peer") l.log.Infof("resending ChannelReady message to peer")
nextRevocation, err := l.channel.NextRevocationKey() nextRevocation, err := l.channel.NextRevocationKey()
if err != nil { if err != nil {
@@ -737,13 +737,13 @@ func (l *channelLink) syncChanStates() error {
"revocation: %v", err) "revocation: %v", err)
} }
fundingLockedMsg := lnwire.NewFundingLocked( channelReadyMsg := lnwire.NewChannelReady(
l.ChanID(), nextRevocation, l.ChanID(), nextRevocation,
) )
// For channels that negotiated the option-scid-alias // For channels that negotiated the option-scid-alias
// feature bit, ensure that we send over the alias in // feature bit, ensure that we send over the alias in
// the funding_locked message. We'll send the first // the channel_ready message. We'll send the first
// alias we find for the channel since it does not // alias we find for the channel since it does not
// matter which alias we send. We'll error out if no // matter which alias we send. We'll error out if no
// aliases are found. // aliases are found.
@@ -759,13 +759,13 @@ func (l *channelLink) syncChanStates() error {
// getAliases returns a copy of the alias slice // getAliases returns a copy of the alias slice
// so it is ok to use a pointer to the first // so it is ok to use a pointer to the first
// entry. // entry.
fundingLockedMsg.AliasScid = &aliases[0] channelReadyMsg.AliasScid = &aliases[0]
} }
err = l.cfg.Peer.SendMessage(false, fundingLockedMsg) err = l.cfg.Peer.SendMessage(false, channelReadyMsg)
if err != nil { if err != nil {
return fmt.Errorf("unable to re-send "+ return fmt.Errorf("unable to re-send "+
"FundingLocked: %v", err) "ChannelReady: %v", err)
} }
} }
+12 -12
View File
@@ -1684,8 +1684,8 @@ func TestChannelLinkSingleHopMessageOrdering(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
{"alice", "bob", &lnwire.UpdateAddHTLC{}, false}, {"alice", "bob", &lnwire.UpdateAddHTLC{}, false},
{"alice", "bob", &lnwire.CommitSig{}, false}, {"alice", "bob", &lnwire.CommitSig{}, false},
@@ -3303,8 +3303,8 @@ func TestChannelRetransmission(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
// Send payment from Alice to Bob and intercept // Send payment from Alice to Bob and intercept
// the last revocation message, in this case // the last revocation message, in this case
@@ -3343,8 +3343,8 @@ func TestChannelRetransmission(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
// Send payment from Alice to Bob and intercept // Send payment from Alice to Bob and intercept
// the last revocation message, in this case // the last revocation message, in this case
@@ -3385,8 +3385,8 @@ func TestChannelRetransmission(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
// Attempt make a payment from Alice to Bob, // Attempt make a payment from Alice to Bob,
// which is intercepted, emulating the Bob // which is intercepted, emulating the Bob
@@ -3399,8 +3399,8 @@ func TestChannelRetransmission(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
// After Bob has notified Alice that he didn't // After Bob has notified Alice that he didn't
// receive updates Alice should re-send them. // receive updates Alice should re-send them.
@@ -3816,8 +3816,8 @@ func TestChannelLinkUpdateCommitFee(t *testing.T) {
{"alice", "bob", &lnwire.ChannelReestablish{}, false}, {"alice", "bob", &lnwire.ChannelReestablish{}, false},
{"bob", "alice", &lnwire.ChannelReestablish{}, false}, {"bob", "alice", &lnwire.ChannelReestablish{}, false},
{"alice", "bob", &lnwire.FundingLocked{}, false}, {"alice", "bob", &lnwire.ChannelReady{}, false},
{"bob", "alice", &lnwire.FundingLocked{}, false}, {"bob", "alice", &lnwire.ChannelReady{}, false},
// First fee update. // First fee update.
{"alice", "bob", &lnwire.UpdateFee{}, false}, {"alice", "bob", &lnwire.UpdateFee{}, false},
+1 -1
View File
@@ -627,7 +627,7 @@ func (s *mockServer) readHandler(message lnwire.Message) error {
targetChan = msg.ChanID targetChan = msg.ChanID
case *lnwire.CommitSig: case *lnwire.CommitSig:
targetChan = msg.ChanID targetChan = msg.ChanID
case *lnwire.FundingLocked: case *lnwire.ChannelReady:
// Ignore // Ignore
return nil return nil
case *lnwire.ChannelReestablish: case *lnwire.ChannelReestablish:
+1 -1
View File
@@ -82,7 +82,7 @@ func TestSwitchAddDuplicateLink(t *testing.T) {
// TestSwitchHasActiveLink tests the behavior of HasActiveLink, and asserts that // TestSwitchHasActiveLink tests the behavior of HasActiveLink, and asserts that
// it only returns true if a link's short channel id has confirmed (meaning the // it only returns true if a link's short channel id has confirmed (meaning the
// channel is no longer pending) and it's EligibleToForward method returns true, // channel is no longer pending) and it's EligibleToForward method returns true,
// i.e. it has received FundingLocked from the remote peer. // i.e. it has received ChannelReady from the remote peer.
func TestSwitchHasActiveLink(t *testing.T) { func TestSwitchHasActiveLink(t *testing.T) {
t.Parallel() t.Parallel()
+1 -1
View File
@@ -495,7 +495,7 @@ func getChanID(msg lnwire.Message) (lnwire.ChannelID, error) {
chanID = msg.ChanID chanID = msg.ChanID
case *lnwire.ChannelReestablish: case *lnwire.ChannelReestablish:
chanID = msg.ChanID chanID = msg.ChanID
case *lnwire.FundingLocked: case *lnwire.ChannelReady:
chanID = msg.ChanID chanID = msg.ChanID
case *lnwire.UpdateFee: case *lnwire.UpdateFee:
chanID = msg.ChanID chanID = msg.ChanID
+2 -2
View File
@@ -101,8 +101,8 @@ the real-world has. Aside from that, `lnd` has several places that use
different code, which is triggered by the build flag `integration`, to speed up different code, which is triggered by the build flag `integration`, to speed up
the tests. They are summarized as followings, the tests. They are summarized as followings,
1. `funding.checkPeerFundingLockInterval`, which is used when we wait for the 1. `funding.checkPeerChannelReadyInterval`, which is used when we wait for the
peer to send us `FundingLocked`. This value is 1 second in `lnd`, and 10 peer to send us `ChannelReady`. This value is 1 second in `lnd`, and 10
milliseconds in `lntest`. milliseconds in `lntest`.
2. `lncfg.ProtocolOptions`, which is used to specify protocol flags. In `lnd`, 2. `lncfg.ProtocolOptions`, which is used to specify protocol flags. In `lnd`,
anchor and script enforced lease are enabled by default, while in `lntest`, anchor and script enforced lease are enabled by default, while in `lntest`,
+2 -2
View File
@@ -4063,7 +4063,7 @@ func (lc *LightningChannel) ProcessChanSyncMsg(
// If we get a failure due to not knowing their next // If we get a failure due to not knowing their next
// point, then this is fine as they'll either send // point, then this is fine as they'll either send
// FundingLocked, or revoke their next state to allow // ChannelReady, or revoke their next state to allow
// us to continue forwards. // us to continue forwards.
case err == ErrNoWindow: case err == ErrNoWindow:
@@ -7220,7 +7220,7 @@ func (lc *LightningChannel) generateRevocation(height uint64) (*lnwire.RevokeAnd
// Along with this revocation, we'll also send the _next_ commitment // Along with this revocation, we'll also send the _next_ commitment
// point that the remote party should use to create our next commitment // point that the remote party should use to create our next commitment
// transaction. We use a +2 here as we already gave them a look ahead // transaction. We use a +2 here as we already gave them a look ahead
// of size one after the FundingLocked message was sent: // of size one after the ChannelReady message was sent:
// //
// 0: current revocation, 1: their "next" revocation, 2: this revocation // 0: current revocation, 1: their "next" revocation, 2: this revocation
// //
@@ -8,12 +8,12 @@ import (
"github.com/lightningnetwork/lnd/tlv" "github.com/lightningnetwork/lnd/tlv"
) )
// FundingLocked is the message that both parties to a new channel creation // ChannelReady is the message that both parties to a new channel creation
// send once they have observed the funding transaction being confirmed on the // send once they have observed the funding transaction being confirmed on the
// blockchain. FundingLocked contains the signatures necessary for the channel // blockchain. ChannelReady contains the signatures necessary for the channel
// participants to advertise the existence of the channel to the rest of the // participants to advertise the existence of the channel to the rest of the
// network. // network.
type FundingLocked struct { type ChannelReady struct {
// ChanID is the outpoint of the channel's funding transaction. This // ChanID is the outpoint of the channel's funding transaction. This
// can be used to query for the channel in the database. // can be used to query for the channel in the database.
ChanID ChannelID ChanID ChannelID
@@ -33,26 +33,26 @@ type FundingLocked struct {
ExtraData ExtraOpaqueData ExtraData ExtraOpaqueData
} }
// NewFundingLocked creates a new FundingLocked message, populating it with the // NewChannelReady creates a new ChannelReady message, populating it with the
// necessary IDs and revocation secret. // necessary IDs and revocation secret.
func NewFundingLocked(cid ChannelID, npcp *btcec.PublicKey) *FundingLocked { func NewChannelReady(cid ChannelID, npcp *btcec.PublicKey) *ChannelReady {
return &FundingLocked{ return &ChannelReady{
ChanID: cid, ChanID: cid,
NextPerCommitmentPoint: npcp, NextPerCommitmentPoint: npcp,
ExtraData: make([]byte, 0), ExtraData: make([]byte, 0),
} }
} }
// A compile time check to ensure FundingLocked implements the lnwire.Message // A compile time check to ensure ChannelReady implements the lnwire.Message
// interface. // interface.
var _ Message = (*FundingLocked)(nil) var _ Message = (*ChannelReady)(nil)
// Decode deserializes the serialized FundingLocked message stored in the // Decode deserializes the serialized ChannelReady message stored in the
// passed io.Reader into the target FundingLocked using the deserialization // passed io.Reader into the target ChannelReady using the deserialization
// rules defined by the passed protocol version. // rules defined by the passed protocol version.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *FundingLocked) Decode(r io.Reader, pver uint32) error { func (c *ChannelReady) Decode(r io.Reader, pver uint32) error {
// Read all the mandatory fields in the message. // Read all the mandatory fields in the message.
err := ReadElements(r, err := ReadElements(r,
&c.ChanID, &c.ChanID,
@@ -80,12 +80,12 @@ func (c *FundingLocked) Decode(r io.Reader, pver uint32) error {
return nil return nil
} }
// Encode serializes the target FundingLocked message into the passed io.Writer // Encode serializes the target ChannelReady message into the passed io.Writer
// implementation. Serialization will observe the rules defined by the passed // implementation. Serialization will observe the rules defined by the passed
// protocol version. // protocol version.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error { func (c *ChannelReady) Encode(w *bytes.Buffer, pver uint32) error {
if err := WriteChannelID(w, c.ChanID); err != nil { if err := WriteChannelID(w, c.ChanID); err != nil {
return err return err
} }
@@ -107,9 +107,9 @@ func (c *FundingLocked) Encode(w *bytes.Buffer, pver uint32) error {
} }
// MsgType returns the uint32 code which uniquely identifies this message as a // MsgType returns the uint32 code which uniquely identifies this message as a
// FundingLocked message on the wire. // ChannelReady message on the wire.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *FundingLocked) MsgType() MessageType { func (c *ChannelReady) MsgType() MessageType {
return MsgFundingLocked return MsgChannelReady
} }
+2 -2
View File
@@ -169,12 +169,12 @@ const (
// ScidAliasRequired is a required feature bit that signals that the // ScidAliasRequired is a required feature bit that signals that the
// node requires understanding of ShortChannelID aliases in the TLV // node requires understanding of ShortChannelID aliases in the TLV
// segment of the funding_locked message. // segment of the channel_ready message.
ScidAliasRequired FeatureBit = 46 ScidAliasRequired FeatureBit = 46
// ScidAliasOptional is an optional feature bit that signals that the // ScidAliasOptional is an optional feature bit that signals that the
// node understands ShortChannelID aliases in the TLV segment of the // node understands ShortChannelID aliases in the TLV segment of the
// funding_locked message. // channel_ready message.
ScidAliasOptional FeatureBit = 47 ScidAliasOptional FeatureBit = 47
// PaymentMetadataRequired is a required bit that denotes that if an // PaymentMetadataRequired is a required bit that denotes that if an
+3 -3
View File
@@ -286,10 +286,10 @@ func FuzzFundingCreated(f *testing.F) {
}) })
} }
func FuzzFundingLocked(f *testing.F) { func FuzzChannelReady(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) { f.Fuzz(func(t *testing.T, data []byte) {
// Prefix with MsgFundingLocked. // Prefix with MsgChannelReady.
data = prefixWithMsgType(data, MsgFundingLocked) data = prefixWithMsgType(data, MsgChannelReady)
// Pass the message into our general fuzz harness for wire // Pass the message into our general fuzz harness for wire
// messages! // messages!
+4 -5
View File
@@ -566,8 +566,7 @@ func TestLightningWireProtocol(t *testing.T) {
v[0] = reflect.ValueOf(req) v[0] = reflect.ValueOf(req)
}, },
MsgFundingLocked: func(v []reflect.Value, r *rand.Rand) { MsgChannelReady: func(v []reflect.Value, r *rand.Rand) {
var c [32]byte var c [32]byte
if _, err := r.Read(c[:]); err != nil { if _, err := r.Read(c[:]); err != nil {
t.Fatalf("unable to generate chan id: %v", err) t.Fatalf("unable to generate chan id: %v", err)
@@ -580,7 +579,7 @@ func TestLightningWireProtocol(t *testing.T) {
return return
} }
req := NewFundingLocked(ChannelID(c), pubKey) req := NewChannelReady(ChannelID(c), pubKey)
v[0] = reflect.ValueOf(*req) v[0] = reflect.ValueOf(*req)
}, },
@@ -1013,8 +1012,8 @@ func TestLightningWireProtocol(t *testing.T) {
}, },
}, },
{ {
msgType: MsgFundingLocked, msgType: MsgChannelReady,
scenario: func(m FundingLocked) bool { scenario: func(m ChannelReady) bool {
return mainScenario(&m) return mainScenario(&m)
}, },
}, },
+5 -5
View File
@@ -31,7 +31,7 @@ const (
MsgAcceptChannel = 33 MsgAcceptChannel = 33
MsgFundingCreated = 34 MsgFundingCreated = 34
MsgFundingSigned = 35 MsgFundingSigned = 35
MsgFundingLocked = 36 MsgChannelReady = 36
MsgShutdown = 38 MsgShutdown = 38
MsgClosingSigned = 39 MsgClosingSigned = 39
MsgUpdateAddHTLC = 128 MsgUpdateAddHTLC = 128
@@ -88,8 +88,8 @@ func (t MessageType) String() string {
return "MsgFundingCreated" return "MsgFundingCreated"
case MsgFundingSigned: case MsgFundingSigned:
return "MsgFundingSigned" return "MsgFundingSigned"
case MsgFundingLocked: case MsgChannelReady:
return "FundingLocked" return "ChannelReady"
case MsgShutdown: case MsgShutdown:
return "Shutdown" return "Shutdown"
case MsgClosingSigned: case MsgClosingSigned:
@@ -190,8 +190,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
msg = &FundingCreated{} msg = &FundingCreated{}
case MsgFundingSigned: case MsgFundingSigned:
msg = &FundingSigned{} msg = &FundingSigned{}
case MsgFundingLocked: case MsgChannelReady:
msg = &FundingLocked{} msg = &ChannelReady{}
case MsgShutdown: case MsgShutdown:
msg = &Shutdown{} msg = &Shutdown{}
case MsgClosingSigned: case MsgClosingSigned:
+3 -3
View File
@@ -268,7 +268,7 @@ func makeAllMessages(t testing.TB, r *rand.Rand) []lnwire.Message {
msgAll = append(msgAll, newMsgAcceptChannel(t, r)) msgAll = append(msgAll, newMsgAcceptChannel(t, r))
msgAll = append(msgAll, newMsgFundingCreated(t, r)) msgAll = append(msgAll, newMsgFundingCreated(t, r))
msgAll = append(msgAll, newMsgFundingSigned(t, r)) msgAll = append(msgAll, newMsgFundingSigned(t, r))
msgAll = append(msgAll, newMsgFundingLocked(t, r)) msgAll = append(msgAll, newMsgChannelReady(t, r))
msgAll = append(msgAll, newMsgShutdown(t, r)) msgAll = append(msgAll, newMsgShutdown(t, r))
msgAll = append(msgAll, newMsgClosingSigned(t, r)) msgAll = append(msgAll, newMsgClosingSigned(t, r))
msgAll = append(msgAll, newMsgUpdateAddHTLC(t, r)) msgAll = append(msgAll, newMsgUpdateAddHTLC(t, r))
@@ -442,7 +442,7 @@ func newMsgFundingSigned(t testing.TB, r io.Reader) *lnwire.FundingSigned {
return msg return msg
} }
func newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.FundingLocked { func newMsgChannelReady(t testing.TB, r io.Reader) *lnwire.ChannelReady {
t.Helper() t.Helper()
var c [32]byte var c [32]byte
@@ -452,7 +452,7 @@ func newMsgFundingLocked(t testing.TB, r io.Reader) *lnwire.FundingLocked {
pubKey := randPubKey(t) pubKey := randPubKey(t)
msg := lnwire.NewFundingLocked(lnwire.ChannelID(c), pubKey) msg := lnwire.NewChannelReady(lnwire.ChannelID(c), pubKey)
msg.ExtraData = createExtraData(t, r) msg.ExtraData = createExtraData(t, r)
return msg return msg
+1 -1
View File
@@ -54,7 +54,7 @@ type ChanStatusConfig struct {
// IsChannelActive checks whether the channel identified by the provided // IsChannelActive checks whether the channel identified by the provided
// ChannelID is considered active. This should only return true if the // ChannelID is considered active. This should only return true if the
// channel has been sufficiently confirmed, the channel has received // channel has been sufficiently confirmed, the channel has received
// FundingLocked, and the remote peer is online. // ChannelReady, and the remote peer is online.
IsChannelActive func(lnwire.ChannelID) bool IsChannelActive func(lnwire.ChannelID) bool
// ApplyChannelUpdate processes new ChannelUpdates signed by our node by // ApplyChannelUpdate processes new ChannelUpdates signed by our node by
+9 -9
View File
@@ -717,11 +717,11 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
// manager are not aware of each other's states and if // manager are not aware of each other's states and if
// we did not do this, we would accept alias channel // we did not do this, we would accept alias channel
// updates after 6 confirmations, which would be buggy. // updates after 6 confirmations, which would be buggy.
// We'll queue a funding_locked message with the new // We'll queue a channel_ready message with the new
// alias. This should technically be done *after* the // alias. This should technically be done *after* the
// reestablish, but this behavior is pre-existing since // reestablish, but this behavior is pre-existing since
// the funding manager may already queue a // the funding manager may already queue a
// funding_locked before the channel_reestablish. // channel_ready before the channel_reestablish.
if !dbChan.IsPending { if !dbChan.IsPending {
aliasScid, err := p.cfg.RequestAlias() aliasScid, err := p.cfg.RequestAlias()
if err != nil { if err != nil {
@@ -740,18 +740,18 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
) )
// Fetch the second commitment point to send in // Fetch the second commitment point to send in
// the funding_locked message. // the channel_ready message.
second, err := dbChan.SecondCommitmentPoint() second, err := dbChan.SecondCommitmentPoint()
if err != nil { if err != nil {
return nil, err return nil, err
} }
fundingLockedMsg := lnwire.NewFundingLocked( channelReadyMsg := lnwire.NewChannelReady(
chanID, second, chanID, second,
) )
fundingLockedMsg.AliasScid = &aliasScid channelReadyMsg.AliasScid = &aliasScid
msgs = append(msgs, fundingLockedMsg) msgs = append(msgs, channelReadyMsg)
} }
// If we've negotiated the option-scid-alias feature // If we've negotiated the option-scid-alias feature
@@ -1549,7 +1549,7 @@ out:
*lnwire.AcceptChannel, *lnwire.AcceptChannel,
*lnwire.FundingCreated, *lnwire.FundingCreated,
*lnwire.FundingSigned, *lnwire.FundingSigned,
*lnwire.FundingLocked: *lnwire.ChannelReady:
p.cfg.FundingManager.ProcessFundingMsg(msg, p) p.cfg.FundingManager.ProcessFundingMsg(msg, p)
@@ -1798,7 +1798,7 @@ func messageSummary(msg lnwire.Message) string {
case *lnwire.FundingSigned: case *lnwire.FundingSigned:
return fmt.Sprintf("chan_id=%v", msg.ChanID) return fmt.Sprintf("chan_id=%v", msg.ChanID)
case *lnwire.FundingLocked: case *lnwire.ChannelReady:
return fmt.Sprintf("chan_id=%v, next_point=%x", return fmt.Sprintf("chan_id=%v, next_point=%x",
msg.ChanID, msg.NextPerCommitmentPoint.SerializeCompressed()) msg.ChanID, msg.NextPerCommitmentPoint.SerializeCompressed())
@@ -2376,7 +2376,7 @@ out:
} }
p.log.Infof("Processing retransmitted "+ p.log.Infof("Processing retransmitted "+
"FundingLocked for ChannelPoint(%v)", "ChannelReady for ChannelPoint(%v)",
chanPoint) chanPoint)
nextRevoke := newChan.RemoteNextRevocation nextRevoke := newChan.RemoteNextRevocation