lnwire

package
v0.2.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2017 License: MIT Imports: 14 Imported by: 0

README

lnwire

Build Status MIT licensed GoDoc

The lnwire package implements the Lightning Network wire protocol.

This package has intentionally been designed so it can be used as a standalone package for any projects needing to interface with lightning peers at the wire protocol level.

Installation and Updating

$ go get -u github.com/lightningnetwork/lnd/lnwire

Documentation

Index

Constants

View Source
const (
	// OptionalFlag represent the feature which we already have but it
	// isn't required yet, and if remote peer doesn't have this feature we
	// may turn it off without disconnecting with peer.
	OptionalFlag featureFlag = 2 // 0b10

	// RequiredFlag represent the features which is required for proper
	// peer interaction, we disconnect with peer if it doesn't have this
	// particular feature.
	RequiredFlag featureFlag = 1 // 0b01

)
View Source
const (
	CmdInit = uint32(1)

	// Commands for opening a channel funded by one party (single funder).
	CmdSingleFundingRequest      = uint32(100)
	CmdSingleFundingResponse     = uint32(110)
	CmdSingleFundingComplete     = uint32(120)
	CmdSingleFundingSignComplete = uint32(130)

	// Command for locking a funded channel
	CmdFundingLocked = uint32(200)

	// Commands for the workflow of cooperatively closing an active channel.
	CmdCloseRequest  = uint32(300)
	CmdCloseComplete = uint32(310)

	// Commands for negotiating HTLCs.
	CmdUpdateAddHTLC    = uint32(1000)
	CmdUpdateFufillHTLC = uint32(1010)
	CmdUpdateFailHTLC   = uint32(1020)

	// Commands for modifying commitment transactions.
	CmdCommitSig    = uint32(2000)
	CmdRevokeAndAck = uint32(2010)

	// Commands for reporting protocol errors.
	CmdErrorGeneric = uint32(4000)

	// Commands for discovery service.
	CmdChannelAnnouncement       = uint32(5000)
	CmdChannelUpdateAnnouncement = uint32(5010)
	CmdNodeAnnouncement          = uint32(5020)
	CmdAnnounceSignatures        = uint32(5030)

	// Commands for connection keep-alive.
	CmdPing = uint32(6000)
	CmdPong = uint32(6010)
)

Commands used in lightning message headers which detail the type of message. TODO(roasbeef): update with latest type numbering from spec

View Source
const MaxMessagePayload = 1024 * 1024 * 32 //  32MB

MaxMessagePayload is the maximum bytes a message can be regardless of other individual limits imposed by messages themselves.

View Source
const MaxSliceLength = 65535

MaxSliceLength is the maximum allowed lenth for any opaque byte slices in the wire protocol.

View Source
const MessageHeaderSize = 12

MessageHeaderSize is the number of bytes in a lightning message header. The bytes are allocated as follows: network magic 4 bytes + command 4 bytes + payload length 4 bytes. Note that a checksum is omitted as lightning messages are assumed to be transmitted over an AEAD secured connection which provides integrity over the entire message.

View Source
const OnionPacketSize = 1254

OnionPacketSize is the size of the serialized Sphinx onion packet included in each UpdateAddHTLC message.

Variables

This section is empty.

Functions

func WriteMessage

func WriteMessage(w io.Writer, msg Message, pver uint32, btcnet wire.BitcoinNet) (int, error)

WriteMessage writes a lightning Message to w including the necessary header information and returns the number of bytes written.

Types

type Alias

type Alias struct {
	// contains filtered or unexported fields
}

Alias a hex encoded UTF-8 string that may be displayed as an alternative to the node's ID. Notice that aliases are not unique and may be freely chosen by the node operators.

func NewAlias

func NewAlias(s string) (Alias, error)

NewAlias create the alias from string and also checks spec requirements.

func (*Alias) String

func (a *Alias) String() string

func (*Alias) Validate

func (a *Alias) Validate() error

Validate check that alias data length is lower than spec size.

type AnnounceSignatures

type AnnounceSignatures struct {
	// ChannelID is the unique description of the funding transaction.
	// Channel id is better for users and debugging and short channel id is
	// used for quick test on existence of the particular utxo inside the
	// block chain, because it contains information about block.
	ChannelID wire.OutPoint

	// ShortChannelID is the unique description of the funding
	// transaction. It is constructed with the most significant 3 bytes
	// as the block height, the next 3 bytes indicating the transaction
	// index within the block, and the least significant two bytes
	// indicating the output index which pays to the channel.
	ShortChannelID ShortChannelID

	// NodeSignature is the signature which contains the signed announce
	// channel message, by this signature we proof that we posses of the
	// node pub key and creating the reference node_key -> bitcoin_key.
	NodeSignature *btcec.Signature

	// BitcoinSignature is the signature which contains the signed node
	// public key, by this signature we proof that we posses of the
	// bitcoin key and and creating the reverse reference bitcoin_key ->
	// node_key.
	BitcoinSignature *btcec.Signature
}

AnnounceSignatures this is a direct message between two endpoints of a channel and serves as an opt-in mechanism to allow the announcement of the channel to the rest of the network. It contains the necessary signatures by the sender to construct the channel announcement message.

func (*AnnounceSignatures) Command

func (a *AnnounceSignatures) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*AnnounceSignatures) Decode

func (a *AnnounceSignatures) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized AnnounceSignatures stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*AnnounceSignatures) Encode

func (a *AnnounceSignatures) Encode(w io.Writer, pver uint32) error

Encode serializes the target AnnounceSignatures into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*AnnounceSignatures) MaxPayloadLength

func (a *AnnounceSignatures) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for this message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*AnnounceSignatures) Validate

func (a *AnnounceSignatures) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the AnnounceSignatures are valid.

This is part of the lnwire.Message interface.

type ChannelAnnouncement

type ChannelAnnouncement struct {
	// This signatures are used by nodes in order to create cross
	// references between node's channel and node. Requiring both nodes
	// to sign indicates they are both willing to route other payments via
	// this node.
	NodeSig1 *btcec.Signature
	NodeSig2 *btcec.Signature

	// This signatures are used by nodes in order to create cross
	// references between node's channel and node. Requiring the bitcoin
	// signatures proves they control the channel.
	BitcoinSig1 *btcec.Signature
	BitcoinSig2 *btcec.Signature

	// ShortChannelID is the unique description of the funding transaction.
	ShortChannelID ShortChannelID

	// The public keys of the two nodes who are operating the channel, such
	// that is NodeID1 the numerically-lesser than NodeID2 (ascending
	// numerical order).
	NodeID1 *btcec.PublicKey
	NodeID2 *btcec.PublicKey

	// Public keys which corresponds to the keys which was declared in
	// multisig funding transaction output.
	BitcoinKey1 *btcec.PublicKey
	BitcoinKey2 *btcec.PublicKey
}

