Merge pull request #930 from halseth/breacharbiter-broadcast-loop
breacharbiter: reuse spend events instead of re-registering
This commit is contained in:
commit
2b00e01c53
@ -490,6 +490,8 @@ func (b *breachArbiter) exactRetribution(confChan *chainntnfs.ConfirmationEvent,
|
|||||||
// construct a sweep transaction and write it to disk. This will allow
|
// construct a sweep transaction and write it to disk. This will allow
|
||||||
// the breach arbiter to re-register for notifications for the justice
|
// the breach arbiter to re-register for notifications for the justice
|
||||||
// txid.
|
// txid.
|
||||||
|
spendNtfns := make(map[wire.OutPoint]*chainntnfs.SpendEvent)
|
||||||
|
|
||||||
secondLevelCheck:
|
secondLevelCheck:
|
||||||
if finalTx == nil {
|
if finalTx == nil {
|
||||||
// Before we create the justice tx, we need to check to see if
|
// Before we create the justice tx, we need to check to see if
|
||||||
@ -510,24 +512,32 @@ secondLevelCheck:
|
|||||||
breachedOutput.outpoint, breachInfo.chanPoint)
|
breachedOutput.outpoint, breachInfo.chanPoint)
|
||||||
|
|
||||||
// Now that we have an HTLC output, we'll quickly check
|
// Now that we have an HTLC output, we'll quickly check
|
||||||
// to see if it has been spent or not.
|
// to see if it has been spent or not. If we have
|
||||||
spendNtfn, err := b.cfg.Notifier.RegisterSpendNtfn(
|
// already registered for a notification for this
|
||||||
&breachedOutput.outpoint, breachInfo.breachHeight,
|
// output, we'll reuse it.
|
||||||
)
|
spendNtfn, ok := spendNtfns[breachedOutput.outpoint]
|
||||||
if err != nil {
|
if !ok {
|
||||||
brarLog.Errorf("unable to check for spentness "+
|
spendNtfn, err = b.cfg.Notifier.RegisterSpendNtfn(
|
||||||
"of out_point=%v: %v",
|
&breachedOutput.outpoint,
|
||||||
breachedOutput.outpoint, err)
|
breachInfo.breachHeight,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
brarLog.Errorf("unable to check for "+
|
||||||
|
"spentness of out_point=%v: %v",
|
||||||
|
breachedOutput.outpoint, err)
|
||||||
|
|
||||||
// Registration may have failed if we've been
|
// Registration may have failed if
|
||||||
// instructed to shutdown. If so, return here to
|
// we've been instructed to shutdown.
|
||||||
// avoid entering an infinite loop.
|
// If so, return here to avoid entering
|
||||||
select {
|
// an infinite loop.
|
||||||
case <-b.quit:
|
select {
|
||||||
return
|
case <-b.quit:
|
||||||
default:
|
return
|
||||||
continue
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
spendNtfns[breachedOutput.outpoint] = spendNtfn
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
@ -536,6 +546,7 @@ secondLevelCheck:
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
delete(spendNtfns, breachedOutput.outpoint)
|
||||||
|
|
||||||
// In this case we'll morph our initial revoke
|
// In this case we'll morph our initial revoke
|
||||||
// spend to instead point to the second level
|
// spend to instead point to the second level
|
||||||
|
Loading…
Reference in New Issue
Block a user