routerrpc

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2020 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const Subsystem = "RRPC"

Subsystem defines the logging code for this subsystem.

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func MarshalTimeNano

func MarshalTimeNano(t time.Time) int64

MarshalTimeNano converts a time.Time into its nanosecond representation. If the time is zero, this method simply returns 0, since calling UnixNano() on a zero-valued time is undefined.

func UnmarshalFeatures

func UnmarshalFeatures(
	rpcFeatures []api.FeatureBit) (*lnwire.FeatureVector, error)

UnmarshalFeatures converts a list of uint32's into a valid feature vector. This method checks that feature bit pairs aren't assigned toegether, and validates transitive dependencies.

func UnmarshalMPP

func UnmarshalMPP(reqMPP *api.MPPRecord) (*record.MPP, error)

UnmarshalMPP accepts the mpp_total_amt_msat and mpp_payment_addr fields from an RPC request and converts into an record.MPP object. An error is returned if the payment address is not 0 or 32 bytes. If the total amount and payment address are zero-value, the return value will be nil signaling there is no MPP record to attach to this hop. Otherwise, a non-nil reocrd will be contained combining the provided values.

func UnmarshallHopWithPubkey

func UnmarshallHopWithPubkey(rpcHop *api.Hop, pubkey route.Vertex) (*route.Hop,
	error)

UnmarshallHopWithPubkey unmarshalls an rpc hop for which the pubkey has already been extracted.

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

func ValidateCLTVLimit

func ValidateCLTVLimit(val, max uint32) (uint32, error)

ValidateCLTVLimit returns a valid CLTV limit given a value and a maximum. If the value exceeds the maximum, then an error is returned. If the value is 0, then the maximum is used.

func ValidatePayReqExpiry

func ValidatePayReqExpiry(payReq *zpay32.Invoice) error

ValidatePayReqExpiry checks if the passed payment request has expired. In the case it has expired, an error will be returned.

Types

type Config

type Config struct{}

Config is the default config struct for the package. When the build tag isn't specified, then we output a blank config.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig defines the config defaults. Without the sub server enabled, there are no defaults to set.

type MissionControl

type MissionControl interface {
	// GetProbability is expected to return the success probability of a
	// payment from fromNode to toNode.
	GetProbability(fromNode, toNode route.Vertex,
		amt lnwire.MilliSatoshi) float64

	// ResetHistory resets the history of MissionControl returning it to a
	// state as if no payment attempts have been made.
	ResetHistory() error

	// GetHistorySnapshot takes a snapshot from the current mission control
	// state and actual probability estimates.
	GetHistorySnapshot() *routing.MissionControlSnapshot

	// GetPairHistorySnapshot returns the stored history for a given node
	// pair.
	GetPairHistorySnapshot(fromNode,
		toNode route.Vertex) routing.TimedPairResult
}

MissionControl defines the mission control dependencies of routerrpc.

type RouterBackend

type RouterBackend struct {
	// MaxPaymentMSat is the largest payment permitted by the backend.
	MaxPaymentMSat lnwire.MilliSatoshi

	// SelfNode is the vertex of the node sending the payment.
	SelfNode route.Vertex

	// FetchChannelCapacity is a closure that we'll use the fetch the total
	// capacity of a channel to populate in responses.
	FetchChannelCapacity func(chanID uint64) (btcutil.Amount, error)

	// FetchChannelEndpoints returns the pubkeys of both endpoints of the
	// given channel id.
	FetchChannelEndpoints func(chanID uint64) (route.Vertex,
		route.Vertex, error)

	// FindRoutes is a closure that abstracts away how we locate/query for
	// routes.
	FindRoute func(source, target route.Vertex,
		amt lnwire.MilliSatoshi, restrictions *routing.RestrictParams,
		destCustomRecords record.CustomSet,
		routeHints map[route.Vertex][]*channeldb.ChannelEdgePolicy,
		finalExpiry uint16) (*route.Route, error)

	MissionControl MissionControl

	// ActiveNetParams are the network parameters of the primary network
	// that the route is operating on. This is necessary so we can ensure
	// that we receive payment requests that send to destinations on our
	// network.
	ActiveNetParams *chaincfg.Params

	// Tower is the ControlTower instance that is used to track pending
	// payments.
	Tower routing.ControlTower

	// MaxTotalTimelock is the maximum total time lock a route is allowed to
	// have.
	MaxTotalTimelock uint32

	// DefaultFinalCltvDelta is the default value used as final cltv delta
	// when an RPC caller doesn't specify a value.
	DefaultFinalCltvDelta uint16
}

