breacharbiter: introduce new sub-system to watch for breaches
This commit introduces a new sub-system into the daemon whose job it is to vigilantly watch for any potential channel breaches throughout the up-time of the daemon. The logic which was moved from the utxoNursery in a prior commit now resides within the breachArbiter. Upon start-up the breachArbiter will query the database for all active channels, launching a goroutine for each channel in order to be able to take action if a channel breach is detected. The breachArbiter is also responsible for notifying the htlcSwitch about channel breaches in order to black-list the breached linked during any multi-hop forwarding decisions.
This commit is contained in:
10 files changed
+593
-43
No files matched your search
+9
-4
@@ -467,7 +467,7 @@ func NewLightningChannel(signer Signer, bio BlockChainIO,
|
||||
FundingWitnessScript: state.FundingWitnessScript,
|
||||
ForceCloseSignal: make(chan struct{}),
|
||||
UnilateralCloseSignal: make(chan struct{}),
|
||||
ContractBreach: make(chan *BreachRetribution),
|
||||
ContractBreach: make(chan *BreachRetribution, 1),
|
||||
}
|
||||
|
||||
// Initialize both of our chains the current un-revoked commitment for
|
||||
@@ -692,6 +692,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
||||
lc.Lock()
|
||||
defer lc.Unlock()
|
||||
|
||||
// TODO(roasbeef): logs duplicated due to breachArbiter...
|
||||
walletLog.Warnf("Unprompted commitment broadcast for ChannelPoint(%v) "+
|
||||
"detected!", lc.channelState.ChanID)
|
||||
|
||||
@@ -704,7 +705,11 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
||||
obsfucator := lc.channelState.StateHintObsfucator
|
||||
broadcastStateNum := uint64(GetStateNumHint(commitTxBroadcast, obsfucator))
|
||||
|
||||
currentStateNum := lc.remoteCommitChain.tail().height
|
||||
currentStateNum, err := lc.channelState.CommitmentHeight()
|
||||
if err != nil {
|
||||
walletLog.Errorf("unable to obtain commitment height: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
// If state number spending transaction matches the current latest
|
||||
@@ -713,7 +718,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
||||
// necessary.
|
||||
case broadcastStateNum == currentStateNum:
|
||||
walletLog.Infof("Unilateral close of ChannelPoint(%v) "+
|
||||
"detected: %v", lc.channelState.ChanID)
|
||||
"detected", lc.channelState.ChanID)
|
||||
close(lc.UnilateralCloseSignal)
|
||||
|
||||
// If the state number broadcast is lower than the remote node's
|
||||
@@ -736,7 +741,7 @@ func (lc *LightningChannel) closeObserver(channelCloseNtfn *chainntnfs.SpendEven
|
||||
return
|
||||
}
|
||||
|
||||
walletLog.Infof("Punishment breach retribution created: %#v",
|
||||
walletLog.Debugf("Punishment breach retribution created: %#v",
|
||||
retribution)
|
||||
|
||||
// Finally, send the retribution struct over the contract beach
|
||||
|
||||
+3
-4
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
WitnessFactor = blockchain.WitnessScaleFactor
|
||||
WitnessFactor = blockchain.WitnessScaleFactor
|
||||
MaxTransactionWeightPolicy = blockchain.MaxBlockCost / 10
|
||||
|
||||
// The weight(cost), which is different from the !size! (see BIP-141),
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
// - WitnessScriptSHA256: 32 bytes
|
||||
P2WSHSize = 1 + 1 + 32
|
||||
|
||||
// P2PKH: 22 bytes
|
||||
// P2WPKH: 22 bytes
|
||||
// - OP_0: 1 byte
|
||||
// - OP_DATA: 1 byte (PublicKeyHASH160 length)
|
||||
// - PublicKeyHASH160: 20 bytes
|
||||
@@ -117,7 +117,6 @@ const (
|
||||
MaxHTLCNumber = 1253
|
||||
)
|
||||
|
||||
|
||||
// estimateCommitTxCost estimate commitment transaction cost depending on the
|
||||
// precalculated cost of base transaction, witness data, which is needed for
|
||||
// paying for funding tx, and htlc cost multiplied by their count.
|
||||
@@ -133,4 +132,4 @@ func estimateCommitTxCost(count int, prediction bool) int64 {
|
||||
witnessCost := int64(WitnessCommitmentTxCost)
|
||||
|
||||
return htlcCost + baseCost + witnessCost
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user