channeldb: add total time locked balance to CloseChannelSummary
This commit adds the total time locked balance of a closed channel at closure time to the CloseChannelSummary struct. With this information, we now provide sub-systems within the daemon further knowledge which can aide them in properly handling querying for the state of pending close transactions, or if they should watch a channel for closure or not.
This commit is contained in:
parent
57f576bbf1
commit
68dbbb046b
@ -699,9 +699,18 @@ type ChannelCloseSummary struct {
|
||||
// Capacity was the total capacity of the channel.
|
||||
Capacity btcutil.Amount
|
||||
|
||||
// OurBalance is our total balance settled balance at the time of
|
||||
// channel closure.
|
||||
OurBalance btcutil.Amount
|
||||
// SettledBalance is our total balance settled balance at the time of
|
||||
// channel closure. This _does not_ include the sum of any outputs that
|
||||
// have been time-locked as a result of the unilateral channel closure.
|
||||
SettledBalance btcutil.Amount
|
||||
|
||||
// TimeLockedBalance is the sum of all the time-locked outputs at the
|
||||
// time of channel closure. If we triggered the force closure of this
|
||||
// channel, then this value will be non-zero if our settled output is
|
||||
// above the dust limit. If we were on the receiving side of a channel
|
||||
// force closure, then this value will be non-zero if we had any
|
||||
// outstanding outgoing HTLC's at the time of channel closure.
|
||||
TimeLockedBalance btcutil.Amount
|
||||
|
||||
// CloseType details exactly _how_ the channel was closed. Three
|
||||
// closure types are possible: cooperative, force, and breach.
|
||||
@ -865,7 +874,10 @@ func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := binary.Write(w, byteOrder, cs.OurBalance); err != nil {
|
||||
if err := binary.Write(w, byteOrder, cs.SettledBalance); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(w, byteOrder, cs.TimeLockedBalance); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := binary.Write(w, byteOrder, cs.Capacity); err != nil {
|
||||
@ -917,7 +929,10 @@ func deserializeCloseChannelSummary(r io.Reader) (*ChannelCloseSummary, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := binary.Read(r, byteOrder, &c.OurBalance); err != nil {
|
||||
if err := binary.Read(r, byteOrder, &c.SettledBalance); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := binary.Read(r, byteOrder, &c.TimeLockedBalance); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := binary.Read(r, byteOrder, &c.Capacity); err != nil {
|
||||
|
@ -373,11 +373,12 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
||||
// written state, and creates a small "summary" elsewhere within the
|
||||
// database.
|
||||
closeSummary := &ChannelCloseSummary{
|
||||
ChanPoint: *state.ChanID,
|
||||
RemotePub: state.IdentityPub,
|
||||
OurBalance: btcutil.Amount(500),
|
||||
IsPending: false,
|
||||
CloseType: CooperativeClose,
|
||||
ChanPoint: *state.ChanID,
|
||||
RemotePub: state.IdentityPub,
|
||||
SettledBalance: btcutil.Amount(500),
|
||||
TimeLockedBalance: btcutil.Amount(10000),
|
||||
IsPending: false,
|
||||
CloseType: CooperativeClose,
|
||||
}
|
||||
if err := state.CloseChannel(closeSummary); err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
@ -605,11 +606,12 @@ func TestChannelStateTransition(t *testing.T) {
|
||||
|
||||
// Now attempt to delete the channel from the database.
|
||||
closeSummary := &ChannelCloseSummary{
|
||||
ChanPoint: *channel.ChanID,
|
||||
RemotePub: channel.IdentityPub,
|
||||
OurBalance: btcutil.Amount(500),
|
||||
IsPending: false,
|
||||
CloseType: ForceClose,
|
||||
ChanPoint: *channel.ChanID,
|
||||
RemotePub: channel.IdentityPub,
|
||||
SettledBalance: btcutil.Amount(500),
|
||||
TimeLockedBalance: btcutil.Amount(10000),
|
||||
IsPending: false,
|
||||
CloseType: ForceClose,
|
||||
}
|
||||
if err := updatedChannel[0].CloseChannel(closeSummary); err != nil {
|
||||
t.Fatalf("unable to delete updated channel: %v", err)
|
||||
@ -728,13 +730,14 @@ func TestFetchClosedChannels(t *testing.T) {
|
||||
// Next, close the channel by including a close channel summary in the
|
||||
// database.
|
||||
summary := &ChannelCloseSummary{
|
||||
ChanPoint: *state.ChanID,
|
||||
ClosingTXID: rev,
|
||||
RemotePub: state.IdentityPub,
|
||||
Capacity: state.Capacity,
|
||||
OurBalance: state.OurBalance,
|
||||
CloseType: ForceClose,
|
||||
IsPending: true,
|
||||
ChanPoint: *state.ChanID,
|
||||
ClosingTXID: rev,
|
||||
RemotePub: state.IdentityPub,
|
||||
Capacity: state.Capacity,
|
||||
SettledBalance: state.OurBalance,
|
||||
TimeLockedBalance: state.OurBalance + 10000,
|
||||
CloseType: ForceClose,
|
||||
IsPending: true,
|
||||
}
|
||||
if err := state.CloseChannel(summary); err != nil {
|
||||
t.Fatalf("unable to close channel: %v", err)
|
||||
|
Loading…
Reference in New Issue
Block a user