Skip to content

Commit 6154219

Browse files
committed
staticaddr: use tx hash not *wire.MsgTx as a key
Do not rely on GetActiveDepositsInState reusing the same *wire.MsgTx pointer for a unique transaction.
1 parent 38aaa4d commit 6154219

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

staticaddr/withdraw/manager.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,18 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
227227
}
228228

229229
// Group the deposits by their finalized withdrawal transaction.
230-
depositsByWithdrawalTx := make(map[*wire.MsgTx][]*deposit.Deposit)
230+
depositsByWithdrawalTx := make(map[chainhash.Hash][]*deposit.Deposit)
231+
hash2tx := make(map[chainhash.Hash]*wire.MsgTx)
231232
for _, d := range activeDeposits {
232233
withdrawalTx := d.FinalizedWithdrawalTx
233234
if withdrawalTx == nil {
234235
continue
235236
}
237+
txid := withdrawalTx.TxHash()
238+
hash2tx[txid] = withdrawalTx
236239

237-
depositsByWithdrawalTx[withdrawalTx] = append(
238-
depositsByWithdrawalTx[withdrawalTx], d,
240+
depositsByWithdrawalTx[txid] = append(
241+
depositsByWithdrawalTx[txid], d,
239242
)
240243
}
241244

@@ -244,7 +247,7 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
244247
eg := &errgroup.Group{}
245248

246249
// We can now reinstate each cluster of deposits for a withdrawal.
247-
for tx, deposits := range depositsByWithdrawalTx {
250+
for txid, deposits := range depositsByWithdrawalTx {
248251
eg.Go(func() error {
249252
err := m.cfg.DepositManager.TransitionDeposits(
250253
ctx, deposits, deposit.OnWithdrawInitiated,
@@ -254,6 +257,11 @@ func (m *Manager) recoverWithdrawals(ctx context.Context) error {
254257
return err
255258
}
256259

260+
tx, ok := hash2tx[txid]
261+
if !ok {
262+
return fmt.Errorf("can't find tx %v", txid)
263+
}
264+
257265
_, err = m.publishFinalizedWithdrawalTx(ctx, tx)
258266
if err != nil {
259267
return err

0 commit comments

Comments
 (0)