routing: move zero hops check

This commit is contained in:
Joost Jager 2019-12-16 14:53:41 +01:00
parent 31b2c22cf5
commit d85f378aa2
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
2 changed files with 5 additions and 7 deletions

@ -271,6 +271,11 @@ func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32,
func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error) {
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.
if len(r.Hops) > sphinx.NumMaxHops {
return nil, ErrMaxRouteHopsExceeded

@ -1487,13 +1487,6 @@ func generateNewSessionKey() (*btcec.PrivateKey, error) {
func generateSphinxPacket(rt *route.Route, paymentHash []byte,
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
// sphinx payument path which includes per-hop paylods for each hop
// that give each node within the route the necessary information