routing: fix format and add more docs
This commit is contained in:
1 parent
25d82fd62b
commit
3259557a46
2 files changed
+49
-36
No files matched your search
@@ -34,9 +34,16 @@ type paymentLifecycle struct {
|
|||||||
// paymentState holds a number of key insights learned from a given MPPayment
|
// paymentState holds a number of key insights learned from a given MPPayment
|
||||||
// that we use to determine what to do on each payment loop iteration.
|
// that we use to determine what to do on each payment loop iteration.
|
||||||
type paymentState struct {
|
type paymentState struct {
|
||||||
|
// numShardsInFlight specifies the number of HTLCs the payment is
|
||||||
|
// waiting results for.
|
||||||
numShardsInFlight int
|
numShardsInFlight int
|
||||||
remainingAmt lnwire.MilliSatoshi
|
|
||||||
remainingFees lnwire.MilliSatoshi
|
// remainingAmt specifies how much more money to be sent.
|
||||||
|
remainingAmt lnwire.MilliSatoshi
|
||||||
|
|
||||||
|
// remainingFees specifies the remaining budget that can be used as
|
||||||
|
// fees.
|
||||||
|
remainingFees lnwire.MilliSatoshi
|
||||||
|
|
||||||
// terminate indicates the payment is in its final stage and no more
|
// terminate indicates the payment is in its final stage and no more
|
||||||
// shards should be launched. This value is true if we have an HTLC
|
// shards should be launched. This value is true if we have an HTLC
|
||||||
@@ -65,9 +72,9 @@ func (ps paymentState) needWaitForShards() bool {
|
|||||||
return ps.terminate || ps.remainingAmt == 0
|
return ps.terminate || ps.remainingAmt == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetchPaymentState will query the db for the latest payment state
|
// fetchPaymentState will query the db for the latest payment state information
|
||||||
// information we need to act on every iteration of the payment loop and update
|
// we need to act on every iteration of the payment loop and update the
|
||||||
// the paymentState.
|
// paymentState.
|
||||||
func (p *paymentLifecycle) fetchPaymentState() (*channeldb.MPPayment,
|
func (p *paymentLifecycle) fetchPaymentState() (*channeldb.MPPayment,
|
||||||
*paymentState, error) {
|
*paymentState, error) {
|
||||||
|
|
||||||
@@ -84,8 +91,8 @@ func (p *paymentLifecycle) fetchPaymentState() (*channeldb.MPPayment,
|
|||||||
// Sanity check we haven't sent a value larger than the payment amount.
|
// Sanity check we haven't sent a value larger than the payment amount.
|
||||||
totalAmt := payment.Info.Value
|
totalAmt := payment.Info.Value
|
||||||
if sentAmt > totalAmt {
|
if sentAmt > totalAmt {
|
||||||
return nil, nil, fmt.Errorf("amount sent %v exceeds "+
|
return nil, nil, fmt.Errorf("amount sent %v exceeds total "+
|
||||||
"total amount %v", sentAmt, totalAmt)
|
"amount %v", sentAmt, totalAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// We'll subtract the used fee from our fee budget, but allow the fees
|
// We'll subtract the used fee from our fee budget, but allow the fees
|
||||||
@@ -635,8 +642,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
|||||||
attempt.AttemptID, &attempt.Route,
|
attempt.AttemptID, &attempt.Route,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Error reporting payment success to mc: %v",
|
log.Errorf("Error reporting payment success to mc: %v", err)
|
||||||
err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// In case of success we atomically store settle result to the DB move
|
// In case of success we atomically store settle result to the DB move
|
||||||
@@ -649,7 +655,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to succeed payment attempt: %v", err)
|
log.Errorf("Unable to settle payment attempt: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+33
-26
@@ -101,20 +101,24 @@ type ChannelGraphSource interface {
|
|||||||
// AddNode is used to add information about a node to the router
|
// AddNode is used to add information about a node to the router
|
||||||
// database. If the node with this pubkey is not present in an existing
|
// database. If the node with this pubkey is not present in an existing
|
||||||
// channel, it will be ignored.
|
// channel, it will be ignored.
|
||||||
AddNode(node *channeldb.LightningNode, op ...batch.SchedulerOption) error
|
AddNode(node *channeldb.LightningNode,
|
||||||
|
op ...batch.SchedulerOption) error
|
||||||
|
|
||||||
// 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, op ...batch.SchedulerOption) error
|
AddEdge(edge *channeldb.ChannelEdgeInfo,
|
||||||
|
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, proof *channeldb.ChannelAuthProof) error
|
AddProof(chanID lnwire.ShortChannelID,
|
||||||
|
proof *channeldb.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, op ...batch.SchedulerOption) error
|
UpdateEdge(policy *channeldb.ChannelEdgePolicy,
|
||||||
|
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
|
||||||
// for the target node with a more recent timestamp. This method will
|
// for the target node with a more recent timestamp. This method will
|
||||||
@@ -152,8 +156,9 @@ type ChannelGraphSource interface {
|
|||||||
CurrentBlockHeight() (uint32, error)
|
CurrentBlockHeight() (uint32, error)
|
||||||
|
|
||||||
// GetChannelByID return the channel by the channel id.
|
// GetChannelByID return the channel by the channel id.
|
||||||
GetChannelByID(chanID lnwire.ShortChannelID) (*channeldb.ChannelEdgeInfo,
|
GetChannelByID(chanID lnwire.ShortChannelID) (
|
||||||
*channeldb.ChannelEdgePolicy, *channeldb.ChannelEdgePolicy, error)
|
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy,
|
||||||
|
*channeldb.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
|
||||||
@@ -226,8 +231,8 @@ type MissionController interface {
|
|||||||
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
failureSourceIdx *int, failure lnwire.FailureMessage) (
|
||||||
*channeldb.FailureReason, error)
|
*channeldb.FailureReason, error)
|
||||||
|
|
||||||
// ReportPaymentSuccess reports a successful payment to mission control as input
|
// ReportPaymentSuccess reports a successful payment to mission control
|
||||||
// for future probability estimates.
|
// as input for future probability estimates.
|
||||||
ReportPaymentSuccess(attemptID uint64, rt *route.Route) error
|
ReportPaymentSuccess(attemptID uint64, rt *route.Route) error
|
||||||
|
|
||||||
// GetProbability is expected to return the success probability of a
|
// GetProbability is expected to return the success probability of a
|
||||||
@@ -410,8 +415,8 @@ type ChannelRouter struct {
|
|||||||
// when doing any path finding.
|
// when doing any path finding.
|
||||||
selfNode *channeldb.LightningNode
|
selfNode *channeldb.LightningNode
|
||||||
|
|
||||||
// cachedGraph is an instance of routingGraph that caches the source node as
|
// cachedGraph is an instance of routingGraph that caches the source
|
||||||
// well as the channel graph itself in memory.
|
// node as well as the channel graph itself in memory.
|
||||||
cachedGraph routingGraph
|
cachedGraph routingGraph
|
||||||
|
|
||||||
// newBlocks is a channel in which new blocks connected to the end of
|
// newBlocks is a channel in which new blocks connected to the end of
|
||||||
@@ -741,8 +746,8 @@ func (r *ChannelRouter) syncGraphWithChain() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Infof("Prune tip for Channel Graph: height=%v, hash=%v", pruneHeight,
|
log.Infof("Prune tip for Channel Graph: height=%v, hash=%v",
|
||||||
pruneHash)
|
pruneHeight, pruneHash)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
@@ -931,9 +936,9 @@ func (r *ChannelRouter) pruneZombieChans() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If AssumeChannelValid is present we'll look at the disabled bit for both
|
// If AssumeChannelValid is present we'll look at the disabled bit for
|
||||||
// edges. If they're both disabled, then we can interpret this as the
|
// both edges. If they're both disabled, then we can interpret this as
|
||||||
// channel being closed and can prune it from our graph.
|
// the channel being closed and can prune it from our graph.
|
||||||
if r.cfg.AssumeChannelValid {
|
if r.cfg.AssumeChannelValid {
|
||||||
disabledChanIDs, err := r.cfg.Graph.DisabledChannelIDs()
|
disabledChanIDs, err := r.cfg.Graph.DisabledChannelIDs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1905,7 +1910,9 @@ func generateSphinxPacket(rt *route.Route, paymentHash []byte,
|
|||||||
|
|
||||||
log.Tracef("Constructed per-hop payloads for payment_hash=%x: %v",
|
log.Tracef("Constructed per-hop payloads for payment_hash=%x: %v",
|
||||||
paymentHash[:], newLogClosure(func() string {
|
paymentHash[:], newLogClosure(func() string {
|
||||||
path := make([]sphinx.OnionHop, sphinxPath.TrueRouteLength())
|
path := make(
|
||||||
|
[]sphinx.OnionHop, sphinxPath.TrueRouteLength(),
|
||||||
|
)
|
||||||
for i := range path {
|
for i := range path {
|
||||||
hopCopy := sphinxPath[i]
|
hopCopy := sphinxPath[i]
|
||||||
path[i] = hopCopy
|
path[i] = hopCopy
|
||||||
@@ -2390,10 +2397,6 @@ func (r *ChannelRouter) sendToRoute(htlcHash lntypes.Hash, rt *route.Route,
|
|||||||
// to reach the destination. Additionally, the payment preimage will also be
|
// to reach the destination. Additionally, the payment preimage will also be
|
||||||
// returned.
|
// returned.
|
||||||
//
|
//
|
||||||
// The existing attempt argument should be set to nil if this is a payment that
|
|
||||||
// haven't had any payment attempt sent to the switch yet. If it has had an
|
|
||||||
// attempt already, it should be passed such that the result can be retrieved.
|
|
||||||
//
|
|
||||||
// This method relies on the ControlTower's internal payment state machine to
|
// This method relies on the ControlTower's internal payment state machine to
|
||||||
// carry out its execution. After restarts it is safe, and assumed, that the
|
// carry out its execution. After restarts it is safe, and assumed, that the
|
||||||
// router will call this method for every payment still in-flight according to
|
// router will call this method for every payment still in-flight according to
|
||||||
@@ -2429,7 +2432,6 @@ func (r *ChannelRouter) sendPayment(feeLimit lnwire.MilliSatoshi,
|
|||||||
}
|
}
|
||||||
|
|
||||||
return p.resumePayment()
|
return p.resumePayment()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// extractChannelUpdate examines the error and extracts the channel update.
|
// extractChannelUpdate examines the error and extracts the channel update.
|
||||||
@@ -2627,10 +2629,13 @@ func (r *ChannelRouter) FetchLightningNode(
|
|||||||
// ForEachNode is used to iterate over every node in router topology.
|
// ForEachNode is used to iterate over every node in router topology.
|
||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) ForEachNode(cb func(*channeldb.LightningNode) error) error {
|
func (r *ChannelRouter) ForEachNode(
|
||||||
return r.cfg.Graph.ForEachNode(func(_ kvdb.RTx, n *channeldb.LightningNode) error {
|
cb func(*channeldb.LightningNode) error) error {
|
||||||
return cb(n)
|
|
||||||
})
|
return r.cfg.Graph.ForEachNode(
|
||||||
|
func(_ kvdb.RTx, n *channeldb.LightningNode) error {
|
||||||
|
return cb(n)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ForAllOutgoingChannels is used to iterate over all outgoing channels owned by
|
// ForAllOutgoingChannels is used to iterate over all outgoing channels owned by
|
||||||
@@ -2699,7 +2704,9 @@ func (r *ChannelRouter) IsPublicNode(node route.Vertex) (bool, error) {
|
|||||||
//
|
//
|
||||||
// NOTE: This method is part of the ChannelGraphSource interface.
|
// NOTE: This method is part of the ChannelGraphSource interface.
|
||||||
func (r *ChannelRouter) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
func (r *ChannelRouter) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
|
||||||
_, _, exists, isZombie, _ := r.cfg.Graph.HasChannelEdge(chanID.ToUint64())
|
_, _, exists, isZombie, _ := r.cfg.Graph.HasChannelEdge(
|
||||||
|
chanID.ToUint64(),
|
||||||
|
)
|
||||||
return exists || isZombie
|
return exists || isZombie
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user