autopilot/pref_attachment: rename ConstrainedPrefAttachment->PrefAttachment
Since the ConstrainedPrefAttachment no longers require the heuristic to be aware of the autopilot constraints, we rename it PrefAttachment.
This commit is contained in:
parent
ccf4b7feab
commit
3739c19ef8
@ -8,38 +8,29 @@ import (
|
||||
"github.com/btcsuite/btcutil"
|
||||
)
|
||||
|
||||
// ConstrainedPrefAttachment is an implementation of the AttachmentHeuristic
|
||||
// interface that implement a constrained non-linear preferential attachment
|
||||
// heuristic. This means that given a threshold to allocate to automatic
|
||||
// channel establishment, the heuristic will attempt to favor connecting to
|
||||
// nodes which already have a set amount of links, selected by sampling from a
|
||||
// power law distribution. The attachment is non-linear in that it favors
|
||||
// nodes with a higher in-degree but less so that regular linear preferential
|
||||
// attachment. As a result, this creates smaller and less clusters than regular
|
||||
// linear preferential attachment.
|
||||
// PrefAttachment is an implementation of the AttachmentHeuristic interface
|
||||
// that implement a non-linear preferential attachment heuristic. This means
|
||||
// that given a threshold to allocate to automatic channel establishment, the
|
||||
// heuristic will attempt to favor connecting to nodes which already have a set
|
||||
// amount of links, selected by sampling from a power law distribution. The
|
||||
// attachment is non-linear in that it favors nodes with a higher in-degree but
|
||||
// less so than regular linear preferential attachment. As a result, this
|
||||
// creates smaller and less clusters than regular linear preferential
|
||||
// attachment.
|
||||
//
|
||||
// TODO(roasbeef): BA, with k=-3
|
||||
type ConstrainedPrefAttachment struct {
|
||||
constraints AgentConstraints
|
||||
type PrefAttachment struct {
|
||||
}
|
||||
|
||||
// NewConstrainedPrefAttachment creates a new instance of a
|
||||
// ConstrainedPrefAttachment heuristics given bounds on allowed channel sizes,
|
||||
// and an allocation amount which is interpreted as a percentage of funds that
|
||||
// is to be committed to channels at all times.
|
||||
func NewConstrainedPrefAttachment(
|
||||
cfg AgentConstraints) *ConstrainedPrefAttachment {
|
||||
|
||||
// NewPrefAttachment creates a new instance of a PrefAttachment heuristic.
|
||||
func NewPrefAttachment() *PrefAttachment {
|
||||
prand.Seed(time.Now().Unix())
|
||||
|
||||
return &ConstrainedPrefAttachment{
|
||||
constraints: cfg,
|
||||
}
|
||||
return &PrefAttachment{}
|
||||
}
|
||||
|
||||
// A compile time assertion to ensure ConstrainedPrefAttachment meets the
|
||||
// A compile time assertion to ensure PrefAttachment meets the
|
||||
// AttachmentHeuristic interface.
|
||||
var _ AttachmentHeuristic = (*ConstrainedPrefAttachment)(nil)
|
||||
var _ AttachmentHeuristic = (*PrefAttachment)(nil)
|
||||
|
||||
// NodeID is a simple type that holds an EC public key serialized in compressed
|
||||
// format.
|
||||
@ -69,7 +60,7 @@ func NewNodeID(pub *btcec.PublicKey) NodeID {
|
||||
// given to nodes already having high connectivity in the graph.
|
||||
//
|
||||
// NOTE: This is a part of the AttachmentHeuristic interface.
|
||||
func (p *ConstrainedPrefAttachment) NodeScores(g ChannelGraph, chans []Channel,
|
||||
func (p *PrefAttachment) NodeScores(g ChannelGraph, chans []Channel,
|
||||
chanSize btcutil.Amount, nodes map[NodeID]struct{}) (
|
||||
map[NodeID]*AttachmentDirective, error) {
|
||||
|
||||
|
@ -71,25 +71,14 @@ var chanGraphs = []struct {
|
||||
},
|
||||
}
|
||||
|
||||
// TestConstrainedPrefAttachmentSelectEmptyGraph ensures that when passed an
|
||||
// TestPrefAttachmentSelectEmptyGraph ensures that when passed an
|
||||
// empty graph, the NodeSores function always returns a score of 0.
|
||||
func TestConstrainedPrefAttachmentSelectEmptyGraph(t *testing.T) {
|
||||
func TestPrefAttachmentSelectEmptyGraph(t *testing.T) {
|
||||
const (
|
||||
minChanSize = 0
|
||||
maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin)
|
||||
chanLimit = 3
|
||||
threshold = 0.5
|
||||
)
|
||||
|
||||
constraints := NewConstraints(
|
||||
minChanSize,
|
||||
maxChanSize,
|
||||
chanLimit,
|
||||
0,
|
||||
threshold,
|
||||
)
|
||||
|
||||
prefAttach := NewConstrainedPrefAttachment(constraints)
|
||||
prefAttach := NewPrefAttachment()
|
||||
|
||||
// Create a random public key, which we will query to get a score for.
|
||||
pub, err := randKey()
|
||||
@ -175,27 +164,16 @@ func completeGraph(t *testing.T, g testGraph, numNodes int) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConstrainedPrefAttachmentSelectTwoVertexes ensures that when passed a
|
||||
// TestPrefAttachmentSelectTwoVertexes ensures that when passed a
|
||||
// graph with only two eligible vertexes, then both are given the same score,
|
||||
// and the funds are appropriately allocated across each peer.
|
||||
func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
||||
func TestPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prand.Seed(time.Now().Unix())
|
||||
|
||||
const (
|
||||
minChanSize = 0
|
||||
maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin)
|
||||
chanLimit = 3
|
||||
threshold = 0.5
|
||||
)
|
||||
|
||||
constraints := NewConstraints(
|
||||
minChanSize,
|
||||
maxChanSize,
|
||||
chanLimit,
|
||||
0,
|
||||
threshold,
|
||||
)
|
||||
|
||||
for _, graph := range chanGraphs {
|
||||
@ -208,7 +186,7 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
prefAttach := NewConstrainedPrefAttachment(constraints)
|
||||
prefAttach := NewPrefAttachment()
|
||||
|
||||
// For this set, we'll load the memory graph with two
|
||||
// nodes, and a random channel connecting them.
|
||||
@ -295,27 +273,16 @@ func TestConstrainedPrefAttachmentSelectTwoVertexes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConstrainedPrefAttachmentSelectInsufficientFunds ensures that if the
|
||||
// TestPrefAttachmentSelectInsufficientFunds ensures that if the
|
||||
// balance of the backing wallet is below the set min channel size, then it
|
||||
// never recommends candidates to attach to.
|
||||
func TestConstrainedPrefAttachmentSelectInsufficientFunds(t *testing.T) {
|
||||
func TestPrefAttachmentSelectInsufficientFunds(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prand.Seed(time.Now().Unix())
|
||||
|
||||
const (
|
||||
minChanSize = 0
|
||||
maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin)
|
||||
chanLimit = 3
|
||||
threshold = 0.5
|
||||
)
|
||||
|
||||
constraints := NewConstraints(
|
||||
minChanSize,
|
||||
maxChanSize,
|
||||
chanLimit,
|
||||
0,
|
||||
threshold,
|
||||
)
|
||||
|
||||
for _, graph := range chanGraphs {
|
||||
@ -332,7 +299,7 @@ func TestConstrainedPrefAttachmentSelectInsufficientFunds(t *testing.T) {
|
||||
// them.
|
||||
completeGraph(t, graph, 10)
|
||||
|
||||
prefAttach := NewConstrainedPrefAttachment(constraints)
|
||||
prefAttach := NewPrefAttachment()
|
||||
|
||||
nodes := make(map[NodeID]struct{})
|
||||
if err := graph.ForEachNode(func(n Node) error {
|
||||
@ -368,27 +335,16 @@ func TestConstrainedPrefAttachmentSelectInsufficientFunds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConstrainedPrefAttachmentSelectGreedyAllocation tests that if upon
|
||||
// TestPrefAttachmentSelectGreedyAllocation tests that if upon
|
||||
// returning node scores, the NodeScores method will attempt to greedily
|
||||
// allocate all funds to each vertex (up to the max channel size).
|
||||
func TestConstrainedPrefAttachmentSelectGreedyAllocation(t *testing.T) {
|
||||
func TestPrefAttachmentSelectGreedyAllocation(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prand.Seed(time.Now().Unix())
|
||||
|
||||
const (
|
||||
minChanSize = 0
|
||||
maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin)
|
||||
chanLimit = 3
|
||||
threshold = 0.5
|
||||
)
|
||||
|
||||
constraints := NewConstraints(
|
||||
minChanSize,
|
||||
maxChanSize,
|
||||
chanLimit,
|
||||
0,
|
||||
threshold,
|
||||
)
|
||||
|
||||
for _, graph := range chanGraphs {
|
||||
@ -401,7 +357,7 @@ func TestConstrainedPrefAttachmentSelectGreedyAllocation(t *testing.T) {
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
prefAttach := NewConstrainedPrefAttachment(constraints)
|
||||
prefAttach := NewPrefAttachment()
|
||||
|
||||
const chanCapacity = btcutil.SatoshiPerBitcoin
|
||||
|
||||
@ -525,27 +481,16 @@ func TestConstrainedPrefAttachmentSelectGreedyAllocation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestConstrainedPrefAttachmentSelectSkipNodes ensures that if a node was
|
||||
// TestPrefAttachmentSelectSkipNodes ensures that if a node was
|
||||
// already selected as a channel counterparty, then that node will get a score
|
||||
// of zero during scoring.
|
||||
func TestConstrainedPrefAttachmentSelectSkipNodes(t *testing.T) {
|
||||
func TestPrefAttachmentSelectSkipNodes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
prand.Seed(time.Now().Unix())
|
||||
|
||||
const (
|
||||
minChanSize = 0
|
||||
maxChanSize = btcutil.Amount(btcutil.SatoshiPerBitcoin)
|
||||
chanLimit = 3
|
||||
threshold = 0.5
|
||||
)
|
||||
|
||||
constraints := NewConstraints(
|
||||
minChanSize,
|
||||
maxChanSize,
|
||||
chanLimit,
|
||||
0,
|
||||
threshold,
|
||||
)
|
||||
|
||||
for _, graph := range chanGraphs {
|
||||
@ -558,7 +503,7 @@ func TestConstrainedPrefAttachmentSelectSkipNodes(t *testing.T) {
|
||||
defer cleanup()
|
||||
}
|
||||
|
||||
prefAttach := NewConstrainedPrefAttachment(constraints)
|
||||
prefAttach := NewPrefAttachment()
|
||||
|
||||
// Next, we'll create a simple topology of two nodes,
|
||||
// with a single channel connecting them.
|
||||
|
7
pilot.go
7
pilot.go
@ -95,11 +95,8 @@ func initAutoPilot(svr *server, cfg *autoPilotConfig) *autopilot.ManagerCfg {
|
||||
cfg.Allocation,
|
||||
)
|
||||
|
||||
// First, we'll create the preferential attachment heuristic,
|
||||
// initialized with the passed auto pilot configuration parameters.
|
||||
prefAttachment := autopilot.NewConstrainedPrefAttachment(
|
||||
atplConstraints,
|
||||
)
|
||||
// First, we'll create the preferential attachment heuristic.
|
||||
prefAttachment := autopilot.NewPrefAttachment()
|
||||
|
||||
// With the heuristic itself created, we can now populate the remainder
|
||||
// of the items that the autopilot agent needs to perform its duties.
|
||||
|
Loading…
Reference in New Issue
Block a user