mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-28 09:45:25 +02:00
lnwallet/chancloser: add state transitions for new protofsm rbf closer
In this commit, we add the state transitions for the new protofsm based RBF chan closer. The underlying protocol is a new asymmetric co-op close process, wherein either side can initiate a chan closer, and use their settled funds to pay for fees within the channel.
This commit is contained in:
parent
f6525c9e7d
commit
e47a632745
@ -539,8 +539,8 @@ func (c *ChanCloser) AuxOutputs() fn.Option[AuxCloseOutputs] {
|
|||||||
// upfront script is set, we check whether it matches the script provided by
|
// upfront script is set, we check whether it matches the script provided by
|
||||||
// our peer. If they do not match, we use the disconnect function provided to
|
// our peer. If they do not match, we use the disconnect function provided to
|
||||||
// disconnect from the peer.
|
// disconnect from the peer.
|
||||||
func validateShutdownScript(disconnect func() error, upfrontScript,
|
func validateShutdownScript(upfrontScript, peerScript lnwire.DeliveryAddress,
|
||||||
peerScript lnwire.DeliveryAddress, netParams *chaincfg.Params) error {
|
netParams *chaincfg.Params) error {
|
||||||
|
|
||||||
// Either way, we'll make sure that the script passed meets our
|
// Either way, we'll make sure that the script passed meets our
|
||||||
// standards. The upfrontScript should have already been checked at an
|
// standards. The upfrontScript should have already been checked at an
|
||||||
@ -568,12 +568,6 @@ func validateShutdownScript(disconnect func() error, upfrontScript,
|
|||||||
chancloserLog.Warnf("peer's script: %x does not match upfront "+
|
chancloserLog.Warnf("peer's script: %x does not match upfront "+
|
||||||
"shutdown script: %x", peerScript, upfrontScript)
|
"shutdown script: %x", peerScript, upfrontScript)
|
||||||
|
|
||||||
// Disconnect from the peer because they have violated option upfront
|
|
||||||
// shutdown.
|
|
||||||
if err := disconnect(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrUpfrontShutdownScriptMismatch
|
return ErrUpfrontShutdownScriptMismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -630,7 +624,6 @@ func (c *ChanCloser) ReceiveShutdown(msg lnwire.Shutdown) (
|
|||||||
// If the remote node opened the channel with option upfront
|
// If the remote node opened the channel with option upfront
|
||||||
// shutdown script, check that the script they provided matches.
|
// shutdown script, check that the script they provided matches.
|
||||||
if err := validateShutdownScript(
|
if err := validateShutdownScript(
|
||||||
c.cfg.Disconnect,
|
|
||||||
c.cfg.Channel.RemoteUpfrontShutdownScript(),
|
c.cfg.Channel.RemoteUpfrontShutdownScript(),
|
||||||
msg.Address, c.cfg.ChainParams,
|
msg.Address, c.cfg.ChainParams,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
@ -681,7 +674,6 @@ func (c *ChanCloser) ReceiveShutdown(msg lnwire.Shutdown) (
|
|||||||
// If the remote node opened the channel with option upfront
|
// If the remote node opened the channel with option upfront
|
||||||
// shutdown script, check that the script they provided matches.
|
// shutdown script, check that the script they provided matches.
|
||||||
if err := validateShutdownScript(
|
if err := validateShutdownScript(
|
||||||
c.cfg.Disconnect,
|
|
||||||
c.cfg.Channel.RemoteUpfrontShutdownScript(),
|
c.cfg.Channel.RemoteUpfrontShutdownScript(),
|
||||||
msg.Address, c.cfg.ChainParams,
|
msg.Address, c.cfg.ChainParams,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
|
@ -129,8 +129,8 @@ func TestMaybeMatchScript(t *testing.T) {
|
|||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
err := validateShutdownScript(
|
err := validateShutdownScript(
|
||||||
func() error { return nil }, test.upfrontScript,
|
test.upfrontScript, test.shutdownScript,
|
||||||
test.shutdownScript, &chaincfg.SimNetParams,
|
&chaincfg.SimNetParams,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != test.expectedErr {
|
if err != test.expectedErr {
|
||||||
|
@ -250,6 +250,11 @@ type ChanStateObserver interface {
|
|||||||
// new outgoing add messages.
|
// new outgoing add messages.
|
||||||
DisableOutgoingAdds() error
|
DisableOutgoingAdds() error
|
||||||
|
|
||||||
|
// DisableChannel attempts to disable a channel (marking it ineligible
|
||||||
|
// to forward), and also sends out a network update to disable the
|
||||||
|
// channel.
|
||||||
|
DisableChannel() error
|
||||||
|
|
||||||
// MarkCoopBroadcasted persistently marks that the channel close
|
// MarkCoopBroadcasted persistently marks that the channel close
|
||||||
// transaction has been broadcast.
|
// transaction has been broadcast.
|
||||||
MarkCoopBroadcasted(*wire.MsgTx, bool) error
|
MarkCoopBroadcasted(*wire.MsgTx, bool) error
|
||||||
|
1048
lnwallet/chancloser/rbf_coop_transitions.go
Normal file
1048
lnwallet/chancloser/rbf_coop_transitions.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user