fundingmanager: move final funding steps from wallet to funding manager.
Once a channel funding process has advanced to the point of broadcasting the funding transaction, the state of the channel should be persisted so that the nodes can disconnect or go down without having to wait for the funding transaction to be confirmed on the blockchain. Previously, the finalization of the funding process was handled by a combination of the funding manager, the peer and the wallet, but if the remote peer is no longer online or no longer connected, this flow will no longer work. This commit moves all funding steps following the transaction broadcast into the funding manager, which is available as long as the daemon is running.
This commit is contained in:
1 parent
508138f8c8
commit
e549a3f0ed
10 files changed
+402
-512
No files matched your search
+9
-46
@@ -290,7 +290,7 @@ func (r *ChannelReservation) OurSignatures() ([]*InputScript, []byte) {
|
||||
return r.ourFundingInputScripts, r.ourCommitmentSig
|
||||
}
|
||||
|
||||
// CompleteFundingReservation finalizes the pending channel reservation,
|
||||
// CompleteReservation finalizes the pending channel reservation,
|
||||
// transitioning from a pending payment channel, to an open payment
|
||||
// channel. All passed signatures to the counterparty's inputs to the funding
|
||||
// transaction will be fully verified. Signatures are expected to be passed in
|
||||
@@ -303,19 +303,21 @@ func (r *ChannelReservation) OurSignatures() ([]*InputScript, []byte) {
|
||||
// of confirmations. Once the method unblocks, a LightningChannel instance is
|
||||
// returned, marking the channel available for updates.
|
||||
func (r *ChannelReservation) CompleteReservation(fundingInputScripts []*InputScript,
|
||||
commitmentSig []byte) error {
|
||||
commitmentSig []byte) (*channeldb.OpenChannel, error) {
|
||||
|
||||
// TODO(roasbeef): add flag for watch or not?
|
||||
errChan := make(chan error, 1)
|
||||
completeChan := make(chan *channeldb.OpenChannel, 1)
|
||||
|
||||
r.wallet.msgChan <- &addCounterPartySigsMsg{
|
||||
pendingFundingID: r.reservationID,
|
||||
theirFundingInputScripts: fundingInputScripts,
|
||||
theirCommitmentSig: commitmentSig,
|
||||
completeChan: completeChan,
|
||||
err: errChan,
|
||||
}
|
||||
|
||||
return <-errChan
|
||||
return <-completeChan, <-errChan
|
||||
}
|
||||
|
||||
// CompleteReservationSingle finalizes the pending single funder channel
|
||||
@@ -329,9 +331,10 @@ func (r *ChannelReservation) CompleteReservation(fundingInputScripts []*InputScr
|
||||
// populated.
|
||||
func (r *ChannelReservation) CompleteReservationSingle(
|
||||
revocationKey *btcec.PublicKey, fundingPoint *wire.OutPoint,
|
||||
commitSig []byte, obsfucator [StateHintSize]byte) error {
|
||||
commitSig []byte, obsfucator [StateHintSize]byte) (*channeldb.OpenChannel, error) {
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
completeChan := make(chan *channeldb.OpenChannel, 1)
|
||||
|
||||
r.wallet.msgChan <- &addSingleFunderSigsMsg{
|
||||
pendingFundingID: r.reservationID,
|
||||
@@ -339,10 +342,11 @@ func (r *ChannelReservation) CompleteReservationSingle(
|
||||
fundingOutpoint: fundingPoint,
|
||||
theirCommitmentSig: commitSig,
|
||||
obsfucator: obsfucator,
|
||||
completeChan: completeChan,
|
||||
err: errChan,
|
||||
}
|
||||
|
||||
return <-errChan
|
||||
return <-completeChan, <-errChan
|
||||
}
|
||||
|
||||
// OurSignatures returns the counterparty's signatures to all inputs to the
|
||||
@@ -453,44 +457,3 @@ type OpenChannelDetails struct {
|
||||
// transaction resides.
|
||||
TransactionIndex uint32
|
||||
}
|
||||
|
||||
// DispatchChan returns a channel which will be sent on once the funding
|
||||
// transaction for this pending payment channel obtains the configured number
|
||||
// of confirmations. Once confirmations have been obtained, a fully initialized
|
||||
// LightningChannel instance is returned, allowing for channel updates.
|
||||
//
|
||||
// NOTE: If this method is called before .CompleteReservation(), it will block
|
||||
// indefinitely.
|
||||
func (r *ChannelReservation) DispatchChan() (*OpenChannelDetails, error) {
|
||||
if err := <-r.chanOpenErr; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
openDetails := <-r.chanOpen
|
||||
return &OpenChannelDetails{
|
||||
Channel: openDetails.channel,
|
||||
ConfirmationHeight: openDetails.blockHeight,
|
||||
TransactionIndex: openDetails.txIndex,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// FinalizeReservation completes the pending reservation, returning an active
|
||||
// open LightningChannel. This method should be called after the responder to
|
||||
// the single funder workflow receives and verifies a proof from the initiator
|
||||
// of an open channel.
|
||||
//
|
||||
// NOTE: This method should *only* be called as the last step when one is the
|
||||
// responder to an initiated single funder workflow.
|
||||
func (r *ChannelReservation) FinalizeReservation() (*LightningChannel, error) {
|
||||
errChan := make(chan error, 1)
|
||||
r.wallet.msgChan <- &channelOpenMsg{
|
||||
pendingFundingID: r.reservationID,
|
||||
err: errChan,
|
||||
}
|
||||
|
||||
if err := <-errChan; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return (<-r.chanOpen).channel, nil
|
||||
}
|
||||
Reference in new issue
Block a user