channeldb+lnwallet: add ShutdownInfo with read and write methods

ShutdownInfo contains any info about a previous Shutdown message that we
have sent. This commit adds this type along with read and write methods
for it in the channel db. The existence of the ShutdownInfo on disk
represents the fact that we have previously sent the Shutdown message
and hence that we should resend it on re-establish.
This commit is contained in:
Elle Mouton
2024-02-06 15:56:27 +02:00
parent 987604effb
commit dc25b425c0
5 changed files with 225 additions and 0 deletions

View File

@@ -154,6 +154,10 @@ func (m *mockChannel) MarkCoopBroadcasted(*wire.MsgTx, bool) error {
return nil
}
func (m *mockChannel) MarkShutdownSent(*channeldb.ShutdownInfo) error {
return nil
}
func (m *mockChannel) IsInitiator() bool {
return m.initiator
}

View File

@@ -35,6 +35,11 @@ type Channel interface { //nolint:interfacebloat
// transaction has been broadcast.
MarkCoopBroadcasted(*wire.MsgTx, bool) error
// MarkShutdownSent persists the given ShutdownInfo. The existence of
// the ShutdownInfo represents the fact that the Shutdown message has
// been sent by us and so should be re-sent on re-establish.
MarkShutdownSent(info *channeldb.ShutdownInfo) error
// IsInitiator returns true we are the initiator of the channel.
IsInitiator() bool

View File

@@ -8823,6 +8823,18 @@ func (lc *LightningChannel) MarkCoopBroadcasted(tx *wire.MsgTx,
return lc.channelState.MarkCoopBroadcasted(tx, localInitiated)
}
// MarkShutdownSent persists the given ShutdownInfo. The existence of the
// ShutdownInfo represents the fact that the Shutdown message has been sent by
// us and so should be re-sent on re-establish.
func (lc *LightningChannel) MarkShutdownSent(
info *channeldb.ShutdownInfo) error {
lc.Lock()
defer lc.Unlock()
return lc.channelState.MarkShutdownSent(info)
}
// MarkDataLoss marks sets the channel status to LocalDataLoss and stores the
// passed commitPoint for use to retrieve funds in case the remote force closes
// the channel.