ChannelAnnouncement message is used to announce the existence of a channel between two peers in the overlay, which is propagated by the discovery service over broadcast handler.

func (*ChannelAnnouncement) Command

func (a *ChannelAnnouncement) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*ChannelAnnouncement) DataToSign

func (a *ChannelAnnouncement) DataToSign() ([]byte, error)

DataToSign is used to retrieve part of the announcement message which should be signed.

func (*ChannelAnnouncement) Decode

func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized ChannelAnnouncement stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ChannelAnnouncement) Encode

func (a *ChannelAnnouncement) Encode(w io.Writer, pver uint32) error

Encode serializes the target ChannelAnnouncement into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*ChannelAnnouncement) MaxPayloadLength

func (a *ChannelAnnouncement) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for this message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ChannelAnnouncement) Validate

func (a *ChannelAnnouncement) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the ChannelAnnouncement are valid.

This is part of the lnwire.Message interface.

type ChannelUpdateAnnouncement

type ChannelUpdateAnnouncement struct {
	// Signature is used to validate the announced data and prove the
	// ownership of node id.
	Signature *btcec.Signature

	// ShortChannelID is the unique description of the funding transaction.
	ShortChannelID ShortChannelID

	// Timestamp allows ordering in the case of multiple announcements.
	// We should ignore the message if timestamp is not greater than
	// the last-received.
	Timestamp uint32

	// Flags least-significant bit must be set to 0 if the creating node
	// corresponds to the first node in the previously sent channel
	// announcement and 1 otherwise.
	Flags uint16

	// TimeLockDelta is the minimum number of blocks this node requires to
	// be added to the expiry of HTLCs. This is a security parameter
	// determined by the node operator. This value represents the required
	// gap between the time locks of the incoming and outgoing HTLC's set
	// to this node.
	TimeLockDelta uint16

	// HtlcMinimumMsat is the minimum HTLC value which will be accepted.
	HtlcMinimumMsat uint32

	// FeeBaseMstat...
	FeeBaseMsat uint32

	// FeeProportionalMillionths...
	FeeProportionalMillionths uint32
}

ChannelUpdateAnnouncement message is used after channel has been initially announced. Each side independently announces its fees and minimum expiry for HTLCs and other parameters. Also this message is used to redeclare initially setted channel parameters.

func (*ChannelUpdateAnnouncement) Command

func (a *ChannelUpdateAnnouncement) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*ChannelUpdateAnnouncement) DataToSign

func (a *ChannelUpdateAnnouncement) DataToSign() ([]byte, error)

DataToSign is used to retrieve part of the announcement message which should be signed.

func (*ChannelUpdateAnnouncement) Decode

func (a *ChannelUpdateAnnouncement) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized ChannelUpdateAnnouncement stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ChannelUpdateAnnouncement) Encode

func (a *ChannelUpdateAnnouncement) Encode(w io.Writer, pver uint32) error

Encode serializes the target ChannelUpdateAnnouncement into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*ChannelUpdateAnnouncement) MaxPayloadLength

func (a *ChannelUpdateAnnouncement) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for this message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ChannelUpdateAnnouncement) Validate

func (a *ChannelUpdateAnnouncement) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the ChannelUpdateAnnouncement are valid.

This is part of the lnwire.Message interface.

type CloseComplete

type CloseComplete struct {
	// ChannelPoint serves to identify which channel is to be closed.
	ChannelPoint wire.OutPoint

	// ResponderCloseSig is the signature of the responder for the
	// transaction which closes the previously active channel.
	ResponderCloseSig *btcec.Signature
}

CloseComplete is sent by Bob signalling a fufillment and completion of Alice's prior CloseRequest message. After Alice receives Bob's CloseComplete message, she is able to broadcast the fully signed transaction executing a cooperative closure of the channel.

NOTE: The responder is able to only send a signature without any additional message as all transactions are assembled observing BIP 69 which defines a cannonical ordering for input/outputs. Therefore, both sides are able to arrive at an identical closure transaction as they know the order of the inputs/outputs.

func NewCloseComplete

func NewCloseComplete() *CloseComplete

NewCloseComplete creates a new empty CloseComplete message. TODO(roasbeef): add params to all constructors...

func (*CloseComplete) Command

func (c *CloseComplete) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*CloseComplete) Decode

func (c *CloseComplete) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized CloseComplete message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CloseComplete) Encode

func (c *CloseComplete) Encode(w io.Writer, pver uint32) error

Encode serializes the target CloseComplete into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*CloseComplete) MaxPayloadLength

func (c *CloseComplete) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a CloseComplete complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CloseComplete) Validate

func (c *CloseComplete) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the CloseComplete are valid.

This is part of the lnwire.Message interface.

type CloseRequest

type CloseRequest struct {
	// ChannelPoint serves to identify which channel is to be closed.
	ChannelPoint wire.OutPoint

	// RequesterCloseSig is the signature of the requester for the fully
	// assembled closing transaction.
	RequesterCloseSig *btcec.Signature

	// Fee is the required fee-per-KB the closing transaction must have.
	// It is recommended that a "sufficient" fee be paid in order to
	// achieve timely channel closure.
	// TODO(roasbeef): if initiator always pays fees, then no longer needed.
	Fee btcutil.Amount
}

CloseRequest is sent by either side in order to initiate the cooperative closure of a channel. This message is rather sparse as both side implicitly know to craft a transaction sending the settled funds of both parties to the final delivery addresses negotiated during the funding workflow.

NOTE: The requester is able to only send a signature to initiate the cooperative channel closure as all transactions are assembled observing BIP 69 which defines a cannonical ordering for input/outputs. Therefore, both sides are able to arrive at an identical closure transaction as they know the order of the inputs/outputs.

func NewCloseRequest

func NewCloseRequest(cp wire.OutPoint, sig *btcec.Signature) *CloseRequest

NewCloseRequest creates a new CloseRequest.

func (*CloseRequest) Command

func (c *CloseRequest) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*CloseRequest) Decode

func (c *CloseRequest) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized CloseRequest stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CloseRequest) Encode

func (c *CloseRequest) Encode(w io.Writer, pver uint32) error

Encode serializes the target CloseRequest into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*CloseRequest) MaxPayloadLength

func (c *CloseRequest) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for this message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CloseRequest) Validate

func (c *CloseRequest) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the CloseRequest are valid.

This is part of the lnwire.Message interface.

type CommitSig

type CommitSig struct {
	// ChannelPoint uniquely identifies to which currently active channel
	// this CommitSig applies to.
	ChannelPoint wire.OutPoint

	// CommitSig is Alice's signature for Bob's new commitment transaction.
	// Alice is able to send this signature without requesting any
	// additional data due to the piggybacking of Bob's next revocation
	// hash in his prior RevokeAndAck message, as well as the canonical
	// ordering used for all inputs/outputs within commitment transactions.
	CommitSig *btcec.Signature
}

