Skip to content

Commit

Permalink
autopilot: for ConstrainedPrefAttachment.Select factor in skipNodes
Browse files Browse the repository at this point in the history
This commit modifies the Select method for the
ConstrainedPrefAttachment attachment heuristic slightly. Previously, it
was possible for an autopilot.Agent to go over the allotted number of
channels as it would unconditionally attempt to establish channel with
all returned Attachment Directives. To remedy this, we now assume that
we already have active, or pending channels to each of the nodes in the
set of skipNodes. Therefore, we now use the size of the skipNodes map
as an  upper limit within the primary selection loop.
  • Loading branch information
Roasbeef committed Aug 22, 2017
1 parent a8576ea commit 77e3e74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions autopilot/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ type AttachmentHeuristic interface {
// indeed need more channels, then the second argument returned will
// represent the amount of additional funds to be used towards creating
// channels.
//
// TODO(roasbeef): return number of chans? ensure doesn't go over
NeedMoreChans(chans []Channel, balance btcutil.Amount) (btcutil.Amount, bool)

// Select is a method that given the current state of the channel
Expand Down
6 changes: 4 additions & 2 deletions autopilot/prefattach.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ func NewNodeID(pub *btcec.PublicKey) NodeID {
//
// NOTE: This is a part of the AttachmentHeuristic interface.
func (p *ConstrainedPrefAttachment) Select(self *btcec.PublicKey, g ChannelGraph,
fundsAvailable btcutil.Amount, skipNodes map[NodeID]struct{}) ([]AttachmentDirective, error) {
fundsAvailable btcutil.Amount,
skipNodes map[NodeID]struct{}) ([]AttachmentDirective, error) {

// TODO(roasbeef): rename?

Expand All @@ -135,7 +136,8 @@ func (p *ConstrainedPrefAttachment) Select(self *btcec.PublicKey, g ChannelGraph
// We'll continue our attachment loop until we've exhausted the current
// amount of available funds.
visited := make(map[NodeID]struct{})
for i := uint16(0); i < p.chanLimit; i++ {
chanLimit := p.chanLimit - uint16(len(skipNodes))
for i := uint16(0); i < chanLimit; i++ {
// selectionSlice will be used to randomly select a node
// according to a power law distribution. For each connected
// edge, we'll add an instance of the node to this slice. Thus,
Expand Down

0 comments on commit 77e3e74

Please sign in to comment.