Skip to content

Commit 9301539

Browse files
authored
Merge pull request #183 from lightninglabs/fix-ancient-sweep
cmd+lnd: fix tweak handling
2 parents 5657a7a + 009c20f commit 9301539

File tree

5 files changed

+1567
-4
lines changed

5 files changed

+1567
-4
lines changed

cmd/chantools/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const (
3131
// version is the current version of the tool. It is set during build.
3232
// NOTE: When changing this, please also update the version in the
3333
// download link shown in the README.
34-
version = "0.13.6"
34+
version = "0.13.7"
3535
na = "n/a"
3636

3737
// lndVersion is the current version of lnd that we support. This is

cmd/chantools/summary.go

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/btcsuite/btcd/btcutil"
10+
"github.com/btcsuite/btcd/wire"
1011
"github.com/lightninglabs/chantools/btc"
1112
"github.com/lightninglabs/chantools/dataformat"
1213
"github.com/lightninglabs/chantools/lnd"
@@ -211,16 +212,40 @@ func summarizeAncientChannelOutputs(apiURL, ancientFile string) error {
211212

212213
var (
213214
api = newExplorerAPI(apiURL)
215+
numSpents uint32
214216
numUnspents uint32
215217
unspentSats uint64
218+
spentSats uint64
216219
)
217-
for _, channel := range ancients {
220+
for idx, channel := range ancients {
221+
// The first entry is for unit tests.
222+
if idx == 0 {
223+
continue
224+
}
225+
226+
closeOutPoint, err := wire.NewOutPointFromString(channel.OP)
227+
if err != nil {
228+
return fmt.Errorf("error parsing outpoint %s: %w",
229+
channel.OP, err)
230+
}
231+
218232
unspents, err := api.Unspent(channel.Addr)
219233
if err != nil {
220234
return fmt.Errorf("error fetching unspents for %s: %w",
221235
channel.Addr, err)
222236
}
223237

238+
if len(unspents) == 0 {
239+
tx, err := api.Transaction(closeOutPoint.Hash.String())
240+
if err != nil {
241+
return fmt.Errorf("error fetching transaction "+
242+
"%s: %w", closeOutPoint.Hash, err)
243+
}
244+
245+
numSpents++
246+
spentSats += tx.Vout[closeOutPoint.Index].Value
247+
}
248+
224249
if len(unspents) > 1 {
225250
log.Infof("Address %s has multiple unspents",
226251
channel.Addr)
@@ -237,6 +262,8 @@ func summarizeAncientChannelOutputs(apiURL, ancientFile string) error {
237262

238263
log.Infof("Found %d unspent outputs with %d sats", numUnspents,
239264
unspentSats)
265+
log.Infof("%d outputs with %d sats have been spent", numSpents,
266+
spentSats)
240267

241268
return nil
242269
}

cmd/chantools/sweepremoteclosed.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,8 @@ func sweepRemoteClosed(extendedKey *hdkeychain.ExtendedKey, apiURL,
371371
// output...
372372
desc.WitnessScript = desc.Output.PkScript
373373
witness, err := input.CommitSpendNoDelay(
374-
signer, desc, sweepTx, true,
374+
signer, desc, sweepTx,
375+
len(desc.SingleTweak) == 0,
375376
)
376377
if err != nil {
377378
return err

0 commit comments

Comments
 (0)