mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-24 18:50:02 +02:00
multi: make MarkCommitmentBroadcasted take closeTx
This commit is contained in:
parent
a810092e53
commit
02b2787e44
@ -444,7 +444,9 @@ func (c *channelCloser) ProcessCloseMsg(msg lnwire.Message) ([]lnwire.Message, b
|
|||||||
if err := c.cfg.broadcastTx(closeTx); err != nil {
|
if err := c.cfg.broadcastTx(closeTx); err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if err := c.cfg.channel.MarkCommitmentBroadcasted(); err != nil {
|
|
||||||
|
err = c.cfg.channel.MarkCommitmentBroadcasted(closeTx)
|
||||||
|
if err != nil {
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,6 +59,10 @@ var (
|
|||||||
// remote peer during a channel sync in case we have lost channel state.
|
// remote peer during a channel sync in case we have lost channel state.
|
||||||
dataLossCommitPointKey = []byte("data-loss-commit-point-key")
|
dataLossCommitPointKey = []byte("data-loss-commit-point-key")
|
||||||
|
|
||||||
|
// closingTxKey points to a the closing tx that we broadcasted when
|
||||||
|
// moving the channel to state CommitBroadcasted.
|
||||||
|
closingTxKey = []byte("closing-tx-key")
|
||||||
|
|
||||||
// commitDiffKey stores the current pending commitment state we've
|
// commitDiffKey stores the current pending commitment state we've
|
||||||
// extended to the remote party (if any). Each time we propose a new
|
// extended to the remote party (if any). Each time we propose a new
|
||||||
// state, we store the information necessary to reconstruct this state
|
// state, we store the information necessary to reconstruct this state
|
||||||
@ -878,12 +882,24 @@ func (c *OpenChannel) isBorked(chanBucket *bbolt.Bucket) (bool, error) {
|
|||||||
|
|
||||||
// MarkCommitmentBroadcasted marks the channel as a commitment transaction has
|
// MarkCommitmentBroadcasted marks the channel as a commitment transaction has
|
||||||
// been broadcast, either our own or the remote, and we should watch the chain
|
// been broadcast, either our own or the remote, and we should watch the chain
|
||||||
// for it to confirm before taking any further action.
|
// for it to confirm before taking any further action. It takes as argument the
|
||||||
func (c *OpenChannel) MarkCommitmentBroadcasted() error {
|
// closing tx _we believe_ will appear in the chain. This is only used to
|
||||||
|
// republish this tx at startup to ensure propagation, and we should still
|
||||||
|
// handle the case where a different tx actually hits the chain.
|
||||||
|
func (c *OpenChannel) MarkCommitmentBroadcasted(closeTx *wire.MsgTx) error {
|
||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
|
|
||||||
return c.putChanStatus(ChanStatusCommitBroadcasted)
|
var b bytes.Buffer
|
||||||
|
if err := WriteElement(&b, closeTx); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
putClosingTx := func(chanBucket *bbolt.Bucket) error {
|
||||||
|
return chanBucket.Put(closingTxKey, b.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.putChanStatus(ChanStatusCommitBroadcasted, putClosingTx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// putChanStatus appends the given status to the channel. fs is an optional
|
// putChanStatus appends the given status to the channel. fs is an optional
|
||||||
|
@ -891,7 +891,8 @@ func TestFetchWaitingCloseChannels(t *testing.T) {
|
|||||||
// This would happen in the event of a force close and should make the
|
// This would happen in the event of a force close and should make the
|
||||||
// channels enter a state of waiting close.
|
// channels enter a state of waiting close.
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
if err := channel.MarkCommitmentBroadcasted(); err != nil {
|
closeTx := &wire.MsgTx{}
|
||||||
|
if err := channel.MarkCommitmentBroadcasted(closeTx); err != nil {
|
||||||
t.Fatalf("unable to mark commitment broadcast: %v", err)
|
t.Fatalf("unable to mark commitment broadcast: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ type ChannelArbitratorConfig struct {
|
|||||||
|
|
||||||
// MarkCommitmentBroadcasted should mark the channel as the commitment
|
// MarkCommitmentBroadcasted should mark the channel as the commitment
|
||||||
// being broadcast, and we are waiting for the commitment to confirm.
|
// being broadcast, and we are waiting for the commitment to confirm.
|
||||||
MarkCommitmentBroadcasted func() error
|
MarkCommitmentBroadcasted func(*wire.MsgTx) error
|
||||||
|
|
||||||
// MarkChannelClosed marks the channel closed in the database, with the
|
// MarkChannelClosed marks the channel closed in the database, with the
|
||||||
// passed close summary. After this method successfully returns we can
|
// passed close summary. After this method successfully returns we can
|
||||||
@ -840,7 +840,7 @@ func (c *ChannelArbitrator) stateStep(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.cfg.MarkCommitmentBroadcasted(); err != nil {
|
if err := c.cfg.MarkCommitmentBroadcasted(closeTx); err != nil {
|
||||||
log.Errorf("ChannelArbitrator(%v): unable to "+
|
log.Errorf("ChannelArbitrator(%v): unable to "+
|
||||||
"mark commitment broadcasted: %v",
|
"mark commitment broadcasted: %v",
|
||||||
c.cfg.ChanPoint, err)
|
c.cfg.ChanPoint, err)
|
||||||
|
@ -213,7 +213,7 @@ func createTestChannelArbitrator(log ArbitratorLog) (*ChannelArbitrator,
|
|||||||
}
|
}
|
||||||
return summary, nil
|
return summary, nil
|
||||||
},
|
},
|
||||||
MarkCommitmentBroadcasted: func() error {
|
MarkCommitmentBroadcasted: func(_ *wire.MsgTx) error {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
MarkChannelClosed: func(*channeldb.ChannelCloseSummary) error {
|
MarkChannelClosed: func(*channeldb.ChannelCloseSummary) error {
|
||||||
|
@ -6259,11 +6259,11 @@ func (lc *LightningChannel) State() *channeldb.OpenChannel {
|
|||||||
// MarkCommitmentBroadcasted marks the channel as a commitment transaction has
|
// MarkCommitmentBroadcasted marks the channel as a commitment transaction has
|
||||||
// been broadcast, either our own or the remote, and we should watch the chain
|
// been broadcast, either our own or the remote, and we should watch the chain
|
||||||
// for it to confirm before taking any further action.
|
// for it to confirm before taking any further action.
|
||||||
func (lc *LightningChannel) MarkCommitmentBroadcasted() error {
|
func (lc *LightningChannel) MarkCommitmentBroadcasted(tx *wire.MsgTx) error {
|
||||||
lc.Lock()
|
lc.Lock()
|
||||||
defer lc.Unlock()
|
defer lc.Unlock()
|
||||||
|
|
||||||
return lc.channelState.MarkCommitmentBroadcasted()
|
return lc.channelState.MarkCommitmentBroadcasted(tx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ActiveHtlcs returns a slice of HTLC's which are currently active on *both*
|
// ActiveHtlcs returns a slice of HTLC's which are currently active on *both*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user