mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-25 21:16:49 +02:00
routing/route/route: add optional MPP field to Hop
This commit also modifies the Router serialization to persist the MPP struct when present, and properly restore it when loading from disk.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@@ -19,9 +20,17 @@ import (
|
||||
// VertexSize is the size of the array to store a vertex.
|
||||
const VertexSize = 33
|
||||
|
||||
// ErrNoRouteHopsProvided is returned when a caller attempts to construct a new
|
||||
// sphinx packet, but provides an empty set of hops for each route.
|
||||
var ErrNoRouteHopsProvided = fmt.Errorf("empty route hops provided")
|
||||
var (
|
||||
// ErrNoRouteHopsProvided is returned when a caller attempts to
|
||||
// construct a new sphinx packet, but provides an empty set of hops for
|
||||
// each route.
|
||||
ErrNoRouteHopsProvided = fmt.Errorf("empty route hops provided")
|
||||
|
||||
// ErrIntermediateMPPHop is returned when a hop tries to deliver an MPP
|
||||
// record to an intermediate hop, only final hops can receive MPP
|
||||
// records.
|
||||
ErrIntermediateMPPHop = errors.New("cannot send MPP to intermediate")
|
||||
)
|
||||
|
||||
// Vertex is a simple alias for the serialization of a compressed Bitcoin
|
||||
// public key.
|
||||
@@ -94,6 +103,10 @@ type Hop struct {
|
||||
// carries as a fee will be subtracted by the hop.
|
||||
AmtToForward lnwire.MilliSatoshi
|
||||
|
||||
// MPP encapsulates the data required for option_mpp. This field should
|
||||
// only be set for the final hop.
|
||||
MPP *record.MPP
|
||||
|
||||
// TLVRecords if non-nil are a set of additional TLV records that
|
||||
// should be included in the forwarding instructions for this node.
|
||||
TLVRecords []tlv.Record
|
||||
@@ -140,6 +153,17 @@ func (h *Hop) PackHopPayload(w io.Writer, nextChanID uint64) error {
|
||||
)
|
||||
}
|
||||
|
||||
// If an MPP record is destined for this hop, ensure that we only ever
|
||||
// attach it to the final hop. Otherwise the route was constructed
|
||||
// incorrectly.
|
||||
if h.MPP != nil {
|
||||
if nextChanID == 0 {
|
||||
records = append(records, h.MPP.Record())
|
||||
} else {
|
||||
return ErrIntermediateMPPHop
|
||||
}
|
||||
}
|
||||
|
||||
// Append any custom types destined for this hop.
|
||||
records = append(records, h.TLVRecords...)
|
||||
|
||||
|
Reference in New Issue
Block a user