CommitSig is sent by either side to stage any pending HTLC's in the receiver's pending set into a new commitment state. Implicitly, the new commitment transaction constructed which has been signed by CommitSig includes all HTLC's in the remote node's pending set. A CommitSig message may be sent after a series of UpdateAddHTLC/UpdateFufillHTLC messages in order to batch add several HTLC's with a single signature covering all implicitly accepted HTLC's.

func NewCommitSig

func NewCommitSig() *CommitSig

NewCommitSig creates a new empty CommitSig message.

func (*CommitSig) Command

func (c *CommitSig) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*CommitSig) Decode

func (c *CommitSig) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized CommitSig message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CommitSig) Encode

func (c *CommitSig) Encode(w io.Writer, pver uint32) error

Encode serializes the target CommitSig into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*CommitSig) MaxPayloadLength

func (c *CommitSig) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a CommitSig complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*CommitSig) Validate

func (c *CommitSig) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the CommitSig are valid.

This is part of the lnwire.Message interface.

type CreditsAmount

type CreditsAmount int64

CreditsAmount are the native currency unit used within the Lightning Network. Credits are denominated in sub-satoshi amounts, so micro-satoshis (1/1000). This value is purposefully signed in order to allow the expression of negative fees.

"In any science-fiction movie, anywhere in the galaxy, currency is referred to as 'credits.'"

--Sam Humphries. Ebert, Roger (1999). Ebert's bigger little movie
glossary. Andrews McMeel. p. 172.

https://en.wikipedia.org/wiki/List_of_fictional_currencies https://en.wikipedia.org/wiki/Fictional_currency#Trends_in_the_use_of_fictional_currencies http://tvtropes.org/pmwiki/pmwiki.php/Main/WeWillSpendCreditsInTheFuture US Display format: 1 BTC = 100,000,000'000 XCB Or in BTC = 1.00000000'000 Credits (XCB, accountants should use XCB :^)

func (CreditsAmount) ToSatoshi

func (c CreditsAmount) ToSatoshi() int64

ToSatoshi converts an amount in Credits to the coresponding amount expressed in Satoshis.

NOTE: This function rounds down by default (floor).

type ErrorCode

type ErrorCode uint16

ErrorCode represents the short error code for each of the defined errors within the Lightning Network protocol spec.

const (
	// ErrMaxPendingChannels is returned by remote peer when the number of
	// active pending channels exceeds their maximum policy limit.
	ErrMaxPendingChannels ErrorCode = 1

	// ErrSynchronizingChain is returned by a remote peer that receives a
	// channel update or a funding request while their still syncing to the
	// latest state of the blockchain.
	ErrSynchronizingChain ErrorCode = 2
)

func (ErrorCode) ToGrpcCode

func (e ErrorCode) ToGrpcCode() codes.Code

ToGrpcCode is used to generate gRPC specific code which will be propagated to the ln rpc client. This code is used to have more detailed view of what goes wrong and also in order to have the ability pragmatically determine the error and take specific actions on the client side.

type ErrorGeneric

type ErrorGeneric struct {
	// ChannelPoint references the active channel in which the error
	// occurred within. A ChannelPoint of zeroHash:0 denotes this error
	// applies to the entire established connection.
	ChannelPoint wire.OutPoint

	// PendingChannelID allows peers communicate errors in the context of a
	// particular pending channel. With this field, once a peer reads an
	// ErrorGeneric message with the PendingChannelID field set, then they
	// can forward the error to the fundingManager who can handle it
	// properly.
	PendingChannelID uint64

	// Code is the short error ID which describes the nature of the error.
	Code ErrorCode

	// Problem is a human-readable string further elaborating upon the
	// nature of the exact error. The maximum allowed length of this
	// message is 8192 bytes.
	Problem string
}

ErrorGeneric represents a generic error bound to an exact channel. The message format is purposefully general in order to allow expression of a wide array of possible errors. Each ErrorGeneric message is directed at a particular open channel referenced by ChannelPoint.

func NewErrorGeneric

func NewErrorGeneric() *ErrorGeneric

NewErrorGeneric creates a new ErrorGeneric message.

func (*ErrorGeneric) Command

func (c *ErrorGeneric) Command() uint32

Command returns the integer uniquely identifying an ErrorGeneric message on the wire.

This is part of the lnwire.Message interface.

func (*ErrorGeneric) Decode

func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized ErrorGeneric message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ErrorGeneric) Encode

func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error

Encode serializes the target ErrorGeneric into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*ErrorGeneric) MaxPayloadLength

func (c *ErrorGeneric) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a ErrorGeneric complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*ErrorGeneric) Validate

func (c *ErrorGeneric) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the ErrorGeneric are valid.

This is part of the lnwire.Message interface.

type FailCode

type FailCode uint16

FailCode specifies the precise reason that an upstream HTLC was cancelled. Each UpdateFailHTLC message carries a FailCode which is to be passed back unaltered to the source of the HTLC within the route.

TODO(roasbeef): implement proper encrypted error messages as defined in spec

  • these errors as it stands reveal the error cause to all links in the route and are horrible for privacy
const (
	// InsufficientCapacity indicates that a payment failed due to a link
	// in the ultimate route not having enough satoshi flow to successfully
	// carry the payment.
	InsufficientCapacity FailCode = 0

	// UpstreamTimeout indicates that an upstream link had to enforce the
	// absolute HTLC timeout, removing the HTLC.
	UpstreamTimeout FailCode = 1

	// UnknownPaymentHash indicates that the destination did not recognize
	// the payment hash.
	UnknownPaymentHash FailCode = 2

	// UnknownDestination indicates that the specified next hop within the
	// Sphinx packet at a point in the route contained an unknown or
	// invalid "next hop".
	UnknownDestination FailCode = 3

	// SphinxParseError indicates that an intermediate node was unable
	// properly parse the HTLC.
	SphinxParseError FailCode = 4

	// IncorrectValue indicates that the HTLC ultimately extended to the
	// destination did not match the value that was expected.
	IncorrectValue FailCode = 5
)

func (FailCode) String

func (c FailCode) String() string

String returns a human-readable version of the FailCode type.

type Feature

type Feature struct {
	Name featureName
	Flag featureFlag
}

Feature represent the feature which is used on stage of initialization of feature vector. Initial feature flags might be changed dynamically later.

type FeatureVector

type FeatureVector struct {
	// contains filtered or unexported fields
}

FeatureVector represents the global/local feature vector. With this structure you may set/get the feature by name and compare feature vector with remote one.

func NewFeatureVector

func NewFeatureVector(features []Feature) *FeatureVector

NewFeatureVector creates new instance of feature vector.

