models

package
v0.18.3-beta.rc3 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidCircuitKeyLen signals that a circuit key could not be
	// decoded because the byte slice is of an invalid length.
	ErrInvalidCircuitKeyLen = fmt.Errorf("length of serialized circuit " +
		"key must be 16 bytes")
)

Functions

This section is empty.

Types

type CachedEdgePolicy

type CachedEdgePolicy struct {
	// 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

	// MessageFlags is a bitfield which indicates the presence of optional
	// fields (like max_htlc) in the policy.
	MessageFlags lnwire.ChanUpdateMsgFlags

	// ChannelFlags is a bitfield which signals the capabilities of the
	// channel as well as the directed edge this update applies to.
	ChannelFlags lnwire.ChanUpdateChanFlags

	// TimeLockDelta is the number of blocks this node will subtract from
	// the expiry of an incoming HTLC. This value expresses the time buffer
	// the node would like to HTLC exchanges.
	TimeLockDelta uint16

	// MinHTLC is the smallest value HTLC this node will forward, expressed
	// in millisatoshi.
	MinHTLC lnwire.MilliSatoshi

	// MaxHTLC is the largest value HTLC this node will forward, expressed
	// in millisatoshi.
	MaxHTLC lnwire.MilliSatoshi

	// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
	// ANY HTLC, expressed in mSAT's.
	FeeBaseMSat lnwire.MilliSatoshi

	// FeeProportionalMillionths is the rate that the node will charge for
	// HTLCs for each millionth of a satoshi forwarded.
	FeeProportionalMillionths lnwire.MilliSatoshi

	// ToNodePubKey is a function that returns the to node of a policy.
	// Since we only ever store the inbound policy, this is always the node
	// that we query the channels for in ForEachChannel(). Therefore, we can
	// save a lot of space by not storing this information in the memory and
	// instead just set this function when we copy the policy from cache in
	// ForEachChannel().
	ToNodePubKey func() route.Vertex

	// ToNodeFeatures are the to node's features. They are never set while
	// the edge is in the cache, only on the copy that is returned in
	// ForEachChannel().
	ToNodeFeatures *lnwire.FeatureVector
}

CachedEdgePolicy is a struct that only caches the information of a ChannelEdgePolicy that we actually use for pathfinding and therefore need to store in the cache.

func NewCachedPolicy

func NewCachedPolicy(policy *ChannelEdgePolicy) *CachedEdgePolicy

NewCachedPolicy turns a full policy into a minimal one that can be cached.

func (*CachedEdgePolicy) ComputeFee

ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over the passed active payment channel. This value is currently computed as specified in BOLT07, but will likely change in the near future.

type ChannelAuthProof

type ChannelAuthProof struct {

	// NodeSig1Bytes are the raw bytes of the first node signature encoded
	// in DER format.
	NodeSig1Bytes []byte

	// NodeSig2Bytes are the raw bytes of the second node signature
	// encoded in DER format.
	NodeSig2Bytes []byte

	// BitcoinSig1Bytes are the raw bytes of the first bitcoin signature
	// encoded in DER format.
	BitcoinSig1Bytes []byte

	// BitcoinSig2Bytes are the raw bytes of the second bitcoin signature
	// encoded in DER format.
	BitcoinSig2Bytes []byte
	// contains filtered or unexported fields
}

ChannelAuthProof is the authentication proof (the signature portion) for a channel. Using the four signatures contained in the struct, and some auxiliary knowledge (the funding script, node identities, and outpoint) nodes on the network are able to validate the authenticity and existence of a channel. Each of these signatures signs the following digest: chanID || nodeID1 || nodeID2 || bitcoinKey1|| bitcoinKey2 || 2-byte-feature-len || features.

func (*ChannelAuthProof) BitcoinSig1

func (c *ChannelAuthProof) BitcoinSig1() (*ecdsa.Signature, error)

BitcoinSig1 is the signature using the public key of the first node that was used in the channel's multi-sig output.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the signature if absolutely necessary.

func (*ChannelAuthProof) BitcoinSig2

func (c *ChannelAuthProof) BitcoinSig2() (*ecdsa.Signature, error)

