mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-13 11:09:23 +01:00
funding+server.go: modify notifications to pass through server
This modifies the various channelnotifier notification functions to instead hit the server and then call the notification routine. This allows us to accurately modify the server's maps.
This commit is contained in:
parent
6eb746fbba
commit
68ec766b61
3 changed files with 62 additions and 10 deletions
|
@ -511,7 +511,7 @@ type Config struct {
|
|||
|
||||
// NotifyOpenChannelEvent informs the ChannelNotifier when channels
|
||||
// transition from pending open to open.
|
||||
NotifyOpenChannelEvent func(wire.OutPoint)
|
||||
NotifyOpenChannelEvent func(wire.OutPoint, *btcec.PublicKey) error
|
||||
|
||||
// OpenChannelPredicate is a predicate on the lnwire.OpenChannel message
|
||||
// and on the requesting node's public key that returns a bool which
|
||||
|
@ -521,7 +521,13 @@ type Config struct {
|
|||
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when
|
||||
// channels enter a pending state.
|
||||
NotifyPendingOpenChannelEvent func(wire.OutPoint,
|
||||
*channeldb.OpenChannel)
|
||||
*channeldb.OpenChannel, *btcec.PublicKey) error
|
||||
|
||||
// NotifyFundingTimeout informs the ChannelNotifier when a pending-open
|
||||
// channel times out because the funding transaction hasn't confirmed.
|
||||
// This is only called for the fundee and only if the channel is
|
||||
// zero-conf.
|
||||
NotifyFundingTimeout func(wire.OutPoint, *btcec.PublicKey) error
|
||||
|
||||
// EnableUpfrontShutdown specifies whether the upfront shutdown script
|
||||
// is enabled.
|
||||
|
@ -1313,7 +1319,13 @@ func (f *Manager) advancePendingChannelState(channel *channeldb.OpenChannel,
|
|||
|
||||
// Inform the ChannelNotifier that the channel has transitioned
|
||||
// from pending open to open.
|
||||
f.cfg.NotifyOpenChannelEvent(channel.FundingOutpoint)
|
||||
if err := f.cfg.NotifyOpenChannelEvent(
|
||||
channel.FundingOutpoint, channel.IdentityPub,
|
||||
); err != nil {
|
||||
log.Errorf("Unable to notify open channel event for "+
|
||||
"ChannelPoint(%v): %v",
|
||||
channel.FundingOutpoint, err)
|
||||
}
|
||||
|
||||
// Find and close the discoverySignal for this channel such
|
||||
// that ChannelReady messages will be processed.
|
||||
|
@ -2654,7 +2666,12 @@ func (f *Manager) fundeeProcessFundingCreated(peer lnpeer.Peer,
|
|||
|
||||
// Inform the ChannelNotifier that the channel has entered
|
||||
// pending open state.
|
||||
f.cfg.NotifyPendingOpenChannelEvent(fundingOut, completeChan)
|
||||
if err := f.cfg.NotifyPendingOpenChannelEvent(
|
||||
fundingOut, completeChan, completeChan.IdentityPub,
|
||||
); err != nil {
|
||||
log.Errorf("Unable to send pending-open channel event for "+
|
||||
"ChannelPoint(%v) %v", fundingOut, err)
|
||||
}
|
||||
|
||||
// At this point we have sent our last funding message to the
|
||||
// initiating peer before the funding transaction will be broadcast.
|
||||
|
@ -2874,7 +2891,14 @@ func (f *Manager) funderProcessFundingSigned(peer lnpeer.Peer,
|
|||
case resCtx.updates <- upd:
|
||||
// Inform the ChannelNotifier that the channel has entered
|
||||
// pending open state.
|
||||
f.cfg.NotifyPendingOpenChannelEvent(*fundingPoint, completeChan)
|
||||
if err := f.cfg.NotifyPendingOpenChannelEvent(
|
||||
*fundingPoint, completeChan, completeChan.IdentityPub,
|
||||
); err != nil {
|
||||
log.Errorf("Unable to send pending-open channel "+
|
||||
"event for ChannelPoint(%v) %v", fundingPoint,
|
||||
err)
|
||||
}
|
||||
|
||||
case <-f.quit:
|
||||
return
|
||||
}
|
||||
|
@ -2930,6 +2954,13 @@ func (f *Manager) fundingTimeout(c *channeldb.OpenChannel,
|
|||
c.FundingOutpoint, err)
|
||||
}
|
||||
|
||||
// Notify other subsystems about the funding timeout.
|
||||
err := f.cfg.NotifyFundingTimeout(c.FundingOutpoint, c.IdentityPub)
|
||||
if err != nil {
|
||||
log.Errorf("failed to notify of funding timeout for "+
|
||||
"ChanPoint(%v): %v", c.FundingOutpoint, err)
|
||||
}
|
||||
|
||||
timeoutErr := fmt.Errorf("timeout waiting for funding tx (%v) to "+
|
||||
"confirm", c.FundingOutpoint)
|
||||
|
||||
|
@ -3310,7 +3341,13 @@ func (f *Manager) handleFundingConfirmation(
|
|||
|
||||
// Inform the ChannelNotifier that the channel has transitioned from
|
||||
// pending open to open.
|
||||
f.cfg.NotifyOpenChannelEvent(completeChan.FundingOutpoint)
|
||||
if err := f.cfg.NotifyOpenChannelEvent(
|
||||
completeChan.FundingOutpoint, completeChan.IdentityPub,
|
||||
); err != nil {
|
||||
log.Errorf("Unable to notify open channel event for "+
|
||||
"ChannelPoint(%v): %v", completeChan.FundingOutpoint,
|
||||
err)
|
||||
}
|
||||
|
||||
// Close the discoverySignal channel, indicating to a separate
|
||||
// goroutine that the channel now is marked as open in the database
|
||||
|
|
|
@ -231,17 +231,30 @@ type mockChanEvent struct {
|
|||
pendingOpenEvent chan channelnotifier.PendingOpenChannelEvent
|
||||
}
|
||||
|
||||
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint) {
|
||||
func (m *mockChanEvent) NotifyOpenChannelEvent(outpoint wire.OutPoint,
|
||||
remotePub *btcec.PublicKey) error {
|
||||
|
||||
m.openEvent <- outpoint
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockChanEvent) NotifyPendingOpenChannelEvent(outpoint wire.OutPoint,
|
||||
pendingChannel *channeldb.OpenChannel) {
|
||||
pendingChannel *channeldb.OpenChannel,
|
||||
remotePub *btcec.PublicKey) error {
|
||||
|
||||
m.pendingOpenEvent <- channelnotifier.PendingOpenChannelEvent{
|
||||
ChannelPoint: &outpoint,
|
||||
PendingChannel: pendingChannel,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockChanEvent) NotifyFundingTimeout(outpoint wire.OutPoint,
|
||||
remotePub *btcec.PublicKey) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// mockZeroConfAcceptor always accepts the channel open request for zero-conf
|
||||
|
@ -550,6 +563,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
|||
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
|
||||
OpenChannelPredicate: chainedAcceptor,
|
||||
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
|
||||
NotifyFundingTimeout: evt.NotifyFundingTimeout,
|
||||
DeleteAliasEdge: func(scid lnwire.ShortChannelID) (
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
|
|
|
@ -1681,9 +1681,10 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||
MaxPendingChannels: cfg.MaxPendingChannels,
|
||||
RejectPush: cfg.RejectPush,
|
||||
MaxLocalCSVDelay: chainCfg.MaxLocalDelay,
|
||||
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
|
||||
NotifyOpenChannelEvent: s.notifyOpenChannelPeerEvent,
|
||||
OpenChannelPredicate: chanPredicate,
|
||||
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
|
||||
NotifyPendingOpenChannelEvent: s.notifyPendingOpenChannelPeerEvent,
|
||||
NotifyFundingTimeout: s.notifyFundingTimeoutPeerEvent,
|
||||
EnableUpfrontShutdown: cfg.EnableUpfrontShutdown,
|
||||
MaxAnchorsCommitFeeRate: chainfee.SatPerKVByte(
|
||||
s.cfg.MaxCommitFeeRateAnchors * 1000).FeePerKWeight(),
|
||||
|
|
Loading…
Add table
Reference in a new issue