fundingmgr+server: don't use global cfg
This commit is contained in:
3 files changed
+20
-9
No files matched your search
+15
-5
@@ -369,6 +369,14 @@ type fundingConfig struct {
|
|||||||
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when channels
|
// NotifyPendingOpenChannelEvent informs the ChannelNotifier when channels
|
||||||
// enter a pending state.
|
// enter a pending state.
|
||||||
NotifyPendingOpenChannelEvent func(wire.OutPoint, *channeldb.OpenChannel)
|
NotifyPendingOpenChannelEvent func(wire.OutPoint, *channeldb.OpenChannel)
|
||||||
|
|
||||||
|
// EnableUpfrontShutdown specifies whether the upfront shutdown script
|
||||||
|
// is enabled.
|
||||||
|
EnableUpfrontShutdown bool
|
||||||
|
|
||||||
|
// RegisteredChains keeps track of all chains that have been registered
|
||||||
|
// with the daemon.
|
||||||
|
RegisteredChains *chainRegistry
|
||||||
}
|
}
|
||||||
|
|
||||||
// fundingManager acts as an orchestrator/bridge between the wallet's
|
// fundingManager acts as an orchestrator/bridge between the wallet's
|
||||||
@@ -1322,7 +1330,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// A nil address is set in place of user input, because this channel open
|
// A nil address is set in place of user input, because this channel open
|
||||||
// was not initiated by the user.
|
// was not initiated by the user.
|
||||||
shutdown, err := getUpfrontShutdownScript(
|
shutdown, err := getUpfrontShutdownScript(
|
||||||
fmsg.peer, nil,
|
f.cfg.EnableUpfrontShutdown, fmsg.peer, nil,
|
||||||
func() (lnwire.DeliveryAddress, error) {
|
func() (lnwire.DeliveryAddress, error) {
|
||||||
addr, err := f.cfg.Wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
addr, err := f.cfg.Wallet.NewAddress(lnwallet.WitnessPubKey, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -2981,7 +2989,8 @@ func (f *fundingManager) initFundingWorkflow(peer lnpeer.Peer, req *openChanReq)
|
|||||||
// our peer does support the feature, we will return the user provided script
|
// our peer does support the feature, we will return the user provided script
|
||||||
// if non-zero, or a freshly generated script if our node is configured to set
|
// if non-zero, or a freshly generated script if our node is configured to set
|
||||||
// upfront shutdown scripts automatically.
|
// upfront shutdown scripts automatically.
|
||||||
func getUpfrontShutdownScript(peer lnpeer.Peer, script lnwire.DeliveryAddress,
|
func getUpfrontShutdownScript(enableUpfrontShutdown bool, peer lnpeer.Peer,
|
||||||
|
script lnwire.DeliveryAddress,
|
||||||
getScript func() (lnwire.DeliveryAddress, error)) (lnwire.DeliveryAddress,
|
getScript func() (lnwire.DeliveryAddress, error)) (lnwire.DeliveryAddress,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
@@ -3010,7 +3019,7 @@ func getUpfrontShutdownScript(peer lnpeer.Peer, script lnwire.DeliveryAddress,
|
|||||||
|
|
||||||
// If we do not have setting of upfront shutdown script enabled, return
|
// If we do not have setting of upfront shutdown script enabled, return
|
||||||
// an empty script.
|
// an empty script.
|
||||||
if !cfg.EnableUpfrontShutdown {
|
if !enableUpfrontShutdown {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3030,7 +3039,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
|
|
||||||
// We'll determine our dust limit depending on which chain is active.
|
// We'll determine our dust limit depending on which chain is active.
|
||||||
var ourDustLimit btcutil.Amount
|
var ourDustLimit btcutil.Amount
|
||||||
switch cfg.registeredChains.PrimaryChain() {
|
switch f.cfg.RegisteredChains.PrimaryChain() {
|
||||||
case bitcoinChain:
|
case bitcoinChain:
|
||||||
ourDustLimit = lnwallet.DefaultDustLimit()
|
ourDustLimit = lnwallet.DefaultDustLimit()
|
||||||
case litecoinChain:
|
case litecoinChain:
|
||||||
@@ -3084,7 +3093,8 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) {
|
|||||||
// address from the wallet if our node is configured to set shutdown
|
// address from the wallet if our node is configured to set shutdown
|
||||||
// address by default).
|
// address by default).
|
||||||
shutdown, err := getUpfrontShutdownScript(
|
shutdown, err := getUpfrontShutdownScript(
|
||||||
msg.peer, msg.openChanReq.shutdownScript,
|
f.cfg.EnableUpfrontShutdown, msg.peer,
|
||||||
|
msg.openChanReq.shutdownScript,
|
||||||
func() (lnwire.DeliveryAddress, error) {
|
func() (lnwire.DeliveryAddress, error) {
|
||||||
addr, err := f.cfg.Wallet.NewAddress(
|
addr, err := f.cfg.Wallet.NewAddress(
|
||||||
lnwallet.WitnessPubKey, false,
|
lnwallet.WitnessPubKey, false,
|
||||||
|
|||||||
@@ -418,6 +418,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
|||||||
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
|
NotifyOpenChannelEvent: evt.NotifyOpenChannelEvent,
|
||||||
OpenChannelPredicate: chainedAcceptor,
|
OpenChannelPredicate: chainedAcceptor,
|
||||||
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
|
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
|
||||||
|
RegisteredChains: newChainRegistry(),
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, op := range options {
|
for _, op := range options {
|
||||||
@@ -3084,11 +3085,9 @@ func TestGetUpfrontShutdownScript(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the command line option in config as needed.
|
|
||||||
cfg = &Config{EnableUpfrontShutdown: test.localEnabled}
|
|
||||||
|
|
||||||
addr, err := getUpfrontShutdownScript(
|
addr, err := getUpfrontShutdownScript(
|
||||||
&mockPeer, test.upfrontScript, test.getScript,
|
test.localEnabled, &mockPeer, test.upfrontScript,
|
||||||
|
test.getScript,
|
||||||
)
|
)
|
||||||
if err != test.expectedErr {
|
if err != test.expectedErr {
|
||||||
t.Fatalf("got: %v, expected error: %v", err, test.expectedErr)
|
t.Fatalf("got: %v, expected error: %v", err, test.expectedErr)
|
||||||
|
|||||||
@@ -1144,6 +1144,8 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
|||||||
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
|
NotifyOpenChannelEvent: s.channelNotifier.NotifyOpenChannelEvent,
|
||||||
OpenChannelPredicate: chanPredicate,
|
OpenChannelPredicate: chanPredicate,
|
||||||
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
|
NotifyPendingOpenChannelEvent: s.channelNotifier.NotifyPendingOpenChannelEvent,
|
||||||
|
EnableUpfrontShutdown: cfg.EnableUpfrontShutdown,
|
||||||
|
RegisteredChains: cfg.registeredChains,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in new issue
Block a user