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,18 +512,24 @@ 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 !ok {
|
||||||
|
spendNtfn, err = b.cfg.Notifier.RegisterSpendNtfn(
|
||||||
|
&breachedOutput.outpoint,
|
||||||
|
breachInfo.breachHeight,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
brarLog.Errorf("unable to check for spentness "+
|
brarLog.Errorf("unable to check for "+
|
||||||
"of out_point=%v: %v",
|
"spentness of out_point=%v: %v",
|
||||||
breachedOutput.outpoint, err)
|
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
|
||||||
|
// an infinite loop.
|
||||||
select {
|
select {
|
||||||
case <-b.quit:
|
case <-b.quit:
|
||||||
return
|
return
|
||||||
@ -529,6 +537,8 @@ secondLevelCheck:
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
spendNtfns[breachedOutput.outpoint] = spendNtfn
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
// The output has been taken to the second level!
|
// The output has been taken to the second level!
|
||||||
@ -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