func NewFeatureVectorFromReader

func NewFeatureVectorFromReader(r io.Reader) (*FeatureVector, error)

NewFeatureVectorFromReader decodes the feature vector from binary representation and creates the instance of it. Every feature decoded as 2 bits where odd bit determine whether the feature is "optional" and even bit told us whether the feature is "required". The even/odd semantic allows future incompatible changes, or backward compatible changes. Bits generally assigned in pairs, so that optional features can later become compulsory.

func (*FeatureVector) Compare

func (f *FeatureVector) Compare(f2 *FeatureVector) (*SharedFeatures, error)

Compare checks that features are compatible and returns the features which were present in both remote and local feature vectors. If remote/local node doesn't have the feature and local/remote node require it than such vectors are incompatible.

func (*FeatureVector) Copy

func (f *FeatureVector) Copy() *FeatureVector

Copy generate new distinct instance of the feature vector.

func (*FeatureVector) Encode

func (f *FeatureVector) Encode(w io.Writer) error

Encode encodes the features vector into bytes representation, every feature encoded as 2 bits where odd bit determine whether the feature is "optional" and even bit told us whether the feature is "required". The even/odd semantic allows future incompatible changes, or backward compatible changes. Bits generally assigned in pairs, so that optional features can later become compulsory.

func (*FeatureVector) SetFeatureFlag

func (f *FeatureVector) SetFeatureFlag(name featureName, flag featureFlag) error

SetFeatureFlag assign flag to the feature.

type FundingLocked

type FundingLocked struct {
	// ChannelOutpoint is the outpoint of the channel's funding
	// transaction. This can be used to query for the channel in the
	// database.
	ChannelOutpoint wire.OutPoint

	// ChannelId serves to uniquely identify the channel created by the
	// current channel funding workflow.
	ChannelID ShortChannelID

	// NextPerCommitmentPoint is the secret that can be used to revoke
	// the next commitment transaction for the channel.
	NextPerCommitmentPoint *btcec.PublicKey
}

FundingLocked is the message that both parties to a new channel creation send once they have observed the funding transaction being confirmed on the blockchain. FundingLocked contains the signatures necessary for the channel participants to advertise the existence of the channel to the rest of the network.

func NewFundingLocked

func NewFundingLocked(op wire.OutPoint, cid ShortChannelID,
	npcp *btcec.PublicKey) *FundingLocked

NewFundingLocked creates a new FundingLocked message, populating it with the necessary IDs and revocation secret..

func (*FundingLocked) Command

func (c *FundingLocked) Command() uint32

Command returns the uint32 code which uniquely identifies this message as a FundingLocked message on the wire.

This is part of the lnwire.Message interface.

func (*FundingLocked) Decode

func (c *FundingLocked) Decode(r io.Reader, pver uint32) error

Decode deserializes the serialized FundingLocked message stored in the passed io.Reader into the target FundingLocked using the deserialization rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*FundingLocked) Encode

func (c *FundingLocked) Encode(w io.Writer, pver uint32) error

Encode serializes the target FundingLocked message into the passed io.Writer implementation. Serialization will observe the rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*FundingLocked) MaxPayloadLength

func (c *FundingLocked) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload length for a FundingLocked message. This is calculated by summing the max length of all the fields within a FundingLocked message.

This is part of the lnwire.Message interface.

func (*FundingLocked) Validate

func (c *FundingLocked) Validate() error

Validate examines each populated field within the FundingLocked message for field sanity. For example, signature fields MUST NOT be nil.

This is part of the lnwire.Message interface.

type Init

type Init struct {
	// GlobalFeatures is feature vector which affects HTLCs and thus are
	// also advertised to other nodes.
	GlobalFeatures *FeatureVector

	// LocalFeatures is feature vector which only affect the protocol
	// between two nodes.
	LocalFeatures *FeatureVector
}

Init is the first message reveals the features supported or required by this node. Nodes wait for receipt of the other's features to simplify error diagnosis where features are incompatible. Each node MUST wait to receive init before sending any other messages.

func NewInitMessage

func NewInitMessage(gf, lf *FeatureVector) *Init

NewInitMessage creates new instance of init message object.

func (*Init) Command

func (msg *Init) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*Init) Decode

func (msg *Init) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized Init message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Init) Encode

func (msg *Init) Encode(w io.Writer, pver uint32) error

Encode serializes the target Init into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*Init) MaxPayloadLength

func (msg *Init) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a Init complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Init) Validate

func (msg *Init) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the Init are valid.

This is part of the lnwire.Message interface.

type Message

type Message interface {
	Decode(io.Reader, uint32) error
	Encode(io.Writer, uint32) error
	Command() uint32
	MaxPayloadLength(uint32) uint32
	Validate() error
}

Message is an interface that defines a lightning wire protocol message. The interface is general in order to allow implementing types full control over the representation of its data.

func ReadMessage

func ReadMessage(r io.Reader, pver uint32, btcnet wire.BitcoinNet) (int, Message, []byte, error)

ReadMessage reads, validates, and parses the next bitcoin Message from r for the provided protocol version and bitcoin network. It returns the number of bytes read in addition to the parsed Message and raw bytes which comprise the message. This function is the same as ReadMessage except it also returns the number of bytes read.

type NetAddress

type NetAddress struct {
	// IdentityKey is the long-term static public key for a node. This node is
	// used throughout the network as a node's identity key. It is used to
	// authenticate any data sent to the network on behalf of the node, and
	// additionally to establish a confidential+authenticated connection with
	// the node.
	IdentityKey *btcec.PublicKey

	// Services defines the set of services supported by the node reachable at
	// the address and identity key defined in the struct.
	Services ServiceFlag

	// Address is is the IP address and port of the node.
	Address *net.TCPAddr

	// ChainNet is the Bitcoin network this node is associated with.
	// TODO(roasbeef): make a slice in the future for multi-chain
	ChainNet wire.BitcoinNet
}

NetAddress represents information pertaining to the identity and network reachability of a peer. Information stored includes the node's identity public key for establishing a confidential+authenticated connection, the service bits it supports, and a TCP address the node is reachable at.

TODO(roasbeef): merge with LinkNode in some fashion

func (*NetAddress) Network

func (n *NetAddress) Network() string

Network returns the name of the network this address is binded to.

This part of the net.Addr interface.

func (*NetAddress) String

func (n *NetAddress) String() string

String returns a human readable string describing the target NetAddress. The current string format is: <pubkey>@host.

This part of the net.Addr interface.

type NodeAnnouncement

