lnd: Create a callback function (UpdatingRoutingConfig)

This callback function is called whenever the command `lncli setmccfg`
is used to change the routing settings.
This commit is contained in:
MPins 2024-07-16 09:52:31 -03:00
parent de495534e4
commit b08e65ec85

View File

@ -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.