mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-10 20:00:31 +02:00
multi: move DB schemas to channeldb/models
This commit moves the ChannelEdgePolicy, ChannelEdgeInfo, ChanelAuthProof and CachedEdgePolicy structs to the `channeldb/models` package.
This commit is contained in:
parent
be23986eda
commit
84cdcd6847
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -89,8 +90,8 @@ func (d *dbNode) Addrs() []net.Addr {
|
|||||||
// NOTE: Part of the autopilot.Node interface.
|
// NOTE: Part of the autopilot.Node interface.
|
||||||
func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
func (d *dbNode) ForEachChannel(cb func(ChannelEdge) error) error {
|
||||||
return d.db.ForEachNodeChannel(d.tx, d.node.PubKeyBytes,
|
return d.db.ForEachNodeChannel(d.tx, d.node.PubKeyBytes,
|
||||||
func(tx kvdb.RTx, ei *channeldb.ChannelEdgeInfo, ep,
|
func(tx kvdb.RTx, ei *models.ChannelEdgeInfo, ep,
|
||||||
_ *channeldb.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// Skip channels for which no outgoing edge policy is
|
// Skip channels for which no outgoing edge policy is
|
||||||
// available.
|
// available.
|
||||||
@ -235,7 +236,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
}
|
}
|
||||||
|
|
||||||
chanID := randChanID()
|
chanID := randChanID()
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
Capacity: capacity,
|
Capacity: capacity,
|
||||||
}
|
}
|
||||||
@ -243,7 +244,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
if err := d.db.AddChannelEdge(edge); err != nil {
|
if err := d.db.AddChannelEdge(edge); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
@ -259,7 +260,7 @@ func (d *databaseChannelGraph) addRandChannel(node1, node2 *btcec.PublicKey,
|
|||||||
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
|
if err := d.db.UpdateEdgePolicy(edgePolicy); err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
edgePolicy = &channeldb.ChannelEdgePolicy{
|
edgePolicy = &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
|
@ -3,6 +3,8 @@ package channeldb
|
|||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestChannelCache checks the behavior of the channelCache with respect to
|
// TestChannelCache checks the behavior of the channelCache with respect to
|
||||||
@ -98,7 +100,7 @@ func assertHasChanEntries(t *testing.T, c *channelCache, start, end uint64) {
|
|||||||
// channelForInt generates a unique ChannelEdge given an integer.
|
// channelForInt generates a unique ChannelEdge given an integer.
|
||||||
func channelForInt(i uint64) ChannelEdge {
|
func channelForInt(i uint64) ChannelEdge {
|
||||||
return ChannelEdge{
|
return ChannelEdge{
|
||||||
Info: &ChannelEdgeInfo{
|
Info: &models.ChannelEdgeInfo{
|
||||||
ChannelID: i,
|
ChannelID: i,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ import (
|
|||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/txscript"
|
"github.com/btcsuite/btcd/txscript"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/aliasmgr"
|
"github.com/lightningnetwork/lnd/aliasmgr"
|
||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -161,9 +161,6 @@ const (
|
|||||||
// would be possible for a node to create a ton of updates and slowly
|
// would be possible for a node to create a ton of updates and slowly
|
||||||
// fill our disk, and also waste bandwidth due to relaying.
|
// fill our disk, and also waste bandwidth due to relaying.
|
||||||
MaxAllowedExtraOpaqueBytes = 10000
|
MaxAllowedExtraOpaqueBytes = 10000
|
||||||
|
|
||||||
// feeRateParts is the total number of parts used to express fee rates.
|
|
||||||
feeRateParts = 1e6
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ChannelGraph is a persistent, on-disk graph representation of the Lightning
|
// ChannelGraph is a persistent, on-disk graph representation of the Lightning
|
||||||
@ -231,8 +228,8 @@ func NewChannelGraph(db kvdb.Backend, rejectCacheSize, chanCacheSize int,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = g.ForEachChannel(func(info *ChannelEdgeInfo,
|
err = g.ForEachChannel(func(info *models.ChannelEdgeInfo,
|
||||||
policy1, policy2 *ChannelEdgePolicy) error {
|
policy1, policy2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
g.graphCache.AddChannel(info, policy1, policy2)
|
g.graphCache.AddChannel(info, policy1, policy2)
|
||||||
|
|
||||||
@ -258,10 +255,10 @@ type channelMapKey struct {
|
|||||||
// getChannelMap loads all channel edge policies from the database and stores
|
// getChannelMap loads all channel edge policies from the database and stores
|
||||||
// them in a map.
|
// them in a map.
|
||||||
func (c *ChannelGraph) getChannelMap(edges kvdb.RBucket) (
|
func (c *ChannelGraph) getChannelMap(edges kvdb.RBucket) (
|
||||||
map[channelMapKey]*ChannelEdgePolicy, error) {
|
map[channelMapKey]*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
// Create a map to store all channel edge policies.
|
// Create a map to store all channel edge policies.
|
||||||
channelMap := make(map[channelMapKey]*ChannelEdgePolicy)
|
channelMap := make(map[channelMapKey]*models.ChannelEdgePolicy)
|
||||||
|
|
||||||
err := kvdb.ForAll(edges, func(k, edgeBytes []byte) error {
|
err := kvdb.ForAll(edges, func(k, edgeBytes []byte) error {
|
||||||
// Skip embedded buckets.
|
// Skip embedded buckets.
|
||||||
@ -411,8 +408,8 @@ func (c *ChannelGraph) NewPathFindTx() (kvdb.RTx, error) {
|
|||||||
// NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer
|
// NOTE: If an edge can't be found, or wasn't advertised, then a nil pointer
|
||||||
// for that particular channel edge routing policy will be passed into the
|
// for that particular channel edge routing policy will be passed into the
|
||||||
// callback.
|
// callback.
|
||||||
func (c *ChannelGraph) ForEachChannel(cb func(*ChannelEdgeInfo,
|
func (c *ChannelGraph) ForEachChannel(cb func(*models.ChannelEdgeInfo,
|
||||||
*ChannelEdgePolicy, *ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return c.db.View(func(tx kvdb.RTx) error {
|
return c.db.View(func(tx kvdb.RTx) error {
|
||||||
edges := tx.ReadBucket(edgeBucket)
|
edges := tx.ReadBucket(edgeBucket)
|
||||||
@ -481,12 +478,12 @@ func (c *ChannelGraph) ForEachNodeDirectedChannel(tx kvdb.RTx,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dbCallback := func(tx kvdb.RTx, e *ChannelEdgeInfo, p1,
|
dbCallback := func(tx kvdb.RTx, e *models.ChannelEdgeInfo, p1,
|
||||||
p2 *ChannelEdgePolicy) error {
|
p2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
var cachedInPolicy *CachedEdgePolicy
|
var cachedInPolicy *models.CachedEdgePolicy
|
||||||
if p2 != nil {
|
if p2 != nil {
|
||||||
cachedInPolicy = NewCachedPolicy(p2)
|
cachedInPolicy = models.NewCachedPolicy(p2)
|
||||||
cachedInPolicy.ToNodePubKey = toNodeCallback
|
cachedInPolicy.ToNodePubKey = toNodeCallback
|
||||||
cachedInPolicy.ToNodeFeatures = toNodeFeatures
|
cachedInPolicy.ToNodeFeatures = toNodeFeatures
|
||||||
}
|
}
|
||||||
@ -556,9 +553,9 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
|||||||
channels := make(map[uint64]*DirectedChannel)
|
channels := make(map[uint64]*DirectedChannel)
|
||||||
|
|
||||||
err := c.ForEachNodeChannel(tx, node.PubKeyBytes,
|
err := c.ForEachNodeChannel(tx, node.PubKeyBytes,
|
||||||
func(tx kvdb.RTx, e *ChannelEdgeInfo,
|
func(tx kvdb.RTx, e *models.ChannelEdgeInfo,
|
||||||
p1 *ChannelEdgePolicy,
|
p1 *models.ChannelEdgePolicy,
|
||||||
p2 *ChannelEdgePolicy) error {
|
p2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
toNodeCallback := func() route.Vertex {
|
toNodeCallback := func() route.Vertex {
|
||||||
return node.PubKeyBytes
|
return node.PubKeyBytes
|
||||||
@ -570,9 +567,10 @@ func (c *ChannelGraph) ForEachNodeCached(cb func(node route.Vertex,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var cachedInPolicy *CachedEdgePolicy
|
var cachedInPolicy *models.CachedEdgePolicy
|
||||||
if p2 != nil {
|
if p2 != nil {
|
||||||
cachedInPolicy := NewCachedPolicy(p2)
|
cachedInPolicy =
|
||||||
|
models.NewCachedPolicy(p2)
|
||||||
cachedInPolicy.ToNodePubKey =
|
cachedInPolicy.ToNodePubKey =
|
||||||
toNodeCallback
|
toNodeCallback
|
||||||
cachedInPolicy.ToNodeFeatures =
|
cachedInPolicy.ToNodeFeatures =
|
||||||
@ -968,7 +966,7 @@ func (c *ChannelGraph) deleteLightningNode(nodes kvdb.RwBucket,
|
|||||||
// involved in creation of the channel, and the set of features that the channel
|
// involved in creation of the channel, and the set of features that the channel
|
||||||
// supports. The chanPoint and chanID are used to uniquely identify the edge
|
// supports. The chanPoint and chanID are used to uniquely identify the edge
|
||||||
// globally within the database.
|
// globally within the database.
|
||||||
func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo,
|
func (c *ChannelGraph) AddChannelEdge(edge *models.ChannelEdgeInfo,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
var alreadyExists bool
|
var alreadyExists bool
|
||||||
@ -1011,7 +1009,7 @@ func (c *ChannelGraph) AddChannelEdge(edge *ChannelEdgeInfo,
|
|||||||
|
|
||||||
// addChannelEdge is the private form of AddChannelEdge that allows callers to
|
// addChannelEdge is the private form of AddChannelEdge that allows callers to
|
||||||
// utilize an existing db transaction.
|
// utilize an existing db transaction.
|
||||||
func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx, edge *ChannelEdgeInfo) error {
|
func (c *ChannelGraph) addChannelEdge(tx kvdb.RwTx, edge *models.ChannelEdgeInfo) error {
|
||||||
// Construct the channel's primary key which is the 8-byte channel ID.
|
// Construct the channel's primary key which is the 8-byte channel ID.
|
||||||
var chanKey [8]byte
|
var chanKey [8]byte
|
||||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
||||||
@ -1222,7 +1220,7 @@ func (c *ChannelGraph) HasChannelEdge(
|
|||||||
// In order to maintain this constraints, we return an error in the scenario
|
// In order to maintain this constraints, we return an error in the scenario
|
||||||
// that an edge info hasn't yet been created yet, but someone attempts to update
|
// that an edge info hasn't yet been created yet, but someone attempts to update
|
||||||
// it.
|
// it.
|
||||||
func (c *ChannelGraph) UpdateChannelEdge(edge *ChannelEdgeInfo) error {
|
func (c *ChannelGraph) UpdateChannelEdge(edge *models.ChannelEdgeInfo) error {
|
||||||
// Construct the channel's primary key which is the 8-byte channel ID.
|
// Construct the channel's primary key which is the 8-byte channel ID.
|
||||||
var chanKey [8]byte
|
var chanKey [8]byte
|
||||||
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
binary.BigEndian.PutUint64(chanKey[:], edge.ChannelID)
|
||||||
@ -1267,12 +1265,12 @@ const (
|
|||||||
// with the current UTXO state. A slice of channels that have been closed by
|
// with the current UTXO state. A slice of channels that have been closed by
|
||||||
// the target block are returned if the function succeeds without error.
|
// the target block are returned if the function succeeds without error.
|
||||||
func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
func (c *ChannelGraph) PruneGraph(spentOutputs []*wire.OutPoint,
|
||||||
blockHash *chainhash.Hash, blockHeight uint32) ([]*ChannelEdgeInfo, error) {
|
blockHash *chainhash.Hash, blockHeight uint32) ([]*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
c.cacheMu.Lock()
|
c.cacheMu.Lock()
|
||||||
defer c.cacheMu.Unlock()
|
defer c.cacheMu.Unlock()
|
||||||
|
|
||||||
var chansClosed []*ChannelEdgeInfo
|
var chansClosed []*models.ChannelEdgeInfo
|
||||||
|
|
||||||
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
// First grab the edges bucket which houses the information
|
// First grab the edges bucket which houses the information
|
||||||
@ -1520,7 +1518,7 @@ func (c *ChannelGraph) pruneGraphNodes(nodes kvdb.RwBucket,
|
|||||||
// set to the last prune height valid for the remaining chain.
|
// set to the last prune height valid for the remaining chain.
|
||||||
// Channels that were removed from the graph resulting from the
|
// Channels that were removed from the graph resulting from the
|
||||||
// disconnected block are returned.
|
// disconnected block are returned.
|
||||||
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInfo,
|
func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*models.ChannelEdgeInfo,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
// Every channel having a ShortChannelID starting at 'height'
|
// Every channel having a ShortChannelID starting at 'height'
|
||||||
@ -1543,7 +1541,7 @@ func (c *ChannelGraph) DisconnectBlockAtHeight(height uint32) ([]*ChannelEdgeInf
|
|||||||
defer c.cacheMu.Unlock()
|
defer c.cacheMu.Unlock()
|
||||||
|
|
||||||
// Keep track of the channels that are removed from the graph.
|
// Keep track of the channels that are removed from the graph.
|
||||||
var removedChans []*ChannelEdgeInfo
|
var removedChans []*models.ChannelEdgeInfo
|
||||||
|
|
||||||
if err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
if err := kvdb.Update(c.db, func(tx kvdb.RwTx) error {
|
||||||
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
edges, err := tx.CreateTopLevelBucket(edgeBucket)
|
||||||
@ -1850,15 +1848,15 @@ func (c *ChannelGraph) HighestChanID() (uint64, error) {
|
|||||||
// edge as well as each of the known advertised edge policies.
|
// edge as well as each of the known advertised edge policies.
|
||||||
type ChannelEdge struct {
|
type ChannelEdge struct {
|
||||||
// Info contains all the static information describing the channel.
|
// Info contains all the static information describing the channel.
|
||||||
Info *ChannelEdgeInfo
|
Info *models.ChannelEdgeInfo
|
||||||
|
|
||||||
// Policy1 points to the "first" edge policy of the channel containing
|
// Policy1 points to the "first" edge policy of the channel containing
|
||||||
// the dynamic information required to properly route through the edge.
|
// the dynamic information required to properly route through the edge.
|
||||||
Policy1 *ChannelEdgePolicy
|
Policy1 *models.ChannelEdgePolicy
|
||||||
|
|
||||||
// Policy2 points to the "second" edge policy of the channel containing
|
// Policy2 points to the "second" edge policy of the channel containing
|
||||||
// the dynamic information required to properly route through the edge.
|
// the dynamic information required to properly route through the edge.
|
||||||
Policy2 *ChannelEdgePolicy
|
Policy2 *models.ChannelEdgePolicy
|
||||||
|
|
||||||
// Node1 is "node 1" in the channel. This is the node that would have
|
// Node1 is "node 1" in the channel. This is the node that would have
|
||||||
// produced Policy1 if it exists.
|
// produced Policy1 if it exists.
|
||||||
@ -2338,7 +2336,7 @@ func (c *ChannelGraph) FetchChanInfos(chanIDs []uint64) ([]ChannelEdge, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func delEdgeUpdateIndexEntry(edgesBucket kvdb.RwBucket, chanID uint64,
|
func delEdgeUpdateIndexEntry(edgesBucket kvdb.RwBucket, chanID uint64,
|
||||||
edge1, edge2 *ChannelEdgePolicy) error {
|
edge1, edge2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// First, we'll fetch the edge update index bucket which currently
|
// First, we'll fetch the edge update index bucket which currently
|
||||||
// stores an entry for the channel we're about to delete.
|
// stores an entry for the channel we're about to delete.
|
||||||
@ -2475,8 +2473,8 @@ func (c *ChannelGraph) delChannelEdge(edges, edgeIndex, chanIndex, zombieIndex,
|
|||||||
// the channel. If the channel were to be marked zombie again, it would be
|
// the channel. If the channel were to be marked zombie again, it would be
|
||||||
// marked with the correct lagging channel since we received an update from only
|
// marked with the correct lagging channel since we received an update from only
|
||||||
// one side.
|
// one side.
|
||||||
func makeZombiePubkeys(info *ChannelEdgeInfo,
|
func makeZombiePubkeys(info *models.ChannelEdgeInfo,
|
||||||
e1, e2 *ChannelEdgePolicy) ([33]byte, [33]byte) {
|
e1, e2 *models.ChannelEdgePolicy) ([33]byte, [33]byte) {
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
// If we don't have either edge policy, we'll return both pubkeys so
|
// If we don't have either edge policy, we'll return both pubkeys so
|
||||||
@ -2506,7 +2504,7 @@ func makeZombiePubkeys(info *ChannelEdgeInfo,
|
|||||||
// updated, otherwise it's the second node's information. The node ordering is
|
// updated, otherwise it's the second node's information. The node ordering is
|
||||||
// determined by the lexicographical ordering of the identity public keys of the
|
// determined by the lexicographical ordering of the identity public keys of the
|
||||||
// nodes on either side of the channel.
|
// nodes on either side of the channel.
|
||||||
func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy,
|
func (c *ChannelGraph) UpdateEdgePolicy(edge *models.ChannelEdgePolicy,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -2554,7 +2552,7 @@ func (c *ChannelGraph) UpdateEdgePolicy(edge *ChannelEdgePolicy,
|
|||||||
return c.chanScheduler.Execute(r)
|
return c.chanScheduler.Execute(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ChannelGraph) updateEdgeCache(e *ChannelEdgePolicy, isUpdate1 bool) {
|
func (c *ChannelGraph) updateEdgeCache(e *models.ChannelEdgePolicy, isUpdate1 bool) {
|
||||||
// If an entry for this channel is found in reject cache, we'll modify
|
// If an entry for this channel is found in reject cache, we'll modify
|
||||||
// the entry with the updated timestamp for the direction that was just
|
// the entry with the updated timestamp for the direction that was just
|
||||||
// written. If the edge doesn't exist, we'll load the cache entry lazily
|
// written. If the edge doesn't exist, we'll load the cache entry lazily
|
||||||
@ -2586,7 +2584,7 @@ func (c *ChannelGraph) updateEdgeCache(e *ChannelEdgePolicy, isUpdate1 bool) {
|
|||||||
// buckets using an existing database transaction. The returned boolean will be
|
// buckets using an existing database transaction. The returned boolean will be
|
||||||
// true if the updated policy belongs to node1, and false if the policy belonged
|
// true if the updated policy belongs to node1, and false if the policy belonged
|
||||||
// to node2.
|
// to node2.
|
||||||
func updateEdgePolicy(tx kvdb.RwTx, edge *ChannelEdgePolicy,
|
func updateEdgePolicy(tx kvdb.RwTx, edge *models.ChannelEdgePolicy,
|
||||||
graphCache *GraphCache) (bool, error) {
|
graphCache *GraphCache) (bool, error) {
|
||||||
|
|
||||||
edges := tx.ReadWriteBucket(edgeBucket)
|
edges := tx.ReadWriteBucket(edgeBucket)
|
||||||
@ -2781,8 +2779,8 @@ func (c *ChannelGraph) isPublic(tx kvdb.RTx, nodePub route.Vertex,
|
|||||||
nodeIsPublic := false
|
nodeIsPublic := false
|
||||||
errDone := errors.New("done")
|
errDone := errors.New("done")
|
||||||
err := c.ForEachNodeChannel(tx, nodePub, func(tx kvdb.RTx,
|
err := c.ForEachNodeChannel(tx, nodePub, func(tx kvdb.RTx,
|
||||||
info *ChannelEdgeInfo, _ *ChannelEdgePolicy,
|
info *models.ChannelEdgeInfo, _ *models.ChannelEdgePolicy,
|
||||||
_ *ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// If this edge doesn't extend to the source node, we'll
|
// If this edge doesn't extend to the source node, we'll
|
||||||
// terminate our search as we can now conclude that the node is
|
// terminate our search as we can now conclude that the node is
|
||||||
@ -2905,8 +2903,8 @@ func (n *graphCacheNode) Features() *lnwire.FeatureVector {
|
|||||||
//
|
//
|
||||||
// Unknown policies are passed into the callback as nil values.
|
// Unknown policies are passed into the callback as nil values.
|
||||||
func (n *graphCacheNode) ForEachChannel(tx kvdb.RTx,
|
func (n *graphCacheNode) ForEachChannel(tx kvdb.RTx,
|
||||||
cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy,
|
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return nodeTraversal(tx, n.pubKeyBytes[:], nil, cb)
|
return nodeTraversal(tx, n.pubKeyBytes[:], nil, cb)
|
||||||
}
|
}
|
||||||
@ -2966,7 +2964,7 @@ func (c *ChannelGraph) HasLightningNode(nodePub [33]byte) (time.Time, bool, erro
|
|||||||
// nodeTraversal is used to traverse all channels of a node given by its
|
// nodeTraversal is used to traverse all channels of a node given by its
|
||||||
// public key and passes channel information into the specified callback.
|
// public key and passes channel information into the specified callback.
|
||||||
func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
||||||
cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy) error) error {
|
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
traversal := func(tx kvdb.RTx) error {
|
traversal := func(tx kvdb.RTx) error {
|
||||||
edges := tx.ReadBucket(edgeBucket)
|
edges := tx.ReadBucket(edgeBucket)
|
||||||
@ -3059,194 +3057,17 @@ func nodeTraversal(tx kvdb.RTx, nodePub []byte, db kvdb.Backend,
|
|||||||
// be nil and a fresh transaction will be created to execute the graph
|
// be nil and a fresh transaction will be created to execute the graph
|
||||||
// traversal.
|
// traversal.
|
||||||
func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, nodePub route.Vertex,
|
func (c *ChannelGraph) ForEachNodeChannel(tx kvdb.RTx, nodePub route.Vertex,
|
||||||
cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy,
|
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return nodeTraversal(tx, nodePub[:], c.db, cb)
|
return nodeTraversal(tx, nodePub[:], c.db, cb)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelEdgeInfo represents a fully authenticated channel along with all its
|
|
||||||
// unique attributes. Once an authenticated channel announcement has been
|
|
||||||
// processed on the network, then an instance of ChannelEdgeInfo encapsulating
|
|
||||||
// the channels attributes is stored. The other portions relevant to routing
|
|
||||||
// policy of a channel are stored within a ChannelEdgePolicy for each direction
|
|
||||||
// of the channel.
|
|
||||||
type ChannelEdgeInfo struct {
|
|
||||||
// ChannelID is the unique channel ID for the channel. The first 3
|
|
||||||
// bytes are the block height, the next 3 the index within the block,
|
|
||||||
// and the last 2 bytes are the output index for the channel.
|
|
||||||
ChannelID uint64
|
|
||||||
|
|
||||||
// ChainHash is the hash that uniquely identifies the chain that this
|
|
||||||
// channel was opened within.
|
|
||||||
//
|
|
||||||
// TODO(roasbeef): need to modify db keying for multi-chain
|
|
||||||
// * must add chain hash to prefix as well
|
|
||||||
ChainHash chainhash.Hash
|
|
||||||
|
|
||||||
// NodeKey1Bytes is the raw public key of the first node.
|
|
||||||
NodeKey1Bytes [33]byte
|
|
||||||
nodeKey1 *btcec.PublicKey
|
|
||||||
|
|
||||||
// NodeKey2Bytes is the raw public key of the first node.
|
|
||||||
NodeKey2Bytes [33]byte
|
|
||||||
nodeKey2 *btcec.PublicKey
|
|
||||||
|
|
||||||
// BitcoinKey1Bytes is the raw public key of the first node.
|
|
||||||
BitcoinKey1Bytes [33]byte
|
|
||||||
bitcoinKey1 *btcec.PublicKey
|
|
||||||
|
|
||||||
// BitcoinKey2Bytes is the raw public key of the first node.
|
|
||||||
BitcoinKey2Bytes [33]byte
|
|
||||||
bitcoinKey2 *btcec.PublicKey
|
|
||||||
|
|
||||||
// Features is an opaque byte slice that encodes the set of channel
|
|
||||||
// specific features that this channel edge supports.
|
|
||||||
Features []byte
|
|
||||||
|
|
||||||
// AuthProof is the authentication proof for this channel. This proof
|
|
||||||
// contains a set of signatures binding four identities, which attests
|
|
||||||
// to the legitimacy of the advertised channel.
|
|
||||||
AuthProof *ChannelAuthProof
|
|
||||||
|
|
||||||
// ChannelPoint is the funding outpoint of the channel. This can be
|
|
||||||
// used to uniquely identify the channel within the channel graph.
|
|
||||||
ChannelPoint wire.OutPoint
|
|
||||||
|
|
||||||
// Capacity is the total capacity of the channel, this is determined by
|
|
||||||
// the value output in the outpoint that created this channel.
|
|
||||||
Capacity btcutil.Amount
|
|
||||||
|
|
||||||
// ExtraOpaqueData is the set of data that was appended to this
|
|
||||||
// message, some of which we may not actually know how to iterate or
|
|
||||||
// parse. By holding onto this data, we ensure that we're able to
|
|
||||||
// properly validate the set of signatures that cover these new fields,
|
|
||||||
// and ensure we're able to make upgrades to the network in a forwards
|
|
||||||
// compatible manner.
|
|
||||||
ExtraOpaqueData []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// AddNodeKeys is a setter-like method that can be used to replace the set of
|
|
||||||
// keys for the target ChannelEdgeInfo.
|
|
||||||
func (c *ChannelEdgeInfo) AddNodeKeys(nodeKey1, nodeKey2, bitcoinKey1,
|
|
||||||
bitcoinKey2 *btcec.PublicKey) {
|
|
||||||
|
|
||||||
c.nodeKey1 = nodeKey1
|
|
||||||
copy(c.NodeKey1Bytes[:], c.nodeKey1.SerializeCompressed())
|
|
||||||
|
|
||||||
c.nodeKey2 = nodeKey2
|
|
||||||
copy(c.NodeKey2Bytes[:], nodeKey2.SerializeCompressed())
|
|
||||||
|
|
||||||
c.bitcoinKey1 = bitcoinKey1
|
|
||||||
copy(c.BitcoinKey1Bytes[:], c.bitcoinKey1.SerializeCompressed())
|
|
||||||
|
|
||||||
c.bitcoinKey2 = bitcoinKey2
|
|
||||||
copy(c.BitcoinKey2Bytes[:], bitcoinKey2.SerializeCompressed())
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeKey1 is the identity public key of the "first" node that was involved in
|
|
||||||
// the creation of this channel. A node is considered "first" if the
|
|
||||||
// lexicographical ordering the its serialized public key is "smaller" than
|
|
||||||
// that of the other node involved in channel creation.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
|
||||||
func (c *ChannelEdgeInfo) NodeKey1() (*btcec.PublicKey, error) {
|
|
||||||
if c.nodeKey1 != nil {
|
|
||||||
return c.nodeKey1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
c.nodeKey1 = key
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// NodeKey2 is the identity public key of the "second" node that was
|
|
||||||
// involved in the creation of this channel. A node is considered
|
|
||||||
// "second" if the lexicographical ordering the its serialized public
|
|
||||||
// key is "larger" than that of the other node involved in channel
|
|
||||||
// creation.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
|
||||||
func (c *ChannelEdgeInfo) NodeKey2() (*btcec.PublicKey, error) {
|
|
||||||
if c.nodeKey2 != nil {
|
|
||||||
return c.nodeKey2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
c.nodeKey2 = key
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitcoinKey1 is the Bitcoin multi-sig key belonging to the first
|
|
||||||
// node, that was involved in the funding transaction that originally
|
|
||||||
// created the channel that this struct represents.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
|
||||||
func (c *ChannelEdgeInfo) BitcoinKey1() (*btcec.PublicKey, error) {
|
|
||||||
if c.bitcoinKey1 != nil {
|
|
||||||
return c.bitcoinKey1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
c.bitcoinKey1 = key
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitcoinKey2 is the Bitcoin multi-sig key belonging to the second
|
|
||||||
// node, that was involved in the funding transaction that originally
|
|
||||||
// created the channel that this struct represents.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the pubkey if absolutely necessary.
|
|
||||||
func (c *ChannelEdgeInfo) BitcoinKey2() (*btcec.PublicKey, error) {
|
|
||||||
if c.bitcoinKey2 != nil {
|
|
||||||
return c.bitcoinKey2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
c.bitcoinKey2 = key
|
|
||||||
|
|
||||||
return key, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// OtherNodeKeyBytes returns the node key bytes of the other end of
|
|
||||||
// the channel.
|
|
||||||
func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
|
|
||||||
[33]byte, error) {
|
|
||||||
|
|
||||||
switch {
|
|
||||||
case bytes.Equal(c.NodeKey1Bytes[:], thisNodeKey):
|
|
||||||
return c.NodeKey2Bytes, nil
|
|
||||||
case bytes.Equal(c.NodeKey2Bytes[:], thisNodeKey):
|
|
||||||
return c.NodeKey1Bytes, nil
|
|
||||||
default:
|
|
||||||
return [33]byte{}, fmt.Errorf("node not participating in this channel")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// FetchOtherNode attempts to fetch the full LightningNode that's opposite of
|
// FetchOtherNode attempts to fetch the full LightningNode that's opposite of
|
||||||
// the target node in the channel. This is useful when one knows the pubkey of
|
// the target node in the channel. This is useful when one knows the pubkey of
|
||||||
// one of the nodes, and wishes to obtain the full LightningNode for the other
|
// one of the nodes, and wishes to obtain the full LightningNode for the other
|
||||||
// end of the channel.
|
// end of the channel.
|
||||||
func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx, channel *ChannelEdgeInfo,
|
func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx, channel *models.ChannelEdgeInfo,
|
||||||
thisNodeKey []byte) (*LightningNode, error) {
|
thisNodeKey []byte) (*LightningNode, error) {
|
||||||
|
|
||||||
// Ensure that the node passed in is actually a member of the channel.
|
// Ensure that the node passed in is actually a member of the channel.
|
||||||
@ -3291,269 +3112,18 @@ func (c *ChannelGraph) FetchOtherNode(tx kvdb.RTx, channel *ChannelEdgeInfo,
|
|||||||
return targetNode, err
|
return targetNode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ChannelAuthProof is the authentication proof (the signature portion) for a
|
|
||||||
// channel. Using the four signatures contained in the struct, and some
|
|
||||||
// auxiliary knowledge (the funding script, node identities, and outpoint) nodes
|
|
||||||
// on the network are able to validate the authenticity and existence of a
|
|
||||||
// channel. Each of these signatures signs the following digest: chanID ||
|
|
||||||
// nodeID1 || nodeID2 || bitcoinKey1|| bitcoinKey2 || 2-byte-feature-len ||
|
|
||||||
// features.
|
|
||||||
type ChannelAuthProof struct {
|
|
||||||
// nodeSig1 is a cached instance of the first node signature.
|
|
||||||
nodeSig1 *ecdsa.Signature
|
|
||||||
|
|
||||||
// NodeSig1Bytes are the raw bytes of the first node signature encoded
|
|
||||||
// in DER format.
|
|
||||||
NodeSig1Bytes []byte
|
|
||||||
|
|
||||||
// nodeSig2 is a cached instance of the second node signature.
|
|
||||||
nodeSig2 *ecdsa.Signature
|
|
||||||
|
|
||||||
// NodeSig2Bytes are the raw bytes of the second node signature
|
|
||||||
// encoded in DER format.
|
|
||||||
NodeSig2Bytes []byte
|
|
||||||
|
|
||||||
// bitcoinSig1 is a cached instance of the first bitcoin signature.
|
|
||||||
bitcoinSig1 *ecdsa.Signature
|
|
||||||
|
|
||||||
// BitcoinSig1Bytes are the raw bytes of the first bitcoin signature
|
|
||||||
// encoded in DER format.
|
|
||||||
BitcoinSig1Bytes []byte
|
|
||||||
|
|
||||||
// bitcoinSig2 is a cached instance of the second bitcoin signature.
|
|
||||||
bitcoinSig2 *ecdsa.Signature
|
|
||||||
|
|
||||||
// BitcoinSig2Bytes are the raw bytes of the second bitcoin signature
|
|
||||||
// encoded in DER format.
|
|
||||||
BitcoinSig2Bytes []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node1Sig is the signature using the identity key of the node that is first
|
|
||||||
// in a lexicographical ordering of the serialized public keys of the two nodes
|
|
||||||
// that created the channel.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (c *ChannelAuthProof) Node1Sig() (*ecdsa.Signature, error) {
|
|
||||||
if c.nodeSig1 != nil {
|
|
||||||
return c.nodeSig1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := ecdsa.ParseSignature(c.NodeSig1Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.nodeSig1 = sig
|
|
||||||
|
|
||||||
return sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Node2Sig is the signature using the identity key of the node that is second
|
|
||||||
// in a lexicographical ordering of the serialized public keys of the two nodes
|
|
||||||
// that created the channel.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (c *ChannelAuthProof) Node2Sig() (*ecdsa.Signature, error) {
|
|
||||||
if c.nodeSig2 != nil {
|
|
||||||
return c.nodeSig2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := ecdsa.ParseSignature(c.NodeSig2Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.nodeSig2 = sig
|
|
||||||
|
|
||||||
return sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitcoinSig1 is the signature using the public key of the first node that was
|
|
||||||
// used in the channel's multi-sig output.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (c *ChannelAuthProof) BitcoinSig1() (*ecdsa.Signature, error) {
|
|
||||||
if c.bitcoinSig1 != nil {
|
|
||||||
return c.bitcoinSig1, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := ecdsa.ParseSignature(c.BitcoinSig1Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.bitcoinSig1 = sig
|
|
||||||
|
|
||||||
return sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BitcoinSig2 is the signature using the public key of the second node that
|
|
||||||
// was used in the channel's multi-sig output.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (c *ChannelAuthProof) BitcoinSig2() (*ecdsa.Signature, error) {
|
|
||||||
if c.bitcoinSig2 != nil {
|
|
||||||
return c.bitcoinSig2, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := ecdsa.ParseSignature(c.BitcoinSig2Bytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.bitcoinSig2 = sig
|
|
||||||
|
|
||||||
return sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsEmpty check is the authentication proof is empty Proof is empty if at
|
|
||||||
// least one of the signatures are equal to nil.
|
|
||||||
func (c *ChannelAuthProof) IsEmpty() bool {
|
|
||||||
return len(c.NodeSig1Bytes) == 0 ||
|
|
||||||
len(c.NodeSig2Bytes) == 0 ||
|
|
||||||
len(c.BitcoinSig1Bytes) == 0 ||
|
|
||||||
len(c.BitcoinSig2Bytes) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// ChannelEdgePolicy represents a *directed* edge within the channel graph. For
|
|
||||||
// each channel in the database, there are two distinct edges: one for each
|
|
||||||
// possible direction of travel along the channel. The edges themselves hold
|
|
||||||
// information concerning fees, and minimum time-lock information which is
|
|
||||||
// utilized during path finding.
|
|
||||||
type ChannelEdgePolicy struct {
|
|
||||||
// SigBytes is the raw bytes of the signature of the channel edge
|
|
||||||
// policy. We'll only parse these if the caller needs to access the
|
|
||||||
// signature for validation purposes. Do not set SigBytes directly, but
|
|
||||||
// use SetSigBytes instead to make sure that the cache is invalidated.
|
|
||||||
SigBytes []byte
|
|
||||||
|
|
||||||
// sig is a cached fully parsed signature.
|
|
||||||
sig *ecdsa.Signature
|
|
||||||
|
|
||||||
// ChannelID is the unique channel ID for the channel. The first 3
|
|
||||||
// bytes are the block height, the next 3 the index within the block,
|
|
||||||
// and the last 2 bytes are the output index for the channel.
|
|
||||||
ChannelID uint64
|
|
||||||
|
|
||||||
// LastUpdate is the last time an authenticated edge for this channel
|
|
||||||
// was received.
|
|
||||||
LastUpdate time.Time
|
|
||||||
|
|
||||||
// MessageFlags is a bitfield which indicates the presence of optional
|
|
||||||
// fields (like max_htlc) in the policy.
|
|
||||||
MessageFlags lnwire.ChanUpdateMsgFlags
|
|
||||||
|
|
||||||
// ChannelFlags is a bitfield which signals the capabilities of the
|
|
||||||
// channel as well as the directed edge this update applies to.
|
|
||||||
ChannelFlags lnwire.ChanUpdateChanFlags
|
|
||||||
|
|
||||||
// TimeLockDelta is the number of blocks this node will subtract from
|
|
||||||
// the expiry of an incoming HTLC. This value expresses the time buffer
|
|
||||||
// the node would like to HTLC exchanges.
|
|
||||||
TimeLockDelta uint16
|
|
||||||
|
|
||||||
// MinHTLC is the smallest value HTLC this node will forward, expressed
|
|
||||||
// in millisatoshi.
|
|
||||||
MinHTLC lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// MaxHTLC is the largest value HTLC this node will forward, expressed
|
|
||||||
// in millisatoshi.
|
|
||||||
MaxHTLC lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
|
|
||||||
// ANY HTLC, expressed in mSAT's.
|
|
||||||
FeeBaseMSat lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// FeeProportionalMillionths is the rate that the node will charge for
|
|
||||||
// HTLCs for each millionth of a satoshi forwarded.
|
|
||||||
FeeProportionalMillionths lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// ToNode is the public key of the node that this directed edge leads
|
|
||||||
// to. Using this pub key, the channel graph can further be traversed.
|
|
||||||
ToNode [33]byte
|
|
||||||
|
|
||||||
// ExtraOpaqueData is the set of data that was appended to this
|
|
||||||
// message, some of which we may not actually know how to iterate or
|
|
||||||
// parse. By holding onto this data, we ensure that we're able to
|
|
||||||
// properly validate the set of signatures that cover these new fields,
|
|
||||||
// and ensure we're able to make upgrades to the network in a forwards
|
|
||||||
// compatible manner.
|
|
||||||
ExtraOpaqueData []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
// Signature is a channel announcement signature, which is needed for proper
|
|
||||||
// edge policy announcement.
|
|
||||||
//
|
|
||||||
// NOTE: By having this method to access an attribute, we ensure we only need
|
|
||||||
// to fully deserialize the signature if absolutely necessary.
|
|
||||||
func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error) {
|
|
||||||
if c.sig != nil {
|
|
||||||
return c.sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := ecdsa.ParseSignature(c.SigBytes)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
c.sig = sig
|
|
||||||
|
|
||||||
return sig, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetSigBytes updates the signature and invalidates the cached parsed
|
|
||||||
// signature.
|
|
||||||
func (c *ChannelEdgePolicy) SetSigBytes(sig []byte) {
|
|
||||||
c.SigBytes = sig
|
|
||||||
c.sig = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsDisabled determines whether the edge has the disabled bit set.
|
|
||||||
func (c *ChannelEdgePolicy) IsDisabled() bool {
|
|
||||||
return c.ChannelFlags.IsDisabled()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
|
|
||||||
// the passed active payment channel. This value is currently computed as
|
|
||||||
// specified in BOLT07, but will likely change in the near future.
|
|
||||||
func (c *ChannelEdgePolicy) ComputeFee(
|
|
||||||
amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|
||||||
|
|
||||||
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
|
||||||
}
|
|
||||||
|
|
||||||
// divideCeil divides dividend by factor and rounds the result up.
|
|
||||||
func divideCeil(dividend, factor lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|
||||||
return (dividend + factor - 1) / factor
|
|
||||||
}
|
|
||||||
|
|
||||||
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
|
|
||||||
// amount.
|
|
||||||
func (c *ChannelEdgePolicy) ComputeFeeFromIncoming(
|
|
||||||
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|
||||||
|
|
||||||
return incomingAmt - divideCeil(
|
|
||||||
feeRateParts*(incomingAmt-c.FeeBaseMSat),
|
|
||||||
feeRateParts+c.FeeProportionalMillionths,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// FetchChannelEdgesByOutpoint attempts to lookup the two directed edges for
|
// FetchChannelEdgesByOutpoint attempts to lookup the two directed edges for
|
||||||
// the channel identified by the funding outpoint. If the channel can't be
|
// the channel identified by the funding outpoint. If the channel can't be
|
||||||
// found, then ErrEdgeNotFound is returned. A struct which houses the general
|
// found, then ErrEdgeNotFound is returned. A struct which houses the general
|
||||||
// information for the channel itself is returned as well as two structs that
|
// information for the channel itself is returned as well as two structs that
|
||||||
// contain the routing policies for the channel in either direction.
|
// contain the routing policies for the channel in either direction.
|
||||||
func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint,
|
func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint,
|
||||||
) (*ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy, error) {
|
) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
edgeInfo *ChannelEdgeInfo
|
edgeInfo *models.ChannelEdgeInfo
|
||||||
policy1 *ChannelEdgePolicy
|
policy1 *models.ChannelEdgePolicy
|
||||||
policy2 *ChannelEdgePolicy
|
policy2 *models.ChannelEdgePolicy
|
||||||
)
|
)
|
||||||
|
|
||||||
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
err := kvdb.View(c.db, func(tx kvdb.RTx) error {
|
||||||
@ -3632,12 +3202,12 @@ func (c *ChannelGraph) FetchChannelEdgesByOutpoint(op *wire.OutPoint,
|
|||||||
// within the database. In this case, the ChannelEdgePolicy's will be nil, and
|
// within the database. In this case, the ChannelEdgePolicy's will be nil, and
|
||||||
// the ChannelEdgeInfo will only include the public keys of each node.
|
// the ChannelEdgeInfo will only include the public keys of each node.
|
||||||
func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64,
|
func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64,
|
||||||
) (*ChannelEdgeInfo, *ChannelEdgePolicy, *ChannelEdgePolicy, error) {
|
) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
edgeInfo *ChannelEdgeInfo
|
edgeInfo *models.ChannelEdgeInfo
|
||||||
policy1 *ChannelEdgePolicy
|
policy1 *models.ChannelEdgePolicy
|
||||||
policy2 *ChannelEdgePolicy
|
policy2 *models.ChannelEdgePolicy
|
||||||
channelID [8]byte
|
channelID [8]byte
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -3688,7 +3258,7 @@ func (c *ChannelGraph) FetchChannelEdgesByID(chanID uint64,
|
|||||||
// populate the edge info with the public keys of each
|
// populate the edge info with the public keys of each
|
||||||
// party as this is the only information we have about
|
// party as this is the only information we have about
|
||||||
// it and return an error signaling so.
|
// it and return an error signaling so.
|
||||||
edgeInfo = &ChannelEdgeInfo{
|
edgeInfo = &models.ChannelEdgeInfo{
|
||||||
NodeKey1Bytes: pubKey1,
|
NodeKey1Bytes: pubKey1,
|
||||||
NodeKey2Bytes: pubKey2,
|
NodeKey2Bytes: pubKey2,
|
||||||
}
|
}
|
||||||
@ -4334,7 +3904,7 @@ func deserializeLightningNode(r io.Reader) (LightningNode, error) {
|
|||||||
return node, nil
|
return node, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func putChanEdgeInfo(edgeIndex kvdb.RwBucket, edgeInfo *ChannelEdgeInfo, chanID [8]byte) error {
|
func putChanEdgeInfo(edgeIndex kvdb.RwBucket, edgeInfo *models.ChannelEdgeInfo, chanID [8]byte) error {
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
|
|
||||||
if _, err := b.Write(edgeInfo.NodeKey1Bytes[:]); err != nil {
|
if _, err := b.Write(edgeInfo.NodeKey1Bytes[:]); err != nil {
|
||||||
@ -4401,58 +3971,58 @@ func putChanEdgeInfo(edgeIndex kvdb.RwBucket, edgeInfo *ChannelEdgeInfo, chanID
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchChanEdgeInfo(edgeIndex kvdb.RBucket,
|
func fetchChanEdgeInfo(edgeIndex kvdb.RBucket,
|
||||||
chanID []byte) (ChannelEdgeInfo, error) {
|
chanID []byte) (models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
edgeInfoBytes := edgeIndex.Get(chanID)
|
edgeInfoBytes := edgeIndex.Get(chanID)
|
||||||
if edgeInfoBytes == nil {
|
if edgeInfoBytes == nil {
|
||||||
return ChannelEdgeInfo{}, ErrEdgeNotFound
|
return models.ChannelEdgeInfo{}, ErrEdgeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
edgeInfoReader := bytes.NewReader(edgeInfoBytes)
|
||||||
return deserializeChanEdgeInfo(edgeInfoReader)
|
return deserializeChanEdgeInfo(edgeInfoReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
|
func deserializeChanEdgeInfo(r io.Reader) (models.ChannelEdgeInfo, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
edgeInfo ChannelEdgeInfo
|
edgeInfo models.ChannelEdgeInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
if _, err := io.ReadFull(r, edgeInfo.NodeKey1Bytes[:]); err != nil {
|
if _, err := io.ReadFull(r, edgeInfo.NodeKey1Bytes[:]); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(r, edgeInfo.NodeKey2Bytes[:]); err != nil {
|
if _, err := io.ReadFull(r, edgeInfo.NodeKey2Bytes[:]); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(r, edgeInfo.BitcoinKey1Bytes[:]); err != nil {
|
if _, err := io.ReadFull(r, edgeInfo.BitcoinKey1Bytes[:]); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(r, edgeInfo.BitcoinKey2Bytes[:]); err != nil {
|
if _, err := io.ReadFull(r, edgeInfo.BitcoinKey2Bytes[:]); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeInfo.Features, err = wire.ReadVarBytes(r, 0, 900, "features")
|
edgeInfo.Features, err = wire.ReadVarBytes(r, 0, 900, "features")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
proof := &ChannelAuthProof{}
|
proof := &models.ChannelAuthProof{}
|
||||||
|
|
||||||
proof.NodeSig1Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
proof.NodeSig1Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
proof.NodeSig2Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
proof.NodeSig2Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
proof.BitcoinSig1Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
proof.BitcoinSig1Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
proof.BitcoinSig2Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
proof.BitcoinSig2Bytes, err = wire.ReadVarBytes(r, 0, 80, "sigs")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if !proof.IsEmpty() {
|
if !proof.IsEmpty() {
|
||||||
@ -4461,17 +4031,17 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
|
|||||||
|
|
||||||
edgeInfo.ChannelPoint = wire.OutPoint{}
|
edgeInfo.ChannelPoint = wire.OutPoint{}
|
||||||
if err := readOutpoint(r, &edgeInfo.ChannelPoint); err != nil {
|
if err := readOutpoint(r, &edgeInfo.ChannelPoint); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
if err := binary.Read(r, byteOrder, &edgeInfo.Capacity); err != nil {
|
if err := binary.Read(r, byteOrder, &edgeInfo.Capacity); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
if err := binary.Read(r, byteOrder, &edgeInfo.ChannelID); err != nil {
|
if err := binary.Read(r, byteOrder, &edgeInfo.ChannelID); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := io.ReadFull(r, edgeInfo.ChainHash[:]); err != nil {
|
if _, err := io.ReadFull(r, edgeInfo.ChainHash[:]); err != nil {
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll try and see if there are any opaque bytes left, if not, then
|
// We'll try and see if there are any opaque bytes left, if not, then
|
||||||
@ -4483,13 +4053,13 @@ func deserializeChanEdgeInfo(r io.Reader) (ChannelEdgeInfo, error) {
|
|||||||
case err == io.ErrUnexpectedEOF:
|
case err == io.ErrUnexpectedEOF:
|
||||||
case err == io.EOF:
|
case err == io.EOF:
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return ChannelEdgeInfo{}, err
|
return models.ChannelEdgeInfo{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return edgeInfo, nil
|
return edgeInfo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func putChanEdgePolicy(edges kvdb.RwBucket, edge *ChannelEdgePolicy, from,
|
func putChanEdgePolicy(edges kvdb.RwBucket, edge *models.ChannelEdgePolicy, from,
|
||||||
to []byte) error {
|
to []byte) error {
|
||||||
|
|
||||||
var edgeKey [33 + 8]byte
|
var edgeKey [33 + 8]byte
|
||||||
@ -4610,7 +4180,7 @@ func putChanEdgePolicyUnknown(edges kvdb.RwBucket, channelID uint64,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
||||||
nodePub []byte) (*ChannelEdgePolicy, error) {
|
nodePub []byte) (*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
var edgeKey [33 + 8]byte
|
var edgeKey [33 + 8]byte
|
||||||
copy(edgeKey[:], nodePub)
|
copy(edgeKey[:], nodePub)
|
||||||
@ -4643,7 +4213,7 @@ func fetchChanEdgePolicy(edges kvdb.RBucket, chanID []byte,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
|
func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
|
||||||
chanID []byte) (*ChannelEdgePolicy, *ChannelEdgePolicy, error) {
|
chanID []byte) (*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
edgeInfo := edgeIndex.Get(chanID)
|
edgeInfo := edgeIndex.Get(chanID)
|
||||||
if edgeInfo == nil {
|
if edgeInfo == nil {
|
||||||
@ -4670,7 +4240,7 @@ func fetchChanEdgePolicies(edgeIndex kvdb.RBucket, edges kvdb.RBucket,
|
|||||||
return edge1, edge2, nil
|
return edge1, edge2, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
|
func serializeChanEdgePolicy(w io.Writer, edge *models.ChannelEdgePolicy,
|
||||||
to []byte) error {
|
to []byte) error {
|
||||||
|
|
||||||
err := wire.WriteVarBytes(w, 0, edge.SigBytes)
|
err := wire.WriteVarBytes(w, 0, edge.SigBytes)
|
||||||
@ -4737,7 +4307,7 @@ func serializeChanEdgePolicy(w io.Writer, edge *ChannelEdgePolicy,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializeChanEdgePolicy(r io.Reader) (*ChannelEdgePolicy, error) {
|
func deserializeChanEdgePolicy(r io.Reader) (*models.ChannelEdgePolicy, error) {
|
||||||
// Deserialize the policy. Note that in case an optional field is not
|
// Deserialize the policy. Note that in case an optional field is not
|
||||||
// found, both an error and a populated policy object are returned.
|
// found, both an error and a populated policy object are returned.
|
||||||
edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
|
edge, deserializeErr := deserializeChanEdgePolicyRaw(r)
|
||||||
@ -4750,8 +4320,8 @@ func deserializeChanEdgePolicy(r io.Reader) (*ChannelEdgePolicy, error) {
|
|||||||
return edge, deserializeErr
|
return edge, deserializeErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func deserializeChanEdgePolicyRaw(r io.Reader) (*ChannelEdgePolicy, error) {
|
func deserializeChanEdgePolicyRaw(r io.Reader) (*models.ChannelEdgePolicy, error) {
|
||||||
edge := &ChannelEdgePolicy{}
|
edge := &models.ChannelEdgePolicy{}
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
edge.SigBytes, err = wire.ReadVarBytes(r, 0, 80, "sig")
|
edge.SigBytes, err = wire.ReadVarBytes(r, 0, 80, "sig")
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -27,94 +28,8 @@ type GraphCacheNode interface {
|
|||||||
// error, then the iteration is halted with the error propagated back up
|
// error, then the iteration is halted with the error propagated back up
|
||||||
// to the caller.
|
// to the caller.
|
||||||
ForEachChannel(kvdb.RTx,
|
ForEachChannel(kvdb.RTx,
|
||||||
func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy,
|
func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
}
|
|
||||||
|
|
||||||
// CachedEdgePolicy is a struct that only caches the information of a
|
|
||||||
// ChannelEdgePolicy that we actually use for pathfinding and therefore need to
|
|
||||||
// store in the cache.
|
|
||||||
type CachedEdgePolicy struct {
|
|
||||||
// ChannelID is the unique channel ID for the channel. The first 3
|
|
||||||
// bytes are the block height, the next 3 the index within the block,
|
|
||||||
// and the last 2 bytes are the output index for the channel.
|
|
||||||
ChannelID uint64
|
|
||||||
|
|
||||||
// MessageFlags is a bitfield which indicates the presence of optional
|
|
||||||
// fields (like max_htlc) in the policy.
|
|
||||||
MessageFlags lnwire.ChanUpdateMsgFlags
|
|
||||||
|
|
||||||
// ChannelFlags is a bitfield which signals the capabilities of the
|
|
||||||
// channel as well as the directed edge this update applies to.
|
|
||||||
ChannelFlags lnwire.ChanUpdateChanFlags
|
|
||||||
|
|
||||||
// TimeLockDelta is the number of blocks this node will subtract from
|
|
||||||
// the expiry of an incoming HTLC. This value expresses the time buffer
|
|
||||||
// the node would like to HTLC exchanges.
|
|
||||||
TimeLockDelta uint16
|
|
||||||
|
|
||||||
// MinHTLC is the smallest value HTLC this node will forward, expressed
|
|
||||||
// in millisatoshi.
|
|
||||||
MinHTLC lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// MaxHTLC is the largest value HTLC this node will forward, expressed
|
|
||||||
// in millisatoshi.
|
|
||||||
MaxHTLC lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
|
|
||||||
// ANY HTLC, expressed in mSAT's.
|
|
||||||
FeeBaseMSat lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// FeeProportionalMillionths is the rate that the node will charge for
|
|
||||||
// HTLCs for each millionth of a satoshi forwarded.
|
|
||||||
FeeProportionalMillionths lnwire.MilliSatoshi
|
|
||||||
|
|
||||||
// ToNodePubKey is a function that returns the to node of a policy.
|
|
||||||
// Since we only ever store the inbound policy, this is always the node
|
|
||||||
// that we query the channels for in ForEachChannel(). Therefore, we can
|
|
||||||
// save a lot of space by not storing this information in the memory and
|
|
||||||
// instead just set this function when we copy the policy from cache in
|
|
||||||
// ForEachChannel().
|
|
||||||
ToNodePubKey func() route.Vertex
|
|
||||||
|
|
||||||
// ToNodeFeatures are the to node's features. They are never set while
|
|
||||||
// the edge is in the cache, only on the copy that is returned in
|
|
||||||
// ForEachChannel().
|
|
||||||
ToNodeFeatures *lnwire.FeatureVector
|
|
||||||
}
|
|
||||||
|
|
||||||
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
|
|
||||||
// the passed active payment channel. This value is currently computed as
|
|
||||||
// specified in BOLT07, but will likely change in the near future.
|
|
||||||
func (c *CachedEdgePolicy) ComputeFee(
|
|
||||||
amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|
||||||
|
|
||||||
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
|
||||||
}
|
|
||||||
|
|
||||||
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
|
|
||||||
// amount.
|
|
||||||
func (c *CachedEdgePolicy) ComputeFeeFromIncoming(
|
|
||||||
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
|
||||||
|
|
||||||
return incomingAmt - divideCeil(
|
|
||||||
feeRateParts*(incomingAmt-c.FeeBaseMSat),
|
|
||||||
feeRateParts+c.FeeProportionalMillionths,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
|
|
||||||
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
|
|
||||||
return &CachedEdgePolicy{
|
|
||||||
ChannelID: policy.ChannelID,
|
|
||||||
MessageFlags: policy.MessageFlags,
|
|
||||||
ChannelFlags: policy.ChannelFlags,
|
|
||||||
TimeLockDelta: policy.TimeLockDelta,
|
|
||||||
MinHTLC: policy.MinHTLC,
|
|
||||||
MaxHTLC: policy.MaxHTLC,
|
|
||||||
FeeBaseMSat: policy.FeeBaseMSat,
|
|
||||||
FeeProportionalMillionths: policy.FeeProportionalMillionths,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// DirectedChannel is a type that stores the channel information as seen from
|
// DirectedChannel is a type that stores the channel information as seen from
|
||||||
@ -142,7 +57,7 @@ type DirectedChannel struct {
|
|||||||
// In path finding, we're walking backward from the destination to the
|
// In path finding, we're walking backward from the destination to the
|
||||||
// source, so we're always interested in the edge that arrives to us
|
// source, so we're always interested in the edge that arrives to us
|
||||||
// from the other node.
|
// from the other node.
|
||||||
InPolicy *CachedEdgePolicy
|
InPolicy *models.CachedEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeepCopy creates a deep copy of the channel, including the incoming policy.
|
// DeepCopy creates a deep copy of the channel, including the incoming policy.
|
||||||
@ -223,9 +138,9 @@ func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
|
|||||||
c.AddNodeFeatures(node)
|
c.AddNodeFeatures(node)
|
||||||
|
|
||||||
return node.ForEachChannel(
|
return node.ForEachChannel(
|
||||||
tx, func(tx kvdb.RTx, info *ChannelEdgeInfo,
|
tx, func(tx kvdb.RTx, info *models.ChannelEdgeInfo,
|
||||||
outPolicy *ChannelEdgePolicy,
|
outPolicy *models.ChannelEdgePolicy,
|
||||||
inPolicy *ChannelEdgePolicy) error {
|
inPolicy *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
c.AddChannel(info, outPolicy, inPolicy)
|
c.AddChannel(info, outPolicy, inPolicy)
|
||||||
|
|
||||||
@ -238,8 +153,8 @@ func (c *GraphCache) AddNode(tx kvdb.RTx, node GraphCacheNode) error {
|
|||||||
// and policy 2 does not matter, the directionality is extracted from the info
|
// and policy 2 does not matter, the directionality is extracted from the info
|
||||||
// and policy flags automatically. The policy will be set as the outgoing policy
|
// and policy flags automatically. The policy will be set as the outgoing policy
|
||||||
// on one node and the incoming policy on the peer's side.
|
// on one node and the incoming policy on the peer's side.
|
||||||
func (c *GraphCache) AddChannel(info *ChannelEdgeInfo,
|
func (c *GraphCache) AddChannel(info *models.ChannelEdgeInfo,
|
||||||
policy1 *ChannelEdgePolicy, policy2 *ChannelEdgePolicy) {
|
policy1 *models.ChannelEdgePolicy, policy2 *models.ChannelEdgePolicy) {
|
||||||
|
|
||||||
if info == nil {
|
if info == nil {
|
||||||
return
|
return
|
||||||
@ -301,7 +216,7 @@ func (c *GraphCache) updateOrAddEdge(node route.Vertex, edge *DirectedChannel) {
|
|||||||
// of the from and to node is not strictly important. But we assume that a
|
// of the from and to node is not strictly important. But we assume that a
|
||||||
// channel edge was added beforehand so that the directed channel struct already
|
// channel edge was added beforehand so that the directed channel struct already
|
||||||
// exists in the cache.
|
// exists in the cache.
|
||||||
func (c *GraphCache) UpdatePolicy(policy *ChannelEdgePolicy, fromNode,
|
func (c *GraphCache) UpdatePolicy(policy *models.ChannelEdgePolicy, fromNode,
|
||||||
toNode route.Vertex, edge1 bool) {
|
toNode route.Vertex, edge1 bool) {
|
||||||
|
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
@ -333,7 +248,7 @@ func (c *GraphCache) UpdatePolicy(policy *ChannelEdgePolicy, fromNode,
|
|||||||
// The other two cases left mean it's the inbound policy for the
|
// The other two cases left mean it's the inbound policy for the
|
||||||
// node.
|
// node.
|
||||||
default:
|
default:
|
||||||
channel.InPolicy = NewCachedPolicy(policy)
|
channel.InPolicy = models.NewCachedPolicy(policy)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +295,7 @@ func (c *GraphCache) removeChannelIfFound(node route.Vertex, chanID uint64) {
|
|||||||
// UpdateChannel updates the channel edge information for a specific edge. We
|
// UpdateChannel updates the channel edge information for a specific edge. We
|
||||||
// expect the edge to already exist and be known. If it does not yet exist, this
|
// expect the edge to already exist and be known. If it does not yet exist, this
|
||||||
// call is a no-op.
|
// call is a no-op.
|
||||||
func (c *GraphCache) UpdateChannel(info *ChannelEdgeInfo) {
|
func (c *GraphCache) UpdateChannel(info *models.ChannelEdgeInfo) {
|
||||||
c.mtx.Lock()
|
c.mtx.Lock()
|
||||||
defer c.mtx.Unlock()
|
defer c.mtx.Unlock()
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -28,9 +29,9 @@ type node struct {
|
|||||||
pubKey route.Vertex
|
pubKey route.Vertex
|
||||||
features *lnwire.FeatureVector
|
features *lnwire.FeatureVector
|
||||||
|
|
||||||
edgeInfos []*ChannelEdgeInfo
|
edgeInfos []*models.ChannelEdgeInfo
|
||||||
outPolicies []*ChannelEdgePolicy
|
outPolicies []*models.ChannelEdgePolicy
|
||||||
inPolicies []*ChannelEdgePolicy
|
inPolicies []*models.ChannelEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) PubKey() route.Vertex {
|
func (n *node) PubKey() route.Vertex {
|
||||||
@ -41,8 +42,8 @@ func (n *node) Features() *lnwire.FeatureVector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *node) ForEachChannel(tx kvdb.RTx,
|
func (n *node) ForEachChannel(tx kvdb.RTx,
|
||||||
cb func(kvdb.RTx, *ChannelEdgeInfo, *ChannelEdgePolicy,
|
cb func(kvdb.RTx, *models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
for idx := range n.edgeInfos {
|
for idx := range n.edgeInfos {
|
||||||
err := cb(
|
err := cb(
|
||||||
@ -70,12 +71,12 @@ func TestGraphCacheAddNode(t *testing.T) {
|
|||||||
channelFlagA, channelFlagB = 1, 0
|
channelFlagA, channelFlagB = 1, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
outPolicy1 := &ChannelEdgePolicy{
|
outPolicy1 := &models.ChannelEdgePolicy{
|
||||||
ChannelID: 1000,
|
ChannelID: 1000,
|
||||||
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
|
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagA),
|
||||||
ToNode: nodeB,
|
ToNode: nodeB,
|
||||||
}
|
}
|
||||||
inPolicy1 := &ChannelEdgePolicy{
|
inPolicy1 := &models.ChannelEdgePolicy{
|
||||||
ChannelID: 1000,
|
ChannelID: 1000,
|
||||||
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagB),
|
ChannelFlags: lnwire.ChanUpdateChanFlags(channelFlagB),
|
||||||
ToNode: nodeA,
|
ToNode: nodeA,
|
||||||
@ -83,15 +84,15 @@ func TestGraphCacheAddNode(t *testing.T) {
|
|||||||
node := &node{
|
node := &node{
|
||||||
pubKey: nodeA,
|
pubKey: nodeA,
|
||||||
features: lnwire.EmptyFeatureVector(),
|
features: lnwire.EmptyFeatureVector(),
|
||||||
edgeInfos: []*ChannelEdgeInfo{{
|
edgeInfos: []*models.ChannelEdgeInfo{{
|
||||||
ChannelID: 1000,
|
ChannelID: 1000,
|
||||||
// Those are direction independent!
|
// Those are direction independent!
|
||||||
NodeKey1Bytes: pubKey1,
|
NodeKey1Bytes: pubKey1,
|
||||||
NodeKey2Bytes: pubKey2,
|
NodeKey2Bytes: pubKey2,
|
||||||
Capacity: 500,
|
Capacity: 500,
|
||||||
}},
|
}},
|
||||||
outPolicies: []*ChannelEdgePolicy{outPolicy1},
|
outPolicies: []*models.ChannelEdgePolicy{outPolicy1},
|
||||||
inPolicies: []*ChannelEdgePolicy{inPolicy1},
|
inPolicies: []*models.ChannelEdgePolicy{inPolicy1},
|
||||||
}
|
}
|
||||||
cache := NewGraphCache(10)
|
cache := NewGraphCache(10)
|
||||||
require.NoError(t, cache.AddNode(nil, node))
|
require.NoError(t, cache.AddNode(nil, node))
|
||||||
@ -138,8 +139,8 @@ func TestGraphCacheAddNode(t *testing.T) {
|
|||||||
runTest(pubKey2, pubKey1)
|
runTest(pubKey2, pubKey1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertCachedPolicyEqual(t *testing.T, original *ChannelEdgePolicy,
|
func assertCachedPolicyEqual(t *testing.T, original *models.ChannelEdgePolicy,
|
||||||
cached *CachedEdgePolicy) {
|
cached *models.CachedEdgePolicy) {
|
||||||
|
|
||||||
require.Equal(t, original.ChannelID, cached.ChannelID)
|
require.Equal(t, original.ChannelID, cached.ChannelID)
|
||||||
require.Equal(t, original.MessageFlags, cached.MessageFlags)
|
require.Equal(t, original.MessageFlags, cached.MessageFlags)
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -324,10 +325,10 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
|||||||
require.NoError(t, err, "unable to generate node key")
|
require.NoError(t, err, "unable to generate node key")
|
||||||
node2Pub, err := node2.PubKey()
|
node2Pub, err := node2.PubKey()
|
||||||
require.NoError(t, err, "unable to generate node key")
|
require.NoError(t, err, "unable to generate node key")
|
||||||
edgeInfo := ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
AuthProof: &ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -384,7 +385,7 @@ func TestEdgeInsertionDeletion(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
|
func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
|
||||||
node1, node2 *LightningNode) (ChannelEdgeInfo, lnwire.ShortChannelID) {
|
node1, node2 *LightningNode) (models.ChannelEdgeInfo, lnwire.ShortChannelID) {
|
||||||
|
|
||||||
shortChanID := lnwire.ShortChannelID{
|
shortChanID := lnwire.ShortChannelID{
|
||||||
BlockHeight: height,
|
BlockHeight: height,
|
||||||
@ -398,10 +399,10 @@ func createEdge(height, txIndex uint32, txPosition uint16, outPointIndex uint32,
|
|||||||
|
|
||||||
node1Pub, _ := node1.PubKey()
|
node1Pub, _ := node1.PubKey()
|
||||||
node2Pub, _ := node2.PubKey()
|
node2Pub, _ := node2.PubKey()
|
||||||
edgeInfo := ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: shortChanID.ToUint64(),
|
ChannelID: shortChanID.ToUint64(),
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
AuthProof: &ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -553,8 +554,8 @@ func TestDisconnectBlockAtHeight(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func assertEdgeInfoEqual(t *testing.T, e1 *ChannelEdgeInfo,
|
func assertEdgeInfoEqual(t *testing.T, e1 *models.ChannelEdgeInfo,
|
||||||
e2 *ChannelEdgeInfo) {
|
e2 *models.ChannelEdgeInfo) {
|
||||||
|
|
||||||
if e1.ChannelID != e2.ChannelID {
|
if e1.ChannelID != e2.ChannelID {
|
||||||
t.Fatalf("chan id's don't match: %v vs %v", e1.ChannelID,
|
t.Fatalf("chan id's don't match: %v vs %v", e1.ChannelID,
|
||||||
@ -615,8 +616,8 @@ func assertEdgeInfoEqual(t *testing.T, e1 *ChannelEdgeInfo,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEdgeInfo,
|
func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*models.ChannelEdgeInfo,
|
||||||
*ChannelEdgePolicy, *ChannelEdgePolicy) {
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
firstNode [33]byte
|
firstNode [33]byte
|
||||||
@ -640,10 +641,10 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
|
|||||||
|
|
||||||
// Add the new edge to the database, this should proceed without any
|
// Add the new edge to the database, this should proceed without any
|
||||||
// errors.
|
// errors.
|
||||||
edgeInfo := &ChannelEdgeInfo{
|
edgeInfo := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
AuthProof: &ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -658,7 +659,7 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
|
|||||||
copy(edgeInfo.BitcoinKey1Bytes[:], firstNode[:])
|
copy(edgeInfo.BitcoinKey1Bytes[:], firstNode[:])
|
||||||
copy(edgeInfo.BitcoinKey2Bytes[:], secondNode[:])
|
copy(edgeInfo.BitcoinKey2Bytes[:], secondNode[:])
|
||||||
|
|
||||||
edge1 := &ChannelEdgePolicy{
|
edge1 := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
LastUpdate: time.Unix(433453, 0),
|
LastUpdate: time.Unix(433453, 0),
|
||||||
@ -672,7 +673,7 @@ func createChannelEdge(db kvdb.Backend, node1, node2 *LightningNode) (*ChannelEd
|
|||||||
ToNode: secondNode,
|
ToNode: secondNode,
|
||||||
ExtraOpaqueData: []byte("new unknown feature2"),
|
ExtraOpaqueData: []byte("new unknown feature2"),
|
||||||
}
|
}
|
||||||
edge2 := &ChannelEdgePolicy{
|
edge2 := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
LastUpdate: time.Unix(124234, 0),
|
LastUpdate: time.Unix(124234, 0),
|
||||||
@ -817,7 +818,7 @@ func assertNodeNotInCache(t *testing.T, g *ChannelGraph, n route.Vertex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertEdgeWithNoPoliciesInCache(t *testing.T, g *ChannelGraph,
|
func assertEdgeWithNoPoliciesInCache(t *testing.T, g *ChannelGraph,
|
||||||
e *ChannelEdgeInfo) {
|
e *models.ChannelEdgeInfo) {
|
||||||
|
|
||||||
// Let's check the internal view first.
|
// Let's check the internal view first.
|
||||||
require.NotEmpty(t, g.graphCache.nodeChannels[e.NodeKey1Bytes])
|
require.NotEmpty(t, g.graphCache.nodeChannels[e.NodeKey1Bytes])
|
||||||
@ -895,7 +896,7 @@ func assertNoEdge(t *testing.T, g *ChannelGraph, chanID uint64) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertEdgeWithPolicyInCache(t *testing.T, g *ChannelGraph,
|
func assertEdgeWithPolicyInCache(t *testing.T, g *ChannelGraph,
|
||||||
e *ChannelEdgeInfo, p *ChannelEdgePolicy, policy1 bool) {
|
e *models.ChannelEdgeInfo, p *models.ChannelEdgePolicy, policy1 bool) {
|
||||||
|
|
||||||
// Check the internal state first.
|
// Check the internal state first.
|
||||||
c1, ok := g.graphCache.nodeChannels[e.NodeKey1Bytes][e.ChannelID]
|
c1, ok := g.graphCache.nodeChannels[e.NodeKey1Bytes][e.ChannelID]
|
||||||
@ -971,16 +972,16 @@ func assertEdgeWithPolicyInCache(t *testing.T, g *ChannelGraph,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func randEdgePolicy(chanID uint64, db kvdb.Backend) *ChannelEdgePolicy {
|
func randEdgePolicy(chanID uint64, db kvdb.Backend) *models.ChannelEdgePolicy {
|
||||||
update := prand.Int63()
|
update := prand.Int63()
|
||||||
|
|
||||||
return newEdgePolicy(chanID, db, update)
|
return newEdgePolicy(chanID, db, update)
|
||||||
}
|
}
|
||||||
|
|
||||||
func newEdgePolicy(chanID uint64, db kvdb.Backend,
|
func newEdgePolicy(chanID uint64, db kvdb.Backend,
|
||||||
updateTime int64) *ChannelEdgePolicy {
|
updateTime int64) *models.ChannelEdgePolicy {
|
||||||
|
|
||||||
return &ChannelEdgePolicy{
|
return &models.ChannelEdgePolicy{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
LastUpdate: time.Unix(updateTime, 0),
|
LastUpdate: time.Unix(updateTime, 0),
|
||||||
MessageFlags: 1,
|
MessageFlags: 1,
|
||||||
@ -1037,8 +1038,8 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
// Iterate through all the known channels within the graph DB, once
|
// Iterate through all the known channels within the graph DB, once
|
||||||
// again if the map is empty that indicates that all edges have
|
// again if the map is empty that indicates that all edges have
|
||||||
// properly been reached.
|
// properly been reached.
|
||||||
err = graph.ForEachChannel(func(ei *ChannelEdgeInfo, _ *ChannelEdgePolicy,
|
err = graph.ForEachChannel(func(ei *models.ChannelEdgeInfo, _ *models.ChannelEdgePolicy,
|
||||||
_ *ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
delete(chanIndex, ei.ChannelID)
|
delete(chanIndex, ei.ChannelID)
|
||||||
return nil
|
return nil
|
||||||
@ -1051,8 +1052,8 @@ func TestGraphTraversal(t *testing.T) {
|
|||||||
numNodeChans := 0
|
numNodeChans := 0
|
||||||
firstNode, secondNode := nodeList[0], nodeList[1]
|
firstNode, secondNode := nodeList[0], nodeList[1]
|
||||||
err = graph.ForEachNodeChannel(nil, firstNode.PubKeyBytes,
|
err = graph.ForEachNodeChannel(nil, firstNode.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, _ *ChannelEdgeInfo, outEdge,
|
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// All channels between first and second node should
|
// All channels between first and second node should
|
||||||
// have fully (both sides) specified policies.
|
// have fully (both sides) specified policies.
|
||||||
@ -1131,9 +1132,9 @@ func TestGraphTraversalCacheable(t *testing.T) {
|
|||||||
err = graph.db.View(func(tx kvdb.RTx) error {
|
err = graph.db.View(func(tx kvdb.RTx) error {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
err := node.ForEachChannel(
|
err := node.ForEachChannel(
|
||||||
tx, func(tx kvdb.RTx, info *ChannelEdgeInfo,
|
tx, func(tx kvdb.RTx, info *models.ChannelEdgeInfo,
|
||||||
policy *ChannelEdgePolicy,
|
policy *models.ChannelEdgePolicy,
|
||||||
policy2 *ChannelEdgePolicy) error {
|
policy2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
delete(chanIndex, info.ChannelID)
|
delete(chanIndex, info.ChannelID)
|
||||||
return nil
|
return nil
|
||||||
@ -1251,10 +1252,10 @@ func fillTestGraph(t require.TestingT, graph *ChannelGraph, numNodes,
|
|||||||
Index: 0,
|
Index: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeInfo := ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
AuthProof: &ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -1315,8 +1316,8 @@ func assertPruneTip(t *testing.T, graph *ChannelGraph, blockHash *chainhash.Hash
|
|||||||
|
|
||||||
func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
|
func assertNumChans(t *testing.T, graph *ChannelGraph, n int) {
|
||||||
numChans := 0
|
numChans := 0
|
||||||
if err := graph.ForEachChannel(func(*ChannelEdgeInfo, *ChannelEdgePolicy,
|
if err := graph.ForEachChannel(func(*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*ChannelEdgePolicy) error {
|
*models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
numChans++
|
numChans++
|
||||||
return nil
|
return nil
|
||||||
@ -1432,10 +1433,10 @@ func TestGraphPruning(t *testing.T) {
|
|||||||
|
|
||||||
channelPoints = append(channelPoints, &op)
|
channelPoints = append(channelPoints, &op)
|
||||||
|
|
||||||
edgeInfo := ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID,
|
ChannelID: chanID,
|
||||||
ChainHash: key,
|
ChainHash: key,
|
||||||
AuthProof: &ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -2283,8 +2284,8 @@ func TestIncompleteChannelPolicies(t *testing.T) {
|
|||||||
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
checkPolicies := func(node *LightningNode, expectedIn, expectedOut bool) {
|
||||||
calls := 0
|
calls := 0
|
||||||
err := graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
err := graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, _ *ChannelEdgeInfo, outEdge,
|
func(_ kvdb.RTx, _ *models.ChannelEdgeInfo, outEdge,
|
||||||
inEdge *ChannelEdgePolicy) error {
|
inEdge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
if !expectedOut && outEdge != nil {
|
if !expectedOut && outEdge != nil {
|
||||||
t.Fatalf("Expected no outgoing policy")
|
t.Fatalf("Expected no outgoing policy")
|
||||||
@ -2701,7 +2702,7 @@ func TestNodeIsPublic(t *testing.T) {
|
|||||||
// After creating all of our nodes and edges, we'll add them to each
|
// After creating all of our nodes and edges, we'll add them to each
|
||||||
// participant's graph.
|
// participant's graph.
|
||||||
nodes := []*LightningNode{aliceNode, bobNode, carolNode}
|
nodes := []*LightningNode{aliceNode, bobNode, carolNode}
|
||||||
edges := []*ChannelEdgeInfo{&aliceBobEdge, &bobCarolEdge}
|
edges := []*models.ChannelEdgeInfo{&aliceBobEdge, &bobCarolEdge}
|
||||||
graphs := []*ChannelGraph{aliceGraph, bobGraph, carolGraph}
|
graphs := []*ChannelGraph{aliceGraph, bobGraph, carolGraph}
|
||||||
for _, graph := range graphs {
|
for _, graph := range graphs {
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
@ -3153,7 +3154,7 @@ func compareNodes(a, b *LightningNode) error {
|
|||||||
|
|
||||||
// compareEdgePolicies is used to compare two ChannelEdgePolices using
|
// compareEdgePolicies is used to compare two ChannelEdgePolices using
|
||||||
// compareNodes, so as to exclude comparisons of the Nodes' Features struct.
|
// compareNodes, so as to exclude comparisons of the Nodes' Features struct.
|
||||||
func compareEdgePolicies(a, b *ChannelEdgePolicy) error {
|
func compareEdgePolicies(a, b *models.ChannelEdgePolicy) error {
|
||||||
if a.ChannelID != b.ChannelID {
|
if a.ChannelID != b.ChannelID {
|
||||||
return fmt.Errorf("ChannelID doesn't match: expected %v, "+
|
return fmt.Errorf("ChannelID doesn't match: expected %v, "+
|
||||||
"got %v", a.ChannelID, b.ChannelID)
|
"got %v", a.ChannelID, b.ChannelID)
|
||||||
@ -3245,7 +3246,7 @@ func TestLightningNodeSigVerification(t *testing.T) {
|
|||||||
// TestComputeFee tests fee calculation based on both in- and outgoing amt.
|
// TestComputeFee tests fee calculation based on both in- and outgoing amt.
|
||||||
func TestComputeFee(t *testing.T) {
|
func TestComputeFee(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
policy = ChannelEdgePolicy{
|
policy = models.ChannelEdgePolicy{
|
||||||
FeeBaseMSat: 10000,
|
FeeBaseMSat: 10000,
|
||||||
FeeProportionalMillionths: 30000,
|
FeeProportionalMillionths: 30000,
|
||||||
}
|
}
|
||||||
@ -3319,7 +3320,7 @@ func TestBatchedAddChannelEdge(t *testing.T) {
|
|||||||
// Create a third edge, this with a block height of 155.
|
// Create a third edge, this with a block height of 155.
|
||||||
edgeInfo3, _ := createEdge(height-1, 0, 0, 2, node1, node2)
|
edgeInfo3, _ := createEdge(height-1, 0, 0, 2, node1, node2)
|
||||||
|
|
||||||
edges := []ChannelEdgeInfo{edgeInfo, edgeInfo2, edgeInfo3}
|
edges := []models.ChannelEdgeInfo{edgeInfo, edgeInfo2, edgeInfo3}
|
||||||
errChan := make(chan error, len(edges))
|
errChan := make(chan error, len(edges))
|
||||||
errTimeout := errors.New("timeout adding batched channel")
|
errTimeout := errors.New("timeout adding batched channel")
|
||||||
|
|
||||||
@ -3327,7 +3328,7 @@ func TestBatchedAddChannelEdge(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, edge := range edges {
|
for _, edge := range edges {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(edge ChannelEdgeInfo) {
|
go func(edge models.ChannelEdgeInfo) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -3378,7 +3379,7 @@ func TestBatchedUpdateEdgePolicy(t *testing.T) {
|
|||||||
|
|
||||||
errTimeout := errors.New("timeout adding batched channel")
|
errTimeout := errors.New("timeout adding batched channel")
|
||||||
|
|
||||||
updates := []*ChannelEdgePolicy{edge1, edge2}
|
updates := []*models.ChannelEdgePolicy{edge1, edge2}
|
||||||
|
|
||||||
errChan := make(chan error, len(updates))
|
errChan := make(chan error, len(updates))
|
||||||
|
|
||||||
@ -3386,7 +3387,7 @@ func TestBatchedUpdateEdgePolicy(t *testing.T) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for _, update := range updates {
|
for _, update := range updates {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(update *ChannelEdgePolicy) {
|
go func(update *models.ChannelEdgePolicy) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -3436,9 +3437,9 @@ func BenchmarkForEachChannel(b *testing.B) {
|
|||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
err := n.ForEachChannel(
|
err := n.ForEachChannel(
|
||||||
tx, func(tx kvdb.RTx,
|
tx, func(tx kvdb.RTx,
|
||||||
info *ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
policy *ChannelEdgePolicy,
|
policy *models.ChannelEdgePolicy,
|
||||||
policy2 *ChannelEdgePolicy) error {
|
policy2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// We need to do something with
|
// We need to do something with
|
||||||
// the data here, otherwise the
|
// the data here, otherwise the
|
||||||
|
97
channeldb/models/cached_edge_policy.go
Normal file
97
channeldb/models/cached_edge_policy.go
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// feeRateParts is the total number of parts used to express fee rates.
|
||||||
|
feeRateParts = 1e6
|
||||||
|
)
|
||||||
|
|
||||||
|
// CachedEdgePolicy is a struct that only caches the information of a
|
||||||
|
// ChannelEdgePolicy that we actually use for pathfinding and therefore need to
|
||||||
|
// store in the cache.
|
||||||
|
type CachedEdgePolicy struct {
|
||||||
|
// ChannelID is the unique channel ID for the channel. The first 3
|
||||||
|
// bytes are the block height, the next 3 the index within the block,
|
||||||
|
// and the last 2 bytes are the output index for the channel.
|
||||||
|
ChannelID uint64
|
||||||
|
|
||||||
|
// MessageFlags is a bitfield which indicates the presence of optional
|
||||||
|
// fields (like max_htlc) in the policy.
|
||||||
|
MessageFlags lnwire.ChanUpdateMsgFlags
|
||||||
|
|
||||||
|
// ChannelFlags is a bitfield which signals the capabilities of the
|
||||||
|
// channel as well as the directed edge this update applies to.
|
||||||
|
ChannelFlags lnwire.ChanUpdateChanFlags
|
||||||
|
|
||||||
|
// TimeLockDelta is the number of blocks this node will subtract from
|
||||||
|
// the expiry of an incoming HTLC. This value expresses the time buffer
|
||||||
|
// the node would like to HTLC exchanges.
|
||||||
|
TimeLockDelta uint16
|
||||||
|
|
||||||
|
// MinHTLC is the smallest value HTLC this node will forward, expressed
|
||||||
|
// in millisatoshi.
|
||||||
|
MinHTLC lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// MaxHTLC is the largest value HTLC this node will forward, expressed
|
||||||
|
// in millisatoshi.
|
||||||
|
MaxHTLC lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
|
||||||
|
// ANY HTLC, expressed in mSAT's.
|
||||||
|
FeeBaseMSat lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// FeeProportionalMillionths is the rate that the node will charge for
|
||||||
|
// HTLCs for each millionth of a satoshi forwarded.
|
||||||
|
FeeProportionalMillionths lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// ToNodePubKey is a function that returns the to node of a policy.
|
||||||
|
// Since we only ever store the inbound policy, this is always the node
|
||||||
|
// that we query the channels for in ForEachChannel(). Therefore, we can
|
||||||
|
// save a lot of space by not storing this information in the memory and
|
||||||
|
// instead just set this function when we copy the policy from cache in
|
||||||
|
// ForEachChannel().
|
||||||
|
ToNodePubKey func() route.Vertex
|
||||||
|
|
||||||
|
// ToNodeFeatures are the to node's features. They are never set while
|
||||||
|
// the edge is in the cache, only on the copy that is returned in
|
||||||
|
// ForEachChannel().
|
||||||
|
ToNodeFeatures *lnwire.FeatureVector
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
|
||||||
|
// the passed active payment channel. This value is currently computed as
|
||||||
|
// specified in BOLT07, but will likely change in the near future.
|
||||||
|
func (c *CachedEdgePolicy) ComputeFee(
|
||||||
|
amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
|
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
|
||||||
|
// amount.
|
||||||
|
func (c *CachedEdgePolicy) ComputeFeeFromIncoming(
|
||||||
|
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
|
return incomingAmt - divideCeil(
|
||||||
|
feeRateParts*(incomingAmt-c.FeeBaseMSat),
|
||||||
|
feeRateParts+c.FeeProportionalMillionths,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewCachedPolicy turns a full policy into a minimal one that can be cached.
|
||||||
|
func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy {
|
||||||
|
return &CachedEdgePolicy{
|
||||||
|
ChannelID: policy.ChannelID,
|
||||||
|
MessageFlags: policy.MessageFlags,
|
||||||
|
ChannelFlags: policy.ChannelFlags,
|
||||||
|
TimeLockDelta: policy.TimeLockDelta,
|
||||||
|
MinHTLC: policy.MinHTLC,
|
||||||
|
MaxHTLC: policy.MaxHTLC,
|
||||||
|
FeeBaseMSat: policy.FeeBaseMSat,
|
||||||
|
FeeProportionalMillionths: policy.FeeProportionalMillionths,
|
||||||
|
}
|
||||||
|
}
|
131
channeldb/models/channel_auth_proof.go
Normal file
131
channeldb/models/channel_auth_proof.go
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import "github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
|
|
||||||
|
// ChannelAuthProof is the authentication proof (the signature portion) for a
|
||||||
|
// channel. Using the four signatures contained in the struct, and some
|
||||||
|
// auxiliary knowledge (the funding script, node identities, and outpoint) nodes
|
||||||
|
// on the network are able to validate the authenticity and existence of a
|
||||||
|
// channel. Each of these signatures signs the following digest: chanID ||
|
||||||
|
// nodeID1 || nodeID2 || bitcoinKey1|| bitcoinKey2 || 2-byte-feature-len ||
|
||||||
|
// features.
|
||||||
|
type ChannelAuthProof struct {
|
||||||
|
// nodeSig1 is a cached instance of the first node signature.
|
||||||
|
nodeSig1 *ecdsa.Signature
|
||||||
|
|
||||||
|
// NodeSig1Bytes are the raw bytes of the first node signature encoded
|
||||||
|
// in DER format.
|
||||||
|
NodeSig1Bytes []byte
|
||||||
|
|
||||||
|
// nodeSig2 is a cached instance of the second node signature.
|
||||||
|
nodeSig2 *ecdsa.Signature
|
||||||
|
|
||||||
|
// NodeSig2Bytes are the raw bytes of the second node signature
|
||||||
|
// encoded in DER format.
|
||||||
|
NodeSig2Bytes []byte
|
||||||
|
|
||||||
|
// bitcoinSig1 is a cached instance of the first bitcoin signature.
|
||||||
|
bitcoinSig1 *ecdsa.Signature
|
||||||
|
|
||||||
|
// BitcoinSig1Bytes are the raw bytes of the first bitcoin signature
|
||||||
|
// encoded in DER format.
|
||||||
|
BitcoinSig1Bytes []byte
|
||||||
|
|
||||||
|
// bitcoinSig2 is a cached instance of the second bitcoin signature.
|
||||||
|
bitcoinSig2 *ecdsa.Signature
|
||||||
|
|
||||||
|
// BitcoinSig2Bytes are the raw bytes of the second bitcoin signature
|
||||||
|
// encoded in DER format.
|
||||||
|
BitcoinSig2Bytes []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node1Sig is the signature using the identity key of the node that is first
|
||||||
|
// in a lexicographical ordering of the serialized public keys of the two nodes
|
||||||
|
// that created the channel.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (c *ChannelAuthProof) Node1Sig() (*ecdsa.Signature, error) {
|
||||||
|
if c.nodeSig1 != nil {
|
||||||
|
return c.nodeSig1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := ecdsa.ParseSignature(c.NodeSig1Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.nodeSig1 = sig
|
||||||
|
|
||||||
|
return sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node2Sig is the signature using the identity key of the node that is second
|
||||||
|
// in a lexicographical ordering of the serialized public keys of the two nodes
|
||||||
|
// that created the channel.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (c *ChannelAuthProof) Node2Sig() (*ecdsa.Signature, error) {
|
||||||
|
if c.nodeSig2 != nil {
|
||||||
|
return c.nodeSig2, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := ecdsa.ParseSignature(c.NodeSig2Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.nodeSig2 = sig
|
||||||
|
|
||||||
|
return sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitcoinSig1 is the signature using the public key of the first node that was
|
||||||
|
// used in the channel's multi-sig output.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (c *ChannelAuthProof) BitcoinSig1() (*ecdsa.Signature, error) {
|
||||||
|
if c.bitcoinSig1 != nil {
|
||||||
|
return c.bitcoinSig1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := ecdsa.ParseSignature(c.BitcoinSig1Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.bitcoinSig1 = sig
|
||||||
|
|
||||||
|
return sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitcoinSig2 is the signature using the public key of the second node that
|
||||||
|
// was used in the channel's multi-sig output.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (c *ChannelAuthProof) BitcoinSig2() (*ecdsa.Signature, error) {
|
||||||
|
if c.bitcoinSig2 != nil {
|
||||||
|
return c.bitcoinSig2, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := ecdsa.ParseSignature(c.BitcoinSig2Bytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.bitcoinSig2 = sig
|
||||||
|
|
||||||
|
return sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsEmpty check is the authentication proof is empty Proof is empty if at
|
||||||
|
// least one of the signatures are equal to nil.
|
||||||
|
func (c *ChannelAuthProof) IsEmpty() bool {
|
||||||
|
return len(c.NodeSig1Bytes) == 0 ||
|
||||||
|
len(c.NodeSig2Bytes) == 0 ||
|
||||||
|
len(c.BitcoinSig1Bytes) == 0 ||
|
||||||
|
len(c.BitcoinSig2Bytes) == 0
|
||||||
|
}
|
187
channeldb/models/channel_edge_info.go
Normal file
187
channeldb/models/channel_edge_info.go
Normal file
@ -0,0 +1,187 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
"github.com/btcsuite/btcd/wire"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChannelEdgeInfo represents a fully authenticated channel along with all its
|
||||||
|
// unique attributes. Once an authenticated channel announcement has been
|
||||||
|
// processed on the network, then an instance of ChannelEdgeInfo encapsulating
|
||||||
|
// the channels attributes is stored. The other portions relevant to routing
|
||||||
|
// policy of a channel are stored within a ChannelEdgePolicy for each direction
|
||||||
|
// of the channel.
|
||||||
|
type ChannelEdgeInfo struct {
|
||||||
|
// ChannelID is the unique channel ID for the channel. The first 3
|
||||||
|
// bytes are the block height, the next 3 the index within the block,
|
||||||
|
// and the last 2 bytes are the output index for the channel.
|
||||||
|
ChannelID uint64
|
||||||
|
|
||||||
|
// ChainHash is the hash that uniquely identifies the chain that this
|
||||||
|
// channel was opened within.
|
||||||
|
//
|
||||||
|
// TODO(roasbeef): need to modify db keying for multi-chain
|
||||||
|
// * must add chain hash to prefix as well
|
||||||
|
ChainHash chainhash.Hash
|
||||||
|
|
||||||
|
// NodeKey1Bytes is the raw public key of the first node.
|
||||||
|
NodeKey1Bytes [33]byte
|
||||||
|
nodeKey1 *btcec.PublicKey
|
||||||
|
|
||||||
|
// NodeKey2Bytes is the raw public key of the first node.
|
||||||
|
NodeKey2Bytes [33]byte
|
||||||
|
nodeKey2 *btcec.PublicKey
|
||||||
|
|
||||||
|
// BitcoinKey1Bytes is the raw public key of the first node.
|
||||||
|
BitcoinKey1Bytes [33]byte
|
||||||
|
bitcoinKey1 *btcec.PublicKey
|
||||||
|
|
||||||
|
// BitcoinKey2Bytes is the raw public key of the first node.
|
||||||
|
BitcoinKey2Bytes [33]byte
|
||||||
|
bitcoinKey2 *btcec.PublicKey
|
||||||
|
|
||||||
|
// Features is an opaque byte slice that encodes the set of channel
|
||||||
|
// specific features that this channel edge supports.
|
||||||
|
Features []byte
|
||||||
|
|
||||||
|
// AuthProof is the authentication proof for this channel. This proof
|
||||||
|
// contains a set of signatures binding four identities, which attests
|
||||||
|
// to the legitimacy of the advertised channel.
|
||||||
|
AuthProof *ChannelAuthProof
|
||||||
|
|
||||||
|
// ChannelPoint is the funding outpoint of the channel. This can be
|
||||||
|
// used to uniquely identify the channel within the channel graph.
|
||||||
|
ChannelPoint wire.OutPoint
|
||||||
|
|
||||||
|
// Capacity is the total capacity of the channel, this is determined by
|
||||||
|
// the value output in the outpoint that created this channel.
|
||||||
|
Capacity btcutil.Amount
|
||||||
|
|
||||||
|
// ExtraOpaqueData is the set of data that was appended to this
|
||||||
|
// message, some of which we may not actually know how to iterate or
|
||||||
|
// parse. By holding onto this data, we ensure that we're able to
|
||||||
|
// properly validate the set of signatures that cover these new fields,
|
||||||
|
// and ensure we're able to make upgrades to the network in a forwards
|
||||||
|
// compatible manner.
|
||||||
|
ExtraOpaqueData []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddNodeKeys is a setter-like method that can be used to replace the set of
|
||||||
|
// keys for the target ChannelEdgeInfo.
|
||||||
|
func (c *ChannelEdgeInfo) AddNodeKeys(nodeKey1, nodeKey2, bitcoinKey1,
|
||||||
|
bitcoinKey2 *btcec.PublicKey) {
|
||||||
|
|
||||||
|
c.nodeKey1 = nodeKey1
|
||||||
|
copy(c.NodeKey1Bytes[:], c.nodeKey1.SerializeCompressed())
|
||||||
|
|
||||||
|
c.nodeKey2 = nodeKey2
|
||||||
|
copy(c.NodeKey2Bytes[:], nodeKey2.SerializeCompressed())
|
||||||
|
|
||||||
|
c.bitcoinKey1 = bitcoinKey1
|
||||||
|
copy(c.BitcoinKey1Bytes[:], c.bitcoinKey1.SerializeCompressed())
|
||||||
|
|
||||||
|
c.bitcoinKey2 = bitcoinKey2
|
||||||
|
copy(c.BitcoinKey2Bytes[:], bitcoinKey2.SerializeCompressed())
|
||||||
|
}
|
||||||
|
|
||||||
|
// NodeKey1 is the identity public key of the "first" node that was involved in
|
||||||
|
// the creation of this channel. A node is considered "first" if the
|
||||||
|
// lexicographical ordering the its serialized public key is "smaller" than
|
||||||
|
// that of the other node involved in channel creation.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
|
func (c *ChannelEdgeInfo) NodeKey1() (*btcec.PublicKey, error) {
|
||||||
|
if c.nodeKey1 != nil {
|
||||||
|
return c.nodeKey1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := btcec.ParsePubKey(c.NodeKey1Bytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.nodeKey1 = key
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NodeKey2 is the identity public key of the "second" node that was involved in
|
||||||
|
// the creation of this channel. A node is considered "second" if the
|
||||||
|
// lexicographical ordering the its serialized public key is "larger" than that
|
||||||
|
// of the other node involved in channel creation.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
|
func (c *ChannelEdgeInfo) NodeKey2() (*btcec.PublicKey, error) {
|
||||||
|
if c.nodeKey2 != nil {
|
||||||
|
return c.nodeKey2, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := btcec.ParsePubKey(c.NodeKey2Bytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.nodeKey2 = key
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitcoinKey1 is the Bitcoin multi-sig key belonging to the first node, that
|
||||||
|
// was involved in the funding transaction that originally created the channel
|
||||||
|
// that this struct represents.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
|
func (c *ChannelEdgeInfo) BitcoinKey1() (*btcec.PublicKey, error) {
|
||||||
|
if c.bitcoinKey1 != nil {
|
||||||
|
return c.bitcoinKey1, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := btcec.ParsePubKey(c.BitcoinKey1Bytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.bitcoinKey1 = key
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// BitcoinKey2 is the Bitcoin multi-sig key belonging to the second node, that
|
||||||
|
// was involved in the funding transaction that originally created the channel
|
||||||
|
// that this struct represents.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the pubkey if absolutely necessary.
|
||||||
|
func (c *ChannelEdgeInfo) BitcoinKey2() (*btcec.PublicKey, error) {
|
||||||
|
if c.bitcoinKey2 != nil {
|
||||||
|
return c.bitcoinKey2, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
key, err := btcec.ParsePubKey(c.BitcoinKey2Bytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
c.bitcoinKey2 = key
|
||||||
|
|
||||||
|
return key, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// OtherNodeKeyBytes returns the node key bytes of the other end of the channel.
|
||||||
|
func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
|
||||||
|
[33]byte, error) {
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case bytes.Equal(c.NodeKey1Bytes[:], thisNodeKey):
|
||||||
|
return c.NodeKey2Bytes, nil
|
||||||
|
case bytes.Equal(c.NodeKey2Bytes[:], thisNodeKey):
|
||||||
|
return c.NodeKey1Bytes, nil
|
||||||
|
default:
|
||||||
|
return [33]byte{}, fmt.Errorf("node not participating in " +
|
||||||
|
"this channel")
|
||||||
|
}
|
||||||
|
}
|
131
channeldb/models/channel_edge_policy.go
Normal file
131
channeldb/models/channel_edge_policy.go
Normal file
@ -0,0 +1,131 @@
|
|||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||||
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ChannelEdgePolicy represents a *directed* edge within the channel graph. For
|
||||||
|
// each channel in the database, there are two distinct edges: one for each
|
||||||
|
// possible direction of travel along the channel. The edges themselves hold
|
||||||
|
// information concerning fees, and minimum time-lock information which is
|
||||||
|
// utilized during path finding.
|
||||||
|
type ChannelEdgePolicy struct {
|
||||||
|
// SigBytes is the raw bytes of the signature of the channel edge
|
||||||
|
// policy. We'll only parse these if the caller needs to access the
|
||||||
|
// signature for validation purposes. Do not set SigBytes directly, but
|
||||||
|
// use SetSigBytes instead to make sure that the cache is invalidated.
|
||||||
|
SigBytes []byte
|
||||||
|
|
||||||
|
// sig is a cached fully parsed signature.
|
||||||
|
sig *ecdsa.Signature
|
||||||
|
|
||||||
|
// ChannelID is the unique channel ID for the channel. The first 3
|
||||||
|
// bytes are the block height, the next 3 the index within the block,
|
||||||
|
// and the last 2 bytes are the output index for the channel.
|
||||||
|
ChannelID uint64
|
||||||
|
|
||||||
|
// LastUpdate is the last time an authenticated edge for this channel
|
||||||
|
// was received.
|
||||||
|
LastUpdate time.Time
|
||||||
|
|
||||||
|
// MessageFlags is a bitfield which indicates the presence of optional
|
||||||
|
// fields (like max_htlc) in the policy.
|
||||||
|
MessageFlags lnwire.ChanUpdateMsgFlags
|
||||||
|
|
||||||
|
// ChannelFlags is a bitfield which signals the capabilities of the
|
||||||
|
// channel as well as the directed edge this update applies to.
|
||||||
|
ChannelFlags lnwire.ChanUpdateChanFlags
|
||||||
|
|
||||||
|
// TimeLockDelta is the number of blocks this node will subtract from
|
||||||
|
// the expiry of an incoming HTLC. This value expresses the time buffer
|
||||||
|
// the node would like to HTLC exchanges.
|
||||||
|
TimeLockDelta uint16
|
||||||
|
|
||||||
|
// MinHTLC is the smallest value HTLC this node will forward, expressed
|
||||||
|
// in millisatoshi.
|
||||||
|
MinHTLC lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// MaxHTLC is the largest value HTLC this node will forward, expressed
|
||||||
|
// in millisatoshi.
|
||||||
|
MaxHTLC lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
|
||||||
|
// ANY HTLC, expressed in mSAT's.
|
||||||
|
FeeBaseMSat lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// FeeProportionalMillionths is the rate that the node will charge for
|
||||||
|
// HTLCs for each millionth of a satoshi forwarded.
|
||||||
|
FeeProportionalMillionths lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// ToNode is the public key of the node that this directed edge leads
|
||||||
|
// to. Using this pub key, the channel graph can further be traversed.
|
||||||
|
ToNode [33]byte
|
||||||
|
|
||||||
|
// ExtraOpaqueData is the set of data that was appended to this
|
||||||
|
// message, some of which we may not actually know how to iterate or
|
||||||
|
// parse. By holding onto this data, we ensure that we're able to
|
||||||
|
// properly validate the set of signatures that cover these new fields,
|
||||||
|
// and ensure we're able to make upgrades to the network in a forwards
|
||||||
|
// compatible manner.
|
||||||
|
ExtraOpaqueData []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// Signature is a channel announcement signature, which is needed for proper
|
||||||
|
// edge policy announcement.
|
||||||
|
//
|
||||||
|
// NOTE: By having this method to access an attribute, we ensure we only need
|
||||||
|
// to fully deserialize the signature if absolutely necessary.
|
||||||
|
func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error) {
|
||||||
|
if c.sig != nil {
|
||||||
|
return c.sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := ecdsa.ParseSignature(c.SigBytes)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.sig = sig
|
||||||
|
|
||||||
|
return sig, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetSigBytes updates the signature and invalidates the cached parsed
|
||||||
|
// signature.
|
||||||
|
func (c *ChannelEdgePolicy) SetSigBytes(sig []byte) {
|
||||||
|
c.SigBytes = sig
|
||||||
|
c.sig = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsDisabled determines whether the edge has the disabled bit set.
|
||||||
|
func (c *ChannelEdgePolicy) IsDisabled() bool {
|
||||||
|
return c.ChannelFlags.IsDisabled()
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over
|
||||||
|
// the passed active payment channel. This value is currently computed as
|
||||||
|
// specified in BOLT07, but will likely change in the near future.
|
||||||
|
func (c *ChannelEdgePolicy) ComputeFee(
|
||||||
|
amt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
|
return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts
|
||||||
|
}
|
||||||
|
|
||||||
|
// divideCeil divides dividend by factor and rounds the result up.
|
||||||
|
func divideCeil(dividend, factor lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
return (dividend + factor - 1) / factor
|
||||||
|
}
|
||||||
|
|
||||||
|
// ComputeFeeFromIncoming computes the fee to forward an HTLC given the incoming
|
||||||
|
// amount.
|
||||||
|
func (c *ChannelEdgePolicy) ComputeFeeFromIncoming(
|
||||||
|
incomingAmt lnwire.MilliSatoshi) lnwire.MilliSatoshi {
|
||||||
|
|
||||||
|
return incomingAmt - divideCeil(
|
||||||
|
feeRateParts*(incomingAmt-c.FeeBaseMSat),
|
||||||
|
feeRateParts+c.FeeProportionalMillionths,
|
||||||
|
)
|
||||||
|
}
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnpeer"
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
@ -527,10 +528,10 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
|
|||||||
// EdgeWithInfo contains the information that is required to update an edge.
|
// EdgeWithInfo contains the information that is required to update an edge.
|
||||||
type EdgeWithInfo struct {
|
type EdgeWithInfo struct {
|
||||||
// Info describes the channel.
|
// Info describes the channel.
|
||||||
Info *channeldb.ChannelEdgeInfo
|
Info *models.ChannelEdgeInfo
|
||||||
|
|
||||||
// Edge describes the policy in one direction of the channel.
|
// Edge describes the policy in one direction of the channel.
|
||||||
Edge *channeldb.ChannelEdgePolicy
|
Edge *models.ChannelEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// PropagateChanPolicyUpdate signals the AuthenticatedGossiper to perform the
|
// PropagateChanPolicyUpdate signals the AuthenticatedGossiper to perform the
|
||||||
@ -1574,8 +1575,8 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
|||||||
// Iterate over all of our channels and check if any of them fall
|
// Iterate over all of our channels and check if any of them fall
|
||||||
// within the prune interval or re-broadcast interval.
|
// within the prune interval or re-broadcast interval.
|
||||||
type updateTuple struct {
|
type updateTuple struct {
|
||||||
info *channeldb.ChannelEdgeInfo
|
info *models.ChannelEdgeInfo
|
||||||
edge *channeldb.ChannelEdgePolicy
|
edge *models.ChannelEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -1584,8 +1585,8 @@ func (d *AuthenticatedGossiper) retransmitStaleAnns(now time.Time) error {
|
|||||||
)
|
)
|
||||||
err := d.cfg.Router.ForAllOutgoingChannels(func(
|
err := d.cfg.Router.ForAllOutgoingChannels(func(
|
||||||
_ kvdb.RTx,
|
_ kvdb.RTx,
|
||||||
info *channeldb.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
edge *channeldb.ChannelEdgePolicy) error {
|
edge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// If there's no auth proof attached to this edge, it means
|
// If there's no auth proof attached to this edge, it means
|
||||||
// that it is a private channel not meant to be announced to
|
// that it is a private channel not meant to be announced to
|
||||||
@ -1790,7 +1791,7 @@ func (d *AuthenticatedGossiper) processChanPolicyUpdate(
|
|||||||
|
|
||||||
// remotePubFromChanInfo returns the public key of the remote peer given a
|
// remotePubFromChanInfo returns the public key of the remote peer given a
|
||||||
// ChannelEdgeInfo that describe a channel we have with them.
|
// ChannelEdgeInfo that describe a channel we have with them.
|
||||||
func remotePubFromChanInfo(chanInfo *channeldb.ChannelEdgeInfo,
|
func remotePubFromChanInfo(chanInfo *models.ChannelEdgeInfo,
|
||||||
chanFlags lnwire.ChanUpdateChanFlags) [33]byte {
|
chanFlags lnwire.ChanUpdateChanFlags) [33]byte {
|
||||||
|
|
||||||
var remotePubKey [33]byte
|
var remotePubKey [33]byte
|
||||||
@ -1813,7 +1814,7 @@ func remotePubFromChanInfo(chanInfo *channeldb.ChannelEdgeInfo,
|
|||||||
// assemble the proof and craft the ChannelAnnouncement.
|
// assemble the proof and craft the ChannelAnnouncement.
|
||||||
func (d *AuthenticatedGossiper) processRejectedEdge(
|
func (d *AuthenticatedGossiper) processRejectedEdge(
|
||||||
chanAnnMsg *lnwire.ChannelAnnouncement,
|
chanAnnMsg *lnwire.ChannelAnnouncement,
|
||||||
proof *channeldb.ChannelAuthProof) ([]networkMsg, error) {
|
proof *models.ChannelAuthProof) ([]networkMsg, error) {
|
||||||
|
|
||||||
// First, we'll fetch the state of the channel as we know if from the
|
// First, we'll fetch the state of the channel as we know if from the
|
||||||
// database.
|
// database.
|
||||||
@ -2022,7 +2023,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement(
|
|||||||
// processZombieUpdate determines whether the provided channel update should
|
// processZombieUpdate determines whether the provided channel update should
|
||||||
// resurrect a given zombie edge.
|
// resurrect a given zombie edge.
|
||||||
func (d *AuthenticatedGossiper) processZombieUpdate(
|
func (d *AuthenticatedGossiper) processZombieUpdate(
|
||||||
chanInfo *channeldb.ChannelEdgeInfo, msg *lnwire.ChannelUpdate) error {
|
chanInfo *models.ChannelEdgeInfo, msg *lnwire.ChannelUpdate) error {
|
||||||
|
|
||||||
// The least-significant bit in the flag on the channel update tells us
|
// The least-significant bit in the flag on the channel update tells us
|
||||||
// which edge is being updated.
|
// which edge is being updated.
|
||||||
@ -2125,7 +2126,7 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
|
|||||||
// Otherwise, we'll retrieve the correct policy that we
|
// Otherwise, we'll retrieve the correct policy that we
|
||||||
// currently have stored within our graph to check if this
|
// currently have stored within our graph to check if this
|
||||||
// message is stale by comparing its timestamp.
|
// message is stale by comparing its timestamp.
|
||||||
var p *channeldb.ChannelEdgePolicy
|
var p *models.ChannelEdgePolicy
|
||||||
if msg.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
if msg.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
||||||
p = p1
|
p = p1
|
||||||
} else {
|
} else {
|
||||||
@ -2150,8 +2151,8 @@ func (d *AuthenticatedGossiper) isMsgStale(msg lnwire.Message) bool {
|
|||||||
|
|
||||||
// updateChannel creates a new fully signed update for the channel, and updates
|
// updateChannel creates a new fully signed update for the channel, and updates
|
||||||
// the underlying graph with the new state.
|
// the underlying graph with the new state.
|
||||||
func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
|
func (d *AuthenticatedGossiper) updateChannel(info *models.ChannelEdgeInfo,
|
||||||
edge *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
edge *models.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
||||||
*lnwire.ChannelUpdate, error) {
|
*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
// Parse the unsigned edge into a channel update.
|
// Parse the unsigned edge into a channel update.
|
||||||
@ -2239,7 +2240,7 @@ func (d *AuthenticatedGossiper) SyncManager() *SyncManager {
|
|||||||
// keep-alive update based on the previous channel update processed for the same
|
// keep-alive update based on the previous channel update processed for the same
|
||||||
// direction.
|
// direction.
|
||||||
func IsKeepAliveUpdate(update *lnwire.ChannelUpdate,
|
func IsKeepAliveUpdate(update *lnwire.ChannelUpdate,
|
||||||
prev *channeldb.ChannelEdgePolicy) bool {
|
prev *models.ChannelEdgePolicy) bool {
|
||||||
|
|
||||||
// Both updates should be from the same direction.
|
// Both updates should be from the same direction.
|
||||||
if update.ChannelFlags&lnwire.ChanUpdateDirection !=
|
if update.ChannelFlags&lnwire.ChanUpdateDirection !=
|
||||||
@ -2428,7 +2429,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
|||||||
|
|
||||||
// If this is a remote channel announcement, then we'll validate all
|
// If this is a remote channel announcement, then we'll validate all
|
||||||
// the signatures within the proof as it should be well formed.
|
// the signatures within the proof as it should be well formed.
|
||||||
var proof *channeldb.ChannelAuthProof
|
var proof *models.ChannelAuthProof
|
||||||
if nMsg.isRemote {
|
if nMsg.isRemote {
|
||||||
if err := routing.ValidateChannelAnn(ann); err != nil {
|
if err := routing.ValidateChannelAnn(ann); err != nil {
|
||||||
err := fmt.Errorf("unable to validate announcement: "+
|
err := fmt.Errorf("unable to validate announcement: "+
|
||||||
@ -2448,7 +2449,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
|||||||
// If the proof checks out, then we'll save the proof itself to
|
// If the proof checks out, then we'll save the proof itself to
|
||||||
// the database so we can fetch it later when gossiping with
|
// the database so we can fetch it later when gossiping with
|
||||||
// other nodes.
|
// other nodes.
|
||||||
proof = &channeldb.ChannelAuthProof{
|
proof = &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: ann.NodeSig1.ToSignatureBytes(),
|
NodeSig1Bytes: ann.NodeSig1.ToSignatureBytes(),
|
||||||
NodeSig2Bytes: ann.NodeSig2.ToSignatureBytes(),
|
NodeSig2Bytes: ann.NodeSig2.ToSignatureBytes(),
|
||||||
BitcoinSig1Bytes: ann.BitcoinSig1.ToSignatureBytes(),
|
BitcoinSig1Bytes: ann.BitcoinSig1.ToSignatureBytes(),
|
||||||
@ -2465,7 +2466,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(nMsg *networkMsg,
|
|||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: ann.ShortChannelID.ToUint64(),
|
ChannelID: ann.ShortChannelID.ToUint64(),
|
||||||
ChainHash: ann.ChainHash,
|
ChainHash: ann.ChainHash,
|
||||||
NodeKey1Bytes: ann.NodeID1,
|
NodeKey1Bytes: ann.NodeID1,
|
||||||
@ -2816,7 +2817,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
|
|||||||
// being updated.
|
// being updated.
|
||||||
var (
|
var (
|
||||||
pubKey *btcec.PublicKey
|
pubKey *btcec.PublicKey
|
||||||
edgeToUpdate *channeldb.ChannelEdgePolicy
|
edgeToUpdate *models.ChannelEdgePolicy
|
||||||
)
|
)
|
||||||
direction := upd.ChannelFlags & lnwire.ChanUpdateDirection
|
direction := upd.ChannelFlags & lnwire.ChanUpdateDirection
|
||||||
switch direction {
|
switch direction {
|
||||||
@ -2905,7 +2906,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
|
|||||||
// different alias. This might mean that SigBytes is incorrect as it
|
// different alias. This might mean that SigBytes is incorrect as it
|
||||||
// signs a different SCID than the database SCID, but since there will
|
// signs a different SCID than the database SCID, but since there will
|
||||||
// only be a difference if AuthProof == nil, this is fine.
|
// only be a difference if AuthProof == nil, this is fine.
|
||||||
update := &channeldb.ChannelEdgePolicy{
|
update := &models.ChannelEdgePolicy{
|
||||||
SigBytes: upd.Signature.ToSignatureBytes(),
|
SigBytes: upd.Signature.ToSignatureBytes(),
|
||||||
ChannelID: chanInfo.ChannelID,
|
ChannelID: chanInfo.ChannelID,
|
||||||
LastUpdate: timestamp,
|
LastUpdate: timestamp,
|
||||||
@ -3217,7 +3218,7 @@ func (d *AuthenticatedGossiper) handleAnnSig(nMsg *networkMsg,
|
|||||||
// We now have both halves of the channel announcement proof, then
|
// We now have both halves of the channel announcement proof, then
|
||||||
// we'll reconstruct the initial announcement so we can validate it
|
// we'll reconstruct the initial announcement so we can validate it
|
||||||
// shortly below.
|
// shortly below.
|
||||||
var dbProof channeldb.ChannelAuthProof
|
var dbProof models.ChannelAuthProof
|
||||||
if isFirstNode {
|
if isFirstNode {
|
||||||
dbProof.NodeSig1Bytes = ann.NodeSignature.ToSignatureBytes()
|
dbProof.NodeSig1Bytes = ann.NodeSignature.ToSignatureBytes()
|
||||||
dbProof.NodeSig2Bytes = oppProof.NodeSignature.ToSignatureBytes()
|
dbProof.NodeSig2Bytes = oppProof.NodeSignature.ToSignatureBytes()
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnpeer"
|
"github.com/lightningnetwork/lnd/lnpeer"
|
||||||
@ -91,8 +92,8 @@ type mockGraphSource struct {
|
|||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
nodes []channeldb.LightningNode
|
nodes []channeldb.LightningNode
|
||||||
infos map[uint64]channeldb.ChannelEdgeInfo
|
infos map[uint64]models.ChannelEdgeInfo
|
||||||
edges map[uint64][]channeldb.ChannelEdgePolicy
|
edges map[uint64][]models.ChannelEdgePolicy
|
||||||
zombies map[uint64][][33]byte
|
zombies map[uint64][][33]byte
|
||||||
chansToReject map[uint64]struct{}
|
chansToReject map[uint64]struct{}
|
||||||
}
|
}
|
||||||
@ -100,8 +101,8 @@ type mockGraphSource struct {
|
|||||||
func newMockRouter(height uint32) *mockGraphSource {
|
func newMockRouter(height uint32) *mockGraphSource {
|
||||||
return &mockGraphSource{
|
return &mockGraphSource{
|
||||||
bestHeight: height,
|
bestHeight: height,
|
||||||
infos: make(map[uint64]channeldb.ChannelEdgeInfo),
|
infos: make(map[uint64]models.ChannelEdgeInfo),
|
||||||
edges: make(map[uint64][]channeldb.ChannelEdgePolicy),
|
edges: make(map[uint64][]models.ChannelEdgePolicy),
|
||||||
zombies: make(map[uint64][][33]byte),
|
zombies: make(map[uint64][][33]byte),
|
||||||
chansToReject: make(map[uint64]struct{}),
|
chansToReject: make(map[uint64]struct{}),
|
||||||
}
|
}
|
||||||
@ -119,7 +120,7 @@ func (r *mockGraphSource) AddNode(node *channeldb.LightningNode,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) AddEdge(info *channeldb.ChannelEdgeInfo,
|
func (r *mockGraphSource) AddEdge(info *models.ChannelEdgeInfo,
|
||||||
_ ...batch.SchedulerOption) error {
|
_ ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
@ -144,14 +145,14 @@ func (r *mockGraphSource) queueValidationFail(chanID uint64) {
|
|||||||
r.chansToReject[chanID] = struct{}{}
|
r.chansToReject[chanID] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) UpdateEdge(edge *channeldb.ChannelEdgePolicy,
|
func (r *mockGraphSource) UpdateEdge(edge *models.ChannelEdgePolicy,
|
||||||
_ ...batch.SchedulerOption) error {
|
_ ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
if len(r.edges[edge.ChannelID]) == 0 {
|
if len(r.edges[edge.ChannelID]) == 0 {
|
||||||
r.edges[edge.ChannelID] = make([]channeldb.ChannelEdgePolicy, 2)
|
r.edges[edge.ChannelID] = make([]models.ChannelEdgePolicy, 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
||||||
@ -168,7 +169,7 @@ func (r *mockGraphSource) CurrentBlockHeight() (uint32, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
func (r *mockGraphSource) AddProof(chanID lnwire.ShortChannelID,
|
||||||
proof *channeldb.ChannelAuthProof) error {
|
proof *models.ChannelAuthProof) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
@ -190,8 +191,8 @@ func (r *mockGraphSource) ForEachNode(func(node *channeldb.LightningNode) error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
func (r *mockGraphSource) ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
||||||
i *channeldb.ChannelEdgeInfo,
|
i *models.ChannelEdgeInfo,
|
||||||
c *channeldb.ChannelEdgePolicy) error) error {
|
c *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
@ -221,15 +222,15 @@ func (r *mockGraphSource) ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) ForEachChannel(func(chanInfo *channeldb.ChannelEdgeInfo,
|
func (r *mockGraphSource) ForEachChannel(func(chanInfo *models.ChannelEdgeInfo,
|
||||||
e1, e2 *channeldb.ChannelEdgePolicy) error) error {
|
e1, e2 *models.ChannelEdgePolicy) error) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgeInfo,
|
*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy,
|
||||||
*channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
@ -242,7 +243,7 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
|||||||
return nil, nil, nil, channeldb.ErrEdgeNotFound
|
return nil, nil, nil, channeldb.ErrEdgeNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
return &channeldb.ChannelEdgeInfo{
|
return &models.ChannelEdgeInfo{
|
||||||
NodeKey1Bytes: pubKeys[0],
|
NodeKey1Bytes: pubKeys[0],
|
||||||
NodeKey2Bytes: pubKeys[1],
|
NodeKey2Bytes: pubKeys[1],
|
||||||
}, nil, nil, channeldb.ErrZombieEdge
|
}, nil, nil, channeldb.ErrZombieEdge
|
||||||
@ -253,13 +254,13 @@ func (r *mockGraphSource) GetChannelByID(chanID lnwire.ShortChannelID) (
|
|||||||
return &chanInfo, nil, nil, nil
|
return &chanInfo, nil, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var edge1 *channeldb.ChannelEdgePolicy
|
var edge1 *models.ChannelEdgePolicy
|
||||||
if !reflect.DeepEqual(edges[0], channeldb.ChannelEdgePolicy{}) {
|
if !reflect.DeepEqual(edges[0], models.ChannelEdgePolicy{}) {
|
||||||
edge1 = &edges[0]
|
edge1 = &edges[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
var edge2 *channeldb.ChannelEdgePolicy
|
var edge2 *models.ChannelEdgePolicy
|
||||||
if !reflect.DeepEqual(edges[1], channeldb.ChannelEdgePolicy{}) {
|
if !reflect.DeepEqual(edges[1], models.ChannelEdgePolicy{}) {
|
||||||
edge2 = &edges[1]
|
edge2 = &edges[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,12 +360,12 @@ func (r *mockGraphSource) IsStaleEdgePolicy(chanID lnwire.ShortChannelID,
|
|||||||
|
|
||||||
switch {
|
switch {
|
||||||
case flags&lnwire.ChanUpdateDirection == 0 &&
|
case flags&lnwire.ChanUpdateDirection == 0 &&
|
||||||
!reflect.DeepEqual(edges[0], channeldb.ChannelEdgePolicy{}):
|
!reflect.DeepEqual(edges[0], models.ChannelEdgePolicy{}):
|
||||||
|
|
||||||
return !timestamp.After(edges[0].LastUpdate)
|
return !timestamp.After(edges[0].LastUpdate)
|
||||||
|
|
||||||
case flags&lnwire.ChanUpdateDirection == 1 &&
|
case flags&lnwire.ChanUpdateDirection == 1 &&
|
||||||
!reflect.DeepEqual(edges[1], channeldb.ChannelEdgePolicy{}):
|
!reflect.DeepEqual(edges[1], models.ChannelEdgePolicy{}):
|
||||||
|
|
||||||
return !timestamp.After(edges[1].LastUpdate)
|
return !timestamp.After(edges[1].LastUpdate)
|
||||||
|
|
||||||
@ -3443,8 +3444,8 @@ out:
|
|||||||
var edgesToUpdate []EdgeWithInfo
|
var edgesToUpdate []EdgeWithInfo
|
||||||
err = ctx.router.ForAllOutgoingChannels(func(
|
err = ctx.router.ForAllOutgoingChannels(func(
|
||||||
_ kvdb.RTx,
|
_ kvdb.RTx,
|
||||||
info *channeldb.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
edge *channeldb.ChannelEdgePolicy) error {
|
edge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
edge.TimeLockDelta = uint16(newTimeLockDelta)
|
edge.TimeLockDelta = uint16(newTimeLockDelta)
|
||||||
edgesToUpdate = append(edgesToUpdate, EdgeWithInfo{
|
edgesToUpdate = append(edgesToUpdate, EdgeWithInfo{
|
||||||
|
@ -524,7 +524,7 @@ type Config struct {
|
|||||||
// DeleteAliasEdge allows the Manager to delete an alias channel edge
|
// DeleteAliasEdge allows the Manager to delete an alias channel edge
|
||||||
// from the graph. It also returns our local to-be-deleted policy.
|
// from the graph. It also returns our local to-be-deleted policy.
|
||||||
DeleteAliasEdge func(scid lnwire.ShortChannelID) (
|
DeleteAliasEdge func(scid lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgePolicy, error)
|
*models.ChannelEdgePolicy, error)
|
||||||
|
|
||||||
// AliasManager is an implementation of the aliasHandler interface that
|
// AliasManager is an implementation of the aliasHandler interface that
|
||||||
// abstracts away the handling of many alias functions.
|
// abstracts away the handling of many alias functions.
|
||||||
@ -3335,7 +3335,7 @@ func (f *Manager) extractAnnounceParams(c *channeldb.OpenChannel) (
|
|||||||
func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
|
func (f *Manager) addToRouterGraph(completeChan *channeldb.OpenChannel,
|
||||||
shortChanID *lnwire.ShortChannelID,
|
shortChanID *lnwire.ShortChannelID,
|
||||||
peerAlias *lnwire.ShortChannelID,
|
peerAlias *lnwire.ShortChannelID,
|
||||||
ourPolicy *channeldb.ChannelEdgePolicy) error {
|
ourPolicy *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
|
chanID := lnwire.NewChanIDFromOutPoint(&completeChan.FundingOutpoint)
|
||||||
|
|
||||||
@ -4067,7 +4067,7 @@ func (f *Manager) newChanAnnouncement(localPubKey,
|
|||||||
remotePubKey *btcec.PublicKey, localFundingKey *keychain.KeyDescriptor,
|
remotePubKey *btcec.PublicKey, localFundingKey *keychain.KeyDescriptor,
|
||||||
remoteFundingKey *btcec.PublicKey, shortChanID lnwire.ShortChannelID,
|
remoteFundingKey *btcec.PublicKey, shortChanID lnwire.ShortChannelID,
|
||||||
chanID lnwire.ChannelID, fwdMinHTLC, fwdMaxHTLC lnwire.MilliSatoshi,
|
chanID lnwire.ChannelID, fwdMinHTLC, fwdMaxHTLC lnwire.MilliSatoshi,
|
||||||
ourPolicy *channeldb.ChannelEdgePolicy,
|
ourPolicy *models.ChannelEdgePolicy,
|
||||||
chanType channeldb.ChannelType) (*chanAnnouncement, error) {
|
chanType channeldb.ChannelType) (*chanAnnouncement, error) {
|
||||||
|
|
||||||
chainHash := *f.cfg.Wallet.Cfg.NetParams.GenesisHash
|
chainHash := *f.cfg.Wallet.Cfg.NetParams.GenesisHash
|
||||||
|
@ -550,7 +550,7 @@ func createTestFundingManager(t *testing.T, privKey *btcec.PrivateKey,
|
|||||||
OpenChannelPredicate: chainedAcceptor,
|
OpenChannelPredicate: chainedAcceptor,
|
||||||
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
|
NotifyPendingOpenChannelEvent: evt.NotifyPendingOpenChannelEvent,
|
||||||
DeleteAliasEdge: func(scid lnwire.ShortChannelID) (
|
DeleteAliasEdge: func(scid lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
},
|
},
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lncfg"
|
"github.com/lightningnetwork/lnd/lncfg"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -261,7 +262,7 @@ func (s *Server) ImportGraph(ctx context.Context,
|
|||||||
for _, rpcEdge := range graph.Edges {
|
for _, rpcEdge := range graph.Edges {
|
||||||
rpcEdge := rpcEdge
|
rpcEdge := rpcEdge
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: rpcEdge.ChannelId,
|
ChannelID: rpcEdge.ChannelId,
|
||||||
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
|
ChainHash: *s.cfg.ActiveNetParams.GenesisHash,
|
||||||
Capacity: btcutil.Amount(rpcEdge.Capacity),
|
Capacity: btcutil.Amount(rpcEdge.Capacity),
|
||||||
@ -288,8 +289,8 @@ func (s *Server) ImportGraph(ctx context.Context,
|
|||||||
rpcEdge.ChanPoint, err)
|
rpcEdge.ChanPoint, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
makePolicy := func(rpcPolicy *lnrpc.RoutingPolicy) *channeldb.ChannelEdgePolicy {
|
makePolicy := func(rpcPolicy *lnrpc.RoutingPolicy) *models.ChannelEdgePolicy {
|
||||||
policy := &channeldb.ChannelEdgePolicy{
|
policy := &models.ChannelEdgePolicy{
|
||||||
ChannelID: rpcEdge.ChannelId,
|
ChannelID: rpcEdge.ChannelId,
|
||||||
LastUpdate: time.Unix(
|
LastUpdate: time.Unix(
|
||||||
int64(rpcPolicy.LastUpdate), 0,
|
int64(rpcPolicy.LastUpdate), 0,
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/invoices"
|
"github.com/lightningnetwork/lnd/invoices"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -489,7 +490,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
|||||||
// chanCanBeHopHint returns true if the target channel is eligible to be a hop
|
// chanCanBeHopHint returns true if the target channel is eligible to be a hop
|
||||||
// hint.
|
// hint.
|
||||||
func chanCanBeHopHint(channel *HopHintInfo, cfg *SelectHopHintsCfg) (
|
func chanCanBeHopHint(channel *HopHintInfo, cfg *SelectHopHintsCfg) (
|
||||||
*channeldb.ChannelEdgePolicy, bool) {
|
*models.ChannelEdgePolicy, bool) {
|
||||||
|
|
||||||
// Since we're only interested in our private channels, we'll skip
|
// Since we're only interested in our private channels, we'll skip
|
||||||
// public ones.
|
// public ones.
|
||||||
@ -544,7 +545,7 @@ func chanCanBeHopHint(channel *HopHintInfo, cfg *SelectHopHintsCfg) (
|
|||||||
|
|
||||||
// Now, we'll need to determine which is the correct policy for HTLCs
|
// Now, we'll need to determine which is the correct policy for HTLCs
|
||||||
// being sent from the remote node.
|
// being sent from the remote node.
|
||||||
var remotePolicy *channeldb.ChannelEdgePolicy
|
var remotePolicy *models.ChannelEdgePolicy
|
||||||
if bytes.Equal(remotePub[:], info.NodeKey1Bytes[:]) {
|
if bytes.Equal(remotePub[:], info.NodeKey1Bytes[:]) {
|
||||||
remotePolicy = p1
|
remotePolicy = p1
|
||||||
} else {
|
} else {
|
||||||
@ -604,7 +605,7 @@ func newHopHintInfo(c *channeldb.OpenChannel, isActive bool) *HopHintInfo {
|
|||||||
// newHopHint returns a new hop hint using the relevant data from a hopHintInfo
|
// newHopHint returns a new hop hint using the relevant data from a hopHintInfo
|
||||||
// and a ChannelEdgePolicy.
|
// and a ChannelEdgePolicy.
|
||||||
func newHopHint(hopHintInfo *HopHintInfo,
|
func newHopHint(hopHintInfo *HopHintInfo,
|
||||||
chanPolicy *channeldb.ChannelEdgePolicy) zpay32.HopHint {
|
chanPolicy *models.ChannelEdgePolicy) zpay32.HopHint {
|
||||||
|
|
||||||
return zpay32.HopHint{
|
return zpay32.HopHint{
|
||||||
NodeID: hopHintInfo.RemotePubkey,
|
NodeID: hopHintInfo.RemotePubkey,
|
||||||
@ -627,8 +628,8 @@ type SelectHopHintsCfg struct {
|
|||||||
|
|
||||||
// FetchChannelEdgesByID attempts to lookup the two directed edges for
|
// FetchChannelEdgesByID attempts to lookup the two directed edges for
|
||||||
// the channel identified by the channel ID.
|
// the channel identified by the channel ID.
|
||||||
FetchChannelEdgesByID func(chanID uint64) (*channeldb.ChannelEdgeInfo,
|
FetchChannelEdgesByID func(chanID uint64) (*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy,
|
||||||
error)
|
error)
|
||||||
|
|
||||||
// GetAlias allows the peer's alias SCID to be retrieved for private
|
// GetAlias allows the peer's alias SCID to be retrieved for private
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/zpay32"
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
"github.com/stretchr/testify/mock"
|
"github.com/stretchr/testify/mock"
|
||||||
@ -51,8 +52,8 @@ func (h *hopHintsConfigMock) FetchAllChannels() ([]*channeldb.OpenChannel,
|
|||||||
// FetchChannelEdgesByID attempts to lookup the two directed edges for
|
// FetchChannelEdgesByID attempts to lookup the two directed edges for
|
||||||
// the channel identified by the channel ID.
|
// the channel identified by the channel ID.
|
||||||
func (h *hopHintsConfigMock) FetchChannelEdgesByID(chanID uint64) (
|
func (h *hopHintsConfigMock) FetchChannelEdgesByID(chanID uint64) (
|
||||||
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy,
|
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
args := h.Mock.Called(chanID)
|
args := h.Mock.Called(chanID)
|
||||||
|
|
||||||
@ -64,9 +65,9 @@ func (h *hopHintsConfigMock) FetchChannelEdgesByID(chanID uint64) (
|
|||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
edgeInfo := args.Get(0).(*channeldb.ChannelEdgeInfo)
|
edgeInfo := args.Get(0).(*models.ChannelEdgeInfo)
|
||||||
policy1 := args.Get(1).(*channeldb.ChannelEdgePolicy)
|
policy1 := args.Get(1).(*models.ChannelEdgePolicy)
|
||||||
policy2 := args.Get(2).(*channeldb.ChannelEdgePolicy)
|
policy2 := args.Get(2).(*models.ChannelEdgePolicy)
|
||||||
|
|
||||||
return edgeInfo, policy1, policy2, err
|
return edgeInfo, policy1, policy2, err
|
||||||
}
|
}
|
||||||
@ -215,9 +216,9 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
@ -253,9 +254,9 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
alias := lnwire.ShortChannelID{TxPosition: 5}
|
alias := lnwire.ShortChannelID{TxPosition: 5}
|
||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
@ -294,15 +295,15 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{
|
&models.ChannelEdgeInfo{
|
||||||
NodeKey1Bytes: selectedPolicy,
|
NodeKey1Bytes: selectedPolicy,
|
||||||
},
|
},
|
||||||
&channeldb.ChannelEdgePolicy{
|
&models.ChannelEdgePolicy{
|
||||||
FeeBaseMSat: 1000,
|
FeeBaseMSat: 1000,
|
||||||
FeeProportionalMillionths: 20,
|
FeeProportionalMillionths: 20,
|
||||||
TimeLockDelta: 13,
|
TimeLockDelta: 13,
|
||||||
},
|
},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@ -342,9 +343,9 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{
|
&models.ChannelEdgePolicy{
|
||||||
FeeBaseMSat: 1000,
|
FeeBaseMSat: 1000,
|
||||||
FeeProportionalMillionths: 20,
|
FeeProportionalMillionths: 20,
|
||||||
TimeLockDelta: 13,
|
TimeLockDelta: 13,
|
||||||
@ -387,9 +388,9 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{
|
&models.ChannelEdgePolicy{
|
||||||
FeeBaseMSat: 1000,
|
FeeBaseMSat: 1000,
|
||||||
FeeProportionalMillionths: 20,
|
FeeProportionalMillionths: 20,
|
||||||
TimeLockDelta: 13,
|
TimeLockDelta: 13,
|
||||||
@ -554,9 +555,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 1,
|
maxHopHints: 1,
|
||||||
@ -604,9 +605,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 10,
|
maxHopHints: 10,
|
||||||
@ -655,9 +656,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 1,
|
maxHopHints: 1,
|
||||||
@ -688,9 +689,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Prepare the mock for the second channel.
|
// Prepare the mock for the second channel.
|
||||||
@ -705,9 +706,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 10,
|
maxHopHints: 10,
|
||||||
@ -742,9 +743,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Prepare the mock for the second channel.
|
// Prepare the mock for the second channel.
|
||||||
@ -759,9 +760,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 10,
|
maxHopHints: 10,
|
||||||
@ -797,9 +798,9 @@ var populateHopHintsTestCases = []struct {
|
|||||||
h.Mock.On(
|
h.Mock.On(
|
||||||
"FetchChannelEdgesByID", mock.Anything,
|
"FetchChannelEdgesByID", mock.Anything,
|
||||||
).Once().Return(
|
).Once().Return(
|
||||||
&channeldb.ChannelEdgeInfo{},
|
&models.ChannelEdgeInfo{},
|
||||||
&channeldb.ChannelEdgePolicy{},
|
&models.ChannelEdgePolicy{},
|
||||||
&channeldb.ChannelEdgePolicy{}, nil,
|
&models.ChannelEdgePolicy{}, nil,
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
maxHopHints: 1,
|
maxHopHints: 1,
|
||||||
|
@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/feature"
|
"github.com/lightningnetwork/lnd/feature"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
@ -272,7 +273,7 @@ func (r *RouterBackend) parseQueryRoutesRequest(in *lnrpc.QueryRoutesRequest) (
|
|||||||
// inside of the path rather than the request's fields.
|
// inside of the path rather than the request's fields.
|
||||||
var (
|
var (
|
||||||
targetPubKey *route.Vertex
|
targetPubKey *route.Vertex
|
||||||
routeHintEdges map[route.Vertex][]*channeldb.CachedEdgePolicy
|
routeHintEdges map[route.Vertex][]*models.CachedEdgePolicy
|
||||||
blindedPmt *routing.BlindedPayment
|
blindedPmt *routing.BlindedPayment
|
||||||
|
|
||||||
// finalCLTVDelta varies depending on whether we're sending to
|
// finalCLTVDelta varies depending on whether we're sending to
|
||||||
|
@ -14,6 +14,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/netann"
|
"github.com/lightningnetwork/lnd/netann"
|
||||||
@ -65,8 +66,8 @@ func createChannel(t *testing.T) *channeldb.OpenChannel {
|
|||||||
// our `pubkey` with the direction bit set appropriately in the policies. Our
|
// our `pubkey` with the direction bit set appropriately in the policies. Our
|
||||||
// update will be created with the disabled bit set if startEnabled is false.
|
// update will be created with the disabled bit set if startEnabled is false.
|
||||||
func createEdgePolicies(t *testing.T, channel *channeldb.OpenChannel,
|
func createEdgePolicies(t *testing.T, channel *channeldb.OpenChannel,
|
||||||
pubkey *btcec.PublicKey, startEnabled bool) (*channeldb.ChannelEdgeInfo,
|
pubkey *btcec.PublicKey, startEnabled bool) (*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy) {
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
pubkey1 [33]byte
|
pubkey1 [33]byte
|
||||||
@ -98,18 +99,18 @@ func createEdgePolicies(t *testing.T, channel *channeldb.OpenChannel,
|
|||||||
// bit.
|
// bit.
|
||||||
dir2 |= lnwire.ChanUpdateDirection
|
dir2 |= lnwire.ChanUpdateDirection
|
||||||
|
|
||||||
return &channeldb.ChannelEdgeInfo{
|
return &models.ChannelEdgeInfo{
|
||||||
ChannelPoint: channel.FundingOutpoint,
|
ChannelPoint: channel.FundingOutpoint,
|
||||||
NodeKey1Bytes: pubkey1,
|
NodeKey1Bytes: pubkey1,
|
||||||
NodeKey2Bytes: pubkey2,
|
NodeKey2Bytes: pubkey2,
|
||||||
},
|
},
|
||||||
&channeldb.ChannelEdgePolicy{
|
&models.ChannelEdgePolicy{
|
||||||
ChannelID: channel.ShortChanID().ToUint64(),
|
ChannelID: channel.ShortChanID().ToUint64(),
|
||||||
ChannelFlags: dir1,
|
ChannelFlags: dir1,
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
SigBytes: testSigBytes,
|
SigBytes: testSigBytes,
|
||||||
},
|
},
|
||||||
&channeldb.ChannelEdgePolicy{
|
&models.ChannelEdgePolicy{
|
||||||
ChannelID: channel.ShortChanID().ToUint64(),
|
ChannelID: channel.ShortChanID().ToUint64(),
|
||||||
ChannelFlags: dir2,
|
ChannelFlags: dir2,
|
||||||
LastUpdate: time.Now(),
|
LastUpdate: time.Now(),
|
||||||
@ -120,9 +121,9 @@ func createEdgePolicies(t *testing.T, channel *channeldb.OpenChannel,
|
|||||||
type mockGraph struct {
|
type mockGraph struct {
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
channels []*channeldb.OpenChannel
|
channels []*channeldb.OpenChannel
|
||||||
chanInfos map[wire.OutPoint]*channeldb.ChannelEdgeInfo
|
chanInfos map[wire.OutPoint]*models.ChannelEdgeInfo
|
||||||
chanPols1 map[wire.OutPoint]*channeldb.ChannelEdgePolicy
|
chanPols1 map[wire.OutPoint]*models.ChannelEdgePolicy
|
||||||
chanPols2 map[wire.OutPoint]*channeldb.ChannelEdgePolicy
|
chanPols2 map[wire.OutPoint]*models.ChannelEdgePolicy
|
||||||
sidToCid map[lnwire.ShortChannelID]wire.OutPoint
|
sidToCid map[lnwire.ShortChannelID]wire.OutPoint
|
||||||
|
|
||||||
updates chan *lnwire.ChannelUpdate
|
updates chan *lnwire.ChannelUpdate
|
||||||
@ -133,9 +134,9 @@ func newMockGraph(t *testing.T, numChannels int,
|
|||||||
|
|
||||||
g := &mockGraph{
|
g := &mockGraph{
|
||||||
channels: make([]*channeldb.OpenChannel, 0, numChannels),
|
channels: make([]*channeldb.OpenChannel, 0, numChannels),
|
||||||
chanInfos: make(map[wire.OutPoint]*channeldb.ChannelEdgeInfo),
|
chanInfos: make(map[wire.OutPoint]*models.ChannelEdgeInfo),
|
||||||
chanPols1: make(map[wire.OutPoint]*channeldb.ChannelEdgePolicy),
|
chanPols1: make(map[wire.OutPoint]*models.ChannelEdgePolicy),
|
||||||
chanPols2: make(map[wire.OutPoint]*channeldb.ChannelEdgePolicy),
|
chanPols2: make(map[wire.OutPoint]*models.ChannelEdgePolicy),
|
||||||
sidToCid: make(map[lnwire.ShortChannelID]wire.OutPoint),
|
sidToCid: make(map[lnwire.ShortChannelID]wire.OutPoint),
|
||||||
updates: make(chan *lnwire.ChannelUpdate, 2*numChannels),
|
updates: make(chan *lnwire.ChannelUpdate, 2*numChannels),
|
||||||
}
|
}
|
||||||
@ -159,8 +160,8 @@ func (g *mockGraph) FetchAllOpenChannels() ([]*channeldb.OpenChannel, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *mockGraph) FetchChannelEdgesByOutpoint(
|
func (g *mockGraph) FetchChannelEdgesByOutpoint(
|
||||||
op *wire.OutPoint) (*channeldb.ChannelEdgeInfo,
|
op *wire.OutPoint) (*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
@ -209,7 +210,7 @@ func (g *mockGraph) ApplyChannelUpdate(update *lnwire.ChannelUpdate,
|
|||||||
|
|
||||||
timestamp := time.Unix(int64(update.Timestamp), 0)
|
timestamp := time.Unix(int64(update.Timestamp), 0)
|
||||||
|
|
||||||
policy := &channeldb.ChannelEdgePolicy{
|
policy := &models.ChannelEdgePolicy{
|
||||||
ChannelID: update.ShortChannelID.ToUint64(),
|
ChannelID: update.ShortChannelID.ToUint64(),
|
||||||
ChannelFlags: update.ChannelFlags,
|
ChannelFlags: update.ChannelFlags,
|
||||||
LastUpdate: timestamp,
|
LastUpdate: timestamp,
|
||||||
@ -247,8 +248,8 @@ func (g *mockGraph) addChannel(channel *channeldb.OpenChannel) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *mockGraph) addEdgePolicy(c *channeldb.OpenChannel,
|
func (g *mockGraph) addEdgePolicy(c *channeldb.OpenChannel,
|
||||||
info *channeldb.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
pol1, pol2 *channeldb.ChannelEdgePolicy) {
|
pol1, pol2 *models.ChannelEdgePolicy) {
|
||||||
|
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
defer g.mu.Unlock()
|
defer g.mu.Unlock()
|
||||||
|
@ -3,7 +3,7 @@ package netann
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -12,9 +12,9 @@ import (
|
|||||||
// function is used to transform out database structs into the corresponding wire
|
// function is used to transform out database structs into the corresponding wire
|
||||||
// structs for announcing new channels to other peers, or simply syncing up a
|
// structs for announcing new channels to other peers, or simply syncing up a
|
||||||
// peer's initial routing table upon connect.
|
// peer's initial routing table upon connect.
|
||||||
func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
|
func CreateChanAnnouncement(chanProof *models.ChannelAuthProof,
|
||||||
chanInfo *channeldb.ChannelEdgeInfo,
|
chanInfo *models.ChannelEdgeInfo,
|
||||||
e1, e2 *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
e1, e2 *models.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
||||||
*lnwire.ChannelUpdate, *lnwire.ChannelUpdate, error) {
|
*lnwire.ChannelUpdate, *lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
// First, using the parameters of the channel, along with the channel
|
// First, using the parameters of the channel, along with the channel
|
||||||
|
@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -39,13 +39,13 @@ func TestCreateChanAnnouncement(t *testing.T) {
|
|||||||
ExtraOpaqueData: []byte{0x1},
|
ExtraOpaqueData: []byte{0x1},
|
||||||
}
|
}
|
||||||
|
|
||||||
chanProof := &channeldb.ChannelAuthProof{
|
chanProof := &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: expChanAnn.NodeSig1.ToSignatureBytes(),
|
NodeSig1Bytes: expChanAnn.NodeSig1.ToSignatureBytes(),
|
||||||
NodeSig2Bytes: expChanAnn.NodeSig2.ToSignatureBytes(),
|
NodeSig2Bytes: expChanAnn.NodeSig2.ToSignatureBytes(),
|
||||||
BitcoinSig1Bytes: expChanAnn.BitcoinSig1.ToSignatureBytes(),
|
BitcoinSig1Bytes: expChanAnn.BitcoinSig1.ToSignatureBytes(),
|
||||||
BitcoinSig2Bytes: expChanAnn.BitcoinSig2.ToSignatureBytes(),
|
BitcoinSig2Bytes: expChanAnn.BitcoinSig2.ToSignatureBytes(),
|
||||||
}
|
}
|
||||||
chanInfo := &channeldb.ChannelEdgeInfo{
|
chanInfo := &models.ChannelEdgeInfo{
|
||||||
ChainHash: expChanAnn.ChainHash,
|
ChainHash: expChanAnn.ChainHash,
|
||||||
ChannelID: expChanAnn.ShortChannelID.ToUint64(),
|
ChannelID: expChanAnn.ShortChannelID.ToUint64(),
|
||||||
ChannelPoint: wire.OutPoint{Index: 1},
|
ChannelPoint: wire.OutPoint{Index: 1},
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/keychain"
|
"github.com/lightningnetwork/lnd/keychain"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -84,12 +84,12 @@ func SignChannelUpdate(signer lnwallet.MessageSigner, keyLoc keychain.KeyLocator
|
|||||||
//
|
//
|
||||||
// NOTE: The passed policies can be nil.
|
// NOTE: The passed policies can be nil.
|
||||||
func ExtractChannelUpdate(ownerPubKey []byte,
|
func ExtractChannelUpdate(ownerPubKey []byte,
|
||||||
info *channeldb.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
policies ...*channeldb.ChannelEdgePolicy) (
|
policies ...*models.ChannelEdgePolicy) (
|
||||||
*lnwire.ChannelUpdate, error) {
|
*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
// Helper function to extract the owner of the given policy.
|
// Helper function to extract the owner of the given policy.
|
||||||
owner := func(edge *channeldb.ChannelEdgePolicy) []byte {
|
owner := func(edge *models.ChannelEdgePolicy) []byte {
|
||||||
var pubKey *btcec.PublicKey
|
var pubKey *btcec.PublicKey
|
||||||
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
if edge.ChannelFlags&lnwire.ChanUpdateDirection == 0 {
|
||||||
pubKey, _ = info.NodeKey1()
|
pubKey, _ = info.NodeKey1()
|
||||||
@ -117,8 +117,8 @@ func ExtractChannelUpdate(ownerPubKey []byte,
|
|||||||
|
|
||||||
// UnsignedChannelUpdateFromEdge reconstructs an unsigned ChannelUpdate from the
|
// UnsignedChannelUpdateFromEdge reconstructs an unsigned ChannelUpdate from the
|
||||||
// given edge info and policy.
|
// given edge info and policy.
|
||||||
func UnsignedChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
func UnsignedChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
|
||||||
policy *channeldb.ChannelEdgePolicy) *lnwire.ChannelUpdate {
|
policy *models.ChannelEdgePolicy) *lnwire.ChannelUpdate {
|
||||||
|
|
||||||
return &lnwire.ChannelUpdate{
|
return &lnwire.ChannelUpdate{
|
||||||
ChainHash: info.ChainHash,
|
ChainHash: info.ChainHash,
|
||||||
@ -137,8 +137,8 @@ func UnsignedChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
|||||||
|
|
||||||
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
// ChannelUpdateFromEdge reconstructs a signed ChannelUpdate from the given edge
|
||||||
// info and policy.
|
// info and policy.
|
||||||
func ChannelUpdateFromEdge(info *channeldb.ChannelEdgeInfo,
|
func ChannelUpdateFromEdge(info *models.ChannelEdgeInfo,
|
||||||
policy *channeldb.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
policy *models.ChannelEdgePolicy) (*lnwire.ChannelUpdate, error) {
|
||||||
|
|
||||||
update := UnsignedChannelUpdateFromEdge(info, policy)
|
update := UnsignedChannelUpdateFromEdge(info, policy)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package netann
|
|||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DB abstracts the required database functionality needed by the
|
// DB abstracts the required database functionality needed by the
|
||||||
@ -18,6 +19,6 @@ type DB interface {
|
|||||||
type ChannelGraph interface {
|
type ChannelGraph interface {
|
||||||
// FetchChannelEdgesByOutpoint returns the channel edge info and most
|
// FetchChannelEdgesByOutpoint returns the channel edge info and most
|
||||||
// recent channel edge policies for a given outpoint.
|
// recent channel edge policies for a given outpoint.
|
||||||
FetchChannelEdgesByOutpoint(*wire.OutPoint) (*channeldb.ChannelEdgeInfo,
|
FetchChannelEdgesByOutpoint(*wire.OutPoint) (*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy, error)
|
*models.ChannelEdgePolicy, *models.ChannelEdgePolicy, error)
|
||||||
}
|
}
|
||||||
|
@ -933,7 +933,7 @@ func (p *Brontide) loadActiveChannels(chans []*channeldb.OpenChannel) (
|
|||||||
//
|
//
|
||||||
// TODO(roasbeef): can add helper method to get policy for
|
// TODO(roasbeef): can add helper method to get policy for
|
||||||
// particular channel.
|
// particular channel.
|
||||||
var selfPolicy *channeldb.ChannelEdgePolicy
|
var selfPolicy *models.ChannelEdgePolicy
|
||||||
if info != nil && bytes.Equal(info.NodeKey1Bytes[:],
|
if info != nil && bytes.Equal(info.NodeKey1Bytes[:],
|
||||||
p.cfg.ServerPubKey[:]) {
|
p.cfg.ServerPubKey[:]) {
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -99,7 +99,7 @@ func (b *BlindedPayment) toRouteHints() RouteHints {
|
|||||||
|
|
||||||
hintCount := len(b.BlindedPath.BlindedHops) - 1
|
hintCount := len(b.BlindedPath.BlindedHops) - 1
|
||||||
hints := make(
|
hints := make(
|
||||||
map[route.Vertex][]*channeldb.CachedEdgePolicy, hintCount,
|
map[route.Vertex][]*models.CachedEdgePolicy, hintCount,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start at the unblinded introduction node, because our pathfinding
|
// Start at the unblinded introduction node, because our pathfinding
|
||||||
@ -116,7 +116,7 @@ func (b *BlindedPayment) toRouteHints() RouteHints {
|
|||||||
// will ensure that pathfinding provides sufficient fees/delay for the
|
// will ensure that pathfinding provides sufficient fees/delay for the
|
||||||
// blinded portion to the introduction node.
|
// blinded portion to the introduction node.
|
||||||
firstBlindedHop := b.BlindedPath.BlindedHops[1].BlindedNodePub
|
firstBlindedHop := b.BlindedPath.BlindedHops[1].BlindedNodePub
|
||||||
hints[fromNode] = []*channeldb.CachedEdgePolicy{
|
hints[fromNode] = []*models.CachedEdgePolicy{
|
||||||
{
|
{
|
||||||
TimeLockDelta: b.CltvExpiryDelta,
|
TimeLockDelta: b.CltvExpiryDelta,
|
||||||
MinHTLC: lnwire.MilliSatoshi(b.HtlcMinimum),
|
MinHTLC: lnwire.MilliSatoshi(b.HtlcMinimum),
|
||||||
@ -156,14 +156,14 @@ func (b *BlindedPayment) toRouteHints() RouteHints {
|
|||||||
b.BlindedPath.BlindedHops[nextHopIdx].BlindedNodePub,
|
b.BlindedPath.BlindedHops[nextHopIdx].BlindedNodePub,
|
||||||
)
|
)
|
||||||
|
|
||||||
hint := &channeldb.CachedEdgePolicy{
|
hint := &models.CachedEdgePolicy{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return nextNode
|
return nextNode
|
||||||
},
|
},
|
||||||
ToNodeFeatures: features,
|
ToNodeFeatures: features,
|
||||||
}
|
}
|
||||||
|
|
||||||
hints[fromNode] = []*channeldb.CachedEdgePolicy{
|
hints[fromNode] = []*models.CachedEdgePolicy{
|
||||||
hint,
|
hint,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"container/heap"
|
"container/heap"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -39,7 +39,7 @@ type nodeWithDist struct {
|
|||||||
weight int64
|
weight int64
|
||||||
|
|
||||||
// nextHop is the edge this route comes from.
|
// nextHop is the edge this route comes from.
|
||||||
nextHop *channeldb.CachedEdgePolicy
|
nextHop *models.CachedEdgePolicy
|
||||||
|
|
||||||
// routingInfoSize is the total size requirement for the payloads field
|
// routingInfoSize is the total size requirement for the payloads field
|
||||||
// in the onion packet from this hop towards the final destination.
|
// in the onion packet from this hop towards the final destination.
|
||||||
|
@ -31,8 +31,8 @@ type Manager struct {
|
|||||||
// ForAllOutgoingChannels is required to iterate over all our local
|
// ForAllOutgoingChannels is required to iterate over all our local
|
||||||
// channels.
|
// channels.
|
||||||
ForAllOutgoingChannels func(cb func(kvdb.RTx,
|
ForAllOutgoingChannels func(cb func(kvdb.RTx,
|
||||||
*channeldb.ChannelEdgeInfo,
|
*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy) error) error
|
*models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
// FetchChannel is used to query local channel parameters. Optionally an
|
// FetchChannel is used to query local channel parameters. Optionally an
|
||||||
// existing db tx can be supplied.
|
// existing db tx can be supplied.
|
||||||
@ -73,8 +73,8 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
|
|||||||
// otherwise we'll collect them all.
|
// otherwise we'll collect them all.
|
||||||
err := r.ForAllOutgoingChannels(func(
|
err := r.ForAllOutgoingChannels(func(
|
||||||
tx kvdb.RTx,
|
tx kvdb.RTx,
|
||||||
info *channeldb.ChannelEdgeInfo,
|
info *models.ChannelEdgeInfo,
|
||||||
edge *channeldb.ChannelEdgePolicy) error {
|
edge *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// If we have a channel filter, and this channel isn't a part
|
// If we have a channel filter, and this channel isn't a part
|
||||||
// of it, then we'll skip it.
|
// of it, then we'll skip it.
|
||||||
@ -172,7 +172,7 @@ func (r *Manager) UpdatePolicy(newSchema routing.ChannelPolicy,
|
|||||||
|
|
||||||
// updateEdge updates the given edge with the new schema.
|
// updateEdge updates the given edge with the new schema.
|
||||||
func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint,
|
func (r *Manager) updateEdge(tx kvdb.RTx, chanPoint wire.OutPoint,
|
||||||
edge *channeldb.ChannelEdgePolicy,
|
edge *models.ChannelEdgePolicy,
|
||||||
newSchema routing.ChannelPolicy) error {
|
newSchema routing.ChannelPolicy) error {
|
||||||
|
|
||||||
// Update forwarding fee scheme and required time lock delta.
|
// Update forwarding fee scheme and required time lock delta.
|
||||||
|
@ -22,7 +22,7 @@ func TestManager(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
type channel struct {
|
type channel struct {
|
||||||
edgeInfo *channeldb.ChannelEdgeInfo
|
edgeInfo *models.ChannelEdgeInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -44,7 +44,7 @@ func TestManager(t *testing.T) {
|
|||||||
MaxHTLC: 5000,
|
MaxHTLC: 5000,
|
||||||
}
|
}
|
||||||
|
|
||||||
currentPolicy := channeldb.ChannelEdgePolicy{
|
currentPolicy := models.ChannelEdgePolicy{
|
||||||
MinHTLC: minHTLC,
|
MinHTLC: minHTLC,
|
||||||
MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
|
MessageFlags: lnwire.ChanUpdateRequiredMaxHtlc,
|
||||||
}
|
}
|
||||||
@ -107,8 +107,8 @@ func TestManager(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
forAllOutgoingChannels := func(cb func(kvdb.RTx,
|
forAllOutgoingChannels := func(cb func(kvdb.RTx,
|
||||||
*channeldb.ChannelEdgeInfo,
|
*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
for _, c := range channelSet {
|
for _, c := range channelSet {
|
||||||
if err := cb(nil, c.edgeInfo, ¤tPolicy); err != nil {
|
if err := cb(nil, c.edgeInfo, ¤tPolicy); err != nil {
|
||||||
@ -152,7 +152,7 @@ func TestManager(t *testing.T) {
|
|||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
currentPolicy channeldb.ChannelEdgePolicy
|
currentPolicy models.ChannelEdgePolicy
|
||||||
newPolicy routing.ChannelPolicy
|
newPolicy routing.ChannelPolicy
|
||||||
channelSet []channel
|
channelSet []channel
|
||||||
specifiedChanPoints []wire.OutPoint
|
specifiedChanPoints []wire.OutPoint
|
||||||
@ -166,7 +166,7 @@ func TestManager(t *testing.T) {
|
|||||||
newPolicy: newPolicy,
|
newPolicy: newPolicy,
|
||||||
channelSet: []channel{
|
channelSet: []channel{
|
||||||
{
|
{
|
||||||
edgeInfo: &channeldb.ChannelEdgeInfo{
|
edgeInfo: &models.ChannelEdgeInfo{
|
||||||
Capacity: chanCap,
|
Capacity: chanCap,
|
||||||
ChannelPoint: chanPointValid,
|
ChannelPoint: chanPointValid,
|
||||||
},
|
},
|
||||||
@ -183,7 +183,7 @@ func TestManager(t *testing.T) {
|
|||||||
newPolicy: newPolicy,
|
newPolicy: newPolicy,
|
||||||
channelSet: []channel{
|
channelSet: []channel{
|
||||||
{
|
{
|
||||||
edgeInfo: &channeldb.ChannelEdgeInfo{
|
edgeInfo: &models.ChannelEdgeInfo{
|
||||||
Capacity: chanCap,
|
Capacity: chanCap,
|
||||||
ChannelPoint: chanPointValid,
|
ChannelPoint: chanPointValid,
|
||||||
},
|
},
|
||||||
@ -200,7 +200,7 @@ func TestManager(t *testing.T) {
|
|||||||
newPolicy: newPolicy,
|
newPolicy: newPolicy,
|
||||||
channelSet: []channel{
|
channelSet: []channel{
|
||||||
{
|
{
|
||||||
edgeInfo: &channeldb.ChannelEdgeInfo{
|
edgeInfo: &models.ChannelEdgeInfo{
|
||||||
Capacity: chanCap,
|
Capacity: chanCap,
|
||||||
ChannelPoint: chanPointValid,
|
ChannelPoint: chanPointValid,
|
||||||
},
|
},
|
||||||
@ -221,7 +221,7 @@ func TestManager(t *testing.T) {
|
|||||||
newPolicy: noMaxHtlcPolicy,
|
newPolicy: noMaxHtlcPolicy,
|
||||||
channelSet: []channel{
|
channelSet: []channel{
|
||||||
{
|
{
|
||||||
edgeInfo: &channeldb.ChannelEdgeInfo{
|
edgeInfo: &models.ChannelEdgeInfo{
|
||||||
Capacity: chanCap,
|
Capacity: chanCap,
|
||||||
ChannelPoint: chanPointValid,
|
ChannelPoint: chanPointValid,
|
||||||
},
|
},
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -193,7 +194,7 @@ func (m *mockGraph) forEachNodeChannel(nodePub route.Vertex,
|
|||||||
OtherNode: peer,
|
OtherNode: peer,
|
||||||
Capacity: channel.capacity,
|
Capacity: channel.capacity,
|
||||||
OutPolicySet: true,
|
OutPolicySet: true,
|
||||||
InPolicy: &channeldb.CachedEdgePolicy{
|
InPolicy: &models.CachedEdgePolicy{
|
||||||
ChannelID: channel.id,
|
ChannelID: channel.id,
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return nodePub
|
return nodePub
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -174,13 +175,13 @@ func (m *mockPaymentSessionOld) RequestRoute(_, _ lnwire.MilliSatoshi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPaymentSessionOld) UpdateAdditionalEdge(_ *lnwire.ChannelUpdate,
|
func (m *mockPaymentSessionOld) UpdateAdditionalEdge(_ *lnwire.ChannelUpdate,
|
||||||
_ *btcec.PublicKey, _ *channeldb.CachedEdgePolicy) bool {
|
_ *btcec.PublicKey, _ *models.CachedEdgePolicy) bool {
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPaymentSessionOld) GetAdditionalEdgePolicy(_ *btcec.PublicKey,
|
func (m *mockPaymentSessionOld) GetAdditionalEdgePolicy(_ *btcec.PublicKey,
|
||||||
_ uint64) *channeldb.CachedEdgePolicy {
|
_ uint64) *models.CachedEdgePolicy {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -676,17 +677,17 @@ func (m *mockPaymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPaymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate,
|
func (m *mockPaymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate,
|
||||||
pubKey *btcec.PublicKey, policy *channeldb.CachedEdgePolicy) bool {
|
pubKey *btcec.PublicKey, policy *models.CachedEdgePolicy) bool {
|
||||||
|
|
||||||
args := m.Called(msg, pubKey, policy)
|
args := m.Called(msg, pubKey, policy)
|
||||||
return args.Bool(0)
|
return args.Bool(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mockPaymentSession) GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
func (m *mockPaymentSession) GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
||||||
channelID uint64) *channeldb.CachedEdgePolicy {
|
channelID uint64) *models.CachedEdgePolicy {
|
||||||
|
|
||||||
args := m.Called(pubKey, channelID)
|
args := m.Called(pubKey, channelID)
|
||||||
return args.Get(0).(*channeldb.CachedEdgePolicy)
|
return args.Get(0).(*models.CachedEdgePolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
type mockControlTower struct {
|
type mockControlTower struct {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -212,7 +213,7 @@ type ClosedChanSummary struct {
|
|||||||
// createCloseSummaries takes in a slice of channels closed at the target block
|
// createCloseSummaries takes in a slice of channels closed at the target block
|
||||||
// height and creates a slice of summaries which of each channel closure.
|
// height and creates a slice of summaries which of each channel closure.
|
||||||
func createCloseSummaries(blockHeight uint32,
|
func createCloseSummaries(blockHeight uint32,
|
||||||
closedChans ...*channeldb.ChannelEdgeInfo) []*ClosedChanSummary {
|
closedChans ...*models.ChannelEdgeInfo) []*ClosedChanSummary {
|
||||||
|
|
||||||
closeSummaries := make([]*ClosedChanSummary, len(closedChans))
|
closeSummaries := make([]*ClosedChanSummary, len(closedChans))
|
||||||
for i, closedChan := range closedChans {
|
for i, closedChan := range closedChans {
|
||||||
@ -333,12 +334,12 @@ func addToTopologyChange(graph *channeldb.ChannelGraph, update *TopologyChange,
|
|||||||
|
|
||||||
// We ignore initial channel announcements as we'll only send out
|
// We ignore initial channel announcements as we'll only send out
|
||||||
// updates once the individual edges themselves have been updated.
|
// updates once the individual edges themselves have been updated.
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *models.ChannelEdgeInfo:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
// Any new ChannelUpdateAnnouncements will generate a corresponding
|
// Any new ChannelUpdateAnnouncements will generate a corresponding
|
||||||
// ChannelEdgeUpdate notification.
|
// ChannelEdgeUpdate notification.
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *models.ChannelEdgePolicy:
|
||||||
// We'll need to fetch the edge's information from the database
|
// We'll need to fetch the edge's information from the database
|
||||||
// in order to get the information concerning which nodes are
|
// in order to get the information concerning which nodes are
|
||||||
// being connected.
|
// being connected.
|
||||||
|
@ -16,6 +16,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
||||||
@ -74,9 +75,9 @@ func createTestNode() (*channeldb.LightningNode, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
func randEdgePolicy(chanID *lnwire.ShortChannelID,
|
||||||
node *channeldb.LightningNode) *channeldb.ChannelEdgePolicy {
|
node *channeldb.LightningNode) *models.ChannelEdgePolicy {
|
||||||
|
|
||||||
return &channeldb.ChannelEdgePolicy{
|
return &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
LastUpdate: time.Unix(int64(prand.Int31()), 0),
|
LastUpdate: time.Unix(int64(prand.Int31()), 0),
|
||||||
@ -431,11 +432,11 @@ func TestEdgeUpdateNotification(t *testing.T) {
|
|||||||
|
|
||||||
// Finally, to conclude our test set up, we'll create a channel
|
// Finally, to conclude our test set up, we'll create a channel
|
||||||
// update to announce the created channel between the two nodes.
|
// update to announce the created channel between the two nodes.
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -469,7 +470,7 @@ func TestEdgeUpdateNotification(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
assertEdgeCorrect := func(t *testing.T, edgeUpdate *ChannelEdgeUpdate,
|
assertEdgeCorrect := func(t *testing.T, edgeUpdate *ChannelEdgeUpdate,
|
||||||
edgeAnn *channeldb.ChannelEdgePolicy) {
|
edgeAnn *models.ChannelEdgePolicy) {
|
||||||
if edgeUpdate.ChanID != edgeAnn.ChannelID {
|
if edgeUpdate.ChanID != edgeAnn.ChannelID {
|
||||||
t.Fatalf("channel ID of edge doesn't match: "+
|
t.Fatalf("channel ID of edge doesn't match: "+
|
||||||
"expected %v, got %v", chanID.ToUint64(), edgeUpdate.ChanID)
|
"expected %v, got %v", chanID.ToUint64(), edgeUpdate.ChanID)
|
||||||
@ -613,11 +614,11 @@ func TestNodeUpdateNotification(t *testing.T) {
|
|||||||
testFeaturesBuf := new(bytes.Buffer)
|
testFeaturesBuf := new(bytes.Buffer)
|
||||||
require.NoError(t, testFeatures.Encode(testFeaturesBuf))
|
require.NoError(t, testFeatures.Encode(testFeaturesBuf))
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -799,11 +800,11 @@ func TestNotificationCancellation(t *testing.T) {
|
|||||||
// to the client.
|
// to the client.
|
||||||
ntfnClient.Cancel()
|
ntfnClient.Cancel()
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -870,11 +871,11 @@ func TestChannelCloseNotification(t *testing.T) {
|
|||||||
|
|
||||||
// Finally, to conclude our test set up, we'll create a channel
|
// Finally, to conclude our test set up, we'll create a channel
|
||||||
// announcement to announce the created channel between the two nodes.
|
// announcement to announce the created channel between the two nodes.
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
|
@ -11,6 +11,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/feature"
|
"github.com/lightningnetwork/lnd/feature"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/record"
|
"github.com/lightningnetwork/lnd/record"
|
||||||
@ -49,7 +50,7 @@ const (
|
|||||||
type pathFinder = func(g *graphParams, r *RestrictParams,
|
type pathFinder = func(g *graphParams, r *RestrictParams,
|
||||||
cfg *PathFindingConfig, source, target route.Vertex,
|
cfg *PathFindingConfig, source, target route.Vertex,
|
||||||
amt lnwire.MilliSatoshi, timePref float64, finalHtlcExpiry int32) (
|
amt lnwire.MilliSatoshi, timePref float64, finalHtlcExpiry int32) (
|
||||||
[]*channeldb.CachedEdgePolicy, float64, error)
|
[]*models.CachedEdgePolicy, float64, error)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultEstimator is the default estimator used for computing
|
// DefaultEstimator is the default estimator used for computing
|
||||||
@ -87,7 +88,7 @@ var (
|
|||||||
// of the edge.
|
// of the edge.
|
||||||
type edgePolicyWithSource struct {
|
type edgePolicyWithSource struct {
|
||||||
sourceNode route.Vertex
|
sourceNode route.Vertex
|
||||||
edge *channeldb.CachedEdgePolicy
|
edge *models.CachedEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// finalHopParams encapsulates various parameters for route construction that
|
// finalHopParams encapsulates various parameters for route construction that
|
||||||
@ -125,7 +126,7 @@ type finalHopParams struct {
|
|||||||
// NOTE: If a non-nil blinded path is provided it is assumed to have been
|
// NOTE: If a non-nil blinded path is provided it is assumed to have been
|
||||||
// validated by the caller.
|
// validated by the caller.
|
||||||
func newRoute(sourceVertex route.Vertex,
|
func newRoute(sourceVertex route.Vertex,
|
||||||
pathEdges []*channeldb.CachedEdgePolicy, currentHeight uint32,
|
pathEdges []*models.CachedEdgePolicy, currentHeight uint32,
|
||||||
finalHop finalHopParams, blindedPath *sphinx.BlindedPath) (
|
finalHop finalHopParams, blindedPath *sphinx.BlindedPath) (
|
||||||
*route.Route, error) {
|
*route.Route, error) {
|
||||||
|
|
||||||
@ -355,7 +356,7 @@ type graphParams struct {
|
|||||||
// additionalEdges is an optional set of edges that should be
|
// additionalEdges is an optional set of edges that should be
|
||||||
// considered during path finding, that is not already found in the
|
// considered during path finding, that is not already found in the
|
||||||
// channel graph.
|
// channel graph.
|
||||||
additionalEdges map[route.Vertex][]*channeldb.CachedEdgePolicy
|
additionalEdges map[route.Vertex][]*models.CachedEdgePolicy
|
||||||
|
|
||||||
// bandwidthHints is an interface that provides bandwidth hints that
|
// bandwidthHints is an interface that provides bandwidth hints that
|
||||||
// can provide a better estimate of the current channel bandwidth than
|
// can provide a better estimate of the current channel bandwidth than
|
||||||
@ -493,7 +494,7 @@ func getOutgoingBalance(node route.Vertex, outgoingChans map[uint64]struct{},
|
|||||||
// available bandwidth.
|
// available bandwidth.
|
||||||
func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
||||||
source, target route.Vertex, amt lnwire.MilliSatoshi, timePref float64,
|
source, target route.Vertex, amt lnwire.MilliSatoshi, timePref float64,
|
||||||
finalHtlcExpiry int32) ([]*channeldb.CachedEdgePolicy, float64, error) {
|
finalHtlcExpiry int32) ([]*models.CachedEdgePolicy, float64, error) {
|
||||||
|
|
||||||
// Pathfinding can be a significant portion of the total payment
|
// Pathfinding can be a significant portion of the total payment
|
||||||
// latency, especially on low-powered devices. Log several metrics to
|
// latency, especially on low-powered devices. Log several metrics to
|
||||||
@ -994,7 +995,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
|
|
||||||
// Use the distance map to unravel the forward path from source to
|
// Use the distance map to unravel the forward path from source to
|
||||||
// target.
|
// target.
|
||||||
var pathEdges []*channeldb.CachedEdgePolicy
|
var pathEdges []*models.CachedEdgePolicy
|
||||||
currentNode := source
|
currentNode := source
|
||||||
for {
|
for {
|
||||||
// Determine the next hop forward using the next map.
|
// Determine the next hop forward using the next map.
|
||||||
|
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/btcsuite/btcd/wire"
|
"github.com/btcsuite/btcd/wire"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/kvdb"
|
"github.com/lightningnetwork/lnd/kvdb"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -96,7 +97,7 @@ var (
|
|||||||
_ = testSScalar.SetByteSlice(testSBytes)
|
_ = testSScalar.SetByteSlice(testSBytes)
|
||||||
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
testSig = ecdsa.NewSignature(testRScalar, testSScalar)
|
||||||
|
|
||||||
testAuthProof = channeldb.ChannelAuthProof{
|
testAuthProof = models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -335,7 +336,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
|
|
||||||
// We first insert the existence of the edge between the two
|
// We first insert the existence of the edge between the two
|
||||||
// nodes.
|
// nodes.
|
||||||
edgeInfo := channeldb.ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
AuthProof: &testAuthProof,
|
AuthProof: &testAuthProof,
|
||||||
ChannelPoint: fundingPoint,
|
ChannelPoint: fundingPoint,
|
||||||
@ -366,7 +367,7 @@ func parseTestGraph(t *testing.T, useCache bool, path string) (
|
|||||||
targetNode = edgeInfo.NodeKey2Bytes
|
targetNode = edgeInfo.NodeKey2Bytes
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
MessageFlags: lnwire.ChanUpdateMsgFlags(edge.MessageFlags),
|
MessageFlags: lnwire.ChanUpdateMsgFlags(edge.MessageFlags),
|
||||||
ChannelFlags: channelFlags,
|
ChannelFlags: channelFlags,
|
||||||
@ -644,7 +645,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
|
|
||||||
// We first insert the existence of the edge between the two
|
// We first insert the existence of the edge between the two
|
||||||
// nodes.
|
// nodes.
|
||||||
edgeInfo := channeldb.ChannelEdgeInfo{
|
edgeInfo := models.ChannelEdgeInfo{
|
||||||
ChannelID: channelID,
|
ChannelID: channelID,
|
||||||
AuthProof: &testAuthProof,
|
AuthProof: &testAuthProof,
|
||||||
ChannelPoint: *fundingPoint,
|
ChannelPoint: *fundingPoint,
|
||||||
@ -671,7 +672,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
channelFlags |= lnwire.ChanUpdateDisabled
|
channelFlags |= lnwire.ChanUpdateDisabled
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
MessageFlags: msgFlags,
|
MessageFlags: msgFlags,
|
||||||
ChannelFlags: channelFlags,
|
ChannelFlags: channelFlags,
|
||||||
@ -700,7 +701,7 @@ func createTestGraphFromChannels(t *testing.T, useCache bool,
|
|||||||
}
|
}
|
||||||
channelFlags |= lnwire.ChanUpdateDirection
|
channelFlags |= lnwire.ChanUpdateDirection
|
||||||
|
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
MessageFlags: msgFlags,
|
MessageFlags: msgFlags,
|
||||||
ChannelFlags: channelFlags,
|
ChannelFlags: channelFlags,
|
||||||
@ -1203,7 +1204,7 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
|
|||||||
|
|
||||||
// Create the channel edge going from songoku to doge and include it in
|
// Create the channel edge going from songoku to doge and include it in
|
||||||
// our map of additional edges.
|
// our map of additional edges.
|
||||||
songokuToDoge := &channeldb.CachedEdgePolicy{
|
songokuToDoge := &models.CachedEdgePolicy{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return doge.PubKeyBytes
|
return doge.PubKeyBytes
|
||||||
},
|
},
|
||||||
@ -1214,12 +1215,12 @@ func runPathFindingWithAdditionalEdges(t *testing.T, useCache bool) {
|
|||||||
TimeLockDelta: 9,
|
TimeLockDelta: 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
additionalEdges := map[route.Vertex][]*channeldb.CachedEdgePolicy{
|
additionalEdges := map[route.Vertex][]*models.CachedEdgePolicy{
|
||||||
graph.aliasMap["songoku"]: {songokuToDoge},
|
graph.aliasMap["songoku"]: {songokuToDoge},
|
||||||
}
|
}
|
||||||
|
|
||||||
find := func(r *RestrictParams) (
|
find := func(r *RestrictParams) (
|
||||||
[]*channeldb.CachedEdgePolicy, error) {
|
[]*models.CachedEdgePolicy, error) {
|
||||||
|
|
||||||
return dbFindPath(
|
return dbFindPath(
|
||||||
graph.graph, additionalEdges, &mockBandwidthHints{},
|
graph.graph, additionalEdges, &mockBandwidthHints{},
|
||||||
@ -1289,7 +1290,7 @@ func runPathFindingWithRedundantAdditionalEdges(t *testing.T, useCache bool) {
|
|||||||
|
|
||||||
// Create the channel edge going from alice to bob and include it in
|
// Create the channel edge going from alice to bob and include it in
|
||||||
// our map of additional edges.
|
// our map of additional edges.
|
||||||
aliceToBob := &channeldb.CachedEdgePolicy{
|
aliceToBob := &models.CachedEdgePolicy{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return target
|
return target
|
||||||
},
|
},
|
||||||
@ -1300,7 +1301,7 @@ func runPathFindingWithRedundantAdditionalEdges(t *testing.T, useCache bool) {
|
|||||||
TimeLockDelta: 9,
|
TimeLockDelta: 9,
|
||||||
}
|
}
|
||||||
|
|
||||||
additionalEdges := map[route.Vertex][]*channeldb.CachedEdgePolicy{
|
additionalEdges := map[route.Vertex][]*models.CachedEdgePolicy{
|
||||||
ctx.source: {aliceToBob},
|
ctx.source: {aliceToBob},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1334,9 +1335,9 @@ func TestNewRoute(t *testing.T) {
|
|||||||
createHop := func(baseFee lnwire.MilliSatoshi,
|
createHop := func(baseFee lnwire.MilliSatoshi,
|
||||||
feeRate lnwire.MilliSatoshi,
|
feeRate lnwire.MilliSatoshi,
|
||||||
bandwidth lnwire.MilliSatoshi,
|
bandwidth lnwire.MilliSatoshi,
|
||||||
timeLockDelta uint16) *channeldb.CachedEdgePolicy {
|
timeLockDelta uint16) *models.CachedEdgePolicy {
|
||||||
|
|
||||||
return &channeldb.CachedEdgePolicy{
|
return &models.CachedEdgePolicy{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return route.Vertex{}
|
return route.Vertex{}
|
||||||
},
|
},
|
||||||
@ -1353,7 +1354,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
|
|
||||||
// hops is the list of hops (the route) that gets passed into
|
// hops is the list of hops (the route) that gets passed into
|
||||||
// the call to newRoute.
|
// the call to newRoute.
|
||||||
hops []*channeldb.CachedEdgePolicy
|
hops []*models.CachedEdgePolicy
|
||||||
|
|
||||||
// paymentAmount is the amount that is send into the route
|
// paymentAmount is the amount that is send into the route
|
||||||
// indicated by hops.
|
// indicated by hops.
|
||||||
@ -1405,7 +1406,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
// For a single hop payment, no fees are expected to be paid.
|
// For a single hop payment, no fees are expected to be paid.
|
||||||
name: "single hop",
|
name: "single hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(100, 1000, 1000000, 10),
|
createHop(100, 1000, 1000000, 10),
|
||||||
},
|
},
|
||||||
metadata: []byte{1, 2, 3},
|
metadata: []byte{1, 2, 3},
|
||||||
@ -1419,7 +1420,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
// a fee to receive the payment.
|
// a fee to receive the payment.
|
||||||
name: "two hop",
|
name: "two hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 1000, 1000000, 10),
|
createHop(0, 1000, 1000000, 10),
|
||||||
createHop(30, 1000, 1000000, 5),
|
createHop(30, 1000, 1000000, 5),
|
||||||
},
|
},
|
||||||
@ -1434,7 +1435,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
name: "two hop tlv onion feature",
|
name: "two hop tlv onion feature",
|
||||||
destFeatures: tlvFeatures,
|
destFeatures: tlvFeatures,
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 1000, 1000000, 10),
|
createHop(0, 1000, 1000000, 10),
|
||||||
createHop(30, 1000, 1000000, 5),
|
createHop(30, 1000, 1000000, 5),
|
||||||
},
|
},
|
||||||
@ -1451,7 +1452,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
destFeatures: tlvPayAddrFeatures,
|
destFeatures: tlvPayAddrFeatures,
|
||||||
paymentAddr: &testPaymentAddr,
|
paymentAddr: &testPaymentAddr,
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 1000, 1000000, 10),
|
createHop(0, 1000, 1000000, 10),
|
||||||
createHop(30, 1000, 1000000, 5),
|
createHop(30, 1000, 1000000, 5),
|
||||||
},
|
},
|
||||||
@ -1471,7 +1472,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
// gets rounded down to 1.
|
// gets rounded down to 1.
|
||||||
name: "three hop",
|
name: "three hop",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 10, 1000000, 10),
|
createHop(0, 10, 1000000, 10),
|
||||||
createHop(0, 10, 1000000, 5),
|
createHop(0, 10, 1000000, 5),
|
||||||
createHop(0, 10, 1000000, 3),
|
createHop(0, 10, 1000000, 3),
|
||||||
@ -1486,7 +1487,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
// because of the increase amount to forward.
|
// because of the increase amount to forward.
|
||||||
name: "three hop with fee carry over",
|
name: "three hop with fee carry over",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 10000, 1000000, 10),
|
createHop(0, 10000, 1000000, 10),
|
||||||
createHop(0, 10000, 1000000, 5),
|
createHop(0, 10000, 1000000, 5),
|
||||||
createHop(0, 10000, 1000000, 3),
|
createHop(0, 10000, 1000000, 3),
|
||||||
@ -1501,7 +1502,7 @@ func TestNewRoute(t *testing.T) {
|
|||||||
// effect.
|
// effect.
|
||||||
name: "three hop with minimal fees for carry over",
|
name: "three hop with minimal fees for carry over",
|
||||||
paymentAmount: 100000,
|
paymentAmount: 100000,
|
||||||
hops: []*channeldb.CachedEdgePolicy{
|
hops: []*models.CachedEdgePolicy{
|
||||||
createHop(0, 10000, 1000000, 10),
|
createHop(0, 10000, 1000000, 10),
|
||||||
|
|
||||||
// First hop charges 0.1% so the second hop fee
|
// First hop charges 0.1% so the second hop fee
|
||||||
@ -1740,7 +1741,7 @@ func runDestTLVGraphFallback(t *testing.T, useCache bool) {
|
|||||||
require.NoError(t, err, "unable to fetch source node")
|
require.NoError(t, err, "unable to fetch source node")
|
||||||
|
|
||||||
find := func(r *RestrictParams,
|
find := func(r *RestrictParams,
|
||||||
target route.Vertex) ([]*channeldb.CachedEdgePolicy, error) {
|
target route.Vertex) ([]*models.CachedEdgePolicy, error) {
|
||||||
|
|
||||||
return dbFindPath(
|
return dbFindPath(
|
||||||
ctx.graph, nil, &mockBandwidthHints{},
|
ctx.graph, nil, &mockBandwidthHints{},
|
||||||
@ -2398,7 +2399,7 @@ func TestPathFindSpecExample(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertExpectedPath(t *testing.T, aliasMap map[string]route.Vertex,
|
func assertExpectedPath(t *testing.T, aliasMap map[string]route.Vertex,
|
||||||
path []*channeldb.CachedEdgePolicy, nodeAliases ...string) {
|
path []*models.CachedEdgePolicy, nodeAliases ...string) {
|
||||||
|
|
||||||
if len(path) != len(nodeAliases) {
|
if len(path) != len(nodeAliases) {
|
||||||
t.Fatal("number of hops and number of aliases do not match")
|
t.Fatal("number of hops and number of aliases do not match")
|
||||||
@ -3043,7 +3044,7 @@ func (c *pathFindingTestContext) aliasFromKey(pubKey route.Vertex) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *pathFindingTestContext) findPath(target route.Vertex,
|
func (c *pathFindingTestContext) findPath(target route.Vertex,
|
||||||
amt lnwire.MilliSatoshi) ([]*channeldb.CachedEdgePolicy,
|
amt lnwire.MilliSatoshi) ([]*models.CachedEdgePolicy,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
return dbFindPath(
|
return dbFindPath(
|
||||||
@ -3052,7 +3053,7 @@ func (c *pathFindingTestContext) findPath(target route.Vertex,
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *pathFindingTestContext) assertPath(path []*channeldb.CachedEdgePolicy,
|
func (c *pathFindingTestContext) assertPath(path []*models.CachedEdgePolicy,
|
||||||
expected []uint64) {
|
expected []uint64) {
|
||||||
|
|
||||||
if len(path) != len(expected) {
|
if len(path) != len(expected) {
|
||||||
@ -3071,11 +3072,11 @@ func (c *pathFindingTestContext) assertPath(path []*channeldb.CachedEdgePolicy,
|
|||||||
// dbFindPath calls findPath after getting a db transaction from the database
|
// dbFindPath calls findPath after getting a db transaction from the database
|
||||||
// graph.
|
// graph.
|
||||||
func dbFindPath(graph *channeldb.ChannelGraph,
|
func dbFindPath(graph *channeldb.ChannelGraph,
|
||||||
additionalEdges map[route.Vertex][]*channeldb.CachedEdgePolicy,
|
additionalEdges map[route.Vertex][]*models.CachedEdgePolicy,
|
||||||
bandwidthHints bandwidthHints,
|
bandwidthHints bandwidthHints,
|
||||||
r *RestrictParams, cfg *PathFindingConfig,
|
r *RestrictParams, cfg *PathFindingConfig,
|
||||||
source, target route.Vertex, amt lnwire.MilliSatoshi, timePref float64,
|
source, target route.Vertex, amt lnwire.MilliSatoshi, timePref float64,
|
||||||
finalHtlcExpiry int32) ([]*channeldb.CachedEdgePolicy, error) {
|
finalHtlcExpiry int32) ([]*models.CachedEdgePolicy, error) {
|
||||||
|
|
||||||
sourceNode, err := graph.SourceNode()
|
sourceNode, err := graph.SourceNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -3179,7 +3180,7 @@ func TestBlindedRouteConstruction(t *testing.T) {
|
|||||||
// route. Proportional fees are omitted for easy test
|
// route. Proportional fees are omitted for easy test
|
||||||
// calculations, but non-zero base fees ensure our fee is
|
// calculations, but non-zero base fees ensure our fee is
|
||||||
// still accounted for.
|
// still accounted for.
|
||||||
aliceBobEdge = &channeldb.CachedEdgePolicy{
|
aliceBobEdge = &models.CachedEdgePolicy{
|
||||||
ChannelID: 1,
|
ChannelID: 1,
|
||||||
// We won't actually use this timelock / fee (since
|
// We won't actually use this timelock / fee (since
|
||||||
// it's the sender's outbound channel), but we include
|
// it's the sender's outbound channel), but we include
|
||||||
@ -3193,7 +3194,7 @@ func TestBlindedRouteConstruction(t *testing.T) {
|
|||||||
ToNodeFeatures: tlvFeatures,
|
ToNodeFeatures: tlvFeatures,
|
||||||
}
|
}
|
||||||
|
|
||||||
bobCarolEdge = &channeldb.CachedEdgePolicy{
|
bobCarolEdge = &models.CachedEdgePolicy{
|
||||||
ChannelID: 2,
|
ChannelID: 2,
|
||||||
TimeLockDelta: 15,
|
TimeLockDelta: 15,
|
||||||
FeeBaseMSat: 20,
|
FeeBaseMSat: 20,
|
||||||
@ -3226,7 +3227,7 @@ func TestBlindedRouteConstruction(t *testing.T) {
|
|||||||
carolDaveEdge := blindedEdges[carolVertex][0]
|
carolDaveEdge := blindedEdges[carolVertex][0]
|
||||||
daveEveEdge := blindedEdges[daveBlindedVertex][0]
|
daveEveEdge := blindedEdges[daveBlindedVertex][0]
|
||||||
|
|
||||||
edges := []*channeldb.CachedEdgePolicy{
|
edges := []*models.CachedEdgePolicy{
|
||||||
aliceBobEdge,
|
aliceBobEdge,
|
||||||
bobCarolEdge,
|
bobCarolEdge,
|
||||||
carolDaveEdge,
|
carolDaveEdge,
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/go-errors/errors"
|
"github.com/go-errors/errors"
|
||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
@ -874,7 +875,7 @@ func (p *shardHandler) handleFailureMessage(rt *route.Route,
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
isAdditionalEdge bool
|
isAdditionalEdge bool
|
||||||
policy *channeldb.CachedEdgePolicy
|
policy *models.CachedEdgePolicy
|
||||||
)
|
)
|
||||||
|
|
||||||
// Before we apply the channel update, we need to decide whether the
|
// Before we apply the channel update, we need to decide whether the
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/davecgh/go-spew/spew"
|
"github.com/davecgh/go-spew/spew"
|
||||||
"github.com/lightningnetwork/lnd/build"
|
"github.com/lightningnetwork/lnd/build"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -144,13 +145,13 @@ type PaymentSession interface {
|
|||||||
// a boolean to indicate whether the update has been applied without
|
// a boolean to indicate whether the update has been applied without
|
||||||
// error.
|
// error.
|
||||||
UpdateAdditionalEdge(msg *lnwire.ChannelUpdate, pubKey *btcec.PublicKey,
|
UpdateAdditionalEdge(msg *lnwire.ChannelUpdate, pubKey *btcec.PublicKey,
|
||||||
policy *channeldb.CachedEdgePolicy) bool
|
policy *models.CachedEdgePolicy) bool
|
||||||
|
|
||||||
// GetAdditionalEdgePolicy uses the public key and channel ID to query
|
// GetAdditionalEdgePolicy uses the public key and channel ID to query
|
||||||
// the ephemeral channel edge policy for additional edges. Returns a nil
|
// the ephemeral channel edge policy for additional edges. Returns a nil
|
||||||
// if nothing found.
|
// if nothing found.
|
||||||
GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
||||||
channelID uint64) *channeldb.CachedEdgePolicy
|
channelID uint64) *models.CachedEdgePolicy
|
||||||
}
|
}
|
||||||
|
|
||||||
// paymentSession is used during an HTLC routings session to prune the local
|
// paymentSession is used during an HTLC routings session to prune the local
|
||||||
@ -162,7 +163,7 @@ type PaymentSession interface {
|
|||||||
// loop if payment attempts take long enough. An additional set of edges can
|
// loop if payment attempts take long enough. An additional set of edges can
|
||||||
// also be provided to assist in reaching the payment's destination.
|
// also be provided to assist in reaching the payment's destination.
|
||||||
type paymentSession struct {
|
type paymentSession struct {
|
||||||
additionalEdges map[route.Vertex][]*channeldb.CachedEdgePolicy
|
additionalEdges map[route.Vertex][]*models.CachedEdgePolicy
|
||||||
|
|
||||||
getBandwidthHints func(routingGraph) (bandwidthHints, error)
|
getBandwidthHints func(routingGraph) (bandwidthHints, error)
|
||||||
|
|
||||||
@ -405,7 +406,7 @@ func (p *paymentSession) RequestRoute(maxAmt, feeLimit lnwire.MilliSatoshi,
|
|||||||
// updates to the supplied policy. It returns a boolean to indicate whether
|
// updates to the supplied policy. It returns a boolean to indicate whether
|
||||||
// there's an error when applying the updates.
|
// there's an error when applying the updates.
|
||||||
func (p *paymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate,
|
func (p *paymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate,
|
||||||
pubKey *btcec.PublicKey, policy *channeldb.CachedEdgePolicy) bool {
|
pubKey *btcec.PublicKey, policy *models.CachedEdgePolicy) bool {
|
||||||
|
|
||||||
// Validate the message signature.
|
// Validate the message signature.
|
||||||
if err := VerifyChannelUpdateSignature(msg, pubKey); err != nil {
|
if err := VerifyChannelUpdateSignature(msg, pubKey); err != nil {
|
||||||
@ -430,7 +431,7 @@ func (p *paymentSession) UpdateAdditionalEdge(msg *lnwire.ChannelUpdate,
|
|||||||
// ephemeral channel edge policy for additional edges. Returns a nil if nothing
|
// ephemeral channel edge policy for additional edges. Returns a nil if nothing
|
||||||
// found.
|
// found.
|
||||||
func (p *paymentSession) GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
func (p *paymentSession) GetAdditionalEdgePolicy(pubKey *btcec.PublicKey,
|
||||||
channelID uint64) *channeldb.CachedEdgePolicy {
|
channelID uint64) *models.CachedEdgePolicy {
|
||||||
|
|
||||||
target := route.NewVertex(pubKey)
|
target := route.NewVertex(pubKey)
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcd/btcec/v2"
|
"github.com/btcsuite/btcd/btcec/v2"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/lightningnetwork/lnd/zpay32"
|
"github.com/lightningnetwork/lnd/zpay32"
|
||||||
@ -94,9 +95,9 @@ func (m *SessionSource) NewPaymentSessionEmpty() PaymentSession {
|
|||||||
// RouteHintsToEdges converts a list of invoice route hints to an edge map that
|
// RouteHintsToEdges converts a list of invoice route hints to an edge map that
|
||||||
// can be passed into pathfinding.
|
// can be passed into pathfinding.
|
||||||
func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
|
func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
|
||||||
map[route.Vertex][]*channeldb.CachedEdgePolicy, error) {
|
map[route.Vertex][]*models.CachedEdgePolicy, error) {
|
||||||
|
|
||||||
edges := make(map[route.Vertex][]*channeldb.CachedEdgePolicy)
|
edges := make(map[route.Vertex][]*models.CachedEdgePolicy)
|
||||||
|
|
||||||
// Traverse through all of the available hop hints and include them in
|
// Traverse through all of the available hop hints and include them in
|
||||||
// our edges map, indexed by the public key of the channel's starting
|
// our edges map, indexed by the public key of the channel's starting
|
||||||
@ -126,7 +127,7 @@ func RouteHintsToEdges(routeHints [][]zpay32.HopHint, target route.Vertex) (
|
|||||||
// Finally, create the channel edge from the hop hint
|
// Finally, create the channel edge from the hop hint
|
||||||
// and add it to list of edges corresponding to the node
|
// and add it to list of edges corresponding to the node
|
||||||
// at the start of the channel.
|
// at the start of the channel.
|
||||||
edge := &channeldb.CachedEdgePolicy{
|
edge := &models.CachedEdgePolicy{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return endNode.PubKeyBytes
|
return endNode.PubKeyBytes
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -211,7 +212,7 @@ func TestRequestRoute(t *testing.T) {
|
|||||||
// Override pathfinder with a mock.
|
// Override pathfinder with a mock.
|
||||||
session.pathFinder = func(_ *graphParams, r *RestrictParams,
|
session.pathFinder = func(_ *graphParams, r *RestrictParams,
|
||||||
_ *PathFindingConfig, _, _ route.Vertex, _ lnwire.MilliSatoshi,
|
_ *PathFindingConfig, _, _ route.Vertex, _ lnwire.MilliSatoshi,
|
||||||
_ float64, _ int32) ([]*channeldb.CachedEdgePolicy, float64,
|
_ float64, _ int32) ([]*models.CachedEdgePolicy, float64,
|
||||||
error) {
|
error) {
|
||||||
|
|
||||||
// We expect find path to receive a cltv limit excluding the
|
// We expect find path to receive a cltv limit excluding the
|
||||||
@ -220,7 +221,7 @@ func TestRequestRoute(t *testing.T) {
|
|||||||
t.Fatal("wrong cltv limit")
|
t.Fatal("wrong cltv limit")
|
||||||
}
|
}
|
||||||
|
|
||||||
path := []*channeldb.CachedEdgePolicy{
|
path := []*models.CachedEdgePolicy{
|
||||||
{
|
{
|
||||||
ToNodePubKey: func() route.Vertex {
|
ToNodePubKey: func() route.Vertex {
|
||||||
return route.Vertex{}
|
return route.Vertex{}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/batch"
|
"github.com/lightningnetwork/lnd/batch"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
"github.com/lightningnetwork/lnd/input"
|
"github.com/lightningnetwork/lnd/input"
|
||||||
@ -135,17 +136,17 @@ type ChannelGraphSource interface {
|
|||||||
// AddEdge is used to add edge/channel to the topology of the router,
|
// AddEdge is used to add edge/channel to the topology of the router,
|
||||||
// after all information about channel will be gathered this
|
// after all information about channel will be gathered this
|
||||||
// edge/channel might be used in construction of payment path.
|
// edge/channel might be used in construction of payment path.
|
||||||
AddEdge(edge *channeldb.ChannelEdgeInfo,
|
AddEdge(edge *models.ChannelEdgeInfo,
|
||||||
op ...batch.SchedulerOption) error
|
op ...batch.SchedulerOption) error
|
||||||
|
|
||||||
// AddProof updates the channel edge info with proof which is needed to
|
// AddProof updates the channel edge info with proof which is needed to
|
||||||
// properly announce the edge to the rest of the network.
|
// properly announce the edge to the rest of the network.
|
||||||
AddProof(chanID lnwire.ShortChannelID,
|
AddProof(chanID lnwire.ShortChannelID,
|
||||||
proof *channeldb.ChannelAuthProof) error
|
proof *models.ChannelAuthProof) error
|
||||||
|
|
||||||
// UpdateEdge is used to update edge information, without this message
|
// UpdateEdge is used to update edge information, without this message
|
||||||
// edge considered as not fully constructed.
|
// edge considered as not fully constructed.
|
||||||
UpdateEdge(policy *channeldb.ChannelEdgePolicy,
|
UpdateEdge(policy *models.ChannelEdgePolicy,
|
||||||
op ...batch.SchedulerOption) error
|
op ...batch.SchedulerOption) error
|
||||||
|
|
||||||
// IsStaleNode returns true if the graph source has a node announcement
|
// IsStaleNode returns true if the graph source has a node announcement
|
||||||
@ -176,8 +177,8 @@ type ChannelGraphSource interface {
|
|||||||
// emanating from the "source" node which is the center of the
|
// emanating from the "source" node which is the center of the
|
||||||
// star-graph.
|
// star-graph.
|
||||||
ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
ForAllOutgoingChannels(cb func(tx kvdb.RTx,
|
||||||
c *channeldb.ChannelEdgeInfo,
|
c *models.ChannelEdgeInfo,
|
||||||
e *channeldb.ChannelEdgePolicy) error) error
|
e *models.ChannelEdgePolicy) error) error
|
||||||
|
|
||||||
// CurrentBlockHeight returns the block height from POV of the router
|
// CurrentBlockHeight returns the block height from POV of the router
|
||||||
// subsystem.
|
// subsystem.
|
||||||
@ -185,8 +186,8 @@ type ChannelGraphSource interface {
|
|||||||
|
|
||||||
// GetChannelByID return the channel by the channel id.
|
// GetChannelByID return the channel by the channel id.
|
||||||
GetChannelByID(chanID lnwire.ShortChannelID) (
|
GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy,
|
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||||
*channeldb.ChannelEdgePolicy, error)
|
*models.ChannelEdgePolicy, error)
|
||||||
|
|
||||||
// FetchLightningNode attempts to look up a target node by its identity
|
// FetchLightningNode attempts to look up a target node by its identity
|
||||||
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
// public key. channeldb.ErrGraphNodeNotFound is returned if the node
|
||||||
@ -897,15 +898,15 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
|||||||
log.Infof("Examining channel graph for zombie channels")
|
log.Infof("Examining channel graph for zombie channels")
|
||||||
|
|
||||||
// A helper method to detect if the channel belongs to this node
|
// A helper method to detect if the channel belongs to this node
|
||||||
isSelfChannelEdge := func(info *channeldb.ChannelEdgeInfo) bool {
|
isSelfChannelEdge := func(info *models.ChannelEdgeInfo) bool {
|
||||||
return info.NodeKey1Bytes == r.selfNode.PubKeyBytes ||
|
return info.NodeKey1Bytes == r.selfNode.PubKeyBytes ||
|
||||||
info.NodeKey2Bytes == r.selfNode.PubKeyBytes
|
info.NodeKey2Bytes == r.selfNode.PubKeyBytes
|
||||||
}
|
}
|
||||||
|
|
||||||
// First, we'll collect all the channels which are eligible for garbage
|
// First, we'll collect all the channels which are eligible for garbage
|
||||||
// collection due to being zombies.
|
// collection due to being zombies.
|
||||||
filterPruneChans := func(info *channeldb.ChannelEdgeInfo,
|
filterPruneChans := func(info *models.ChannelEdgeInfo,
|
||||||
e1, e2 *channeldb.ChannelEdgePolicy) error {
|
e1, e2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// Exit early in case this channel is already marked to be pruned
|
// Exit early in case this channel is already marked to be pruned
|
||||||
if _, markedToPrune := chansToPrune[info.ChannelID]; markedToPrune {
|
if _, markedToPrune := chansToPrune[info.ChannelID]; markedToPrune {
|
||||||
@ -1539,7 +1540,7 @@ func (r *ChannelRouter) processUpdate(msg interface{},
|
|||||||
log.Tracef("Updated vertex data for node=%x", msg.PubKeyBytes)
|
log.Tracef("Updated vertex data for node=%x", msg.PubKeyBytes)
|
||||||
r.stats.incNumNodeUpdates()
|
r.stats.incNumNodeUpdates()
|
||||||
|
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *models.ChannelEdgeInfo:
|
||||||
log.Debugf("Received ChannelEdgeInfo for channel %v",
|
log.Debugf("Received ChannelEdgeInfo for channel %v",
|
||||||
msg.ChannelID)
|
msg.ChannelID)
|
||||||
|
|
||||||
@ -1706,7 +1707,7 @@ func (r *ChannelRouter) processUpdate(msg interface{},
|
|||||||
"view: %v", err)
|
"view: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *models.ChannelEdgePolicy:
|
||||||
log.Debugf("Received ChannelEdgePolicy for channel %v",
|
log.Debugf("Received ChannelEdgePolicy for channel %v",
|
||||||
msg.ChannelID)
|
msg.ChannelID)
|
||||||
|
|
||||||
@ -1883,7 +1884,7 @@ type RouteRequest struct {
|
|||||||
|
|
||||||
// RouteHints is an alias type for a set of route hints, with the source node
|
// RouteHints is an alias type for a set of route hints, with the source node
|
||||||
// as the map's key and the details of the hint(s) in the edge policy.
|
// as the map's key and the details of the hint(s) in the edge policy.
|
||||||
type RouteHints map[route.Vertex][]*channeldb.CachedEdgePolicy
|
type RouteHints map[route.Vertex][]*models.CachedEdgePolicy
|
||||||
|
|
||||||
// NewRouteRequest produces a new route request for a regular payment or one
|
// NewRouteRequest produces a new route request for a regular payment or one
|
||||||
// to a blinded route, validating that the target, routeHints and finalExpiry
|
// to a blinded route, validating that the target, routeHints and finalExpiry
|
||||||
@ -2668,7 +2669,7 @@ func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err = r.UpdateEdge(&channeldb.ChannelEdgePolicy{
|
err = r.UpdateEdge(&models.ChannelEdgePolicy{
|
||||||
SigBytes: msg.Signature.ToSignatureBytes(),
|
SigBytes: msg.Signature.ToSignatureBytes(),
|
||||||
ChannelID: msg.ShortChannelID.ToUint64(),
|
ChannelID: msg.ShortChannelID.ToUint64(),
|
||||||
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
|
LastUpdate: time.Unix(int64(msg.Timestamp), 0),
|
||||||
@ -2720,7 +2721,7 @@ func (r *ChannelRouter) AddNode(node *channeldb.LightningNode,
|
|||||||
// in construction of payment path.
|
// in construction of payment path.
|
||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) AddEdge(edge *channeldb.ChannelEdgeInfo,
|
func (r *ChannelRouter) AddEdge(edge *models.ChannelEdgeInfo,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
rMsg := &routingMsg{
|
rMsg := &routingMsg{
|
||||||
@ -2746,7 +2747,7 @@ func (r *ChannelRouter) AddEdge(edge *channeldb.ChannelEdgeInfo,
|
|||||||
// considered as not fully constructed.
|
// considered as not fully constructed.
|
||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) UpdateEdge(update *channeldb.ChannelEdgePolicy,
|
func (r *ChannelRouter) UpdateEdge(update *models.ChannelEdgePolicy,
|
||||||
op ...batch.SchedulerOption) error {
|
op ...batch.SchedulerOption) error {
|
||||||
|
|
||||||
rMsg := &routingMsg{
|
rMsg := &routingMsg{
|
||||||
@ -2787,9 +2788,9 @@ func (r *ChannelRouter) SyncedHeight() uint32 {
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) GetChannelByID(chanID lnwire.ShortChannelID) (
|
func (r *ChannelRouter) GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgeInfo,
|
*models.ChannelEdgeInfo,
|
||||||
*channeldb.ChannelEdgePolicy,
|
*models.ChannelEdgePolicy,
|
||||||
*channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
return r.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
return r.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
||||||
}
|
}
|
||||||
@ -2822,12 +2823,12 @@ func (r *ChannelRouter) ForEachNode(
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
||||||
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy) error) error {
|
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy) error) error {
|
||||||
|
|
||||||
return r.cfg.Graph.ForEachNodeChannel(nil, r.selfNode.PubKeyBytes,
|
return r.cfg.Graph.ForEachNodeChannel(nil, r.selfNode.PubKeyBytes,
|
||||||
func(tx kvdb.RTx, c *channeldb.ChannelEdgeInfo,
|
func(tx kvdb.RTx, c *models.ChannelEdgeInfo,
|
||||||
e *channeldb.ChannelEdgePolicy,
|
e *models.ChannelEdgePolicy,
|
||||||
_ *channeldb.ChannelEdgePolicy) error {
|
_ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return fmt.Errorf("channel from self node " +
|
return fmt.Errorf("channel from self node " +
|
||||||
@ -2844,7 +2845,7 @@ func (r *ChannelRouter) ForAllOutgoingChannels(cb func(kvdb.RTx,
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) AddProof(chanID lnwire.ShortChannelID,
|
func (r *ChannelRouter) AddProof(chanID lnwire.ShortChannelID,
|
||||||
proof *channeldb.ChannelAuthProof) error {
|
proof *models.ChannelAuthProof) error {
|
||||||
|
|
||||||
info, _, _, err := r.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
info, _, _, err := r.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -3129,14 +3130,14 @@ func getRouteUnifiers(source route.Vertex, hops []route.Vertex,
|
|||||||
// including fees, to send the payment.
|
// including fees, to send the payment.
|
||||||
func getPathEdges(source route.Vertex, receiverAmt lnwire.MilliSatoshi,
|
func getPathEdges(source route.Vertex, receiverAmt lnwire.MilliSatoshi,
|
||||||
unifiers []*edgeUnifier, bandwidthHints *bandwidthManager,
|
unifiers []*edgeUnifier, bandwidthHints *bandwidthManager,
|
||||||
hops []route.Vertex) ([]*channeldb.CachedEdgePolicy,
|
hops []route.Vertex) ([]*models.CachedEdgePolicy,
|
||||||
lnwire.MilliSatoshi, error) {
|
lnwire.MilliSatoshi, error) {
|
||||||
|
|
||||||
// Now that we arrived at the start of the route and found out the route
|
// Now that we arrived at the start of the route and found out the route
|
||||||
// total amount, we make a forward pass. Because the amount may have
|
// total amount, we make a forward pass. Because the amount may have
|
||||||
// been increased in the backward pass, fees need to be recalculated and
|
// been increased in the backward pass, fees need to be recalculated and
|
||||||
// amount ranges re-checked.
|
// amount ranges re-checked.
|
||||||
var pathEdges []*channeldb.CachedEdgePolicy
|
var pathEdges []*models.CachedEdgePolicy
|
||||||
for i, unifier := range unifiers {
|
for i, unifier := range unifiers {
|
||||||
edge := unifier.getEdge(receiverAmt, bandwidthHints)
|
edge := unifier.getEdge(receiverAmt, bandwidthHints)
|
||||||
if edge == nil {
|
if edge == nil {
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||||
"github.com/lightningnetwork/lnd/chainntnfs"
|
"github.com/lightningnetwork/lnd/chainntnfs"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/htlcswitch"
|
"github.com/lightningnetwork/lnd/htlcswitch"
|
||||||
lnmock "github.com/lightningnetwork/lnd/lntest/mock"
|
lnmock "github.com/lightningnetwork/lnd/lntest/mock"
|
||||||
@ -1241,7 +1242,7 @@ func TestAddProof(t *testing.T) {
|
|||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
// After utxo was recreated adding the edge without the proof.
|
// After utxo was recreated adding the edge without the proof.
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
@ -1330,7 +1331,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: pub1,
|
NodeKey1Bytes: pub1,
|
||||||
NodeKey2Bytes: pub2,
|
NodeKey2Bytes: pub2,
|
||||||
@ -1338,7 +1339,7 @@ func TestIgnoreChannelEdgePolicyForUnknownChannel(t *testing.T) {
|
|||||||
BitcoinKey2Bytes: pub2,
|
BitcoinKey2Bytes: pub2,
|
||||||
AuthProof: nil,
|
AuthProof: nil,
|
||||||
}
|
}
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@ -1408,7 +1409,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: pub1,
|
NodeKey1Bytes: pub1,
|
||||||
NodeKey2Bytes: pub2,
|
NodeKey2Bytes: pub2,
|
||||||
@ -1423,7 +1424,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
|
|
||||||
// We must add the edge policy to be able to use the edge for route
|
// We must add the edge policy to be able to use the edge for route
|
||||||
// finding.
|
// finding.
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@ -1440,7 +1441,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create edge in the other direction as well.
|
// Create edge in the other direction as well.
|
||||||
edgePolicy = &channeldb.ChannelEdgePolicy{
|
edgePolicy = &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@ -1503,7 +1504,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
edge = &channeldb.ChannelEdgeInfo{
|
edge = &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
AuthProof: nil,
|
AuthProof: nil,
|
||||||
}
|
}
|
||||||
@ -1516,7 +1517,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
t.Fatalf("unable to add edge to the channel graph: %v.", err)
|
t.Fatalf("unable to add edge to the channel graph: %v.", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy = &channeldb.ChannelEdgePolicy{
|
edgePolicy = &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@ -1532,7 +1533,7 @@ func TestAddEdgeUnknownVertexes(t *testing.T) {
|
|||||||
t.Fatalf("unable to update edge policy: %v", err)
|
t.Fatalf("unable to update edge policy: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy = &channeldb.ChannelEdgePolicy{
|
edgePolicy = &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: testTime,
|
LastUpdate: testTime,
|
||||||
@ -1702,11 +1703,11 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
node2, err := createTestNode()
|
node2, err := createTestNode()
|
||||||
require.NoError(t, err, "unable to create test node")
|
require.NoError(t, err, "unable to create test node")
|
||||||
|
|
||||||
edge1 := &channeldb.ChannelEdgeInfo{
|
edge1 := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID1,
|
ChannelID: chanID1,
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -1720,11 +1721,11 @@ func TestWakeUpOnStaleBranch(t *testing.T) {
|
|||||||
t.Fatalf("unable to add edge: %v", err)
|
t.Fatalf("unable to add edge: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edge2 := &channeldb.ChannelEdgeInfo{
|
edge2 := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID2,
|
ChannelID: chanID2,
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -1910,13 +1911,13 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
node2, err := createTestNode()
|
node2, err := createTestNode()
|
||||||
require.NoError(t, err, "unable to create test node")
|
require.NoError(t, err, "unable to create test node")
|
||||||
|
|
||||||
edge1 := &channeldb.ChannelEdgeInfo{
|
edge1 := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID1,
|
ChannelID: chanID1,
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
BitcoinKey1Bytes: node1.PubKeyBytes,
|
BitcoinKey1Bytes: node1.PubKeyBytes,
|
||||||
BitcoinKey2Bytes: node2.PubKeyBytes,
|
BitcoinKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -1930,13 +1931,13 @@ func TestDisconnectedBlocks(t *testing.T) {
|
|||||||
t.Fatalf("unable to add edge: %v", err)
|
t.Fatalf("unable to add edge: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edge2 := &channeldb.ChannelEdgeInfo{
|
edge2 := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID2,
|
ChannelID: chanID2,
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
BitcoinKey1Bytes: node1.PubKeyBytes,
|
BitcoinKey1Bytes: node1.PubKeyBytes,
|
||||||
BitcoinKey2Bytes: node2.PubKeyBytes,
|
BitcoinKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -2061,11 +2062,11 @@ func TestRouterChansClosedOfflinePruneGraph(t *testing.T) {
|
|||||||
require.NoError(t, err, "unable to create test node")
|
require.NoError(t, err, "unable to create test node")
|
||||||
node2, err := createTestNode()
|
node2, err := createTestNode()
|
||||||
require.NoError(t, err, "unable to create test node")
|
require.NoError(t, err, "unable to create test node")
|
||||||
edge1 := &channeldb.ChannelEdgeInfo{
|
edge1 := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID1.ToUint64(),
|
ChannelID: chanID1.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
AuthProof: &channeldb.ChannelAuthProof{
|
AuthProof: &models.ChannelAuthProof{
|
||||||
NodeSig1Bytes: testSig.Serialize(),
|
NodeSig1Bytes: testSig.Serialize(),
|
||||||
NodeSig2Bytes: testSig.Serialize(),
|
NodeSig2Bytes: testSig.Serialize(),
|
||||||
BitcoinSig1Bytes: testSig.Serialize(),
|
BitcoinSig1Bytes: testSig.Serialize(),
|
||||||
@ -2500,7 +2501,7 @@ func TestIsStaleNode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: pub1,
|
NodeKey1Bytes: pub1,
|
||||||
NodeKey2Bytes: pub2,
|
NodeKey2Bytes: pub2,
|
||||||
@ -2576,7 +2577,7 @@ func TestIsKnownEdge(t *testing.T) {
|
|||||||
}
|
}
|
||||||
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
ctx.chain.addBlock(fundingBlock, chanID.BlockHeight, chanID.BlockHeight)
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: pub1,
|
NodeKey1Bytes: pub1,
|
||||||
NodeKey2Bytes: pub2,
|
NodeKey2Bytes: pub2,
|
||||||
@ -2632,7 +2633,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
|
|||||||
t.Fatalf("router failed to detect fresh edge policy")
|
t.Fatalf("router failed to detect fresh edge policy")
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: pub1,
|
NodeKey1Bytes: pub1,
|
||||||
NodeKey2Bytes: pub2,
|
NodeKey2Bytes: pub2,
|
||||||
@ -2645,7 +2646,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We'll also add two edge policies, one for each direction.
|
// We'll also add two edge policies, one for each direction.
|
||||||
edgePolicy := &channeldb.ChannelEdgePolicy{
|
edgePolicy := &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: updateTimeStamp,
|
LastUpdate: updateTimeStamp,
|
||||||
@ -2659,7 +2660,7 @@ func TestIsStaleEdgePolicy(t *testing.T) {
|
|||||||
t.Fatalf("unable to update edge policy: %v", err)
|
t.Fatalf("unable to update edge policy: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edgePolicy = &channeldb.ChannelEdgePolicy{
|
edgePolicy = &models.ChannelEdgePolicy{
|
||||||
SigBytes: testSig.Serialize(),
|
SigBytes: testSig.Serialize(),
|
||||||
ChannelID: edge.ChannelID,
|
ChannelID: edge.ChannelID,
|
||||||
LastUpdate: updateTimeStamp,
|
LastUpdate: updateTimeStamp,
|
||||||
@ -3202,7 +3203,7 @@ func TestGetPathEdges(t *testing.T) {
|
|||||||
bandwidthHints *bandwidthManager
|
bandwidthHints *bandwidthManager
|
||||||
hops []route.Vertex
|
hops []route.Vertex
|
||||||
|
|
||||||
expectedEdges []*channeldb.CachedEdgePolicy
|
expectedEdges []*models.CachedEdgePolicy
|
||||||
expectedAmt lnwire.MilliSatoshi
|
expectedAmt lnwire.MilliSatoshi
|
||||||
expectedErr string
|
expectedErr string
|
||||||
}{{
|
}{{
|
||||||
@ -3257,7 +3258,7 @@ const (
|
|||||||
// newChannelEdgeInfo is a helper function used to create a new channel edge,
|
// newChannelEdgeInfo is a helper function used to create a new channel edge,
|
||||||
// possibly skipping adding it to parts of the chain/state as well.
|
// possibly skipping adding it to parts of the chain/state as well.
|
||||||
func newChannelEdgeInfo(ctx *testCtx, fundingHeight uint32,
|
func newChannelEdgeInfo(ctx *testCtx, fundingHeight uint32,
|
||||||
ecm edgeCreationModifier) (*channeldb.ChannelEdgeInfo, error) {
|
ecm edgeCreationModifier) (*models.ChannelEdgeInfo, error) {
|
||||||
|
|
||||||
node1, err := createTestNode()
|
node1, err := createTestNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -3276,7 +3277,7 @@ func newChannelEdgeInfo(ctx *testCtx, fundingHeight uint32,
|
|||||||
return nil, fmt.Errorf("unable to create edge: %w", err)
|
return nil, fmt.Errorf("unable to create edge: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
edge := &channeldb.ChannelEdgeInfo{
|
edge := &models.ChannelEdgeInfo{
|
||||||
ChannelID: chanID.ToUint64(),
|
ChannelID: chanID.ToUint64(),
|
||||||
NodeKey1Bytes: node1.PubKeyBytes,
|
NodeKey1Bytes: node1.PubKeyBytes,
|
||||||
NodeKey2Bytes: node2.PubKeyBytes,
|
NodeKey2Bytes: node2.PubKeyBytes,
|
||||||
@ -3307,7 +3308,7 @@ func newChannelEdgeInfo(ctx *testCtx, fundingHeight uint32,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
func assertChanChainRejection(t *testing.T, ctx *testCtx,
|
||||||
edge *channeldb.ChannelEdgeInfo, failCode errorCode) {
|
edge *models.ChannelEdgeInfo, failCode errorCode) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
@ -4715,7 +4716,7 @@ func TestNewRouteRequest(t *testing.T) {
|
|||||||
name: "hints and blinded",
|
name: "hints and blinded",
|
||||||
blindedPayment: blindedMultiHop,
|
blindedPayment: blindedMultiHop,
|
||||||
routeHints: make(
|
routeHints: make(
|
||||||
map[route.Vertex][]*channeldb.CachedEdgePolicy,
|
map[route.Vertex][]*models.CachedEdgePolicy,
|
||||||
),
|
),
|
||||||
err: ErrHintsAndBlinded,
|
err: ErrHintsAndBlinded,
|
||||||
},
|
},
|
||||||
|
@ -3,6 +3,7 @@ package routing
|
|||||||
import (
|
import (
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lntypes"
|
"github.com/lightningnetwork/lnd/lntypes"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
@ -41,7 +42,7 @@ func newNodeEdgeUnifier(sourceNode, toNode route.Vertex,
|
|||||||
// addPolicy adds a single channel policy. Capacity may be zero if unknown
|
// addPolicy adds a single channel policy. Capacity may be zero if unknown
|
||||||
// (light clients).
|
// (light clients).
|
||||||
func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
||||||
edge *channeldb.CachedEdgePolicy, capacity btcutil.Amount) {
|
edge *models.CachedEdgePolicy, capacity btcutil.Amount) {
|
||||||
|
|
||||||
localChan := fromNode == u.sourceNode
|
localChan := fromNode == u.sourceNode
|
||||||
|
|
||||||
@ -93,7 +94,7 @@ func (u *nodeEdgeUnifier) addGraphPolicies(g routingGraph) error {
|
|||||||
// unifiedEdge is the individual channel data that is kept inside an edgeUnifier
|
// unifiedEdge is the individual channel data that is kept inside an edgeUnifier
|
||||||
// object.
|
// object.
|
||||||
type unifiedEdge struct {
|
type unifiedEdge struct {
|
||||||
policy *channeldb.CachedEdgePolicy
|
policy *models.CachedEdgePolicy
|
||||||
capacity btcutil.Amount
|
capacity btcutil.Amount
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,7 +234,7 @@ func (u *edgeUnifier) getEdgeLocal(amt lnwire.MilliSatoshi,
|
|||||||
// forwarding context.
|
// forwarding context.
|
||||||
func (u *edgeUnifier) getEdgeNetwork(amt lnwire.MilliSatoshi) *unifiedEdge {
|
func (u *edgeUnifier) getEdgeNetwork(amt lnwire.MilliSatoshi) *unifiedEdge {
|
||||||
var (
|
var (
|
||||||
bestPolicy *channeldb.CachedEdgePolicy
|
bestPolicy *models.CachedEdgePolicy
|
||||||
maxFee lnwire.MilliSatoshi
|
maxFee lnwire.MilliSatoshi
|
||||||
maxTimelock uint16
|
maxTimelock uint16
|
||||||
maxCapMsat lnwire.MilliSatoshi
|
maxCapMsat lnwire.MilliSatoshi
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/btcutil"
|
"github.com/btcsuite/btcd/btcutil"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -21,7 +21,7 @@ func TestNodeEdgeUnifier(t *testing.T) {
|
|||||||
bandwidthHints := &mockBandwidthHints{}
|
bandwidthHints := &mockBandwidthHints{}
|
||||||
|
|
||||||
// Add two channels between the pair of nodes.
|
// Add two channels between the pair of nodes.
|
||||||
p1 := channeldb.CachedEdgePolicy{
|
p1 := models.CachedEdgePolicy{
|
||||||
FeeProportionalMillionths: 100000,
|
FeeProportionalMillionths: 100000,
|
||||||
FeeBaseMSat: 30,
|
FeeBaseMSat: 30,
|
||||||
TimeLockDelta: 60,
|
TimeLockDelta: 60,
|
||||||
@ -29,7 +29,7 @@ func TestNodeEdgeUnifier(t *testing.T) {
|
|||||||
MaxHTLC: 5000,
|
MaxHTLC: 5000,
|
||||||
MinHTLC: 100,
|
MinHTLC: 100,
|
||||||
}
|
}
|
||||||
p2 := channeldb.CachedEdgePolicy{
|
p2 := models.CachedEdgePolicy{
|
||||||
FeeProportionalMillionths: 190000,
|
FeeProportionalMillionths: 190000,
|
||||||
FeeBaseMSat: 10,
|
FeeBaseMSat: 10,
|
||||||
TimeLockDelta: 40,
|
TimeLockDelta: 40,
|
||||||
@ -49,7 +49,7 @@ func TestNodeEdgeUnifier(t *testing.T) {
|
|||||||
unifierNoCapacity.addPolicy(fromNode, &p2, 0)
|
unifierNoCapacity.addPolicy(fromNode, &p2, 0)
|
||||||
|
|
||||||
unifierNoInfo := newNodeEdgeUnifier(source, toNode, nil)
|
unifierNoInfo := newNodeEdgeUnifier(source, toNode, nil)
|
||||||
unifierNoInfo.addPolicy(fromNode, &channeldb.CachedEdgePolicy{}, 0)
|
unifierNoInfo.addPolicy(fromNode, &models.CachedEdgePolicy{}, 0)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -5,6 +5,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing/route"
|
"github.com/lightningnetwork/lnd/routing/route"
|
||||||
)
|
)
|
||||||
@ -125,7 +126,7 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
|
|||||||
v.nodeAnnDependencies[route.Vertex(msg.NodeID1)] = signals
|
v.nodeAnnDependencies[route.Vertex(msg.NodeID1)] = signals
|
||||||
v.nodeAnnDependencies[route.Vertex(msg.NodeID2)] = signals
|
v.nodeAnnDependencies[route.Vertex(msg.NodeID2)] = signals
|
||||||
}
|
}
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *models.ChannelEdgeInfo:
|
||||||
|
|
||||||
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
if _, ok := v.chanAnnFinSignal[shortID]; !ok {
|
if _, ok := v.chanAnnFinSignal[shortID]; !ok {
|
||||||
@ -143,7 +144,7 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
|
|||||||
|
|
||||||
// These other types don't have any dependants, so no further
|
// These other types don't have any dependants, so no further
|
||||||
// initialization needs to be done beyond just occupying a job slot.
|
// initialization needs to be done beyond just occupying a job slot.
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *models.ChannelEdgePolicy:
|
||||||
return
|
return
|
||||||
case *lnwire.ChannelUpdate:
|
case *lnwire.ChannelUpdate:
|
||||||
return
|
return
|
||||||
@ -187,7 +188,7 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
|||||||
switch msg := job.(type) {
|
switch msg := job.(type) {
|
||||||
// Any ChannelUpdate or NodeAnnouncement jobs will need to wait on the
|
// Any ChannelUpdate or NodeAnnouncement jobs will need to wait on the
|
||||||
// completion of any active ChannelAnnouncement jobs related to them.
|
// completion of any active ChannelAnnouncement jobs related to them.
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *models.ChannelEdgePolicy:
|
||||||
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
signals, ok = v.chanEdgeDependencies[shortID]
|
signals, ok = v.chanEdgeDependencies[shortID]
|
||||||
|
|
||||||
@ -217,7 +218,7 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
|
|||||||
// return directly.
|
// return directly.
|
||||||
case *lnwire.AnnounceSignatures:
|
case *lnwire.AnnounceSignatures:
|
||||||
// TODO(roasbeef): need to wait on chan ann?
|
// TODO(roasbeef): need to wait on chan ann?
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *models.ChannelEdgeInfo:
|
||||||
case *lnwire.ChannelAnnouncement:
|
case *lnwire.ChannelAnnouncement:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +264,7 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
|
|||||||
// If we've just finished executing a ChannelAnnouncement, then we'll
|
// If we've just finished executing a ChannelAnnouncement, then we'll
|
||||||
// close out the signal, and remove the signal from the map of active
|
// close out the signal, and remove the signal from the map of active
|
||||||
// ones. This will allow/deny any dependent jobs to continue execution.
|
// ones. This will allow/deny any dependent jobs to continue execution.
|
||||||
case *channeldb.ChannelEdgeInfo:
|
case *models.ChannelEdgeInfo:
|
||||||
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
finSignals, ok := v.chanAnnFinSignal[shortID]
|
finSignals, ok := v.chanAnnFinSignal[shortID]
|
||||||
if ok {
|
if ok {
|
||||||
@ -296,7 +297,7 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
|
|||||||
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
|
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
|
||||||
case *lnwire.ChannelUpdate:
|
case *lnwire.ChannelUpdate:
|
||||||
delete(v.chanEdgeDependencies, msg.ShortChannelID)
|
delete(v.chanEdgeDependencies, msg.ShortChannelID)
|
||||||
case *channeldb.ChannelEdgePolicy:
|
case *models.ChannelEdgePolicy:
|
||||||
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
|
||||||
delete(v.chanEdgeDependencies, shortID)
|
delete(v.chanEdgeDependencies, shortID)
|
||||||
|
|
||||||
|
19
rpcserver.go
19
rpcserver.go
@ -38,6 +38,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chanbackup"
|
"github.com/lightningnetwork/lnd/chanbackup"
|
||||||
"github.com/lightningnetwork/lnd/chanfitness"
|
"github.com/lightningnetwork/lnd/chanfitness"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
"github.com/lightningnetwork/lnd/discovery"
|
"github.com/lightningnetwork/lnd/discovery"
|
||||||
@ -5921,8 +5922,8 @@ func (r *rpcServer) DescribeGraph(ctx context.Context,
|
|||||||
// Next, for each active channel we know of within the graph, create a
|
// Next, for each active channel we know of within the graph, create a
|
||||||
// similar response which details both the edge information as well as
|
// similar response which details both the edge information as well as
|
||||||
// the routing policies of th nodes connecting the two edges.
|
// the routing policies of th nodes connecting the two edges.
|
||||||
err = graph.ForEachChannel(func(edgeInfo *channeldb.ChannelEdgeInfo,
|
err = graph.ForEachChannel(func(edgeInfo *models.ChannelEdgeInfo,
|
||||||
c1, c2 *channeldb.ChannelEdgePolicy) error {
|
c1, c2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// Do not include unannounced channels unless specifically
|
// Do not include unannounced channels unless specifically
|
||||||
// requested. Unannounced channels include both private channels as
|
// requested. Unannounced channels include both private channels as
|
||||||
@ -5977,8 +5978,8 @@ func marshalExtraOpaqueData(data []byte) map[uint64][]byte {
|
|||||||
return records
|
return records
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
|
func marshalDbEdge(edgeInfo *models.ChannelEdgeInfo,
|
||||||
c1, c2 *channeldb.ChannelEdgePolicy) *lnrpc.ChannelEdge {
|
c1, c2 *models.ChannelEdgePolicy) *lnrpc.ChannelEdge {
|
||||||
|
|
||||||
// Make sure the policies match the node they belong to. c1 should point
|
// Make sure the policies match the node they belong to. c1 should point
|
||||||
// to the policy for NodeKey1, and c2 for NodeKey2.
|
// to the policy for NodeKey1, and c2 for NodeKey2.
|
||||||
@ -6021,7 +6022,7 @@ func marshalDbEdge(edgeInfo *channeldb.ChannelEdgeInfo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func marshalDBRoutingPolicy(
|
func marshalDBRoutingPolicy(
|
||||||
policy *channeldb.ChannelEdgePolicy) *lnrpc.RoutingPolicy {
|
policy *models.ChannelEdgePolicy) *lnrpc.RoutingPolicy {
|
||||||
|
|
||||||
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
|
disabled := policy.ChannelFlags&lnwire.ChanUpdateDisabled != 0
|
||||||
|
|
||||||
@ -6152,8 +6153,8 @@ func (r *rpcServer) GetNodeInfo(ctx context.Context,
|
|||||||
)
|
)
|
||||||
|
|
||||||
err = graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
err = graph.ForEachNodeChannel(nil, node.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, edge *channeldb.ChannelEdgeInfo,
|
func(_ kvdb.RTx, edge *models.ChannelEdgeInfo,
|
||||||
c1, c2 *channeldb.ChannelEdgePolicy) error {
|
c1, c2 *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
numChannels++
|
numChannels++
|
||||||
totalCapacity += edge.Capacity
|
totalCapacity += edge.Capacity
|
||||||
@ -6767,8 +6768,8 @@ func (r *rpcServer) FeeReport(ctx context.Context,
|
|||||||
|
|
||||||
var feeReports []*lnrpc.ChannelFeeReport
|
var feeReports []*lnrpc.ChannelFeeReport
|
||||||
err = channelGraph.ForEachNodeChannel(nil, selfNode.PubKeyBytes,
|
err = channelGraph.ForEachNodeChannel(nil, selfNode.PubKeyBytes,
|
||||||
func(_ kvdb.RTx, chanInfo *channeldb.ChannelEdgeInfo,
|
func(_ kvdb.RTx, chanInfo *models.ChannelEdgeInfo,
|
||||||
edgePolicy, _ *channeldb.ChannelEdgePolicy) error {
|
edgePolicy, _ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// Self node should always have policies for its
|
// Self node should always have policies for its
|
||||||
// channels.
|
// channels.
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/chanbackup"
|
"github.com/lightningnetwork/lnd/chanbackup"
|
||||||
"github.com/lightningnetwork/lnd/chanfitness"
|
"github.com/lightningnetwork/lnd/chanfitness"
|
||||||
"github.com/lightningnetwork/lnd/channeldb"
|
"github.com/lightningnetwork/lnd/channeldb"
|
||||||
|
"github.com/lightningnetwork/lnd/channeldb/models"
|
||||||
"github.com/lightningnetwork/lnd/channelnotifier"
|
"github.com/lightningnetwork/lnd/channelnotifier"
|
||||||
"github.com/lightningnetwork/lnd/clock"
|
"github.com/lightningnetwork/lnd/clock"
|
||||||
"github.com/lightningnetwork/lnd/contractcourt"
|
"github.com/lightningnetwork/lnd/contractcourt"
|
||||||
@ -1232,7 +1233,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
// Wrap the DeleteChannelEdges method so that the funding manager can
|
// Wrap the DeleteChannelEdges method so that the funding manager can
|
||||||
// use it without depending on several layers of indirection.
|
// use it without depending on several layers of indirection.
|
||||||
deleteAliasEdge := func(scid lnwire.ShortChannelID) (
|
deleteAliasEdge := func(scid lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgePolicy, error) {
|
*models.ChannelEdgePolicy, error) {
|
||||||
|
|
||||||
info, e1, e2, err := s.graphDB.FetchChannelEdgesByID(
|
info, e1, e2, err := s.graphDB.FetchChannelEdgesByID(
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
@ -1251,7 +1252,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr,
|
|||||||
var ourKey [33]byte
|
var ourKey [33]byte
|
||||||
copy(ourKey[:], nodeKeyDesc.PubKey.SerializeCompressed())
|
copy(ourKey[:], nodeKeyDesc.PubKey.SerializeCompressed())
|
||||||
|
|
||||||
var ourPolicy *channeldb.ChannelEdgePolicy
|
var ourPolicy *models.ChannelEdgePolicy
|
||||||
if info != nil && info.NodeKey1Bytes == ourKey {
|
if info != nil && info.NodeKey1Bytes == ourKey {
|
||||||
ourPolicy = e1
|
ourPolicy = e1
|
||||||
} else {
|
} else {
|
||||||
@ -3094,8 +3095,8 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
selfPub := s.identityECDH.PubKey().SerializeCompressed()
|
selfPub := s.identityECDH.PubKey().SerializeCompressed()
|
||||||
err = s.graphDB.ForEachNodeChannel(nil, sourceNode.PubKeyBytes, func(
|
err = s.graphDB.ForEachNodeChannel(nil, sourceNode.PubKeyBytes, func(
|
||||||
tx kvdb.RTx,
|
tx kvdb.RTx,
|
||||||
chanInfo *channeldb.ChannelEdgeInfo,
|
chanInfo *models.ChannelEdgeInfo,
|
||||||
policy, _ *channeldb.ChannelEdgePolicy) error {
|
policy, _ *models.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
// If the remote party has announced the channel to us, but we
|
// If the remote party has announced the channel to us, but we
|
||||||
// haven't yet, then we won't have a policy. However, we don't
|
// haven't yet, then we won't have a policy. However, we don't
|
||||||
|
Loading…
x
Reference in New Issue
Block a user