From ed7e4ad715ea2f80f2198e5d4e7b7e8c99a6194b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 4 May 2017 15:45:31 -0700 Subject: [PATCH] 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. --- utxonursery.go | 13 ++++++++++++- utxonursery_test.go | 9 +++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/utxonursery.go b/utxonursery.go index 7a4fafba..7c2bc93b 100644 --- a/utxonursery.go +++ b/utxonursery.go @@ -261,7 +261,11 @@ func (u *utxoNursery) Stop() error { // 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 // the witness required to sweep the output once it's mature. +// +// TODO(roasbeef): rename to immatureOutput? type kidOutput struct { + originChanPoint wire.OutPoint + amt btcutil.Amount outPoint wire.OutPoint @@ -286,7 +290,7 @@ type incubationRequest struct { // incubateOutputs sends a request to utxoNursery to incubate the outputs // defined within the summary of a closed channel. Individually, as all outputs // 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 // 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 { outputAmt := btcutil.Amount(closeSummary.SelfOutputSignDesc.Output.Value) selfOutput := &kidOutput{ + originChanPoint: closeSummary.ChanPoint, amt: outputAmt, outPoint: closeSummary.SelfOutpoint, blocksToMaturity: closeSummary.SelfOutputMaturity, @@ -769,6 +774,9 @@ func serializeKidOutput(w io.Writer, kid *kidOutput) error { if err := writeOutpoint(w, &kid.outPoint); err != nil { return err } + if err := writeOutpoint(w, &kid.originChanPoint); err != nil { + return err + } byteOrder.PutUint32(scratch[:4], kid.blocksToMaturity) 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 { 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 { return nil, err diff --git a/utxonursery_test.go b/utxonursery_test.go index f21fcc7b..9938ca90 100644 --- a/utxonursery_test.go +++ b/utxonursery_test.go @@ -2,7 +2,6 @@ package main import ( "bytes" - "fmt" "reflect" "testing" @@ -166,23 +165,29 @@ var ( kidOutputs = []kidOutput{ { + originChanPoint: outPoints[1], amt: btcutil.Amount(13e7), outPoint: outPoints[0], blocksToMaturity: uint32(100), + witnessType: commitmentTimeLock, confHeight: uint32(1770001), }, { + originChanPoint: outPoints[0], amt: btcutil.Amount(24e7), outPoint: outPoints[1], blocksToMaturity: uint32(50), + witnessType: commitmentTimeLock, confHeight: uint32(22342321), }, { + originChanPoint: outPoints[2], amt: btcutil.Amount(2e5), outPoint: outPoints[2], blocksToMaturity: uint32(12), + witnessType: commitmentTimeLock, confHeight: uint32(34241), }, } @@ -236,7 +241,7 @@ func TestSerializeKidOutput(t *testing.T) { deserializedKid, err := deserializeKidOutput(&b) if err != nil { - fmt.Printf(err.Error()) + t.Fatalf(err.Error()) } if !reflect.DeepEqual(kid, deserializedKid) {