Skip to content

Commit b8cb81a

Browse files
authored
Merge pull request #184 from lightninglabs/match-node-id
zombierecovery: match against ancient channel list
2 parents 9301539 + c15cf58 commit b8cb81a

File tree

5 files changed

+5573
-2771
lines changed

5 files changed

+5573
-2771
lines changed

cmd/chantools/summary.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,24 @@ func summarizeAncientChannels(apiURL string,
120120

121121
api := newExplorerAPI(apiURL)
122122

123+
results, err := ancientChannelCandidates(api, channels)
124+
if err != nil {
125+
return fmt.Errorf("error finding ancient channels: %w", err)
126+
}
127+
128+
summaryBytes, err := json.MarshalIndent(results, "", " ")
129+
if err != nil {
130+
return err
131+
}
132+
fileName := fmt.Sprintf("results/summary-ancient-%s.json",
133+
time.Now().Format("2006-01-02-15-04-05"))
134+
log.Infof("Writing result to %s", fileName)
135+
return os.WriteFile(fileName, summaryBytes, 0644)
136+
}
137+
138+
func ancientChannelCandidates(api *btc.ExplorerAPI,
139+
channels []*dataformat.SummaryEntry) ([]*ancientChannel, error) {
140+
123141
var results []*ancientChannel
124142
for _, target := range channels {
125143
if target.ClosingTX == nil {
@@ -155,8 +173,9 @@ func summarizeAncientChannels(apiURL string,
155173

156174
addr, err := lnd.ParseAddress(closeTx.ToRemoteAddr, chainParams)
157175
if err != nil {
158-
return fmt.Errorf("error parsing address %s of %s: %w",
159-
closeTx.ToRemoteAddr, closeTx.TXID, err)
176+
return nil, fmt.Errorf("error parsing address %s of "+
177+
"%s: %w", closeTx.ToRemoteAddr, closeTx.TXID,
178+
err)
160179
}
161180

162181
if _, ok := addr.(*btcutil.AddressWitnessPubKeyHash); !ok {
@@ -167,8 +186,8 @@ func summarizeAncientChannels(apiURL string,
167186

168187
tx, err := api.Transaction(closeTx.TXID)
169188
if err != nil {
170-
return fmt.Errorf("error fetching transaction %s: %w",
171-
closeTx.TXID, err)
189+
return nil, fmt.Errorf("error fetching transaction "+
190+
"%s: %w", closeTx.TXID, err)
172191
}
173192

174193
for idx, txOut := range tx.Vout {
@@ -182,19 +201,13 @@ func summarizeAncientChannels(apiURL string,
182201
idx),
183202
Addr: closeTx.ToRemoteAddr,
184203
CP: target.LocalUnrevokedCommitPoint,
204+
Node: target.RemotePubkey,
185205
})
186206
}
187207
}
188208
}
189209

190-
summaryBytes, err := json.MarshalIndent(results, "", " ")
191-
if err != nil {
192-
return err
193-
}
194-
fileName := fmt.Sprintf("results/summary-ancient-%s.json",
195-
time.Now().Format("2006-01-02-15-04-05"))
196-
log.Infof("Writing result to %s", fileName)
197-
return os.WriteFile(fileName, summaryBytes, 0644)
210+
return results, nil
198211
}
199212

200213
func summarizeAncientChannelOutputs(apiURL, ancientFile string) error {

cmd/chantools/sweepremoteclosed.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ type ancientChannel struct {
462462
OP string `json:"close_outpoint"`
463463
Addr string `json:"close_addr"`
464464
CP string `json:"commit_point"`
465+
Node string `json:"node"`
465466
}
466467

467468
func findAncientChannels(channels []ancientChannel, numKeys uint32,

0 commit comments

Comments
 (0)