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 was the total capacity of the channel.
|
||||||
Capacity btcutil.Amount
|
Capacity btcutil.Amount
|
||||||
|
|
||||||
// OurBalance is our total balance settled balance at the time of
|
// SettledBalance is our total balance settled balance at the time of
|
||||||
// channel closure.
|
// channel closure. This _does not_ include the sum of any outputs that
|
||||||
OurBalance btcutil.Amount
|
// 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
|
// CloseType details exactly _how_ the channel was closed. Three
|
||||||
// closure types are possible: cooperative, force, and breach.
|
// closure types are possible: cooperative, force, and breach.
|
||||||
@ -865,7 +874,10 @@ func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error {
|
|||||||
return err
|
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
|
return err
|
||||||
}
|
}
|
||||||
if err := binary.Write(w, byteOrder, cs.Capacity); err != nil {
|
if err := binary.Write(w, byteOrder, cs.Capacity); err != nil {
|
||||||
@ -917,7 +929,10 @@ func deserializeCloseChannelSummary(r io.Reader) (*ChannelCloseSummary, error) {
|
|||||||
return nil, err
|
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
|
return nil, err
|
||||||
}
|
}
|
||||||
if err := binary.Read(r, byteOrder, &c.Capacity); err != nil {
|
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
|
// written state, and creates a small "summary" elsewhere within the
|
||||||
// database.
|
// database.
|
||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *state.ChanID,
|
ChanPoint: *state.ChanID,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
OurBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
IsPending: false,
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
CloseType: CooperativeClose,
|
IsPending: false,
|
||||||
|
CloseType: CooperativeClose,
|
||||||
}
|
}
|
||||||
if err := state.CloseChannel(closeSummary); err != nil {
|
if err := state.CloseChannel(closeSummary); err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
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.
|
// Now attempt to delete the channel from the database.
|
||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *channel.ChanID,
|
ChanPoint: *channel.ChanID,
|
||||||
RemotePub: channel.IdentityPub,
|
RemotePub: channel.IdentityPub,
|
||||||
OurBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
IsPending: false,
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
CloseType: ForceClose,
|
IsPending: false,
|
||||||
|
CloseType: ForceClose,
|
||||||
}
|
}
|
||||||
if err := updatedChannel[0].CloseChannel(closeSummary); err != nil {
|
if err := updatedChannel[0].CloseChannel(closeSummary); err != nil {
|
||||||
t.Fatalf("unable to delete updated channel: %v", err)
|
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
|
// Next, close the channel by including a close channel summary in the
|
||||||
// database.
|
// database.
|
||||||
summary := &ChannelCloseSummary{
|
summary := &ChannelCloseSummary{
|
||||||
ChanPoint: *state.ChanID,
|
ChanPoint: *state.ChanID,
|
||||||
ClosingTXID: rev,
|
ClosingTXID: rev,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
OurBalance: state.OurBalance,
|
SettledBalance: state.OurBalance,
|
||||||
CloseType: ForceClose,
|
TimeLockedBalance: state.OurBalance + 10000,
|
||||||
IsPending: true,
|
CloseType: ForceClose,
|
||||||
|
IsPending: true,
|
||||||
}
|
}
|
||||||
if err := state.CloseChannel(summary); err != nil {
|
if err := state.CloseChannel(summary); err != nil {
|
||||||
t.Fatalf("unable to close channel: %v", err)
|
t.Fatalf("unable to close channel: %v", err)
|
||||||
|
Loading…
Reference in New Issue
Block a user