BitcoinSig2 is the signature using the public key of the second node that was used in the channel's multi-sig output.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the signature if absolutely necessary.

func (*ChannelAuthProof) IsEmpty

func (c *ChannelAuthProof) IsEmpty() bool

IsEmpty check is the authentication proof is empty Proof is empty if at least one of the signatures are equal to nil.

func (*ChannelAuthProof) Node1Sig

func (c *ChannelAuthProof) Node1Sig() (*ecdsa.Signature, error)

Node1Sig is the signature using the identity key of the node that is first in a lexicographical ordering of the serialized public keys of the two nodes that created the channel.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the signature if absolutely necessary.

func (*ChannelAuthProof) Node2Sig

func (c *ChannelAuthProof) Node2Sig() (*ecdsa.Signature, error)

Node2Sig is the signature using the identity key of the node that is second in a lexicographical ordering of the serialized public keys of the two nodes that created the channel.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the signature if absolutely necessary.

type ChannelEdgeInfo

type ChannelEdgeInfo struct {
	// 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

	// ChainHash is the hash that uniquely identifies the chain that this
	// channel was opened within.
	//
	// TODO(roasbeef): need to modify db keying for multi-chain
	//  * must add chain hash to prefix as well
	ChainHash chainhash.Hash

	// NodeKey1Bytes is the raw public key of the first node.
	NodeKey1Bytes [33]byte

	// NodeKey2Bytes is the raw public key of the first node.
	NodeKey2Bytes [33]byte

	// BitcoinKey1Bytes is the raw public key of the first node.
	BitcoinKey1Bytes [33]byte

	// BitcoinKey2Bytes is the raw public key of the first node.
	BitcoinKey2Bytes [33]byte

	// Features is an opaque byte slice that encodes the set of channel
	// specific features that this channel edge supports.
	Features []byte

	// AuthProof is the authentication proof for this channel. This proof
	// contains a set of signatures binding four identities, which attests
	// to the legitimacy of the advertised channel.
	AuthProof *ChannelAuthProof

	// ChannelPoint is the funding outpoint of the channel. This can be
	// used to uniquely identify the channel within the channel graph.
	ChannelPoint wire.OutPoint

	// Capacity is the total capacity of the channel, this is determined by
	// the value output in the outpoint that created this channel.
	Capacity btcutil.Amount

	// ExtraOpaqueData is the set of data that was appended to this
	// message, some of which we may not actually know how to iterate or
	// parse. By holding onto this data, we ensure that we're able to
	// properly validate the set of signatures that cover these new fields,
	// and ensure we're able to make upgrades to the network in a forwards
	// compatible manner.
	ExtraOpaqueData []byte
	// contains filtered or unexported fields
}

ChannelEdgeInfo represents a fully authenticated channel along with all its unique attributes. Once an authenticated channel announcement has been processed on the network, then an instance of ChannelEdgeInfo encapsulating the channels attributes is stored. The other portions relevant to routing policy of a channel are stored within a ChannelEdgePolicy for each direction of the channel.

func (*ChannelEdgeInfo) AddNodeKeys

func (c *ChannelEdgeInfo) AddNodeKeys(nodeKey1, nodeKey2, bitcoinKey1,
	bitcoinKey2 *btcec.PublicKey)

AddNodeKeys is a setter-like method that can be used to replace the set of keys for the target ChannelEdgeInfo.

func (*ChannelEdgeInfo) BitcoinKey1

func (c *ChannelEdgeInfo) BitcoinKey1() (*btcec.PublicKey, error)

BitcoinKey1 is the Bitcoin multi-sig key belonging to the first node, that was involved in the funding transaction that originally created the channel that this struct represents.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the pubkey if absolutely necessary.

func (*ChannelEdgeInfo) BitcoinKey2

func (c *ChannelEdgeInfo) BitcoinKey2() (*btcec.PublicKey, error)

BitcoinKey2 is the Bitcoin multi-sig key belonging to the second node, that was involved in the funding transaction that originally created the channel that this struct represents.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the pubkey if absolutely necessary.

func (*ChannelEdgeInfo) NodeKey1

func (c *ChannelEdgeInfo) NodeKey1() (*btcec.PublicKey, error)

