router: move self node out of config

We are going to use the config struct to allow getting and setting
of the mission control config in the commits that follow. Self node
is not something we want to change, so we move it out for better
separation.
This commit is contained in:
carla 2021-01-19 10:57:10 +02:00
parent b2857bf392
commit 0735d359b9
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
6 changed files with 11 additions and 16 deletions

View File

@ -61,7 +61,6 @@ func newIntegratedRoutingContext(t *testing.T) *integratedRoutingContext {
PenaltyHalfLife: 30 * time.Minute,
AprioriHopProbability: 0.6,
AprioriWeight: 0.5,
SelfNode: source.pubkey,
},
pathFindingCfg: PathFindingConfig{
@ -115,7 +114,7 @@ func (c *integratedRoutingContext) testPayment(maxParts uint32) ([]htlcAttempt,
// Instantiate a new mission control with the current configuration
// values.
mc, err := NewMissionControl(db, &c.mcCfg)
mc, err := NewMissionControl(db, c.source.pubkey, &c.mcCfg)
if err != nil {
c.t.Fatal(err)
}

View File

@ -78,7 +78,8 @@ type MissionControl struct {
// external function to enable deterministic unit tests.
now func() time.Time
cfg *MissionControlConfig
// selfNode is our pubkey.
selfNode route.Vertex
store *missionControlStore
@ -122,9 +123,6 @@ type MissionControlConfig struct {
// since the previously recorded failure before the failure amount may
// be raised.
MinFailureRelaxInterval time.Duration
// SelfNode is our own pubkey.
SelfNode route.Vertex
}
// TimedPairResult describes a timestamped pair result.
@ -177,8 +175,8 @@ type paymentResult struct {
}
// NewMissionControl returns a new instance of missionControl.
func NewMissionControl(db kvdb.Backend, cfg *MissionControlConfig) (
*MissionControl, error) {
func NewMissionControl(db kvdb.Backend, self route.Vertex,
cfg *MissionControlConfig) (*MissionControl, error) {
log.Debugf("Instantiating mission control with config: "+
"PenaltyHalfLife=%v, AprioriHopProbability=%v, "+
@ -200,7 +198,7 @@ func NewMissionControl(db kvdb.Backend, cfg *MissionControlConfig) (
mc := &MissionControl{
state: newMissionControlState(cfg.MinFailureRelaxInterval),
now: time.Now,
cfg: cfg,
selfNode: self,
store: store,
estimator: estimator,
}
@ -262,7 +260,7 @@ func (m *MissionControl) GetProbability(fromNode, toNode route.Vertex,
results, _ := m.state.getLastPairResult(fromNode)
// Use a distinct probability estimation function for local channels.
if fromNode == m.cfg.SelfNode {
if fromNode == m.selfNode {
return m.estimator.getLocalPairProbability(now, results, toNode)
}

View File

@ -78,12 +78,11 @@ func createMcTestContext(t *testing.T) *mcTestContext {
// restartMc creates a new instances of mission control on the same database.
func (ctx *mcTestContext) restartMc() {
mc, err := NewMissionControl(
ctx.db,
ctx.db, mcTestSelf,
&MissionControlConfig{
PenaltyHalfLife: testPenaltyHalfLife,
AprioriHopProbability: testAprioriHopProbability,
AprioriWeight: testAprioriWeight,
SelfNode: mcTestSelf,
},
)
if err != nil {

View File

@ -33,7 +33,7 @@ func TestRequestRoute(t *testing.T) {
func() (routingGraph, func(), error) {
return &sessionGraph{}, func() {}, nil
},
&MissionControl{cfg: &MissionControlConfig{}},
&MissionControl{},
PathFindingConfig{},
)
if err != nil {

View File

@ -91,7 +91,7 @@ func createTestCtxFromGraphInstance(startingHeight uint32, graphInstance *testGr
}
mc, err := NewMissionControl(
graphInstance.graph.Database(),
graphInstance.graph.Database(), route.Vertex{},
mcConfig,
)
if err != nil {

View File

@ -726,13 +726,12 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
routingConfig := routerrpc.GetRoutingConfig(cfg.SubRPCServers.RouterRPC)
s.missionControl, err = routing.NewMissionControl(
remoteChanDB,
remoteChanDB, selfNode.PubKeyBytes,
&routing.MissionControlConfig{
AprioriHopProbability: routingConfig.AprioriHopProbability,
PenaltyHalfLife: routingConfig.PenaltyHalfLife,
MaxMcHistory: routingConfig.MaxMcHistory,
AprioriWeight: routingConfig.AprioriWeight,
SelfNode: selfNode.PubKeyBytes,
MinFailureRelaxInterval: routing.DefaultMinFailureRelaxInterval,
},
)