lnwire

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2017 License: MIT Imports: 13 Imported by: 493

README

lnwire

[Build Status] (https://travis-ci.org/lightningnetwork/lnd) [MIT licensed] (https://github.com/lightningnetwork/lnd/blob/master/LICENSE) [GoDoc] (http://godoc.org/github.com/lightningnetwork/lnd/lnwire)

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

Overview

Code derived from https:// github.com/btcsuite/btcd/blob/master/wire/message.go

Index

Constants

View Source
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 = 0

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

	// UnknownPaymentHash indicates that the destination did not recognize
	// the payment hash.
	UnknownPaymentHash = 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 = 3

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

	// IncorrectValue indicates that the HTLC ultimately extended to the
	// destination did not match the value that was expected.
	IncorrectValue = 5
)
View Source
const (
	// Commands for opening a channel funded by one party (single funder).
	CmdSingleFundingRequest      = uint32(100)
	CmdSingleFundingResponse     = uint32(110)
	CmdSingleFundingComplete     = uint32(120)
	CmdSingleFundingSignComplete = uint32(130)
	CmdSingleFundingOpenProof    = uint32(140)

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

	// Commands for negotiating HTLCs.
	CmdHTLCAddRequest    = uint32(1000)
	CmdHTLCAddAccept     = uint32(1010)
	CmdHTLCAddReject     = uint32(1020)
	CmdHTLCSettleRequest = uint32(1100)
	CmdCancelHTLC        = uint32(1300)

	// Commands for modifying commitment transactions.
	CmdCommitSignature  = uint32(2000)
	CmdCommitRevocation = uint32(2010)

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

	// Commands for discovery service.
	CmdChannelAnnoucmentMessage       = uint32(5000)
	CmdChannelUpdateAnnoucmentMessage = uint32(5010)
	CmdNodeAnnoucmentMessage          = uint32(5020)

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

Commands used in lightning message headers which detail the type of message.

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.

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 CancelHTLC

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

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

	// Reason described the event that caused the HTLC to be cancelled
	// within the route.
	Reason CancelReason
}

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

func NewHTLCTimeoutRequest

func NewHTLCTimeoutRequest() *CancelHTLC

CancelHTLC creates a new CancelHTLC message.

func (*CancelHTLC) Command

func (c *CancelHTLC) Command() uint32

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

This is part of the lnwire.Message interface.

func (*CancelHTLC) Decode

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

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

This is part of the lnwire.Message interface.

func (*CancelHTLC) Encode

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

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

This is part of the lnwire.Message interface.

func (*CancelHTLC) MaxPayloadLength

func (c *CancelHTLC) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*CancelHTLC) Validate

func (c *CancelHTLC) Validate() error

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

This is part of the lnwire.Message interface.

type CancelReason

type CancelReason uint16

CancelReason specifies the precise reason that an upstream HTLC was cancelled. Each CancelHTLC message carries a CancelReason 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

func (CancelReason) String