type NodeAnnouncement struct {
	// Signature is used to prove the ownership of node id.
	Signature *btcec.Signature

	// Timestamp allows ordering in the case of multiple
	// announcements.
	Timestamp uint32

	// NodeID is a public key which is used as node identification.
	NodeID *btcec.PublicKey

	// RGBColor is used to customize their node's appearance in
	// maps and graphs
	RGBColor RGB

	// Alias is used to customize their node's appearance in maps and graphs
	Alias Alias

	// Features is the list of protocol features this node supports.
	Features *FeatureVector

	// Address includes two specification fields: 'ipv6' and 'port' on which
	// the node is accepting incoming connections.
	Addresses []net.Addr
}

NodeAnnouncement message is used to announce the presence of a Lightning node and also to signal that the node is accepting incoming connections. Each NodeAnnouncement authenticating the advertised information within the announcement via a signature using the advertised node pubkey.

func (*NodeAnnouncement) Command

func (a *NodeAnnouncement) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*NodeAnnouncement) DataToSign

func (a *NodeAnnouncement) DataToSign() ([]byte, error)

DataToSign returns the part of the message that should be signed.

func (*NodeAnnouncement) Decode

func (a *NodeAnnouncement) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized NodeAnnouncement stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*NodeAnnouncement) Encode

func (a *NodeAnnouncement) Encode(w io.Writer, pver uint32) error

Encode serializes the target NodeAnnouncement into the passed io.Writer observing the protocol version specified.

func (*NodeAnnouncement) MaxPayloadLength

func (a *NodeAnnouncement) MaxPayloadLength(pver uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for this message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*NodeAnnouncement) Validate

func (a *NodeAnnouncement) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the NodeAnnouncement are valid.

This is part of the lnwire.Message interface.

type OpaqueReason

type OpaqueReason []byte

OpaqueReason is an opaque encrypted byte slice that encodes the exact failure reason and additional some supplemental data. The contents of this slice can only be decrypted by the sender of the original HTLC.

type Ping

type Ping struct {
	// Nonce is a unique value associated with this ping message. The pong
	// message that responds to this ping should reference the same value.
	Nonce uint64
}

Ping defines a message which is sent by peers periodically to determine if the connection is still valid. Each ping message should carry a unique nonce which is to be echoed back within the Pong response.

func NewPing

func NewPing(nonce uint64) *Ping

NewPing returns a new Ping message binded to the specified nonce.

func (*Ping) Command

func (p *Ping) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*Ping) Decode

func (p *Ping) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized Ping message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Ping) Encode

func (p *Ping) Encode(w io.Writer, pver uint32) error

Encode serializes the target Ping into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (Ping) MaxPayloadLength

func (p Ping) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a Ping complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Ping) Validate

func (p *Ping) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the Ping are valid.

This is part of the lnwire.Message interface.

type PkScript

type PkScript []byte

PkScript is simple type definition which represents a raw serialized public key script.

type Pong

type Pong struct {
	// Nonce is the unique nonce that was associated with the Ping message
	// that this Pong is replying to.
	Nonce uint64
}

Pong defines a message which is the direct response to a received Ping message. A Pong reply indicates that a connection is still active. The Pong reply to a Ping message should contain the nonce carried in the original Pong message.

func NewPong

func NewPong(nonce uint64) *Pong

NewPong returns a new Pong message binded to the specified nonce.

func (*Pong) Command

func (p *Pong) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*Pong) Decode

func (p *Pong) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized Pong message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Pong) Encode

func (p *Pong) Encode(w io.Writer, pver uint32) error

Encode serializes the target Pong into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*Pong) MaxPayloadLength

func (p *Pong) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a Pong complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*Pong) Validate

func (p *Pong) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the Pong are valid.

This is part of the lnwire.Message interface.

type RGB

type RGB struct {
	// contains filtered or unexported fields
}

RGB is used to represent the color.

type RevokeAndAck

type RevokeAndAck struct {
	// ChannelPoint uniquely identifies to which currently active channel
	// this RevokeAndAck applies to.
	ChannelPoint wire.OutPoint

	// Revocation is the preimage to the revocation hash of the now prior
	// commitment transaction.
	//
	// If the received revocation is the all zeroes hash ('0' * 32), then
	// this RevokeAndAck is being sent in order to build up the sender's
	// initial revocation window (IRW). In this case, the RevokeAndAck
	// should be added to the receiver's queue of unused revocations to be
	// used to construct future commitment transactions.
	Revocation [32]byte

	// NextRevocationKey is the next revocation key which should be added
	// to the queue of unused revocation keys for the remote peer. This key
	// will be used within the revocation clause for any new commitment
	// transactions created for the remote peer.
	NextRevocationKey *btcec.PublicKey

	// NextRevocationHash is the next revocation hash which should be added
	// to the queue on unused revocation hashes for the remote peer. This
	// revocation hash will be used within any HTLCs included within this
	// next commitment transaction.
	NextRevocationHash [32]byte
}

RevokeAndAck is sent by either side once a CommitSig message has been received, and validated. This message serves to revoke the prior commitment transaction, which was the most up to date version until a CommitSig message referencing the specified ChannelPoint was received. Additionally, this message also piggyback's the next revocation hash that Alice should use when constructing the Bob's version of the next commitment transaction (which would be done before sending a CommitSig message). This piggybacking allows Alice to send the next CommitSig message modifying Bob's commitment transaction without first asking for a revocation hash initially.

func NewRevokeAndAck

func NewRevokeAndAck() *RevokeAndAck

NewRevokeAndAck creates a new RevokeAndAck message.

func (*RevokeAndAck) Command

func (c *RevokeAndAck) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*RevokeAndAck) Decode

func (c *RevokeAndAck) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized RevokeAndAck message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*RevokeAndAck) Encode

func (c *RevokeAndAck) Encode(w io.Writer, pver uint32) error

Encode serializes the target RevokeAndAck into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*RevokeAndAck) MaxPayloadLength

func (c *RevokeAndAck) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a RevokeAndAck complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*RevokeAndAck) Validate

func (c *RevokeAndAck) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the RevokeAndAck are valid.

This is part of the lnwire.Message interface.

type ServiceFlag

type ServiceFlag uint64

ServiceFlag identifies the services supported by a particular Lightning Network peer.

type SharedFeatures

type SharedFeatures struct {
	*FeatureVector
}

SharedFeatures is a product of comparison of two features vector which consist of features which are present in both local and remote features vectors.

func (*SharedFeatures) IsActive

func (f *SharedFeatures) IsActive(name featureName) bool

IsActive checks is feature active or not, it might be disabled during comparision with remote feature vector if it was optional and remote peer doesn't support it.

type ShortChannelID

type ShortChannelID struct {
	// BlockHeight is the height of the block where funding transaction
	// located.
	//
	// NOTE: This field is limited to 3 bytes.
	BlockHeight uint32

	// TxIndex is a position of funding transaction within a block.
	//
	// NOTE: This field is limited to 3 bytes.
	TxIndex uint32

	// TxPosition indicating transaction output which pays to the channel.
	TxPosition uint16
}

