mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-08 14:57:38 +02:00
channeldb: save channel status on channel close
Add an optional channel status CloseChannel which will be stored on the hitsorical channel which is persisted at channel close. This status is used to set the close initiator for channels that do not complete the funding flow or we abandon. In follow up commits, this status will be used to record force and breach closes. The value is written to the historical channel bucket for diplay over rpc.
This commit is contained in:
@@ -1357,3 +1357,39 @@ func TestCloseInitiator(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestCloseChannelStatus tests setting of a channel status on the historical
|
||||
// channel on channel close.
|
||||
func TestCloseChannelStatus(t *testing.T) {
|
||||
cdb, cleanUp, err := makeTestDB()
|
||||
if err != nil {
|
||||
t.Fatalf("unable to make test database: %v",
|
||||
err)
|
||||
}
|
||||
defer cleanUp()
|
||||
|
||||
// Create an open channel.
|
||||
channel := createTestChannel(
|
||||
t, cdb, openChannelOption(),
|
||||
)
|
||||
|
||||
if err := channel.CloseChannel(
|
||||
&ChannelCloseSummary{
|
||||
ChanPoint: channel.FundingOutpoint,
|
||||
RemotePub: channel.IdentityPub,
|
||||
}, ChanStatusRemoteCloseInitiator,
|
||||
); err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
histChan, err := channel.Db.FetchHistoricalChannel(
|
||||
&channel.FundingOutpoint,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
|
||||
if !histChan.HasChanStatus(ChanStatusRemoteCloseInitiator) {
|
||||
t.Fatalf("channel should have status")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user