func (c CancelReason) String() string

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

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.
	FirstNodeSig  *btcec.Signature
	SecondNodeSig *btcec.Signature

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

	// 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.
	FirstBitcoinSig  *btcec.Signature
	SecondBitcoinSig *btcec.Signature

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

	// Public keys which corresponds to the keys which was declared in
	// multisig funding transaction output.
	FirstBitcoinKey  *btcec.PublicKey
	SecondBitcoinKey *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 (c *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 (c *ChannelAnnouncement) DataToSign() ([]byte, error)

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

func (*ChannelAnnouncement) Decode

func (c *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 (c *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 (c *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 ChannelID

type ChannelID 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
}

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

func NewChanIDFromInt

func NewChanIDFromInt(chanID uint64) ChannelID

NewChanIDFromInt returns a new ChannelID 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 (*ChannelID) ToUint64

func (c *ChannelID) ToUint64() uint64

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

type ChannelUpdateAnnouncement

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

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

	// 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 previously sent channel
	// announcement and 1 otherwise.
	Flags uint16

	// Expiry 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.
	Expiry uint16

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

	// FeeBaseMstat...
	FeeBaseMstat 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 (c *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 (c *ChannelUpdateAnnouncement) DataToSign() ([]byte, error)

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

func (*ChannelUpdateAnnouncement) Decode

func (c *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 (c *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 (c *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 CommitHeight

type CommitHeight uint64

CommitHeight is an integer which represents the highest HTLCKey seen by either side within their commitment transaction. Any addition to the pending, HTLC lists on either side will increment this height. As a result this value should always be monotonically increasing. Any CommitSignature or CommitRevocation messages will reference a value for the commitment height up to which it covers. HTLCs are only explicitly excluded by sending HTLCReject messages referencing a particular HTLCKey.

type CommitRevocation

type CommitRevocation struct {
	// ChannelPoint uniquely identifies to which currently active channel this
	// CommitRevocation 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 CommitRevocation is being sent in order to build up the
	// sender's initial revocation window (IRW). In this case, the
	// CommitRevocation 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
}

CommitRevocation is sent by either side once a CommitSignature 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 CommitSignature 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 CommitSignature message). This piggybacking allows Alice to send the next CommitSignature message modifying Bob's commitment transaction without first asking for a revocation hash initially. TODO(roasbeef): update docs everywhere

func NewCommitRevocation

func NewCommitRevocation() *CommitRevocation

NewCommitRevocation creates a new CommitRevocation message.

func (*CommitRevocation) Command

func (c *CommitRevocation) Command() uint32

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

This is part of the lnwire.Message interface.

func (*CommitRevocation) Decode

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

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

This is part of the lnwire.Message interface.

func (*CommitRevocation) Encode

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

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

This is part of the lnwire.Message interface.

func (*CommitRevocation) MaxPayloadLength

func (c *CommitRevocation) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*CommitRevocation) Validate

func (c *CommitRevocation) Validate() error

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

This is part of the lnwire.Message interface.

type CommitSignature

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

	// LogIndex is the index into the receiver's HTLC log to which this
	// commitment signature covers. In order to properly verify this
	// signature, the receiver should include all the HTLCs within their
	// log with an index less-than-or-equal to the listed log-index.
	LogIndex uint64

	// Fee represents the total miner's fee that was used when constructing
	// the new commitment transaction.
	// TODO(roasbeef): is the above comment correct?
	Fee btcutil.Amount

	// 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 CommitRevocation message, as well as the canonical ordering
	// used for all inputs/outputs within commitment transactions.
	CommitSig *btcec.Signature
}

CommitSignature is sent by either side to stage any pending HTLCs in the receiver's pending set which has not explicitly been rejected via an HTLCAddReject message. Implicitly, the new commitment transaction constructed which has been signed by CommitSig includes all HTLCs in the remote node's pending set. A CommitSignature message may be sent after a series of HTLCAdd messages in order to batch add several HTLCs with a single signature covering all implicitly accepted HTLCs.

func NewCommitSignature

func NewCommitSignature() *CommitSignature

NewCommitSignature creates a new empty CommitSignature message.

func (*CommitSignature) Command

func (c *CommitSignature) Command() uint32

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

This is part of the lnwire.Message interface.

func (*CommitSignature) Decode

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

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

This is part of the lnwire.Message interface.

func (*CommitSignature) Encode

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

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

This is part of the lnwire.Message interface.

func (*CommitSignature) MaxPayloadLength

func (c *CommitSignature) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*CommitSignature) Validate

func (c *CommitSignature) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the CommitSignature 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 (
	// ErrorMaxPendingChannels is returned by remote peer when the number
	// of active pending channels exceeds their maximum policy limit.
	ErrorMaxPendingChannels ErrorCode = 1
)

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 HTLCAddReject

type HTLCAddReject struct {
	// ChannelPoint references the particular active channel to which this
	// HTLCAddReject message is binded to.
	ChannelPoint *wire.OutPoint

	// HTLCKey is used to identify which HTLC previously attempted to be
	// added via an HTLCAddRequest message is being declined.
	HTLCKey HTLCKey
}

HTLCAddReject is sent by Bob when he wishes to reject a particular HTLC that Alice attempted to add via an HTLCAddRequest message. The rejected HTLC is referenced by its unique HTLCKey ID. An HTLCAddReject message is bound to a single active channel, referenced by a unique ChannelPoint. Additionally, the HTLCKey of the rejected HTLC is present

func NewHTLCAddReject

func NewHTLCAddReject() *HTLCAddReject

NewHTLCAddReject returns a new empty HTLCAddReject message.

func (*HTLCAddReject) Command

func (c *HTLCAddReject) Command() uint32

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

This is part of the lnwire.Message interface.

func (*HTLCAddReject) Decode

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

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

This is part of the lnwire.Message interface.

func (*HTLCAddReject) Encode

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

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

This is part of the lnwire.Message interface.

func (*HTLCAddReject) MaxPayloadLength

func (c *HTLCAddReject) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*HTLCAddReject) Validate

func (c *HTLCAddReject) Validate() error

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

This is part of the lnwire.Message interface.

type HTLCAddRequest

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

	// 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 incmoing HTLC.
	Expiry uint32

	// Amount of BTC that the HTLC is worth.
	Amount btcutil.Amount

	// RefundContext is for payment cancellation
	// TODO(j): not currently in use, add later
	RefundContext HTLCKey

	// ContractType defines the particular output script to be used for
	// this HTLC. This value defaults to zero for regular HTLCs. For
	// multi-sig HTLCs, then first 4 bit represents N, while the second 4
	// bits are M, within the N-of-M multi-sig.
	ContractType uint8

	// RedemptionHashes are the hashes to be used within the HTLC script.
	// An HTLC is only fufilled once Bob is provided with the required
	// number of preimages for each of the listed hashes. For regular HTLCs
	// this slice only has one hash. However, for "multi-sig" HTLCs, the
	// length of this slice should be N.
	RedemptionHashes [][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 stip off a layer
	// of encryption, exposing the next hop to be used in the subsequent
	// HTLCAddRequest message.
	// TODO(roasbeef): can be fixed sized now that v1 Sphinx is "done".
	OnionBlob []byte
}

HTLCAddRequest 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, and contract type of the HTLC, and 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" HTLCs. A subsequent CommitSignature message will move the pending HTLC to the newly created commitment transaction, marking them as "staged".

func NewHTLCAddRequest

func NewHTLCAddRequest() *HTLCAddRequest

NewHTLCAddRequest returns a new empty HTLCAddRequest message.

func (*HTLCAddRequest) Command

func (c *HTLCAddRequest) Command() uint32

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

This is part of the lnwire.Message interface.

func (*HTLCAddRequest) Decode

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

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

This is part of the lnwire.Message interface.

func (*HTLCAddRequest) Encode

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

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

This is part of the lnwire.Message interface.

func (*HTLCAddRequest) MaxPayloadLength

func (c *HTLCAddRequest) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*HTLCAddRequest) Validate

func (c *HTLCAddRequest) Validate() error

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

This is part of the lnwire.Message interface.

type HTLCKey

type HTLCKey int64

HTLCKey is an identifier used to uniquely identify any HTLCs transmitted between Alice and Bob. In order to cancel, timeout, or settle HTLCs this identifier should be used to allow either side to easily locate and modify any staged or pending HTLCs. TODO(roasbeef): change to HTLCIdentifier?

type HTLCSettleRequest

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

	// HTLCKey denotes the exact HTLC stage within the receiving node's
	// commitment transaction to be removed.
	// TODO(roasbeef): rename to LogIndex
	HTLCKey HTLCKey

	// RedemptionProofs are the R-value preimages required to fully settle
	// an HTLC. The number of preimages in the slice will depend on the
	// specific ContractType of the referenced HTLC.
	RedemptionProofs [][32]byte
}

