mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-01-19 05:45:21 +01:00
breacharbiter: extract countRevokedFunds
This commit is contained in:
parent
ba5aaec632
commit
bca5839929
@ -641,22 +641,7 @@ justiceTxBroadcast:
|
|||||||
|
|
||||||
// Compute both the total value of funds being swept and the
|
// Compute both the total value of funds being swept and the
|
||||||
// amount of funds that were revoked from the counter party.
|
// amount of funds that were revoked from the counter party.
|
||||||
var totalFunds, revokedFunds btcutil.Amount
|
totalFunds, revokedFunds := countRevokedFunds(breachInfo, finalTx)
|
||||||
for _, inp := range breachInfo.breachedOutputs {
|
|
||||||
totalFunds += inp.Amount()
|
|
||||||
|
|
||||||
// If the output being revoked is the remote commitment
|
|
||||||
// output or an offered HTLC output, it's amount
|
|
||||||
// contributes to the value of funds being revoked from
|
|
||||||
// the counter party.
|
|
||||||
switch inp.WitnessType() {
|
|
||||||
case input.CommitmentRevoke:
|
|
||||||
revokedFunds += inp.Amount()
|
|
||||||
case input.HtlcOfferedRevoke:
|
|
||||||
revokedFunds += inp.Amount()
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
brarLog.Infof("Justice for ChannelPoint(%v) has "+
|
brarLog.Infof("Justice for ChannelPoint(%v) has "+
|
||||||
"been served, %v revoked funds (%v total) "+
|
"been served, %v revoked funds (%v total) "+
|
||||||
@ -674,13 +659,53 @@ justiceTxBroadcast:
|
|||||||
|
|
||||||
// TODO(roasbeef): close other active channels with offending
|
// TODO(roasbeef): close other active channels with offending
|
||||||
// peer
|
// peer
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
case <-b.quit:
|
case <-b.quit:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// countRevokedFunds counts the total and revoked funds swept by our justice
|
||||||
|
// TX.
|
||||||
|
func countRevokedFunds(breachInfo *retributionInfo,
|
||||||
|
spendTx *wire.MsgTx) (btcutil.Amount, btcutil.Amount) {
|
||||||
|
|
||||||
|
// Compute both the total value of funds being swept and the
|
||||||
|
// amount of funds that were revoked from the counter party.
|
||||||
|
var totalFunds, revokedFunds btcutil.Amount
|
||||||
|
for _, txIn := range spendTx.TxIn {
|
||||||
|
op := txIn.PreviousOutPoint
|
||||||
|
|
||||||
|
// Find the corresponding output in our retribution info.
|
||||||
|
for _, inp := range breachInfo.breachedOutputs {
|
||||||
|
// If the spent outpoint is not among the ouputs that
|
||||||
|
// were breached, we can ignore it.
|
||||||
|
if inp.outpoint != op {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
totalFunds += inp.Amount()
|
||||||
|
|
||||||
|
// If the output being revoked is the remote commitment
|
||||||
|
// output or an offered HTLC output, it's amount
|
||||||
|
// contributes to the value of funds being revoked from
|
||||||
|
// the counter party.
|
||||||
|
switch inp.WitnessType() {
|
||||||
|
case input.CommitmentRevoke:
|
||||||
|
revokedFunds += inp.Amount()
|
||||||
|
case input.HtlcOfferedRevoke:
|
||||||
|
revokedFunds += inp.Amount()
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return totalFunds, revokedFunds
|
||||||
|
}
|
||||||
|
|
||||||
// cleanupBreach marks the given channel point as fully resolved and removes the
|
// cleanupBreach marks the given channel point as fully resolved and removes the
|
||||||
// retribution for that the channel from the retribution store.
|
// retribution for that the channel from the retribution store.
|
||||||
func (b *breachArbiter) cleanupBreach(chanPoint *wire.OutPoint) error {
|
func (b *breachArbiter) cleanupBreach(chanPoint *wire.OutPoint) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user