NodeKey1 is the identity public key of the "first" node that was involved in the creation of this channel. A node is considered "first" if the lexicographical ordering the its serialized public key is "smaller" than that of the other node involved in channel creation.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the pubkey if absolutely necessary.

func (*ChannelEdgeInfo) NodeKey2

func (c *ChannelEdgeInfo) NodeKey2() (*btcec.PublicKey, error)

NodeKey2 is the identity public key of the "second" node that was involved in the creation of this channel. A node is considered "second" if the lexicographical ordering the its serialized public key is "larger" than that of the other node involved in channel creation.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the pubkey if absolutely necessary.

func (*ChannelEdgeInfo) OtherNodeKeyBytes

func (c *ChannelEdgeInfo) OtherNodeKeyBytes(thisNodeKey []byte) (
	[33]byte, error)

OtherNodeKeyBytes returns the node key bytes of the other end of the channel.

type ChannelEdgePolicy

type ChannelEdgePolicy struct {
	// SigBytes is the raw bytes of the signature of the channel edge
	// policy. We'll only parse these if the caller needs to access the
	// signature for validation purposes. Do not set SigBytes directly, but
	// use SetSigBytes instead to make sure that the cache is invalidated.
	SigBytes []byte

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

	// LastUpdate is the last time an authenticated edge for this channel
	// was received.
	LastUpdate time.Time

	// MessageFlags is a bitfield which indicates the presence of optional
	// fields (like max_htlc) in the policy.
	MessageFlags lnwire.ChanUpdateMsgFlags

	// ChannelFlags is a bitfield which signals the capabilities of the
	// channel as well as the directed edge this update applies to.
	ChannelFlags lnwire.ChanUpdateChanFlags

	// TimeLockDelta is the number of blocks this node will subtract from
	// the expiry of an incoming HTLC. This value expresses the time buffer
	// the node would like to HTLC exchanges.
	TimeLockDelta uint16

	// MinHTLC is the smallest value HTLC this node will forward, expressed
	// in millisatoshi.
	MinHTLC lnwire.MilliSatoshi

	// MaxHTLC is the largest value HTLC this node will forward, expressed
	// in millisatoshi.
	MaxHTLC lnwire.MilliSatoshi

	// FeeBaseMSat is the base HTLC fee that will be charged for forwarding
	// ANY HTLC, expressed in mSAT's.
	FeeBaseMSat lnwire.MilliSatoshi

	// FeeProportionalMillionths is the rate that the node will charge for
	// HTLCs for each millionth of a satoshi forwarded.
	FeeProportionalMillionths lnwire.MilliSatoshi

	// ToNode is the public key of the node that this directed edge leads
	// to. Using this pub key, the channel graph can further be traversed.
	ToNode [33]byte

	// ExtraOpaqueData is the set of data that was appended to this
	// message, some of which we may not actually know how to iterate or
	// parse. By holding onto this data, we ensure that we're able to
	// properly validate the set of signatures that cover these new fields,
	// and ensure we're able to make upgrades to the network in a forwards
	// compatible manner.
	ExtraOpaqueData lnwire.ExtraOpaqueData
	// contains filtered or unexported fields
}

ChannelEdgePolicy represents a *directed* edge within the channel graph. For each channel in the database, there are two distinct edges: one for each possible direction of travel along the channel. The edges themselves hold information concerning fees, and minimum time-lock information which is utilized during path finding.

func (*ChannelEdgePolicy) ComputeFee

ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over the passed active payment channel. This value is currently computed as specified in BOLT07, but will likely change in the near future.

func (*ChannelEdgePolicy) IsDisabled

func (c *ChannelEdgePolicy) IsDisabled() bool

IsDisabled determines whether the edge has the disabled bit set.

func (*ChannelEdgePolicy) SetSigBytes

func (c *ChannelEdgePolicy) SetSigBytes(sig []byte)

SetSigBytes updates the signature and invalidates the cached parsed signature.

func (*ChannelEdgePolicy) Signature

func (c *ChannelEdgePolicy) Signature() (*ecdsa.Signature, error)

Signature is a channel announcement signature, which is needed for proper edge policy announcement.