HTLCSettleRequest 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. The message allows multiple hash preimages to be presented in order to support N-of-M HTLC contracts. A subsequent CommitSignature message will be sent by Alice to "lock-in" the removal of the specified HTLC, possible containing a batch signature covering several settled HTLCs.

func NewHTLCSettleRequest

func NewHTLCSettleRequest(chanPoint *wire.OutPoint, key HTLCKey,
	redemptionProofs [][32]byte) *HTLCSettleRequest

NewHTLCSettleRequest returns a new empty HTLCSettleRequest.

func (*HTLCSettleRequest) Command

func (c *HTLCSettleRequest) Command() uint32

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

This is part of the lnwire.Message interface.

func (*HTLCSettleRequest) Decode

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

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

This is part of the lnwire.Message interface.

func (*HTLCSettleRequest) Encode

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

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

This is part of the lnwire.Message interface.

func (*HTLCSettleRequest) MaxPayloadLength

func (c *HTLCSettleRequest) MaxPayloadLength(uint32) uint32

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

This is part of the lnwire.Message interface.

func (*HTLCSettleRequest) Validate

func (c *HTLCSettleRequest) Validate() error

Validate performs any necessary sanity checks to ensure all fields present on the HTLCSettleRequest 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)

ReadMessageN 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

	// Address includes two specification fields: 'ipv6' and 'port' on which
	// the node is accepting incoming connections.
	Address *net.TCPAddr

	// 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
	// contains filtered or unexported fields
}

