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:
bryanvu authored and Olaoluwa Osuntokun committed 2017-02-24 11:37:33 -08:00
1 parent 508138f8c8
commit e549a3f0ed
10 files changed
+402 -512

No files matched your search

+54 -27
View File
@@ -77,14 +77,18 @@ type SingleFundingRequest struct {
// this amount are not enforceable onchain from our point view.
DustLimit btcutil.Amount
// TODO(roasbeef): confirmation depth
// 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
}
// NewSingleFundingRequest creates, and returns a new empty SingleFundingRequest.
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 {
dustLimit btcutil.Amount, pushSat btcutil.Amount,
confDepth uint32) *SingleFundingRequest {
return &SingleFundingRequest{
ChannelID: chanID,
@@ -98,6 +102,7 @@ func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
DeliveryPkScript: deliveryScript,
DustLimit: dustLimit,
PushSatoshis: pushSat,
ConfirmationDepth: confDepth,
}
}
@@ -107,16 +112,6 @@ func NewSingleFundingRequest(chanID uint64, chanType uint8, coinType uint64,
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
// ChannelID (8)
// ChannelType (1)
// CoinType (8)
// FeePerKb (8)
// PaymentAmount (8)
// Delay (4)
// Pubkey (33)
// Pubkey (33)
// DeliveryPkScript (final delivery)
// DustLimit (8)
err := readElements(r,
&c.ChannelID,
&c.ChannelType,
@@ -128,7 +123,8 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
&c.CommitmentKey,
&c.ChannelDerivationPoint,
&c.DeliveryPkScript,
&c.DustLimit)
&c.DustLimit,
&c.ConfirmationDepth)
if err != nil {
return err
}
@@ -142,16 +138,6 @@ func (c *SingleFundingRequest) Decode(r io.Reader, pver uint32) error {
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error {
// ChannelID (8)
// ChannelType (1)
// CoinType (8)
// FeePerKb (8)
// PaymentAmount (8)
// Delay (4)
// Pubkey (33)
// Pubkey (33)
// DeliveryPkScript (final delivery)
// DustLimit (8)
err := writeElements(w,
c.ChannelID,
c.ChannelType,
@@ -163,7 +149,8 @@ func (c *SingleFundingRequest) Encode(w io.Writer, pver uint32) error {
c.CommitmentKey,
c.ChannelDerivationPoint,
c.DeliveryPkScript,
c.DustLimit)
c.DustLimit,
c.ConfirmationDepth)
if err != nil {
return err
}
@@ -183,12 +170,48 @@ func (c *SingleFundingRequest) Command() uint32 {
// 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 (c *SingleFundingRequest) MaxPayloadLength(uint32) uint32 {
return 174
var length uint32
// ChannelID - 8 bytes
length += 8
// ChannelType - 1 byte
length += 1
// CoinType - 8 bytes
length += 8
// FeePerKb - 8 bytes
length += 8
// FundingAmount - 8 bytes
length += 8
// PushSatoshis - 8 bytes
length += 8
// CsvDelay - 4 bytes
length += 4
// CommitmentKey - 33 bytes
length += 33
// ChannelDerivationPoint - 33 bytes
length += 33
// DeliveryPkScript - 25 bytes
length += 25
// DustLimit - 8 bytes
length += 8
// ConfirmationDepth - 4 bytes
length += 4
return length
}
// Validate examines each populated field within the SingleFundingRequest for
@@ -233,6 +256,10 @@ func (c *SingleFundingRequest) Validate() error {
return fmt.Errorf("Dust limit should be greater than zero.")
}
if c.ConfirmationDepth == 0 {
return fmt.Errorf("ConfirmationDepth must be non-zero")
}
// We're good!
return nil
}
+1 -1
View File
@@ -11,7 +11,7 @@ func TestSingleFundingRequestWire(t *testing.T) {
cdp := pubKey
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
sfr := NewSingleFundingRequest(20, 21, 22, 23, 5, 5, cdp, cdp,
delivery, 540, 10000)
delivery, 540, 10000, 6)
// Next encode the SFR message into an empty bytes buffer.
var b bytes.Buffer
+43 -12
View File
@@ -51,13 +51,18 @@ type SingleFundingResponse struct {
// 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
}
// NewSingleFundingResponse creates, and returns a new empty
// SingleFundingResponse.
func NewSingleFundingResponse(chanID uint64, rk, ck, cdp *btcec.PublicKey,
delay uint32, deliveryScript PkScript,
dustLimit btcutil.Amount) *SingleFundingResponse {
dustLimit btcutil.Amount, confDepth uint32) *SingleFundingResponse {
return &SingleFundingResponse{
ChannelID: chanID,
@@ -67,6 +72,7 @@ func NewSingleFundingResponse(chanID uint64, rk, ck, cdp *btcec.PublicKey,
CsvDelay: delay,
DeliveryPkScript: deliveryScript,
DustLimit: dustLimit,
ConfirmationDepth: confDepth,
}
}
@@ -87,6 +93,7 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
// CsvDelay (4)
// DeliveryPkScript (final delivery)
// DustLimit (8)
// ConfirmationDepth (4)
err := readElements(r,
&c.ChannelID,
&c.ChannelDerivationPoint,
@@ -94,7 +101,8 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
&c.RevocationKey,
&c.CsvDelay,
&c.DeliveryPkScript,
&c.DustLimit)
&c.DustLimit,
&c.ConfirmationDepth)
if err != nil {
return err
}
@@ -108,13 +116,6 @@ func (c *SingleFundingResponse) Decode(r io.Reader, pver uint32) error {
//
// This is part of the lnwire.Message interface.
func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error {
// ChannelID (8)
// ChannelDerivationPoint (33)
// CommitmentKey (33)
// RevocationKey (33)
// CsvDelay (4)
// DeliveryPkScript (final delivery)
// DustLimit (8)
err := writeElements(w,
c.ChannelID,
c.ChannelDerivationPoint,
@@ -122,7 +123,8 @@ func (c *SingleFundingResponse) Encode(w io.Writer, pver uint32) error {
c.RevocationKey,
c.CsvDelay,
c.DeliveryPkScript,
c.DustLimit)
c.DustLimit,
c.ConfirmationDepth)
if err != nil {
return err
}
@@ -142,11 +144,36 @@ func (c *SingleFundingResponse) Command() uint32 {
// 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 (c *SingleFundingResponse) MaxPayloadLength(uint32) uint32 {
return 148
var length uint32
// ChannelID - 8 bytes
length += 8
// ChannelDerivationPoint - 33 bytes
length += 33
// CommitmentKey - 33 bytes
length += 33
// RevocationKey - 33 bytes
length += 33
// CsvDelay - 4 bytes
length += 4
// DeliveryPkScript - 25 bytes
length += 25
// DustLimit - 8 bytes
length += 8
// ConfirmationDepth - 4 bytes
length += 4
return length
}
// Validate examines each populated field within the SingleFundingResponse for
@@ -177,6 +204,10 @@ func (c *SingleFundingResponse) Validate() error {
"zero.")
}
if c.ConfirmationDepth == 0 {
return fmt.Errorf("ConfirmationDepth must be non-zero")
}
// We're good!
return nil
}
+1 -1
View File
@@ -10,7 +10,7 @@ func TestSingleFundingResponseWire(t *testing.T) {
// First create a new SFR message.
delivery := PkScript(bytes.Repeat([]byte{0x02}, 25))
sfr := NewSingleFundingResponse(22, pubKey, pubKey, pubKey, 5,
delivery, 540)
delivery, 540, 4)
// Next encode the SFR message into an empty bytes buffer.
var b bytes.Buffer