ShortChannelID represent the set of data which is needed to retrieve all necessary data to validate the channel existence.

func NewShortChanIDFromInt

func NewShortChanIDFromInt(chanID uint64) ShortChannelID

NewShortChanIDFromInt returns a new ShortChannelID which is the decoded version of the compact channel ID encoded within the uint64. The format of the compact channel ID is as follows: 3 bytes for the block height, 3 bytes for the transaction index, and 2 bytes for the output index.

func (*ShortChannelID) ToUint64

func (c *ShortChannelID) ToUint64() uint64

ToUint64 converts the ShortChannelID into a compact format encoded within a uint64 (8 bytes).

type SingleFundingComplete

type SingleFundingComplete struct {
	// ChannelID serves to uniquely identify the future channel created by
	// the initiated single funder workflow.
	// TODO(roasbeef): change all to PendingChannelID, document schema
	ChannelID uint64

	// FundingOutPoint is the outpoint (txid:index) of the funding
	// transaction. With this value, Bob will be able to generate a
	// signature for Alice's version of the commitment transaction.
	FundingOutPoint wire.OutPoint

	// CommitSignature is Alice's signature for Bob's version of the
	// commitment transaction.
	CommitSignature *btcec.Signature

	// RevocationKey is the initial key to be used for the revocation
	// clause within the self-output of the initiators's commitment
	// transaction. Once an initial new state is created, the initiator
	// will send a preimage which will allow the initiator to sweep the
	// initiator's funds if the violate the contract.
	RevocationKey *btcec.PublicKey

	// StateHintObsfucator is the set of bytes used by the initiator to
	// obsfucate the state number encoded within the sequence number for
	// the commitment transaction's only input. The initiator generates
	// this value by hashing the 0th' state derived from the revocation PRF
	// an additional time.
	StateHintObsfucator [6]byte
}

SingleFundingComplete is the message Alice sends to Bob once she is able to fully assemble the funding transaction, and both versions of the commitment transaction. The purpose of this message is to present Bob with the items required for him to generate a signature for Alice's version of the commitment transaction.

func NewSingleFundingComplete

func NewSingleFundingComplete(chanID uint64, fundingPoint wire.OutPoint,
	commitSig *btcec.Signature, revokeKey *btcec.PublicKey,
	obsfucator [6]byte) *SingleFundingComplete

NewSingleFundingComplete creates, and returns a new empty SingleFundingResponse.

func (*SingleFundingComplete) Command

func (s *SingleFundingComplete) Command() uint32

Command returns the uint32 code which uniquely identifies this message as a SingleFundingComplete on the wire.

This is part of the lnwire.Message interface.

func (*SingleFundingComplete) Decode

func (s *SingleFundingComplete) Decode(r io.Reader, pver uint32) error

Decode deserializes the serialized SingleFundingComplete stored in the passed io.Reader into the target SingleFundingComplete using the deserialization rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingComplete) Encode

func (s *SingleFundingComplete) Encode(w io.Writer, pver uint32) error

Encode serializes the target SingleFundingComplete into the passed io.Writer implementation. Serialization will observe the rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingComplete) MaxPayloadLength

func (s *SingleFundingComplete) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload length for a SingleFundingComplete. This is calculated by summing the max length of all the fields within a SingleFundingComplete. Therefore, the final breakdown is: 8 + 36 + 33 + 73 + 4 = 154

This is part of the lnwire.Message interface.

func (*SingleFundingComplete) Validate

func (s *SingleFundingComplete) Validate() error

Validate examines each populated field within the SingleFundingComplete for field sanity.

This is part of the lnwire.Message interface.

type SingleFundingRequest

type SingleFundingRequest struct {
	// ChannelID serves to uniquely identify the future channel created by
	// the initiated single funder workflow.
	ChannelID uint64

	// ChannelType represents the type of channel this request would like
	// to open. At this point, the only supported channels are type 0
	// channels, which are channels with regular commitment transactions
	// utilizing HTLCs for payments.
	ChannelType uint8

	// CoinType represents which blockchain the channel will be opened
	// using. By default, this field should be set to 0, indicating usage
	// of the Bitcoin blockchain.
	CoinType uint64

	// FeePerKb is the required number of satoshis per KB that the
	// requester will pay at all timers, for both the funding transaction
	// and commitment transaction. This value can later be updated once the
	// channel is open.
	FeePerKb btcutil.Amount

	// FundingAmount is the number of satoshis the initiator would like
	// to commit to the channel.
	FundingAmount btcutil.Amount

	// PushSatoshis is the number of satoshis that will be pushed to the
	// responder as a part of the first commitment state.
	PushSatoshis btcutil.Amount

	// CsvDelay is the number of blocks to use for the relative time lock
	// in the pay-to-self output of both commitment transactions.
	CsvDelay uint32

	// CommitmentKey is key the initiator of the funding workflow wishes to
	// use within their versino of the commitment transaction for any
	// delayed (CSV) or immediate outputs to them.
	CommitmentKey *btcec.PublicKey

	// ChannelDerivationPoint is an secp256k1 point which will be used to
	// derive the public key the initiator will use for the half of the
	// 2-of-2 multi-sig. Using the channel derivation point (CDP), and the
	// initiators identity public key (A), the channel public key is
	// computed as: C = A + CDP. In order to be valid all CDP's MUST have
	// an odd y-coordinate.
	ChannelDerivationPoint *btcec.PublicKey

	// DeliveryPkScript defines the public key script that the initiator
	// would like to use to receive their balance in the case of a
	// cooperative close. Only the following script templates are
	// supported: P2PKH, P2WKH, P2SH, and P2WSH.
	DeliveryPkScript PkScript

	// DustLimit is the threshold below which no HTLC output should be
	// generated for our commitment transaction; ie. HTLCs below
	// this amount are not enforceable onchain from our point view.
	DustLimit btcutil.Amount

	// ConfirmationDepth is the number of confirmations that the initiator
	// of a funding workflow is requesting be required before the channel
	// is considered fully open.
	ConfirmationDepth uint32
}

SingleFundingRequest is the message Alice sends to Bob if we should like to create a channel with Bob where she's the sole provider of funds to the channel. Single funder channels simplify the initial funding workflow, are supported by nodes backed by SPV Bitcoin clients, and have a simpler security models than dual funded channels.

NOTE: In order to avoid a slow loris like resource exhaustion attack, the responder of a single funding channel workflow *should not* watch the blockchain for the funding transaction. Instead, it is the initiator's job to provide the responder with an SPV proof of funding transaction inclusion after a sufficient number of confirmations.

func NewSingleFundingRequest

func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
	fee btcutil.Amount, amt btcutil.Amount, delay uint32, ck,
	cdp *btcec.PublicKey, deliveryScript PkScript,
	dustLimit btcutil.Amount, pushSat btcutil.Amount,
	confDepth uint32) *SingleFundingRequest