NodeAnnouncement message is used to announce the presence of a lightning node and signal that the node is accepting incoming connections.

func (*NodeAnnouncement) Command

func (c *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 (c *NodeAnnouncement) DataToSign() ([]byte, error)

dataToSign...

func (*NodeAnnouncement) Decode

func (c *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 (c *NodeAnnouncement) Encode(w io.Writer, pver uint32) error

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

This is part of the lnwire.Message interface.

func (*NodeAnnouncement) MaxPayloadLength

func (c *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 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 ServiceFlag

type ServiceFlag uint64

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

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 [4]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 [4]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 SingleFundingRequest 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 SingleFundingResponse. 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 SingleFundingOpenProof

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

	// ChanChainID is the channel ID of the completed channel which
	// compactly encodes the location of the channel within the current
	// main chain.
	ChanChainID ChannelID
}

SingleFundingOpenProof is the message sent by the channel initiator to the responder after the previously constructed funding transaction has achieved a sufficient number of confirmations. It is the initiator's duty to present a proof of an open channel to the responder. Otherwise, responding node may be vulnerable to a resource exhaustion attack wherein the requesting node repeatedly negotiates funding transactions which are never broadcast. If the responding node commits resources to watch the chain for each funding transaction, then this attack is very cheap for the initiator.

func NewSingleFundingOpenProof

func NewSingleFundingOpenProof(chanID uint64, chainID ChannelID) *SingleFundingOpenProof

NewSingleFundingSignComplete creates a new empty SingleFundingOpenProof message.

func (*SingleFundingOpenProof) Command

func (s *SingleFundingOpenProof) 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 (*SingleFundingOpenProof) Decode

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

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

This is part of the lnwire.Message interface.

func (*SingleFundingOpenProof) Encode

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

Encode serializes the target SingleFundingOpenProof 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 (*SingleFundingOpenProof) MaxPayloadLength

func (s *SingleFundingOpenProof) 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 SingleFundingOpenProof.

This is part of the lnwire.Message interface.

func (*SingleFundingOpenProof) Validate

func (s *SingleFundingOpenProof) Validate() error

Validate examines each populated field within the SingleFundingOpenProof 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
}

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) *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. Therefore, the final breakdown is: 8 + 1 + 8 + 8 + 8 + 4 + 33 + 33 + 25 + 8 + 9 = 166.

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
}

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) *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 SingleFundingRequest 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. Therefore, the final breakdown is: 8 + (33 * 3) + 8 + 25 + 8

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 SingleFundingComplete. This is calculated by summing the max length of all the fields within a SingleFundingResponse. The final breakdown is: 8 + 73 = 81

This is part of the lnwire.Message interface.

func (*SingleFundingSignComplete) Validate

func (s *SingleFundingSignComplete) Validate() error

Validate examines each populated field within the SingleFundingComplete 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.

Jump to

Keyboard shortcuts

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