autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
package autopilot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2022-02-23 14:48:00 +01:00
|
|
|
"encoding/hex"
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
"net"
|
2019-03-27 15:04:14 +01:00
|
|
|
"sort"
|
2017-08-16 02:56:19 +02:00
|
|
|
"sync/atomic"
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
"time"
|
|
|
|
|
2022-02-23 14:48:00 +01:00
|
|
|
"github.com/btcsuite/btcd/btcec/v2"
|
|
|
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
|
|
|
"github.com/btcsuite/btcd/btcutil"
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
2021-04-26 19:08:11 +02:00
|
|
|
"github.com/lightningnetwork/lnd/kvdb"
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
2019-12-18 12:43:18 +01:00
|
|
|
"github.com/lightningnetwork/lnd/routing/route"
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2022-02-23 14:48:00 +01:00
|
|
|
testRBytes, _ = hex.DecodeString("8ce2bc69281ce27da07e6683571319d18e949ddfa2965fb6caa1bf0314f882d7")
|
|
|
|
testSBytes, _ = hex.DecodeString("299105481d63e0f4bc2a88121167221b6700d72a0ead154c03be696a292d24ae")
|
|
|
|
testRScalar = new(btcec.ModNScalar)
|
|
|
|
testSScalar = new(btcec.ModNScalar)
|
|
|
|
_ = testRScalar.SetByteSlice(testRBytes)
|
|
|
|
_ = testSScalar.SetByteSlice(testSBytes)
|
|
|
|
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
2017-08-16 02:56:19 +02:00
|
|
|
|
2018-06-01 00:41:41 +02:00
|
|
|
chanIDCounter uint64 // To be used atomically.
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// databaseChannelGraph wraps a channeldb.ChannelGraph instance with the
|
|
|
|
// necessary API to properly implement the autopilot.ChannelGraph interface.
|
|
|
|
//
|
|
|
|
// TODO(roasbeef): move inmpl to main package?
|
|
|
|
type databaseChannelGraph struct {
|
|
|
|
db *channeldb.ChannelGraph
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure databaseChannelGraph meets the
|
|
|
|
// autopilot.ChannelGraph interface.
|
|
|
|
var _ ChannelGraph = (*databaseChannelGraph)(nil)
|
|
|
|
|
2018-04-18 04:02:04 +02:00
|
|
|
// ChannelGraphFromDatabase returns an instance of the autopilot.ChannelGraph
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
// backed by a live, open channeldb instance.
|
|
|
|
func ChannelGraphFromDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
|
|
|
return &databaseChannelGraph{
|
|
|
|
db: db,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// type dbNode is a wrapper struct around a database transaction an
|
|
|
|
// channeldb.LightningNode. The wrapper method implement the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
type dbNode struct {
|
2020-05-07 00:45:50 +02:00
|
|
|
tx kvdb.RTx
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
|
|
|
|
node *channeldb.LightningNode
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure dbNode meets the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
var _ Node = (*dbNode)(nil)
|
|
|
|
|
|
|
|
// PubKey is the identity public key of the node. This will be used to attempt
|
2018-08-30 00:44:26 +02:00
|
|
|
// to target a node for channel opening by the main autopilot agent. The key
|
|
|
|
// will be returned in serialized compressed format.
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
2018-08-30 00:44:26 +02:00
|
|
|
func (d dbNode) PubKey() [33]byte {
|
|
|
|
return d.node.PubKeyBytes
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Addrs returns a slice of publicly reachable public TCP addresses that the
|
|
|
|
// peer is known to be listening on.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (d dbNode) Addrs() []net.Addr {
|
|
|
|
return d.node.Addresses
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachChannel is a higher-order function that will be used to iterate
|
|
|
|
// through all edges emanating from/to the target node. For each active
|
|
|
|
// channel, this function should be called with the populated ChannelEdge that
|
|
|
|
// describes the active channel.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (d dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
2020-05-07 00:45:50 +02:00
|
|
|
return d.node.ForEachChannel(d.tx, func(tx kvdb.RTx,
|
2017-08-22 08:07:56 +02:00
|
|
|
ei *channeldb.ChannelEdgeInfo, ep, _ *channeldb.ChannelEdgePolicy) error {
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
|
2018-06-18 12:35:22 +02:00
|
|
|
// Skip channels for which no outgoing edge policy is available.
|
|
|
|
//
|
|
|
|
// TODO(joostjager): Ideally the case where channels have a nil
|
2018-10-09 18:28:34 +02:00
|
|
|
// policy should be supported, as autopilot is not looking at
|
2018-06-18 12:35:22 +02:00
|
|
|
// the policies. For now, it is not easily possible to get a
|
|
|
|
// reference to the other end LightningNode object without
|
|
|
|
// retrieving the policy.
|
|
|
|
if ep == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
edge := ChannelEdge{
|
2020-10-02 13:56:43 +02:00
|
|
|
ChanID: lnwire.NewShortChanIDFromInt(ep.ChannelID),
|
|
|
|
Capacity: ei.Capacity,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
Peer: dbNode{
|
|
|
|
tx: tx,
|
|
|
|
node: ep.Node,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(edge)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachNode is a higher-order function that should be called once for each
|
|
|
|
// connected node within the channel graph. If the passed callback returns an
|
|
|
|
// error, then execution should be terminated.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.ChannelGraph interface.
|
|
|
|
func (d *databaseChannelGraph) ForEachNode(cb func(Node) error) error {
|
2020-05-07 00:45:50 +02:00
|
|
|
return d.db.ForEachNode(func(tx kvdb.RTx, n *channeldb.LightningNode) error {
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
// We'll skip over any node that doesn't have any advertised
|
|
|
|
// addresses. As we won't be able to reach them to actually
|
|
|
|
// open any channels.
|
|
|
|
if len(n.Addresses) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
node := dbNode{
|
|
|
|
tx: tx,
|
|
|
|
node: n,
|
|
|
|
}
|
|
|
|
return cb(node)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// addRandChannel creates a new channel two target nodes. This function is
|
|
|
|
// meant to aide in the generation of random graphs for use within test cases
|
|
|
|
// the exercise the autopilot package.
|
|
|
|
func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|
|
|
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
|
|
|
|
|
|
|
|
fetchNode := func(pub *btcec.PublicKey) (*channeldb.LightningNode, error) {
|
|
|
|
if pub != nil {
|
2019-12-18 12:43:18 +01:00
|
|
|
vertex, err := route.NewVertexFromBytes(
|
|
|
|
pub.SerializeCompressed(),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-09-21 19:18:18 +02:00
|
|
|
dbNode, err := d.db.FetchLightningNode(vertex)
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
switch {
|
|
|
|
case err == channeldb.ErrGraphNodeNotFound:
|
|
|
|
fallthrough
|
|
|
|
case err == channeldb.ErrGraphNotFound:
|
|
|
|
graphNode := &channeldb.LightningNode{
|
|
|
|
HaveNodeAnnouncement: true,
|
|
|
|
Addresses: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
2019-11-08 14:32:00 +01:00
|
|
|
Features: lnwire.NewFeatureVector(
|
|
|
|
nil, lnwire.Features,
|
|
|
|
),
|
2018-01-31 05:23:56 +01:00
|
|
|
AuthSigBytes: testSig.Serialize(),
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
2018-01-31 05:23:56 +01:00
|
|
|
graphNode.AddPubKey(pub)
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
if err := d.db.AddLightningNode(graphNode); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
case err != nil:
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbNode, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
nodeKey, err := randKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dbNode := &channeldb.LightningNode{
|
|
|
|
HaveNodeAnnouncement: true,
|
|
|
|
Addresses: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
2019-11-08 14:32:00 +01:00
|
|
|
Features: lnwire.NewFeatureVector(
|
|
|
|
nil, lnwire.Features,
|
|
|
|
),
|
2018-01-31 05:23:56 +01:00
|
|
|
AuthSigBytes: testSig.Serialize(),
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
2018-01-31 05:23:56 +01:00
|
|
|
dbNode.AddPubKey(nodeKey)
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
if err := d.db.AddLightningNode(dbNode); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return dbNode, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
vertex1, err := fetchNode(node1)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
vertex2, err := fetchNode(node2)
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var lnNode1, lnNode2 *btcec.PublicKey
|
2018-01-31 05:23:56 +01:00
|
|
|
if bytes.Compare(vertex1.PubKeyBytes[:], vertex2.PubKeyBytes[:]) == -1 {
|
|
|
|
lnNode1, _ = vertex1.PubKey()
|
|
|
|
lnNode2, _ = vertex2.PubKey()
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
} else {
|
2018-01-31 05:23:56 +01:00
|
|
|
lnNode1, _ = vertex2.PubKey()
|
|
|
|
lnNode2, _ = vertex1.PubKey()
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
chanID := randChanID()
|
|
|
|
edge := &channeldb.ChannelEdgeInfo{
|
2018-01-31 05:23:56 +01:00
|
|
|
ChannelID: chanID.ToUint64(),
|
|
|
|
Capacity: capacity,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
2018-01-31 05:23:56 +01:00
|
|
|
edge.AddNodeKeys(lnNode1, lnNode2, lnNode1, lnNode2)
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
if err := d.db.AddChannelEdge(edge); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
edgePolicy := &channeldb.ChannelEdgePolicy{
|
2018-01-31 05:23:56 +01:00
|
|
|
SigBytes: testSig.Serialize(),
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
ChannelID: chanID.ToUint64(),
|
|
|
|
LastUpdate: time.Now(),
|
|
|
|
TimeLockDelta: 10,
|
2017-08-22 08:07:56 +02:00
|
|
|
MinHTLC: 1,
|
2019-01-12 18:59:45 +01:00
|
|
|
MaxHTLC: lnwire.NewMSatFromSatoshis(capacity),
|
2017-08-22 08:07:56 +02:00
|
|
|
FeeBaseMSat: 10,
|
|
|
|
FeeProportionalMillionths: 10000,
|
2019-01-12 18:59:45 +01:00
|
|
|
MessageFlags: 1,
|
2019-01-12 18:59:43 +01:00
|
|
|
ChannelFlags: 0,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
edgePolicy = &channeldb.ChannelEdgePolicy{
|
2018-01-31 05:23:56 +01:00
|
|
|
SigBytes: testSig.Serialize(),
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
ChannelID: chanID.ToUint64(),
|
|
|
|
LastUpdate: time.Now(),
|
|
|
|
TimeLockDelta: 10,
|
2017-08-22 08:07:56 +02:00
|
|
|
MinHTLC: 1,
|
2019-01-12 18:59:45 +01:00
|
|
|
MaxHTLC: lnwire.NewMSatFromSatoshis(capacity),
|
2017-08-22 08:07:56 +02:00
|
|
|
FeeBaseMSat: 10,
|
|
|
|
FeeProportionalMillionths: 10000,
|
2019-01-12 18:59:45 +01:00
|
|
|
MessageFlags: 1,
|
2019-01-12 18:59:43 +01:00
|
|
|
ChannelFlags: 1,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ChannelEdge{
|
2020-10-02 13:56:43 +02:00
|
|
|
ChanID: chanID,
|
|
|
|
Capacity: capacity,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
Peer: dbNode{
|
|
|
|
node: vertex1,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
&ChannelEdge{
|
2020-10-02 13:56:43 +02:00
|
|
|
ChanID: chanID,
|
|
|
|
Capacity: capacity,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
Peer: dbNode{
|
|
|
|
node: vertex2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
nil
|
|
|
|
}
|
|
|
|
|
2018-12-10 14:56:54 +01:00
|
|
|
func (d *databaseChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
|
|
|
nodeKey, err := randKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
dbNode := &channeldb.LightningNode{
|
|
|
|
HaveNodeAnnouncement: true,
|
|
|
|
Addresses: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
2019-11-08 14:32:00 +01:00
|
|
|
Features: lnwire.NewFeatureVector(
|
|
|
|
nil, lnwire.Features,
|
|
|
|
),
|
2018-12-10 14:56:54 +01:00
|
|
|
AuthSigBytes: testSig.Serialize(),
|
|
|
|
}
|
|
|
|
dbNode.AddPubKey(nodeKey)
|
|
|
|
if err := d.db.AddLightningNode(dbNode); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nodeKey, nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-18 04:02:04 +02:00
|
|
|
// memChannelGraph is an implementation of the autopilot.ChannelGraph backed by
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
// an in-memory graph.
|
|
|
|
type memChannelGraph struct {
|
2019-12-19 22:19:18 +01:00
|
|
|
graph map[NodeID]*memNode
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure memChannelGraph meets the
|
|
|
|
// autopilot.ChannelGraph interface.
|
|
|
|
var _ ChannelGraph = (*memChannelGraph)(nil)
|
|
|
|
|
|
|
|
// newMemChannelGraph creates a new blank in-memory channel graph
|
|
|
|
// implementation.
|
|
|
|
func newMemChannelGraph() *memChannelGraph {
|
|
|
|
return &memChannelGraph{
|
2019-12-19 22:19:18 +01:00
|
|
|
graph: make(map[NodeID]*memNode),
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachNode is a higher-order function that should be called once for each
|
|
|
|
// connected node within the channel graph. If the passed callback returns an
|
|
|
|
// error, then execution should be terminated.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.ChannelGraph interface.
|
|
|
|
func (m memChannelGraph) ForEachNode(cb func(Node) error) error {
|
|
|
|
for _, node := range m.graph {
|
|
|
|
if err := cb(node); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// randChanID generates a new random channel ID.
|
|
|
|
func randChanID() lnwire.ShortChannelID {
|
2017-08-16 03:26:49 +02:00
|
|
|
id := atomic.AddUint64(&chanIDCounter, 1)
|
2017-08-16 02:56:19 +02:00
|
|
|
return lnwire.NewShortChanIDFromInt(id)
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// randKey returns a random public key.
|
|
|
|
func randKey() (*btcec.PublicKey, error) {
|
2022-02-23 14:48:00 +01:00
|
|
|
priv, err := btcec.NewPrivateKey()
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return priv.PubKey(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// addRandChannel creates a new channel two target nodes. This function is
|
|
|
|
// meant to aide in the generation of random graphs for use within test cases
|
|
|
|
// the exercise the autopilot package.
|
|
|
|
func (m *memChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|
|
|
capacity btcutil.Amount) (*ChannelEdge, *ChannelEdge, error) {
|
|
|
|
|
|
|
|
var (
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex1, vertex2 *memNode
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
ok bool
|
|
|
|
)
|
|
|
|
|
|
|
|
if node1 != nil {
|
|
|
|
vertex1, ok = m.graph[NewNodeID(node1)]
|
|
|
|
if !ok {
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex1 = &memNode{
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
pub: node1,
|
2018-12-10 14:56:54 +01:00
|
|
|
addrs: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newPub, err := randKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex1 = &memNode{
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
pub: newPub,
|
2018-12-10 14:56:54 +01:00
|
|
|
addrs: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if node2 != nil {
|
|
|
|
vertex2, ok = m.graph[NewNodeID(node2)]
|
|
|
|
if !ok {
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex2 = &memNode{
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
pub: node2,
|
2018-12-10 14:56:54 +01:00
|
|
|
addrs: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newPub, err := randKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex2 = &memNode{
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
pub: newPub,
|
2018-12-10 14:56:54 +01:00
|
|
|
addrs: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 13:56:43 +02:00
|
|
|
edge1 := ChannelEdge{
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
ChanID: randChanID(),
|
|
|
|
Capacity: capacity,
|
2020-10-02 13:56:43 +02:00
|
|
|
Peer: vertex2,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
vertex1.chans = append(vertex1.chans, edge1)
|
|
|
|
|
|
|
|
edge2 := ChannelEdge{
|
2020-10-02 13:56:43 +02:00
|
|
|
ChanID: randChanID(),
|
|
|
|
Capacity: capacity,
|
|
|
|
Peer: vertex1,
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
vertex2.chans = append(vertex2.chans, edge2)
|
|
|
|
|
|
|
|
m.graph[NewNodeID(vertex1.pub)] = vertex1
|
|
|
|
m.graph[NewNodeID(vertex2.pub)] = vertex2
|
|
|
|
|
|
|
|
return &edge1, &edge2, nil
|
|
|
|
}
|
|
|
|
|
2018-12-10 14:56:54 +01:00
|
|
|
func (m *memChannelGraph) addRandNode() (*btcec.PublicKey, error) {
|
|
|
|
newPub, err := randKey()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-12-19 22:19:18 +01:00
|
|
|
vertex := &memNode{
|
2018-12-10 14:56:54 +01:00
|
|
|
pub: newPub,
|
|
|
|
addrs: []net.Addr{
|
|
|
|
&net.TCPAddr{
|
|
|
|
IP: bytes.Repeat([]byte("a"), 16),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
m.graph[NewNodeID(newPub)] = vertex
|
|
|
|
|
|
|
|
return newPub, nil
|
|
|
|
}
|
|
|
|
|
2021-12-04 12:28:07 +01:00
|
|
|
// databaseChannelGraphCached wraps a channeldb.ChannelGraph instance with the
|
|
|
|
// necessary API to properly implement the autopilot.ChannelGraph interface.
|
|
|
|
type databaseChannelGraphCached struct {
|
|
|
|
db *channeldb.ChannelGraph
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure databaseChannelGraphCached meets the
|
|
|
|
// autopilot.ChannelGraph interface.
|
|
|
|
var _ ChannelGraph = (*databaseChannelGraphCached)(nil)
|
|
|
|
|
|
|
|
// ChannelGraphFromCachedDatabase returns an instance of the
|
|
|
|
// autopilot.ChannelGraph backed by a live, open channeldb instance.
|
|
|
|
func ChannelGraphFromCachedDatabase(db *channeldb.ChannelGraph) ChannelGraph {
|
|
|
|
return &databaseChannelGraphCached{
|
|
|
|
db: db,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// dbNodeCached is a wrapper struct around a database transaction for a
|
|
|
|
// channeldb.LightningNode. The wrapper methods implement the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
type dbNodeCached struct {
|
|
|
|
node route.Vertex
|
|
|
|
channels map[uint64]*channeldb.DirectedChannel
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure dbNodeCached meets the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
var _ Node = (*dbNodeCached)(nil)
|
|
|
|
|
|
|
|
// PubKey is the identity public key of the node.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (nc dbNodeCached) PubKey() [33]byte {
|
|
|
|
return nc.node
|
|
|
|
}
|
|
|
|
|
|
|
|
// Addrs returns a slice of publicly reachable public TCP addresses that the
|
|
|
|
// peer is known to be listening on.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (nc dbNodeCached) Addrs() []net.Addr {
|
|
|
|
// TODO: Add addresses to be usable by autopilot.
|
|
|
|
return []net.Addr{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachChannel is a higher-order function that will be used to iterate
|
|
|
|
// through all edges emanating from/to the target node. For each active
|
|
|
|
// channel, this function should be called with the populated ChannelEdge that
|
|
|
|
// describes the active channel.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (nc dbNodeCached) ForEachChannel(cb func(ChannelEdge) error) error {
|
|
|
|
for cid, channel := range nc.channels {
|
|
|
|
edge := ChannelEdge{
|
|
|
|
ChanID: lnwire.NewShortChanIDFromInt(cid),
|
|
|
|
Capacity: channel.Capacity,
|
|
|
|
Peer: dbNodeCached{
|
|
|
|
node: channel.OtherNode,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cb(edge); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachNode is a higher-order function that should be called once for each
|
|
|
|
// connected node within the channel graph. If the passed callback returns an
|
|
|
|
// error, then execution should be terminated.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.ChannelGraph interface.
|
|
|
|
func (dc *databaseChannelGraphCached) ForEachNode(cb func(Node) error) error {
|
|
|
|
return dc.db.ForEachNodeCached(func(n route.Vertex,
|
|
|
|
channels map[uint64]*channeldb.DirectedChannel) error {
|
|
|
|
|
|
|
|
if len(channels) > 0 {
|
|
|
|
node := dbNodeCached{
|
|
|
|
node: n,
|
|
|
|
channels: channels,
|
|
|
|
}
|
|
|
|
return cb(node)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
// memNode is a purely in-memory implementation of the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
type memNode struct {
|
|
|
|
pub *btcec.PublicKey
|
|
|
|
|
|
|
|
chans []ChannelEdge
|
|
|
|
|
|
|
|
addrs []net.Addr
|
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time assertion to ensure memNode meets the autopilot.Node
|
|
|
|
// interface.
|
|
|
|
var _ Node = (*memNode)(nil)
|
|
|
|
|
|
|
|
// PubKey is the identity public key of the node. This will be used to attempt
|
|
|
|
// to target a node for channel opening by the main autopilot agent.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
2018-08-30 00:44:26 +02:00
|
|
|
func (m memNode) PubKey() [33]byte {
|
|
|
|
var n [33]byte
|
|
|
|
copy(n[:], m.pub.SerializeCompressed())
|
|
|
|
|
|
|
|
return n
|
autopilot: "Look ma no hands!", introducing autopilot mode
This commit introduces the initial implementation of the autopilot
mode. Autopilot is new mode within lnd that enables automatic channel
management. This means that if enabled lnd will attempt to
automatically manage channels according to a set of heuristic defined
within the main configuration for autopilot.Agent instance.
The autopilot.Agent implements a simple closed control loop. It takes
in external signals such as wallet balance updates, new open channel,
and channels that are now closed the updates its internal state. With
each external trigger it will consult the registered
AttachmentHeuristic to decide: if it needs to open any more channels,
and if so how much it should use to open the channels, ultimately
returning a set of recommended AttachmentDirectives. The
autopilot.Agent loop will then take those attempt to establish
connection, and go back in waiting for a new external signal.
With this first implementation the default heuristic is the
ConstrainedPrefAttachment implementation of AttachmentHeuristic. Given
a min and max channel size, a limit on the number of channels, and the
percentage of wallet funds to allocate to channels, it will attempt to
execute a heuristic drive by the Barabási–Albert model model in order
to attempt to drive the global graph towards a scale free topology.
This is commit implements a foundational layer for future simulations,
optimization, and additional heuristics.
2017-08-11 06:14:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Addrs returns a slice of publicly reachable public TCP addresses that the
|
|
|
|
// peer is known to be listening on.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (m memNode) Addrs() []net.Addr {
|
|
|
|
return m.addrs
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForEachChannel is a higher-order function that will be used to iterate
|
|
|
|
// through all edges emanating from/to the target node. For each active
|
|
|
|
// channel, this function should be called with the populated ChannelEdge that
|
|
|
|
// describes the active channel.
|
|
|
|
//
|
|
|
|
// NOTE: Part of the autopilot.Node interface.
|
|
|
|
func (m memNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
|
|
|
for _, channel := range m.chans {
|
|
|
|
if err := cb(channel); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-03-27 15:04:14 +01:00
|
|
|
|
|
|
|
// Median returns the median value in the slice of Amounts.
|
|
|
|
func Median(vals []btcutil.Amount) btcutil.Amount {
|
|
|
|
sort.Slice(vals, func(i, j int) bool {
|
|
|
|
return vals[i] < vals[j]
|
|
|
|
})
|
|
|
|
|
|
|
|
num := len(vals)
|
|
|
|
switch {
|
|
|
|
case num == 0:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
case num%2 == 0:
|
|
|
|
return (vals[num/2-1] + vals[num/2]) / 2
|
|
|
|
|
|
|
|
default:
|
|
|
|
return vals[num/2]
|
|
|
|
}
|
|
|
|
}
|