NOTE: By having this method to access an attribute, we ensure we only need to fully deserialize the signature if absolutely necessary.

type CircuitKey

type CircuitKey struct {
	// ChanID is the short chanid indicating the HTLC's origin.
	//
	// NOTE: It is fine for this value to be blank, as this indicates a
	// locally-sourced payment.
	ChanID lnwire.ShortChannelID

	// HtlcID is the unique htlc index predominately assigned by links,
	// though can also be assigned by switch in the case of locally-sourced
	// payments.
	HtlcID uint64
}

CircuitKey is used by a channel to uniquely identify the HTLCs it receives from the switch, and is used to purge our in-memory state of HTLCs that have already been processed by a link. Two list of CircuitKeys are included in each CommitDiff to allow a link to determine which in-memory htlcs directed the opening and closing of circuits in the switch's circuit map.

func (CircuitKey) Bytes

func (k CircuitKey) Bytes() []byte

Bytes returns the serialized bytes for this circuit key.

func (*CircuitKey) Decode

func (k *CircuitKey) Decode(r io.Reader) error

Decode reads a CircuitKey from the provided io.Reader.

func (*CircuitKey) Encode

func (k *CircuitKey) Encode(w io.Writer) error

Encode writes a CircuitKey to the provided io.Writer.

func (*CircuitKey) SetBytes

func (k *CircuitKey) SetBytes(bs []byte) error

SetBytes deserializes the given bytes into this CircuitKey.

func (CircuitKey) String

func (k CircuitKey) String() string

String returns a string representation of the CircuitKey.

type ForwardingPolicy

type ForwardingPolicy struct {
	// MinHTLCOut is the smallest HTLC that is to be forwarded.
	MinHTLCOut lnwire.MilliSatoshi

	// MaxHTLC is the largest HTLC that is to be forwarded.
	MaxHTLC lnwire.MilliSatoshi

	// BaseFee is the base fee, expressed in milli-satoshi that must be
	// paid for each incoming HTLC. This field, combined with FeeRate is
	// used to compute the required fee for a given HTLC.
	BaseFee lnwire.MilliSatoshi

	// FeeRate is the fee rate, expressed in milli-satoshi that must be
	// paid for each incoming HTLC. This field combined with BaseFee is
	// used to compute the required fee for a given HTLC.
	FeeRate lnwire.MilliSatoshi

	// InboundFee is the fee that must be paid for incoming HTLCs.
	InboundFee InboundFee

	// TimeLockDelta is the absolute time-lock value, expressed in blocks,
	// that will be subtracted from an incoming HTLC's timelock value to
	// create the time-lock value for the forwarded outgoing HTLC. The
	// following constraint MUST hold for an HTLC to be forwarded:
	//
	//  * incomingHtlc.timeLock - timeLockDelta = fwdInfo.OutgoingCTLV
	//
	// where fwdInfo is the forwarding information extracted from the
	// per-hop payload of the incoming HTLC's onion packet.
	TimeLockDelta uint32
}

ForwardingPolicy describes the set of constraints that a given ChannelLink is to adhere to when forwarding HTLC's. For each incoming HTLC, this set of constraints will be consulted in order to ensure that adequate fees are paid, and our time-lock parameters are respected. In the event that an incoming HTLC violates any of these constraints, it is to be _rejected_ with the error possibly carrying along a ChannelUpdate message that includes the latest policy.

type InboundFee

type InboundFee struct {
	Base int32
	Rate int32
}

func NewInboundFeeFromWire

func NewInboundFeeFromWire(fee lnwire.Fee) InboundFee

NewInboundFeeFromWire constructs an inbound fee structure from a wire fee.

func (*InboundFee) CalcFee

func (i *InboundFee) CalcFee(amt lnwire.MilliSatoshi) int64

CalcFee calculates what the inbound fee should minimally be for forwarding the given amount. This amount is the total of the outgoing amount plus the outbound fee, which is what the inbound fee is based on.

func (*InboundFee) ToWire

func (i *InboundFee) ToWire() lnwire.Fee

ToWire converts the inbound fee to a wire fee structure.

Jump to

Keyboard shortcuts

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