NewSingleFundingRequest creates, and returns a new empty SingleFundingRequest.

func (*SingleFundingRequest) Command

func (c *SingleFundingRequest) Command() uint32

Command returns the uint32 code which uniquely identifies this message as a SingleFundingRequest on the wire.

This is part of the lnwire.Message interface.

func (*SingleFundingRequest) Decode

func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error

Decode deserializes the serialized SingleFundingRequest stored in the passed io.Reader into the target SingleFundingRequest using the deserialization rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingRequest) Encode

func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error

Encode serializes the target SingleFundingRequest into the passed io.Writer implementation. Serialization will observe the rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingRequest) MaxPayloadLength

func (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload length for a SingleFundingRequest. This is calculated by summing the max length of all the fields within a SingleFundingRequest. To enforce a maximum DeliveryPkScript size, the size of a P2PKH public key script is used.

This is part of the lnwire.Message interface.

func (*SingleFundingRequest) Validate

func (c *SingleFundingRequest) Validate() error

Validate examines each populated field within the SingleFundingRequest for field sanity. For example, all fields MUST NOT be negative, and all pkScripts must belong to the allowed set of public key scripts.

This is part of the lnwire.Message interface.

type SingleFundingResponse

type SingleFundingResponse struct {
	// ChannelID serves to uniquely identify the future channel created by
	// the initiated single funder workflow.
	ChannelID uint64

	// ChannelDerivationPoint is an secp256k1 point which will be used to
	// derive the public key the responder will use for the half of the
	// 2-of-2 multi-sig. Using the channel derivation point (CDP), and the
	// responder's identity public key (A), the channel public key is
	// computed as: C = A + CDP. In order to be valid all CDP's MUST have
	// an odd y-coordinate.
	ChannelDerivationPoint *btcec.PublicKey

	// CommitmentKey is key the responder to the funding workflow wishes to
	// use within their versino of the commitment transaction for any
	// delayed (CSV) or immediate outputs to them.
	CommitmentKey *btcec.PublicKey

	// RevocationKey is the initial key to be used for the revocation
	// clause within the self-output of the responder's commitment
	// transaction. Once an initial new state is created, the responder
	// will send a preimage which will allow the initiator to sweep the
	// responder's funds if the violate the contract.
	RevocationKey *btcec.PublicKey

	// CsvDelay is the number of blocks to use for the relative time lock
	// in the pay-to-self output of both commitment transactions.
	CsvDelay uint32

	// DeliveryPkScript defines the public key script that the initiator
	// would like to use to receive their balance in the case of a
	// cooperative close. Only the following script templates are
	// supported: P2PKH, P2WKH, P2SH, and P2WSH.
	DeliveryPkScript PkScript

	// DustLimit is the threshold below which no HTLC output should be
	// generated for remote commitment transaction; ie. HTLCs below
	// this amount are not enforceable onchain for their point of view.
	DustLimit btcutil.Amount

	// ConfirmationDepth is the number of confirmations that the initiator
	// of a funding workflow is requesting be required before the channel
	// is considered fully open.
	ConfirmationDepth uint32
}

SingleFundingResponse is the message Bob sends to Alice after she initiates the single funder channel workflow via a SingleFundingRequest message. Once Alice receives Bob's reponse, then she has all the items neccessary to construct the funding transaction, and both commitment transactions.

func NewSingleFundingResponse

func NewSingleFundingResponse(chanID uint64, rk, ck, cdp *btcec.PublicKey,
	delay uint32, deliveryScript PkScript,
	dustLimit btcutil.Amount, confDepth uint32) *SingleFundingResponse

NewSingleFundingResponse creates, and returns a new empty SingleFundingResponse.

func (*SingleFundingResponse) Command

func (c *SingleFundingResponse) Command() uint32

Command returns the uint32 code which uniquely identifies this message as a SingleFundingResponse on the wire.

This is part of the lnwire.Message interface.

func (*SingleFundingResponse) Decode

func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error

Decode deserializes the serialized SingleFundingResponse stored in the passed io.Reader into the target SingleFundingResponse using the deserialization rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingResponse) Encode

func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error

Encode serializes the target SingleFundingResponse into the passed io.Writer implementation. Serialization will observe the rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingResponse) MaxPayloadLength

func (c *SingleFundingResponse) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload length for a SingleFundingResponse. This is calculated by summing the max length of all the fields within a SingleFundingResponse. To enforce a maximum DeliveryPkScript size, the size of a P2PKH public key script is used.

This is part of the lnwire.Message interface.

func (*SingleFundingResponse) Validate

func (c *SingleFundingResponse) Validate() error

Validate examines each populated field within the SingleFundingResponse for field sanity. For example, all fields MUST NOT be negative, and all pkScripts must belong to the allowed set of public key scripts.

This is part of the lnwire.Message interface.

type SingleFundingSignComplete

type SingleFundingSignComplete struct {
	// ChannelID serves to uniquely identify the future channel created by
	// the initiated single funder workflow.
	ChannelID uint64

	// CommitSignature is Bobs's signature for Alice's version of the
	// commitment transaction.
	CommitSignature *btcec.Signature
}

SingleFundingSignComplete is the message Bob sends to Alice which delivers a signature for Alice's version of the commitment transaction. After this message is received and processed by Alice, she is free to broadcast the funding transaction.

func NewSingleFundingSignComplete

func NewSingleFundingSignComplete(chanID uint64,
	sig *btcec.Signature) *SingleFundingSignComplete

NewSingleFundingSignComplete creates a new empty SingleFundingSignComplete message.

func (*SingleFundingSignComplete) Command

func (c *SingleFundingSignComplete) Command() uint32

Command returns the uint32 code which uniquely identifies this message as a SingleFundingSignComplete on the wire.

This is part of the lnwire.Message interface.

func (*SingleFundingSignComplete) Decode

func (c *SingleFundingSignComplete) Decode(r io.Reader, pver uint32) error

Decode deserializes the serialized SingleFundingSignComplete stored in the passed io.Reader into the target SingleFundingComplete using the deserialization rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingSignComplete) Encode

func (c *SingleFundingSignComplete) Encode(w io.Writer, pver uint32) error

Encode serializes the target SingleFundingSignComplete into the passed io.Writer implementation. Serialization will observe the rules defined by the passed protocol version.

This is part of the lnwire.Message interface.

func (*SingleFundingSignComplete) MaxPayloadLength

func (c *SingleFundingSignComplete) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload length for a SingleFundingSignComplete. This is calculated by summing the max length of all the fields within a SingleFundingSignComplete. The final breakdown is: 8 + 73 = 81

This is part of the lnwire.Message interface.

func (*SingleFundingSignComplete) Validate

