mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-27 14:11:04 +02:00
routing: store missioncontrol state in blocks and eliminate cursor use
This commit changes missioncontrol's store update from per payment to every second. Updating the missioncontrol store on every payment caused gradual slowdown when using etcd. We also completely eliminate the use of the cursor, further reducing the performance bottleneck.
This commit is contained in:
@@ -45,6 +45,10 @@ const (
|
||||
// DefaultMaxMcHistory is the default maximum history size.
|
||||
DefaultMaxMcHistory = 1000
|
||||
|
||||
// DefaultMcFlushInterval is the defaul inteval we use to flush MC state
|
||||
// to the database.
|
||||
DefaultMcFlushInterval = time.Second
|
||||
|
||||
// prevSuccessProbability is the assumed probability for node pairs that
|
||||
// successfully relayed the previous attempt.
|
||||
prevSuccessProbability = 0.95
|
||||
@@ -119,6 +123,10 @@ type MissionControlConfig struct {
|
||||
// held on disk.
|
||||
MaxMcHistory int
|
||||
|
||||
// McFlushInterval defines the ticker interval when we flush the
|
||||
// accumulated state to the DB.
|
||||
McFlushInterval time.Duration
|
||||
|
||||
// MinFailureRelaxInterval is the minimum time that must have passed
|
||||
// since the previously recorded failure before the failure amount may
|
||||
// be raised.
|
||||
@@ -209,7 +217,9 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
store, err := newMissionControlStore(db, cfg.MaxMcHistory)
|
||||
store, err := newMissionControlStore(
|
||||
db, cfg.MaxMcHistory, cfg.McFlushInterval,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -234,6 +244,16 @@ func NewMissionControl(db kvdb.Backend, self route.Vertex,
|
||||
return mc, nil
|
||||
}
|
||||
|
||||
// RunStoreTicker runs the mission control store's ticker.
|
||||
func (m *MissionControl) RunStoreTicker() {
|
||||
m.store.run()
|
||||
}
|
||||
|
||||
// StopStoreTicker stops the mission control store's ticker.
|
||||
func (m *MissionControl) StopStoreTicker() {
|
||||
m.store.stop()
|
||||
}
|
||||
|
||||
// init initializes mission control with historical data.
|
||||
func (m *MissionControl) init() error {
|
||||
log.Debugf("Mission control state reconstruction started")
|
||||
@@ -265,6 +285,7 @@ func (m *MissionControl) GetConfig() *MissionControlConfig {
|
||||
return &MissionControlConfig{
|
||||
ProbabilityEstimatorCfg: m.estimator.ProbabilityEstimatorCfg,
|
||||
MaxMcHistory: m.store.maxRecords,
|
||||
McFlushInterval: m.store.flushInterval,
|
||||
MinFailureRelaxInterval: m.state.minFailureRelaxInterval,
|
||||
}
|
||||
}
|
||||
@@ -429,9 +450,7 @@ func (m *MissionControl) processPaymentResult(result *paymentResult) (
|
||||
*channeldb.FailureReason, error) {
|
||||
|
||||
// Store complete result in database.
|
||||
if err := m.store.AddResult(result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
m.store.AddResult(result)
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
Reference in New Issue
Block a user