RouterBackend contains the backend implementation of the router rpc sub server calls.

func (*RouterBackend) MarshalHTLCAttempt

func (r *RouterBackend) MarshalHTLCAttempt(
	htlc channeldb.HTLCAttempt) (*api.HTLCAttempt, error)

MarshalHTLCAttempt constructs an RPC HTLCAttempt from the db representation.

func (*RouterBackend) MarshallRoute

func (r *RouterBackend) MarshallRoute(route *route.Route) (*api.Route, error)

MarshallRoute marshalls an internal route to an rpc route struct.

func (*RouterBackend) QueryRoutes

QueryRoutes attempts to query the daemons' Channel Router for a possible route to a target destination capable of carrying a specific amount of satoshis within the route's flow. The retuned route contains the full details required to craft and send an HTLC, also including the necessary information that should be present within the Sphinx packet encapsulated within the HTLC.

TODO(roasbeef): should return a slice of routes in reality * create separate PR to send based on well formatted route

func (*RouterBackend) UnmarshallHop

func (r *RouterBackend) UnmarshallHop(rpcHop *api.Hop,
	prevNodePubKey [33]byte) (*route.Hop, error)

UnmarshallHop unmarshalls an rpc hop that may or may not contain a node pubkey.

func (*RouterBackend) UnmarshallRoute

func (r *RouterBackend) UnmarshallRoute(rpcroute *api.Route) (
	*route.Route, error)

UnmarshallRoute unmarshalls an rpc route. For hops that don't specify a pubkey, the channel graph is queried.

type RoutingConfig

type RoutingConfig struct {
	// MinRouteProbability is the minimum required route success probability
	// to attempt the payment.
	MinRouteProbability float64 `long:"minrtprob" description:"Minimum required route success probability to attempt the payment"`

	// AprioriHopProbability is the assumed success probability of a hop in
	// a route when no other information is available.
	AprioriHopProbability float64 `long:"apriorihopprob" description:"Assumed success probability of a hop in a route when no other information is available."`

	// AprioriWeight is a value in the range [0, 1] that defines to what
	// extent historical results should be extrapolated to untried
	// connections. Setting it to one will completely ignore historical
	// results and always assume the configured a priori probability for
	// untried connections. A value of zero will ignore the a priori
	// probability completely and only base the probability on historical
	// results, unless there are none available.
	AprioriWeight float64 `` /* 132-byte string literal not displayed */

	// PenaltyHalfLife defines after how much time a penalized node or
	// channel is back at 50% probability.
	PenaltyHalfLife time.Duration `long:"penaltyhalflife" description:"Defines the duration after which a penalized node or channel is back at 50% probability"`

	// AttemptCost is the virtual cost in path finding weight units of
	// executing a payment attempt that fails. It is used to trade off
	// potentially better routes against their probability of succeeding.
	AttemptCost btcutil.Amount `long:"attemptcost" description:"The (virtual) cost in sats of a failed payment attempt"`

	// MaxMcHistory defines the maximum number of payment results that
	// are held on disk by mission control.
	MaxMcHistory int `long:"maxmchistory" description:"the maximum number of payment results that are held on disk by mission control"`
}

RoutingConfig contains the configurable parameters that control routing.

func GetRoutingConfig

func GetRoutingConfig(cfg *Config) *RoutingConfig

GetRoutingConfig returns the routing config based on this sub server config.

Jump to

Keyboard shortcuts

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