fundingmgr: add new function closure to send new channels to the ChainArbitrator

This commit is contained in:
Olaoluwa Osuntokun 2018-01-16 20:05:07 -08:00
parent 3c66d94f87
commit 8807d1d752
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
3 changed files with 45 additions and 14 deletions

@ -996,7 +996,7 @@ func (d *AuthenticatedGossiper) networkHandler() {
}
}
// retransmitStaleChannels eaxmines all outgoing channels that the source node
// retransmitStaleChannels examines all outgoing channels that the source node
// is known to maintain to check to see if any of them are "stale". A channel
// is stale iff, the last timestamp of it's rebroadcast is older then
// broadcastInterval.
@ -1012,10 +1012,10 @@ func (d *AuthenticatedGossiper) retransmitStaleChannels() error {
info *channeldb.ChannelEdgeInfo,
edge *channeldb.ChannelEdgePolicy) error {
// If there's no auth proof attaced to this edge, it
// means that it is a private channel not meant to be
// announced to the greater network, so avoid sending
// channel updates for this channel to not leak its
// If there's no auth proof attached to this edge, it means
// that it is a private channel not meant to be announced to
// the greater network, so avoid sending channel updates for
// this channel to not leak its
// existence.
if info.AuthProof == nil {
log.Debugf("Skipping retransmission of channel "+

@ -234,6 +234,14 @@ type fundingConfig struct {
// in order to give us more time to claim funds in the case of a
// contract breach.
RequiredRemoteDelay func(btcutil.Amount) uint16
// ArbitrateNewChan is to be called once a new channel enters the final
// funding stage: waiting for on-chain confirmation. This method sends
// the channel to the ChainArbitrator so it can watch for any on-chain
// events related to the channel.
//
// TODO(roasbeef): pass signal as well?
ArbitrateNewChan func(*channeldb.OpenChannel) error
}
// fundingManager acts as an orchestrator/bridge between the wallet's
@ -1198,6 +1206,14 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) {
return
}
// Now that we've sent over our final signature for this channel, we'll
// send it to the ChainArbitrator so it can watch for any on-chain
// actions during this final confirmation stage.
if err := f.cfg.ArbitrateNewChan(completeChan); err != nil {
fndgLog.Error("Unable to send new ChannelPoint(%v) for "+
"arbitration", fundingOut)
}
// Create an entry in the local discovery map so we can ensure that we
// process the channel confirmation fully before we receive a funding
// locked message.
@ -1328,6 +1344,17 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
return
}
// Now that we have a finalized reservation for this funding flow,
// we'll send the to be active channel to the ChainArbitrator so it can
// watch for any on-chin actions before the channel has fully
// confirmed.
//
// TODO(roasbeef): ensure later it also gets new signals
if err := f.cfg.ArbitrateNewChan(completeChan); err != nil {
fndgLog.Error("Unable to send new ChannelPoint(%v) for "+
"arbitration", fundingPoint)
}
fndgLog.Infof("Finalizing pendingID(%x) over ChannelPoint(%v), "+
"waiting for channel open on-chain", pendingChanID[:], fundingPoint)
@ -1352,7 +1379,7 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
// In case the fundingManager is stopped at some point during
// the remaining part of the opening process, we must wait for
// this process to finish (either successully or with some
// this process to finish (either successfully or with some
// error), before the fundingManager can be shut down.
f.wg.Add(1)
go func() {
@ -1374,16 +1401,14 @@ func (f *fundingManager) handleFundingSigned(fmsg *fundingSignedMsg) {
}
}
// Success, funding transaction was confirmed.
fndgLog.Debugf("Channel with ShortChanID %v now confirmed",
shortChanID.ToUint64())
// Go on adding the channel to the channel graph, and crafting
// channel announcements.
// We create the state-machine object which wraps the database state.
lnChannel, err := lnwallet.NewLightningChannel(nil, nil, f.cfg.FeeEstimator,
completeChan)
lnChannel, err := lnwallet.NewLightningChannel(
nil, nil, nil, completeChan,
)
if err != nil {
fndgLog.Errorf("failed creating lnChannel: %v", err)
return
@ -1628,8 +1653,9 @@ func (f *fundingManager) handleFundingConfirmation(completeChan *channeldb.OpenC
shortChanID *lnwire.ShortChannelID) error {
// We create the state-machine object which wraps the database state.
lnChannel, err := lnwallet.NewLightningChannel(nil, nil, f.cfg.FeeEstimator,
completeChan)
lnChannel, err := lnwallet.NewLightningChannel(
nil, nil, nil, completeChan,
)
if err != nil {
return err
}

@ -14,6 +14,7 @@ import (
"github.com/btcsuite/btclog"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/contractcourt"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwire"
@ -135,6 +136,7 @@ type testNode struct {
func init() {
channeldb.UseLogger(btclog.Disabled)
lnwallet.UseLogger(btclog.Disabled)
contractcourt.UseLogger(btclog.Disabled)
fndgLog = btclog.Disabled
}
@ -255,7 +257,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
return lnwallet.NewLightningChannel(
signer,
nil,
estimator,
nil,
channel)
}
}
@ -269,6 +271,9 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
RequiredRemoteDelay: func(amt btcutil.Amount) uint16 {
return 4
},
ArbitrateNewChan: func(*channeldb.OpenChannel) error {
return nil
},
})
if err != nil {
t.Fatalf("failed creating fundingManager: %v", err)