From de495534e47c9ac5ad445f09539130a47fb23b3a Mon Sep 17 00:00:00 2001 From: MPins Date: Tue, 16 Jul 2024 09:53:31 -0300 Subject: [PATCH 1/4] routing: Call the function to update routing config on main cfg NewMissionControl propagate the callback function defined on server.go and SetConfig call it to update the infos on main cfg. --- routing/missioncontrol.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/routing/missioncontrol.go b/routing/missioncontrol.go index 1dceace7c0..100d900a72 100644 --- a/routing/missioncontrol.go +++ b/routing/missioncontrol.go @@ -8,6 +8,7 @@ import ( "github.com/btcsuite/btcd/btcutil" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/fn" "github.com/lightningnetwork/lnd/kvdb" "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" @@ -110,6 +111,10 @@ type MissionControl struct { // results that mission control collects. estimator Estimator + // onConfigUpdate is a function that is called whenever the + // mission control state is updated. + onConfigUpdate fn.Option[func(cfg *MissionControlConfig)] + sync.Mutex // TODO(roasbeef): further counters, if vertex continually unavailable, @@ -124,6 +129,10 @@ type MissionControlConfig struct { // Estimator gives probability estimates for node pairs. Estimator Estimator + // OnConfigUpdate is function that is called whenever the + // mission control state is updated. + OnConfigUpdate fn.Option[func(cfg *MissionControlConfig)] + // MaxMcHistory defines the maximum number of payment results that are // held on disk. MaxMcHistory int @@ -224,11 +233,14 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex, } mc := &MissionControl{ - state: newMissionControlState(cfg.MinFailureRelaxInterval), - now: time.Now, - selfNode: self, - store: store, - estimator: cfg.Estimator, + state: newMissionControlState( + cfg.MinFailureRelaxInterval, + ), + now: time.Now, + selfNode: self, + store: store, + estimator: cfg.Estimator, + onConfigUpdate: cfg.OnConfigUpdate, } if err := mc.init(); err != nil { @@ -308,6 +320,11 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error { m.state.minFailureRelaxInterval = cfg.MinFailureRelaxInterval m.estimator = cfg.Estimator + // Execute the callback function if it is set. + m.onConfigUpdate.WhenSome(func(f func(cfg *MissionControlConfig)) { + f(cfg) + }) + return nil } From b08e65ec858cb2b07f400672f829e28594d40b53 Mon Sep 17 00:00:00 2001 From: MPins Date: Tue, 16 Jul 2024 09:52:31 -0300 Subject: [PATCH 2/4] lnd: Create a callback function (UpdatingRoutingConfig) This callback function is called whenever the command `lncli setmccfg` is used to change the routing settings. --- server.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server.go b/server.go index 555ee26274..fd746a85ea 100644 --- a/server.go +++ b/server.go @@ -928,6 +928,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, } mcCfg := &routing.MissionControlConfig{ + OnConfigUpdate: fn.Some(s.UpdateRoutingConfig), Estimator: estimator, MaxMcHistory: routingConfig.MaxMcHistory, McFlushInterval: routingConfig.McFlushInterval, @@ -1699,6 +1700,35 @@ func newServer(cfg *Config, listenAddrs []net.Addr, return s, nil } +// UpdateRoutingConfig is a callback function to update the routing config +// values in the main cfg. +func (s *server) UpdateRoutingConfig(cfg *routing.MissionControlConfig) { + routerCfg := s.cfg.SubRPCServers.RouterRPC + + switch c := cfg.Estimator.Config().(type) { + case routing.AprioriConfig: + routerCfg.ProbabilityEstimatorType = + routing.AprioriEstimatorName + + targetCfg := routerCfg.AprioriConfig + targetCfg.PenaltyHalfLife = c.PenaltyHalfLife + targetCfg.Weight = c.AprioriWeight + targetCfg.CapacityFraction = c.CapacityFraction + targetCfg.HopProbability = c.AprioriHopProbability + + case routing.BimodalConfig: + routerCfg.ProbabilityEstimatorType = + routing.BimodalEstimatorName + + targetCfg := routerCfg.BimodalConfig + targetCfg.Scale = int64(c.BimodalScaleMsat) + targetCfg.NodeWeight = c.BimodalNodeWeight + targetCfg.DecayTime = c.BimodalDecayTime + } + + routerCfg.MaxMcHistory = cfg.MaxMcHistory +} + // signAliasUpdate takes a ChannelUpdate and returns the signature. This is // used for option_scid_alias channels where the ChannelUpdate to be sent back // may differ from what is on disk. From cde5c5b59d3bc6fd9776ea5e446a7964bf70502d Mon Sep 17 00:00:00 2001 From: MPins Date: Tue, 16 Jul 2024 09:54:26 -0300 Subject: [PATCH 3/4] lnd: Update the DebugLevel on main cfg --- rpcserver.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 7fef873266..7c2c066746 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -7061,6 +7061,9 @@ func (r *rpcServer) DebugLevel(ctx context.Context, return nil, err } + // Propagate the new config level to the main config struct. + r.cfg.DebugLevel = req.LevelSpec + return &lnrpc.DebugLevelResponse{}, nil } From 4dda2e2c2309b33ddda083452ff057a564b916db Mon Sep 17 00:00:00 2001 From: MPins Date: Wed, 14 Aug 2024 14:44:17 -0300 Subject: [PATCH 4/4] docs: release-notes-0.19.0.md --- docs/release-notes/release-notes-0.19.0.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/release-notes/release-notes-0.19.0.md b/docs/release-notes/release-notes-0.19.0.md index 35d93ed107..869e235115 100644 --- a/docs/release-notes/release-notes-0.19.0.md +++ b/docs/release-notes/release-notes-0.19.0.md @@ -19,6 +19,10 @@ # Bug Fixes +* [Fixed a bug](https://github.com/lightningnetwork/lnd/pull/8857) to correctly + propagate mission control and debug level config values to the main LND config + struct so that the GetDebugInfo response is accurate. + # New Features ## Functional Enhancements ## RPC Additions @@ -53,4 +57,5 @@ # Contributors (Alphabetical Order) +* Pins * Ziggie