utxonursery: remove unused commit sweep code

Now that the commit sweep resolver is no longer relying on the nursery,
all code associated with commit sweeping can be removed.
This commit is contained in:
Joost Jager 2019-10-30 11:44:39 +01:00
parent 9acb236665
commit 919ab60540
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
8 changed files with 7 additions and 126 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {

View File

@ -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 {
@ -864,7 +863,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
}
return s.utxoNursery.IncubateOutputs(
chanPoint, commitRes, outRes, inRes,
chanPoint, outRes, inRes,
broadcastHeight,
)
},

View File

@ -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 {
@ -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
@ -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
@ -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()
@ -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
@ -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
@ -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
@ -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
}
@ -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) {

View File

@ -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,
)
@ -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