mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-12-01 08:29:00 +01:00
routing: move zero hops check
This commit is contained in:
@@ -271,6 +271,11 @@ func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32,
|
|||||||
func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) {
|
func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) {
|
||||||
var path sphinx.PaymentPath
|
var path sphinx.PaymentPath
|
||||||
|
|
||||||
|
// We can only construct a route if there are hops provided.
|
||||||
|
if len(r.Hops) == 0 {
|
||||||
|
return nil, ErrNoRouteHopsProvided
|
||||||
|
}
|
||||||
|
|
||||||
// Check maximum route length.
|
// Check maximum route length.
|
||||||
if len(r.Hops) > sphinx.NumMaxHops {
|
if len(r.Hops) > sphinx.NumMaxHops {
|
||||||
return nil, ErrMaxRouteHopsExceeded
|
return nil, ErrMaxRouteHopsExceeded
|
||||||
|
|||||||
@@ -1487,13 +1487,6 @@ func generateNewSessionKey() (*btcec.PrivateKey, error) {
|
|||||||
func generateSphinxPacket(rt *route.Route, paymentHash []byte,
|
func generateSphinxPacket(rt *route.Route, paymentHash []byte,
|
||||||
sessionKey *btcec.PrivateKey) ([]byte, *sphinx.Circuit, error) {
|
sessionKey *btcec.PrivateKey) ([]byte, *sphinx.Circuit, error) {
|
||||||
|
|
||||||
// As a sanity check, we'll ensure that the set of hops has been
|
|
||||||
// properly filled in, otherwise, we won't actually be able to
|
|
||||||
// construct a route.
|
|
||||||
if len(rt.Hops) == 0 {
|
|
||||||
return nil, nil, route.ErrNoRouteHopsProvided
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that we know we have an actual route, we'll map the route into a
|
// Now that we know we have an actual route, we'll map the route into a
|
||||||
// sphinx payument path which includes per-hop paylods for each hop
|
// sphinx payument path which includes per-hop paylods for each hop
|
||||||
// that give each node within the route the necessary information
|
// that give each node within the route the necessary information
|
||||||
|
|||||||
Reference in New Issue
Block a user