mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-26 13:42:49 +02:00
lnd+routing+rpc: switch mc to (external) estimator
We use a more general `Estimator` interface for probability estimation in missioncontrol. The estimator is created outside of `NewMissionControl`, passed in as a `MissionControlConfig` field, to facilitate usage of externally supplied estimators.
This commit is contained in:
@@ -103,7 +103,7 @@ type MissionControl struct {
|
||||
|
||||
// estimator is the probability estimator that is used with the payment
|
||||
// results that mission control collects.
|
||||
estimator *AprioriEstimator
|
||||
estimator Estimator
|
||||
|
||||
sync.Mutex
|
||||
|
||||
@@ -116,8 +116,8 @@ type MissionControl struct {
|
||||
// MissionControlConfig defines parameters that control mission control
|
||||
// behaviour.
|
||||
type MissionControlConfig struct {
|
||||
// AprioriConfig is the config we will use for probability calculations.
|
||||
AprioriConfig
|
||||
// Estimator gives probability estimates for node pairs.
|
||||
Estimator Estimator
|
||||
|
||||
// MaxMcHistory defines the maximum number of payment results that are
|
||||
// held on disk.
|
||||
@@ -134,10 +134,6 @@ type MissionControlConfig struct {
|
||||
}
|
||||
|
||||
func (c *MissionControlConfig) validate() error {
|
||||
if err := c.AprioriConfig.validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.MaxMcHistory < 0 {
|
||||
return ErrInvalidMcHistory
|
||||
}
|
||||
@@ -151,11 +147,8 @@ func (c *MissionControlConfig) validate() error {
|
||||
|
||||
// String returns a string representation of a mission control config.
|
||||
func (c *MissionControlConfig) String() string {
|
||||
return fmt.Sprintf("Penalty Half Life: %v, Apriori Hop "+
|
||||
"Probablity: %v, Maximum History: %v, Apriori Weight: %v, "+
|
||||
"Minimum Failure Relax Interval: %v", c.PenaltyHalfLife,
|
||||
c.AprioriHopProbability, c.MaxMcHistory, c.AprioriWeight,
|
||||
c.MinFailureRelaxInterval)
|
||||
return fmt.Sprintf("maximum history: %v, minimum failure relax "+
|
||||
"interval: %v", c.MaxMcHistory, c.MinFailureRelaxInterval)
|
||||
}
|
||||
|
||||
// TimedPairResult describes a timestamped pair result.
|
||||
@@ -211,7 +204,8 @@ type paymentResult struct {
|
||||
func NewMissionControl(db kvdb.Backend, self route.Vertex,
|
||||
cfg *MissionControlConfig) (*MissionControl, error) {
|
||||
|
||||
log.Debugf("Instantiating mission control with config: %v", cfg)
|
||||
log.Debugf("Instantiating mission control with config: %v, %v", cfg,
|
||||
cfg.Estimator)
|
||||
|
||||
if err := cfg.validate(); err != nil {
|
||||
return nil, err
|
||||
@@ -224,17 +218,12 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
estimator := &AprioriEstimator{
|
||||
AprioriConfig: cfg.AprioriConfig,
|
||||
prevSuccessProbability: prevSuccessProbability,
|
||||
}
|
||||
|
||||
mc := &MissionControl{
|
||||
state: newMissionControlState(cfg.MinFailureRelaxInterval),
|
||||
now: time.Now,
|
||||
selfNode: self,
|
||||
store: store,
|
||||
estimator: estimator,
|
||||
estimator: cfg.Estimator,
|
||||
}
|
||||
|
||||
if err := mc.init(); err != nil {
|
||||
@@ -283,7 +272,7 @@ func (m *MissionControl) GetConfig() *MissionControlConfig {
|
||||
defer m.Unlock()
|
||||
|
||||
return &MissionControlConfig{
|
||||
AprioriConfig: m.estimator.AprioriConfig,
|
||||
Estimator: m.estimator,
|
||||
MaxMcHistory: m.store.maxRecords,
|
||||
McFlushInterval: m.store.flushInterval,
|
||||
MinFailureRelaxInterval: m.state.minFailureRelaxInterval,
|
||||
@@ -304,11 +293,12 @@ func (m *MissionControl) SetConfig(cfg *MissionControlConfig) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
log.Infof("Updating mission control cfg: %v", cfg)
|
||||
log.Infof("Active mission control cfg: %v, estimator: %v", cfg,
|
||||
cfg.Estimator)
|
||||
|
||||
m.store.maxRecords = cfg.MaxMcHistory
|
||||
m.state.minFailureRelaxInterval = cfg.MinFailureRelaxInterval
|
||||
m.estimator.AprioriConfig = cfg.AprioriConfig
|
||||
m.estimator = cfg.Estimator
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user