breacharbiter: notify the ChainArbitrator of fresh signals for a channel on startup
This commit is contained in:
2 files changed
+31
-8
No files matched your search
@@ -45,6 +45,14 @@ type BreachConfig struct {
|
|||||||
// a close type to be included in the channel close summary.
|
// a close type to be included in the channel close summary.
|
||||||
CloseLink func(*wire.OutPoint, htlcswitch.ChannelCloseType)
|
CloseLink func(*wire.OutPoint, htlcswitch.ChannelCloseType)
|
||||||
|
|
||||||
|
// UpdateCloseSignal allows the breach arbiter to notify the
|
||||||
|
// ChainArbitrator that a set of new signals for the unilateral closing
|
||||||
|
// of a channel is now available. This ensures that ifa channel hasn't
|
||||||
|
// had any updates since it was live, then we're still able to act on
|
||||||
|
// on-chain events.
|
||||||
|
UpdateCloseSignal func(*wire.OutPoint,
|
||||||
|
chan *lnwallet.UnilateralCloseSummary) error
|
||||||
|
|
||||||
// DB provides access to the user's channels, allowing the breach
|
// DB provides access to the user's channels, allowing the breach
|
||||||
// arbiter to determine the current state of a user's channels, and how
|
// arbiter to determine the current state of a user's channels, and how
|
||||||
// it should respond to channel closure.
|
// it should respond to channel closure.
|
||||||
@@ -306,6 +314,15 @@ func (b *breachArbiter) contractObserver(
|
|||||||
chanPoint := channel.ChanPoint
|
chanPoint := channel.ChanPoint
|
||||||
b.breachObservers[*chanPoint] = settleSignal
|
b.breachObservers[*chanPoint] = settleSignal
|
||||||
|
|
||||||
|
// Before we'll launch our breach observe, we'll send this
|
||||||
|
// latest set of contract signals to the ChainArbitrator.
|
||||||
|
//
|
||||||
|
// TODO(roasbeef): just move now?
|
||||||
|
err := b.cfg.UpdateCloseSignal(chanPoint, channel.UnilateralClose)
|
||||||
|
if err != nil {
|
||||||
|
brarLog.Errorf("unable to update close signals: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
b.wg.Add(1)
|
b.wg.Add(1)
|
||||||
go b.breachObserver(channel, settleSignal)
|
go b.breachObserver(channel, settleSignal)
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-8
@@ -1097,10 +1097,9 @@ func TestBreachHandoffFail(t *testing.T) {
|
|||||||
aliceKeyPriv, _ := btcec.PrivKeyFromBytes(btcec.S256(),
|
aliceKeyPriv, _ := btcec.PrivKeyFromBytes(btcec.S256(),
|
||||||
alicesPrivKey)
|
alicesPrivKey)
|
||||||
aliceSigner := &mockSigner{aliceKeyPriv}
|
aliceSigner := &mockSigner{aliceKeyPriv}
|
||||||
estimator := &lnwallet.StaticFeeEstimator{FeeRate: 50}
|
|
||||||
|
|
||||||
alice2, err := lnwallet.NewLightningChannel(aliceSigner, notifier,
|
alice2, err := lnwallet.NewLightningChannel(aliceSigner, notifier,
|
||||||
estimator, alice.State())
|
nil, alice.State())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unable to create test channels: %v", err)
|
t.Fatalf("unable to create test channels: %v", err)
|
||||||
}
|
}
|
||||||
@@ -1382,16 +1381,23 @@ func createInitChannelsWithNotifier(revocationWindow int,
|
|||||||
Db: dbBob,
|
Db: dbBob,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pCache := &mockPreimageCache{
|
||||||
|
// hash -> preimage
|
||||||
|
preimageMap: make(map[[32]byte][]byte),
|
||||||
|
}
|
||||||
|
|
||||||
aliceSigner := &mockSigner{aliceKeyPriv}
|
aliceSigner := &mockSigner{aliceKeyPriv}
|
||||||
bobSigner := &mockSigner{bobKeyPriv}
|
bobSigner := &mockSigner{bobKeyPriv}
|
||||||
|
|
||||||
channelAlice, err := lnwallet.NewLightningChannel(aliceSigner, notifier,
|
channelAlice, err := lnwallet.NewLightningChannel(
|
||||||
estimator, aliceChannelState)
|
aliceSigner, notifier, pCache, aliceChannelState,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
channelBob, err := lnwallet.NewLightningChannel(bobSigner, notifier,
|
channelBob, err := lnwallet.NewLightningChannel(
|
||||||
estimator, bobChannelState)
|
bobSigner, notifier, pCache, bobChannelState,
|
||||||
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, nil, err
|
return nil, nil, nil, err
|
||||||
}
|
}
|
||||||
@@ -1476,7 +1482,7 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
bobRevocation, err := chanB.RevokeCurrentCommitment()
|
bobRevocation, _, err := chanB.RevokeCurrentCommitment()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1492,7 +1498,7 @@ func forceStateTransition(chanA, chanB *lnwallet.LightningChannel) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
aliceRevocation, err := chanA.RevokeCurrentCommitment()
|
aliceRevocation, _, err := chanA.RevokeCurrentCommitment()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user