Skip to content

Commit

Permalink
utxonursery: remove unused commit sweep code
Browse files Browse the repository at this point in the history
Now that the commit sweep resolver is no longer relying on the nursery,
all code associated with commit sweeping can be removed.
  • Loading branch information
joostjager committed Nov 14, 2019
1 parent 9acb236 commit 919ab60
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 126 deletions.
3 changes: 1 addition & 2 deletions contractcourt/chain_arbitrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ type ChainArbitratorConfig struct {
// the process of incubation. This is used when a resolver wishes to
// pass off the output to the nursery as we're only waiting on an
// absolute/relative item block.
IncubateOutputs func(wire.OutPoint, *lnwallet.CommitOutputResolution,
*lnwallet.OutgoingHtlcResolution,
IncubateOutputs func(wire.OutPoint, *lnwallet.OutgoingHtlcResolution,
*lnwallet.IncomingHtlcResolution, uint32) error

// PreimageDB is a global store of all known pre-images. We'll use this
Expand Down
2 changes: 1 addition & 1 deletion contractcourt/channel_arbitrator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ func createTestChannelArbitrator(t *testing.T, log ArbitratorLog) (*chanArbTestC
spendChan: make(chan *chainntnfs.SpendDetail),
confChan: make(chan *chainntnfs.TxConfirmation),
},
IncubateOutputs: func(wire.OutPoint, *lnwallet.CommitOutputResolution,
IncubateOutputs: func(wire.OutPoint,
*lnwallet.OutgoingHtlcResolution,
*lnwallet.IncomingHtlcResolution, uint32) error {

Expand Down
2 changes: 1 addition & 1 deletion contractcourt/htlc_success_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (h *htlcSuccessResolver) Resolve() (ContractResolver, error) {
h, h.htlc.RHash[:])

err := h.IncubateOutputs(
h.ChanPoint, nil, nil, &h.htlcResolution,
h.ChanPoint, nil, &h.htlcResolution,
h.broadcastHeight,
)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion contractcourt/htlc_timeout_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func (h *htlcTimeoutResolver) Resolve() (ContractResolver, error) {
h.htlcResolution.ClaimOutpoint)

err := h.IncubateOutputs(
h.ChanPoint, nil, &h.htlcResolution, nil,
h.ChanPoint, &h.htlcResolution, nil,
h.broadcastHeight,
)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion contractcourt/htlc_timeout_resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func TestHtlcTimeoutResolver(t *testing.T) {
Notifier: notifier,
PreimageDB: witnessBeacon,
IncubateOutputs: func(wire.OutPoint,
*lnwallet.CommitOutputResolution,
*lnwallet.OutgoingHtlcResolution,
*lnwallet.IncomingHtlcResolution,
uint32) error {
Expand Down
3 changes: 1 addition & 2 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,6 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
return nil
},
IncubateOutputs: func(chanPoint wire.OutPoint,
commitRes *lnwallet.CommitOutputResolution,
outHtlcRes *lnwallet.OutgoingHtlcResolution,
inHtlcRes *lnwallet.IncomingHtlcResolution,
broadcastHeight uint32) error {
Expand All @@ -864,7 +863,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
}

return s.utxoNursery.IncubateOutputs(
chanPoint, commitRes, outRes, inRes,
chanPoint, outRes, inRes,
broadcastHeight,
)
},
Expand Down
66 changes: 2 additions & 64 deletions utxonursery.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ func (u *utxoNursery) Stop() error {
// they're CLTV absolute time locked, or if they're CSV relative time locked.
// Once all outputs reach maturity, they'll be swept back into the wallet.
func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
commitResolution *lnwallet.CommitOutputResolution,
outgoingHtlcs []lnwallet.OutgoingHtlcResolution,
incomingHtlcs []lnwallet.IncomingHtlcResolution,
broadcastHeight uint32) error {
Expand All @@ -352,8 +351,6 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,

numHtlcs := len(incomingHtlcs) + len(outgoingHtlcs)
var (
hasCommit bool

// Kid outputs can be swept after an initial confirmation
// followed by a maturity period.Baby outputs are two stage and
// will need to wait for an absolute time out to reach a
Expand All @@ -364,28 +361,6 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,

// 1. Build all the spendable outputs that we will try to incubate.

// It could be that our to-self output was below the dust limit. In
// that case the commit resolution would be nil and we would not have
// that output to incubate.
if commitResolution != nil {
hasCommit = true
selfOutput := makeKidOutput(
&commitResolution.SelfOutPoint,
&chanPoint,
commitResolution.MaturityDelay,
input.CommitmentTimeLock,
&commitResolution.SelfOutputSignDesc,
0,
)

// We'll skip any zero valued outputs as this indicates we
// don't have a settled balance within the commitment
// transaction.
if selfOutput.Amount() > 0 {
kidOutputs = append(kidOutputs, selfOutput)
}
}

// TODO(roasbeef): query and see if we already have, if so don't add?

// For each incoming HTLC, we'll register a kid output marked as a
Expand Down Expand Up @@ -436,8 +411,8 @@ func (u *utxoNursery) IncubateOutputs(chanPoint wire.OutPoint,
// * need ability to cancel in the case that we learn of pre-image or
// remote party pulls

utxnLog.Infof("Incubating Channel(%s) has-commit=%v, num-htlcs=%d",
chanPoint, hasCommit, numHtlcs)
utxnLog.Infof("Incubating Channel(%s) num-htlcs=%d",
chanPoint, numHtlcs)

u.mu.Lock()
defer u.mu.Unlock()
Expand Down Expand Up @@ -538,8 +513,6 @@ func (u *utxoNursery) NurseryReport(
// Preschool outputs are awaiting the
// confirmation of the commitment transaction.
switch kid.WitnessType() {
case input.CommitmentTimeLock:
report.AddLimboCommitment(&kid)

case input.HtlcAcceptedSuccessSecondLevel:
// An HTLC output on our commitment transaction
Expand All @@ -561,11 +534,6 @@ func (u *utxoNursery) NurseryReport(
// We can distinguish them via their witness
// types.
switch kid.WitnessType() {
case input.CommitmentTimeLock:
// The commitment transaction has been
// confirmed, and we are waiting the CSV
// delay to expire.
report.AddLimboCommitment(&kid)

case input.HtlcOfferedRemoteTimeout:
// This is an HTLC output on the
Expand All @@ -590,11 +558,6 @@ func (u *utxoNursery) NurseryReport(
// will contribute towards the recovered
// balance.
switch kid.WitnessType() {
case input.CommitmentTimeLock:
// The commitment output was
// successfully swept back into a
// regular p2wkh output.
report.AddRecoveredCommitment(&kid)

case input.HtlcAcceptedSuccessSecondLevel:
fallthrough
Expand Down Expand Up @@ -1071,11 +1034,6 @@ type contractMaturityReport struct {
// recoveredBalance is the total value that has been successfully swept
// back to the user's wallet.
recoveredBalance btcutil.Amount

// maturityHeight is the absolute block height that this output will
// mature at.
maturityHeight uint32

// htlcs records a maturity report for each htlc output in this channel.
htlcs []htlcMaturityReport
}
Expand All @@ -1100,26 +1058,6 @@ type htlcMaturityReport struct {
stage uint32
}

// AddLimboCommitment adds an incubating commitment output to maturity
// report's htlcs, and contributes its amount to the limbo balance.
func (c *contractMaturityReport) AddLimboCommitment(kid *kidOutput) {
c.limboBalance += kid.Amount()

// If the confirmation height is set, then this means the contract has
// been confirmed, and we know the final maturity height.
if kid.ConfHeight() != 0 {
c.maturityHeight = kid.BlocksToMaturity() + kid.ConfHeight()
}
}

// AddRecoveredCommitment adds a graduated commitment output to maturity
// report's htlcs, and contributes its amount to the recovered balance.
func (c *contractMaturityReport) AddRecoveredCommitment(kid *kidOutput) {
c.recoveredBalance += kid.Amount()

c.maturityHeight = kid.BlocksToMaturity() + kid.ConfHeight()
}

// AddLimboStage1TimeoutHtlc adds an htlc crib output to the maturity report's
// htlcs, and contributes its amount to the limbo balance.
func (c *contractMaturityReport) AddLimboStage1TimeoutHtlc(baby *babyOutput) {
Expand Down
54 changes: 0 additions & 54 deletions utxonursery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,6 @@ func incubateTestOutput(t *testing.T, nursery *utxoNursery,
// Hand off to nursery.
err := nursery.IncubateOutputs(
testChanPoint,
nil,
[]lnwallet.OutgoingHtlcResolution{*outgoingRes},
nil, 0,
)
Expand Down Expand Up @@ -839,59 +838,6 @@ func testNurseryOutgoingHtlcSuccessOnRemote(t *testing.T,
ctx.finish()
}

func TestNurseryCommitSuccessOnLocal(t *testing.T) {
testRestartLoop(t, testNurseryCommitSuccessOnLocal)
}

func testNurseryCommitSuccessOnLocal(t *testing.T,
checkStartStop func(func()) bool) {

ctx := createNurseryTestContext(t, checkStartStop)

commitRes := createCommitmentRes()

// Hand off to nursery.
err := ctx.nursery.IncubateOutputs(
testChanPoint,
commitRes, nil, nil, 0,
)
if err != nil {
t.Fatal(err)
}

// Verify that commitment output is showing up in nursery report as
// limbo balance.
assertNurseryReport(t, ctx.nursery, 0, 0, 10000)

ctx.restart()

// Notify confirmation of the commitment tx.
err = ctx.notifier.ConfirmTx(&commitRes.SelfOutPoint.Hash, 124)
if err != nil {
t.Fatal(err)
}

// Wait for output to be promoted from PSCL to KNDR.
select {
case <-ctx.store.preschoolToKinderChan:
case <-time.After(defaultTestTimeout):
t.Fatalf("output not promoted to KNDR")
}

ctx.restart()

// Notify arrival of block where commit output CSV expires.
ctx.notifyEpoch(126)

// Check final sweep into wallet.
testSweep(t, ctx, func() {
// Check limbo balance after sweep publication
assertNurseryReport(t, ctx.nursery, 0, 0, 10000)
})

ctx.finish()
}

func testSweepHtlc(t *testing.T, ctx *nurseryTestContext) {
testSweep(t, ctx, func() {
// Verify stage in nursery report. HTLCs should now both still
Expand Down

0 comments on commit 919ab60

Please sign in to comment.