From f48c8f91c4841963e39716ed0b37beccf3f4013d Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Wed, 9 Jan 2019 09:14:45 +0100 Subject: [PATCH] lnd+pilot: use WeightedCombAttachment We make the default autopilot agent use the WeightedCombAttachment. Currently it uses only one sub-heuristic, prefAttachment. --- lnd.go | 9 +++++++-- pilot.go | 16 +++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lnd.go b/lnd.go index f6219811..46adb4a4 100644 --- a/lnd.go +++ b/lnd.go @@ -313,10 +313,15 @@ func lndMain() error { return err } - // Set up an auotpilot manager from the current config. This will be + // Set up an autopilot manager from the current config. This will be // used to manage the underlying autopilot agent, starting and stopping // it at will. - atplCfg := initAutoPilot(server, cfg.Autopilot) + atplCfg, err := initAutoPilot(server, cfg.Autopilot) + if err != nil { + ltndLog.Errorf("unable to init autopilot: %v", err) + return err + } + atplManager, err := autopilot.NewManager(atplCfg) if err != nil { ltndLog.Errorf("unable to create autopilot manager: %v", err) diff --git a/pilot.go b/pilot.go index b6d9f63f..3c3e1659 100644 --- a/pilot.go +++ b/pilot.go @@ -83,7 +83,7 @@ var _ autopilot.ChannelController = (*chanController)(nil) // autopilot.Agent instance based on the passed configuration struct. The agent // and all interfaces needed to drive it won't be launched before the Manager's // StartAgent method is called. -func initAutoPilot(svr *server, cfg *autoPilotConfig) *autopilot.ManagerCfg { +func initAutoPilot(svr *server, cfg *autoPilotConfig) (*autopilot.ManagerCfg, error) { atplLog.Infof("Instantiating autopilot with cfg: %v", spew.Sdump(cfg)) // Set up the constraints the autopilot heuristics must adhere to. @@ -98,12 +98,22 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) *autopilot.ManagerCfg { // First, we'll create the preferential attachment heuristic. prefAttachment := autopilot.NewPrefAttachment() + weightedAttachment, err := autopilot.NewWeightedCombAttachment( + &autopilot.WeightedHeuristic{ + Weight: 1.0, + AttachmentHeuristic: prefAttachment, + }, + ) + if err != nil { + return nil, err + } + // With the heuristic itself created, we can now populate the remainder // of the items that the autopilot agent needs to perform its duties. self := svr.identityPriv.PubKey() pilotCfg := autopilot.Config{ Self: self, - Heuristic: prefAttachment, + Heuristic: weightedAttachment, ChanController: &chanController{ server: svr, private: cfg.Private, @@ -202,5 +212,5 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) *autopilot.ManagerCfg { }, SubscribeTransactions: svr.cc.wallet.SubscribeTransactions, SubscribeTopology: svr.chanRouter.SubscribeTopology, - } + }, nil }