utxonursery: store the chanPoint of the source channel in kidOutput

This commit adds an additional field to the kidOutput struct: the
outpoint of the channel that originally created the output. This field
is now needed in order to add some additional indexes that are required
to enable callers to query the internal state of the utxoNursery.
This commit is contained in:
Olaoluwa Osuntokun 2017-05-04 15:45:31 -07:00
parent dbed552d8e
commit ed7e4ad715
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
2 changed files with 19 additions and 3 deletions

View File

@ -261,7 +261,11 @@ func (u *utxoNursery) Stop() error {
// before its funds will be available to be moved into the user's wallet. The // before its funds will be available to be moved into the user's wallet. The
// struct includes a witnessGenerator closure which will be used to generate // struct includes a witnessGenerator closure which will be used to generate
// the witness required to sweep the output once it's mature. // the witness required to sweep the output once it's mature.
//
// TODO(roasbeef): rename to immatureOutput?
type kidOutput struct { type kidOutput struct {
originChanPoint wire.OutPoint
amt btcutil.Amount amt btcutil.Amount
outPoint wire.OutPoint outPoint wire.OutPoint
@ -286,7 +290,7 @@ type incubationRequest struct {
// incubateOutputs sends a request to utxoNursery to incubate the outputs // incubateOutputs sends a request to utxoNursery to incubate the outputs
// defined within the summary of a closed channel. Individually, as all outputs // defined within the summary of a closed channel. Individually, as all outputs
// reach maturity they'll be swept back into the wallet. // reach maturity they'll be swept back into the wallet.
func (u *utxoNursery) incubateOutputs(closeSummary *lnwallet.ForceCloseSummary) { func (u *utxoNursery) IncubateOutputs(closeSummary *lnwallet.ForceCloseSummary) {
var incReq incubationRequest var incReq incubationRequest
// It could be that our to-self output was below the dust limit. In that // It could be that our to-self output was below the dust limit. In that
@ -295,6 +299,7 @@ func (u *utxoNursery) incubateOutputs(closeSummary *lnwallet.ForceCloseSummary)
if closeSummary.SelfOutputSignDesc != nil { if closeSummary.SelfOutputSignDesc != nil {
outputAmt := btcutil.Amount(closeSummary.SelfOutputSignDesc.Output.Value) outputAmt := btcutil.Amount(closeSummary.SelfOutputSignDesc.Output.Value)
selfOutput := &kidOutput{ selfOutput := &kidOutput{
originChanPoint: closeSummary.ChanPoint,
amt: outputAmt, amt: outputAmt,
outPoint: closeSummary.SelfOutpoint, outPoint: closeSummary.SelfOutpoint,
blocksToMaturity: closeSummary.SelfOutputMaturity, blocksToMaturity: closeSummary.SelfOutputMaturity,
@ -769,6 +774,9 @@ func serializeKidOutput(w io.Writer, kid *kidOutput) error {
if err := writeOutpoint(w, &kid.outPoint); err != nil { if err := writeOutpoint(w, &kid.outPoint); err != nil {
return err return err
} }
if err := writeOutpoint(w, &kid.originChanPoint); err != nil {
return err
}
byteOrder.PutUint32(scratch[:4], kid.blocksToMaturity) byteOrder.PutUint32(scratch[:4], kid.blocksToMaturity)
if _, err := w.Write(scratch[:4]); err != nil { if _, err := w.Write(scratch[:4]); err != nil {
@ -824,6 +832,9 @@ func deserializeKidOutput(r io.Reader) (*kidOutput, error) {
if err := readOutpoint(io.LimitReader(r, 40), &kid.outPoint); err != nil { if err := readOutpoint(io.LimitReader(r, 40), &kid.outPoint); err != nil {
return nil, err return nil, err
} }
if err := readOutpoint(io.LimitReader(r, 40), &kid.originChanPoint); err != nil {
return nil, err
}
if _, err := r.Read(scratch[:4]); err != nil { if _, err := r.Read(scratch[:4]); err != nil {
return nil, err return nil, err

View File

@ -2,7 +2,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt"
"reflect" "reflect"
"testing" "testing"
@ -166,23 +165,29 @@ var (
kidOutputs = []kidOutput{ kidOutputs = []kidOutput{
{ {
originChanPoint: outPoints[1],
amt: btcutil.Amount(13e7), amt: btcutil.Amount(13e7),
outPoint: outPoints[0], outPoint: outPoints[0],
blocksToMaturity: uint32(100), blocksToMaturity: uint32(100),
witnessType: commitmentTimeLock,
confHeight: uint32(1770001), confHeight: uint32(1770001),
}, },
{ {
originChanPoint: outPoints[0],
amt: btcutil.Amount(24e7), amt: btcutil.Amount(24e7),
outPoint: outPoints[1], outPoint: outPoints[1],
blocksToMaturity: uint32(50), blocksToMaturity: uint32(50),
witnessType: commitmentTimeLock,
confHeight: uint32(22342321), confHeight: uint32(22342321),
}, },
{ {
originChanPoint: outPoints[2],
amt: btcutil.Amount(2e5), amt: btcutil.Amount(2e5),
outPoint: outPoints[2], outPoint: outPoints[2],
blocksToMaturity: uint32(12), blocksToMaturity: uint32(12),
witnessType: commitmentTimeLock,
confHeight: uint32(34241), confHeight: uint32(34241),
}, },
} }
@ -236,7 +241,7 @@ func TestSerializeKidOutput(t *testing.T) {
deserializedKid, err := deserializeKidOutput(&b) deserializedKid, err := deserializeKidOutput(&b)
if err != nil { if err != nil {
fmt.Printf(err.Error()) t.Fatalf(err.Error())
} }
if !reflect.DeepEqual(kid, deserializedKid) { if !reflect.DeepEqual(kid, deserializedKid) {