route

package
v0.7.1-beta-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRouteHopsProvided = fmt.Errorf("empty route hops provided")

ErrNoRouteHopsProvided is returned when a caller attempts to construct a new sphinx packet, but provides an empty set of hops for each route.

Functions

This section is empty.

Types

type Hop

type Hop struct {
	// PubKeyBytes is the raw bytes of the public key of the target node.
	PubKeyBytes Vertex

	// 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

	// OutgoingTimeLock is the timelock value that should be used when
	// crafting the _outgoing_ HTLC from this hop.
	OutgoingTimeLock uint32

	// AmtToForward is the amount that this hop will forward to the next
	// hop. This value is less than the value that the incoming HTLC
	// carries as a fee will be subtracted by the hop.
	AmtToForward lnwire.MilliSatoshi
}

Hop represents an intermediate or final node of the route. This naming is in line with the definition given in BOLT #4: Onion Routing Protocol. The struct houses the channel along which this hop can be reached and the values necessary to create the HTLC that needs to be sent to the next hop. It is also used to encode the per-hop payload included within the Sphinx packet.

type Route

type Route struct {
	// TotalTimeLock is the cumulative (final) time lock across the entire
	// route. This is the CLTV value that should be extended to the first
	// hop in the route. All other hops will decrement the time-lock as
	// advertised, leaving enough time for all hops to wait for or present
	// the payment preimage to complete the payment.
	TotalTimeLock uint32

	// TotalAmount is the total amount of funds required to complete a
	// payment over this route. This value includes the cumulative fees at
	// each hop. As a result, the HTLC extended to the first-hop in the
	// route will need to have at least this many satoshis, otherwise the
	// route will fail at an intermediate node due to an insufficient
	// amount of fees.
	TotalAmount lnwire.MilliSatoshi

	// SourcePubKey is the pubkey of the node where this route originates
	// from.
	SourcePubKey Vertex

	// Hops contains details concerning the specific forwarding details at
	// each hop.
	Hops []*Hop
}

Route represents a path through the channel graph which runs over one or more channels in succession. This struct carries all the information required to craft the Sphinx onion packet, and send the payment along the first hop in the path. A route is only selected as valid if all the channels have sufficient capacity to carry the initial payment amount after fees are accounted for.

func NewRouteFromHops

func NewRouteFromHops(amtToSend lnwire.MilliSatoshi, timeLock uint32,
	sourceVertex Vertex, hops []*Hop) (*Route, error)

NewRouteFromHops creates a new Route structure from the minimally required information to perform the payment. It infers fee amounts and populates the node, chan and prev/next hop maps.

func (*Route) HopFee

func (r *Route) HopFee(hopIndex int) lnwire.MilliSatoshi

HopFee returns the fee charged by the route hop indicated by hopIndex.

func (*Route) String

func (r *Route) String() string

String returns a human readable representation of the route.

func (*Route) ToSphinxPath

func (r *Route) ToSphinxPath() (*sphinx.PaymentPath, error)

ToSphinxPath converts a complete route into a sphinx PaymentPath that contains the per-hop paylods used to encoding the HTLC routing data for each hop in the route.

func (*Route) TotalFees

func (r *Route) TotalFees() lnwire.MilliSatoshi

TotalFees is the sum of the fees paid at each hop within the final route. In the case of a one-hop payment, this value will be zero as we don't need to pay a fee to ourself.

type Vertex

type Vertex [33]byte

Vertex is a simple alias for the serialization of a compressed Bitcoin public key.

func NewVertex

func NewVertex(pub *btcec.PublicKey) Vertex

NewVertex returns a new Vertex given a public key.

func (Vertex) String

func (v Vertex) String() string

String returns a human readable version of the Vertex which is the hex-encoding of the serialized compressed public key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL