Skip to content

Commit f20e729

Browse files
committed
triggerforceclose: better logging, abort retry after 60s
1 parent 2af1849 commit f20e729

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

cmd/chantools/triggerforceclose.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,22 @@ func (c *triggerForceCloseCommand) Execute(_ *cobra.Command, _ []string) error {
169169
pubKeys []string
170170
outputs []string
171171
)
172-
for _, openChan := range channels {
172+
for idx, openChan := range channels {
173173
addr := pickAddr(openChan.Node2Info.Node.Addresses)
174174
peerAddr := fmt.Sprintf("%s@%s", openChan.Node2, addr)
175175
log.Infof("Attempting to force close channel %s with "+
176-
"peer %s", openChan.ChanPoint, peerAddr)
176+
"peer %s (channel %d of %d)",
177+
openChan.ChanPoint, peerAddr, idx+1,
178+
len(channels))
177179

178180
outputAddrs, err := closeChannel(
179181
identityPriv, api, openChan.ChanPoint,
180182
peerAddr, c.TorProxy,
181183
)
182184
if err != nil {
183185
log.Errorf("Error closing channel %s, "+
184-
"skipping: %v", openChan.ChanPoint, err)
186+
"skipping and trying next one. "+
187+
"Reason: %v", openChan.ChanPoint, err)
185188
continue
186189
}
187190

@@ -262,13 +265,21 @@ func closeChannel(identityPriv *btcec.PrivateKey, api *btc.ExplorerAPI,
262265
if err != nil {
263266
return nil, fmt.Errorf("error getting spends: %w", err)
264267
}
268+
269+
counter := 0
265270
for len(spends) == 0 {
266271
log.Infof("No spends found yet, waiting 5 seconds...")
267272
time.Sleep(5 * time.Second)
268273
spends, err = api.Spends(channelAddress)
269274
if err != nil {
270275
return nil, fmt.Errorf("error getting spends: %w", err)
271276
}
277+
278+
counter++
279+
if counter >= 12 {
280+
return nil, fmt.Errorf("no spends found after 60 " +
281+
"seconds, aborting re-try loop")
282+
}
272283
}
273284

274285
log.Infof("Found force close transaction %v", spends[0].TXID)

0 commit comments

Comments
 (0)