Documentation ¶
Index ¶
- Variables
- func DisableLog()
- func ParseUpfrontShutdownAddress(address string, params *chaincfg.Params) (lnwire.DeliveryAddress, error)
- func UseLogger(logger btclog.Logger)
- type ChanCloseCfg
- type ChanCloser
- func (c *ChanCloser) Channel() *lnwallet.LightningChannel
- func (c *ChanCloser) CloseRequest() *htlcswitch.ChanClose
- func (c *ChanCloser) ClosingTx() (*wire.MsgTx, error)
- func (c *ChanCloser) NegotiationHeight() uint32
- func (c *ChanCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, bool, error)
- func (c *ChanCloser) ShutdownChan() (*lnwire.Shutdown, error)
- type Channel
Constants ¶
This section is empty.
Variables ¶
var ( // ErrChanAlreadyClosing is returned when a channel shutdown is attempted // more than once. ErrChanAlreadyClosing = fmt.Errorf("channel shutdown already initiated") // ErrChanCloseNotFinished is returned when a caller attempts to access // a field or function that is contingent on the channel closure negotiation // already being completed. ErrChanCloseNotFinished = fmt.Errorf("close negotiation not finished") // ErrInvalidState is returned when the closing state machine receives a // message while it is in an unknown state. ErrInvalidState = fmt.Errorf("invalid state") // ErrUpfrontShutdownScriptMismatch is returned when a peer or end user // provides a cooperative close script which does not match the upfront // shutdown script previously set for that party. ErrUpfrontShutdownScriptMismatch = fmt.Errorf("shutdown script does not " + "match upfront shutdown script") // ErrProposalExeceedsMaxFee is returned when as the initiator, the // latest fee proposal sent by the responder exceed our max fee. // responder. ErrProposalExeceedsMaxFee = fmt.Errorf("latest fee proposal exceeds " + "max fee") // ErrInvalidShutdownScript is returned when we receive an address from // a peer that isn't either a p2wsh or p2tr address. ErrInvalidShutdownScript = fmt.Errorf("invalid shutdown script") )
Functions ¶
func ParseUpfrontShutdownAddress ¶
func ParseUpfrontShutdownAddress(address string, params *chaincfg.Params) (lnwire.DeliveryAddress, error)
ParseUpfrontShutdownAddress attempts to parse an upfront shutdown address. If the address is empty, it returns nil. If it successfully decoded the address, it returns a script that pays out to the address.
Types ¶
type ChanCloseCfg ¶
type ChanCloseCfg struct { // Channel is the channel that should be closed. Channel Channel // BroadcastTx broadcasts the passed transaction to the network. BroadcastTx func(*wire.MsgTx, string) error // DisableChannel disables a channel, resulting in it not being able to // forward payments. DisableChannel func(wire.OutPoint) error // Disconnect will disconnect from the remote peer in this close. Disconnect func() error // MaxFee, is non-zero represents the highest fee that the initiator is // willing to pay to close the channel. MaxFee chainfee.SatPerKWeight // ChainParams holds the parameters of the chain that we're active on. ChainParams *chaincfg.Params // Quit is a channel that should be sent upon in the occasion the state // machine should cease all progress and shutdown. Quit chan struct{} }
ChanCloseCfg holds all the items that a ChanCloser requires to carry out its duties.
type ChanCloser ¶
type ChanCloser struct {
// contains filtered or unexported fields
}
ChanCloser is a state machine that handles the cooperative channel closure procedure. This includes shutting down a channel, marking it ineligible for routing HTLC's, negotiating fees with the remote party, and finally broadcasting the fully signed closure transaction to the network.
func NewChanCloser ¶
func NewChanCloser(cfg ChanCloseCfg, deliveryScript []byte, idealFeePerKw chainfee.SatPerKWeight, negotiationHeight uint32, closeReq *htlcswitch.ChanClose, locallyInitiated bool) *ChanCloser
NewChanCloser creates a new instance of the channel closure given the passed configuration, and delivery+fee preference. The final argument should only be populated iff, we're the initiator of this closing request.
func (*ChanCloser) Channel ¶
func (c *ChanCloser) Channel() *lnwallet.LightningChannel
Channel returns the channel stored in the config as a *lnwallet.LightningChannel.
NOTE: This method will PANIC if the underlying channel implementation isn't the desired type.
func (*ChanCloser) CloseRequest ¶
func (c *ChanCloser) CloseRequest() *htlcswitch.ChanClose
CloseRequest returns the original close request that prompted the creation of the state machine.
NOTE: This will only return a non-nil pointer if we were the initiator of the cooperative closure workflow.
func (*ChanCloser) ClosingTx ¶
func (c *ChanCloser) ClosingTx() (*wire.MsgTx, error)
ClosingTx returns the fully signed, final closing transaction.
NOTE: This transaction is only available if the state machine is in the closeFinished state.
func (*ChanCloser) NegotiationHeight ¶
func (c *ChanCloser) NegotiationHeight() uint32
NegotiationHeight returns the negotiation height.
func (*ChanCloser) ProcessCloseMsg ¶
ProcessCloseMsg attempts to process the next message in the closing series. This method will update the state accordingly and return two primary values: the next set of messages to be sent, and a bool indicating if the fee negotiation process has completed. If the second value is true, then this means the ChanCloser can be garbage collected.
func (*ChanCloser) ShutdownChan ¶
func (c *ChanCloser) ShutdownChan() (*lnwire.Shutdown, error)
ShutdownChan is the first method that's to be called by the initiator of the cooperative channel closure. This message returns the shutdown message to send to the remote party. Upon completion, we enter the closeShutdownInitiated phase as we await a response.
type Channel ¶
type Channel interface { // CalcFee returns the absolute fee for the given fee rate. CalcFee(chainfee.SatPerKWeight) btcutil.Amount // ChannelPoint returns the channel point of the target channel. ChannelPoint() *wire.OutPoint // MarkCoopBroadcasted persistently marks that the channel close // transaction has been broadcast. MarkCoopBroadcasted(*wire.MsgTx, bool) error // IsInitiator returns true we are the initiator of the channel. IsInitiator() bool // ShortChanID returns the scid of the channel. ShortChanID() lnwire.ShortChannelID // AbsoluteThawHeight returns the absolute thaw height of the channel. // If the channel is pending, or an unconfirmed zero conf channel, then // an error should be returned. AbsoluteThawHeight() (uint32, error) // RemoteUpfrontShutdownScript returns the upfront shutdown script of // the remote party. If the remote party didn't specify such a script, // an empty delivery address should be returned. RemoteUpfrontShutdownScript() lnwire.DeliveryAddress // CreateCloseProposal creates a new co-op close proposal in the form // of a valid signature, the chainhash of the final txid, and our final // balance in the created state. CreateCloseProposal(proposedFee btcutil.Amount, localDeliveryScript []byte, remoteDeliveryScript []byte) (input.Signature, *chainhash.Hash, btcutil.Amount, error) // CompleteCooperativeClose persistently "completes" the cooperative // close by producing a fully signed co-op close transaction. CompleteCooperativeClose(localSig, remoteSig input.Signature, localDeliveryScript, remoteDeliveryScript []byte, proposedFee btcutil.Amount) (*wire.MsgTx, btcutil.Amount, error) }
Channel abstracts away from the core channel state machine by exposing an interface that requires only the methods we need to carry out the channel closing process.