mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-05 12:39:54 +02:00
server: reliably hand off breach from the ChainArbitrator to the breachArb
This commit make the server populate the ChainArbitrator's ContractBreach method, by a method that will reliably handoff the breach event ot the breachArbiter. The server will now forward the breach event to the breachArbiter, and only let the closure return a non-nil error when the breachArbiter ACKs this event.
This commit is contained in:
parent
08f1a3689d
commit
e9eab3f79f
38
server.go
38
server.go
@ -396,6 +396,10 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
s.htlcSwitch.CloseLink(chanPoint, closureType, 0)
|
s.htlcSwitch.CloseLink(chanPoint, closureType, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We will use the following channel to reliably hand off contract
|
||||||
|
// breach events from the ChannelArbitrator to the breachArbiter,
|
||||||
|
contractBreaches := make(chan *ContractBreachEvent, 1)
|
||||||
|
|
||||||
s.chainArb = contractcourt.NewChainArbitrator(contractcourt.ChainArbitratorConfig{
|
s.chainArb = contractcourt.NewChainArbitrator(contractcourt.ChainArbitratorConfig{
|
||||||
ChainHash: *activeNetParams.GenesisHash,
|
ChainHash: *activeNetParams.GenesisHash,
|
||||||
// TODO(roasbeef): properly configure
|
// TODO(roasbeef): properly configure
|
||||||
@ -447,6 +451,29 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
_, err := cc.wallet.GetPrivKey(addr)
|
_, err := cc.wallet.GetPrivKey(addr)
|
||||||
return err == nil
|
return err == nil
|
||||||
},
|
},
|
||||||
|
ContractBreach: func(chanPoint wire.OutPoint,
|
||||||
|
breachRet *lnwallet.BreachRetribution) error {
|
||||||
|
event := &ContractBreachEvent{
|
||||||
|
ChanPoint: chanPoint,
|
||||||
|
ProcessACK: make(chan error, 1),
|
||||||
|
BreachRetribution: breachRet,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the contract breach event to the breachArbiter.
|
||||||
|
select {
|
||||||
|
case contractBreaches <- event:
|
||||||
|
case <-s.quit:
|
||||||
|
return ErrServerShuttingDown
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait for the breachArbiter to ACK the event.
|
||||||
|
select {
|
||||||
|
case err := <-event.ProcessACK:
|
||||||
|
return err
|
||||||
|
case <-s.quit:
|
||||||
|
return ErrServerShuttingDown
|
||||||
|
}
|
||||||
|
},
|
||||||
}, chanDB)
|
}, chanDB)
|
||||||
|
|
||||||
s.breachArbiter = newBreachArbiter(&BreachConfig{
|
s.breachArbiter = newBreachArbiter(&BreachConfig{
|
||||||
@ -458,14 +485,9 @@ func newServer(listenAddrs []string, chanDB *channeldb.DB, cc *chainControl,
|
|||||||
},
|
},
|
||||||
Notifier: cc.chainNotifier,
|
Notifier: cc.chainNotifier,
|
||||||
PublishTransaction: cc.wallet.PublishTransaction,
|
PublishTransaction: cc.wallet.PublishTransaction,
|
||||||
SubscribeChannelEvents: func(chanPoint wire.OutPoint) (*contractcourt.ChainEventSubscription, error) {
|
ContractBreaches: contractBreaches,
|
||||||
// We'll request a sync dispatch to ensure that the channel
|
Signer: cc.wallet.Cfg.Signer,
|
||||||
// is only marked as closed *after* we update our internal
|
Store: newRetributionStore(chanDB),
|
||||||
// state.
|
|
||||||
return s.chainArb.SubscribeChannelEvents(chanPoint, true)
|
|
||||||
},
|
|
||||||
Signer: cc.wallet.Cfg.Signer,
|
|
||||||
Store: newRetributionStore(chanDB),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create the connection manager which will be responsible for
|
// Create the connection manager which will be responsible for
|
||||||
|
Loading…
x
Reference in New Issue
Block a user