func (c *SingleFundingSignComplete) Validate() error

Validate examines each populated field within the SingleFundingSignComplete for field sanity.

This is part of the lnwire.Message interface.

type UnknownMessage

type UnknownMessage struct {
	// contains filtered or unexported fields
}

UnknownMessage is an implementation of the error interface that allows the creation of an error in response to an unknown message.

func (*UnknownMessage) Error

func (u *UnknownMessage) Error() string

Error returns a human readable string describing the error.

This is part of the error interface.

type UpdateAddHTLC

type UpdateAddHTLC struct {
	// ChannelPoint is the particular active channel that this
	// UpdateAddHTLC is binded to.
	ChannelPoint wire.OutPoint

	// ID is the identification server for this HTLC. This value is
	// explicitly included as it allows nodes to survive single-sided
	// restarts. The ID value for this sides starts at zero, and increases
	// with each offered HTLC.
	ID uint64

	// Expiry is the number of blocks after which this HTLC should expire.
	// It is the receiver's duty to ensure that the outgoing HTLC has a
	// sufficient expiry value to allow her to redeem the incoming HTLC.
	Expiry uint32

	// Amount is the amount of satoshis this HTLC is worth.
	Amount btcutil.Amount

	// PaymentHash is the payment hash to be included in the HTLC this
	// request creates. The pre-image to this HTLC must be revelaed by the
	// upstream peer in order to fully settle the HTLC.
	PaymentHash [32]byte

	// OnionBlob is the raw serialized mix header used to route an HTLC in
	// a privacy-preserving manner. The mix header is defined currently to
	// be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
	// body).  First the receiving node should use the groupElement, and
	// its current onion key to derive a shared secret with the source.
	// Once the shared secret has been derived, the headerMAC should be
	// checked FIRST. Note that the MAC only covers the routingInfo field.
	// If the MAC matches, and the shared secret is fresh, then the node
	// should strip off a layer of encryption, exposing the next hop to be
	// used in the subsequent UpdateAddHTLC message.
	OnionBlob [OnionPacketSize]byte
}

UpdateAddHTLC is the message sent by Alice to Bob when she wishes to add an HTLC to his remote commitment transaction. In addition to information detailing the value, the ID, expiry, and the onion blob is also included which allows Bob to derive the next hop in the route. The HTLC added by this message is to be added to the remote node's "pending" HTLC's. A subsequent CommitSig message will move the pending HTLC to the newly created commitment transaction, marking them as "staged".

func NewUpdateAddHTLC

func NewUpdateAddHTLC() *UpdateAddHTLC

NewUpdateAddHTLC returns a new empty UpdateAddHTLC message.

func (*UpdateAddHTLC) Command

func (c *UpdateAddHTLC) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*UpdateAddHTLC) Decode

func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized UpdateAddHTLC message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateAddHTLC) Encode

func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error

Encode serializes the target UpdateAddHTLC into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*UpdateAddHTLC) MaxPayloadLength

func (c *UpdateAddHTLC) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a UpdateAddHTLC complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateAddHTLC) Validate

func (c *UpdateAddHTLC) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the UpdateAddHTLC are valid.

This is part of the lnwire.Message interface.

type UpdateFailHTLC

type UpdateFailHTLC struct {
	// ChannelPoint is the particular active channel that this
	// UpdateFailHTLC is binded to.
	ChannelPoint wire.OutPoint

	// ID references which HTLC on the remote node's commitment transaction
	// has timed out.
	ID uint64

	// Reason is an onion-encrypted blob that details why the HTLC was
	// failed. This blob is only fully decryptable by the initiator of the
	// HTLC message.
	// TODO(roasbeef): properly format the encrypted failure reason
	Reason OpaqueReason
}

UpdateFailHTLC is sent by Alice to Bob in order to remove a previously added HTLC. Upon receipt of an UpdateFailHTLC the HTLC should be removed from the next commitment transaction, with the UpdateFailHTLC propagated backwards in the route to fully undo the HTLC.

func (*UpdateFailHTLC) Command

func (c *UpdateFailHTLC) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*UpdateFailHTLC) Decode

func (c *UpdateFailHTLC) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized UpdateFailHTLC message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateFailHTLC) Encode

func (c *UpdateFailHTLC) Encode(w io.Writer, pver uint32) error

Encode serializes the target UpdateFailHTLC into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*UpdateFailHTLC) MaxPayloadLength

func (c *UpdateFailHTLC) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a UpdateFailHTLC complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateFailHTLC) Validate

func (c *UpdateFailHTLC) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the UpdateFailHTLC are valid.

This is part of the lnwire.Message interface.

type UpdateFufillHTLC

type UpdateFufillHTLC struct {
	// ChannelPoint references an active channel which holds the HTLC to be
	// settled.
	ChannelPoint wire.OutPoint

	// ID denotes the exact HTLC stage within the receiving node's
	// commitment transaction to be removed.
	ID uint64

	// PaymentPreimage is the R-value preimage required to fully settle an
	// HTLC.
	PaymentPreimage [32]byte
}

UpdateFufillHTLC is sent by Alice to Bob when she wishes to settle a particular HTLC referenced by its HTLCKey within a specific active channel referenced by ChannelPoint. A subsequent CommitSig message will be sent by Alice to "lock-in" the removal of the specified HTLC, possible containing a batch signature covering several settled HTLC's.

func NewUpdateFufillHTLC

func NewUpdateFufillHTLC(chanPoint wire.OutPoint, id uint64,
	preimage [32]byte) *UpdateFufillHTLC

NewUpdateFufillHTLC returns a new empty UpdateFufillHTLC.

func (*UpdateFufillHTLC) Command

func (c *UpdateFufillHTLC) Command() uint32

Command returns the integer uniquely identifying this message type on the wire.

This is part of the lnwire.Message interface.

func (*UpdateFufillHTLC) Decode

func (c *UpdateFufillHTLC) Decode(r io.Reader, pver uint32) error

Decode deserializes a serialized UpdateFufillHTLC message stored in the passed io.Reader observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateFufillHTLC) Encode

func (c *UpdateFufillHTLC) Encode(w io.Writer, pver uint32) error

Encode serializes the target UpdateFufillHTLC into the passed io.Writer observing the protocol version specified.

This is part of the lnwire.Message interface.

func (*UpdateFufillHTLC) MaxPayloadLength

func (c *UpdateFufillHTLC) MaxPayloadLength(uint32) uint32

MaxPayloadLength returns the maximum allowed payload size for a UpdateFufillHTLC complete message observing the specified protocol version.

This is part of the lnwire.Message interface.

func (*UpdateFufillHTLC) Validate

func (c *UpdateFufillHTLC) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the UpdateFufillHTLC are valid.

This is part of the lnwire.Message interface.

Jump to

Keyboard shortcuts

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