From b08e65ec858cb2b07f400672f829e28594d40b53 Mon Sep 17 00:00:00 2001 From: MPins Date: Tue, 16 Jul 2024 09:52:31 -0300 Subject: [PATCH] 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 555ee2627..fd746a85e 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.