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:
2 files changed
+26
-8
No files matched your search
+20
-5
@@ -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 {
|
||||||
|
|||||||
@@ -375,7 +375,8 @@ func TestOpenChannelPutGetDelete(t *testing.T) {
|
|||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *state.ChanID,
|
ChanPoint: *state.ChanID,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
OurBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
IsPending: false,
|
IsPending: false,
|
||||||
CloseType: CooperativeClose,
|
CloseType: CooperativeClose,
|
||||||
}
|
}
|
||||||
@@ -607,7 +608,8 @@ func TestChannelStateTransition(t *testing.T) {
|
|||||||
closeSummary := &ChannelCloseSummary{
|
closeSummary := &ChannelCloseSummary{
|
||||||
ChanPoint: *channel.ChanID,
|
ChanPoint: *channel.ChanID,
|
||||||
RemotePub: channel.IdentityPub,
|
RemotePub: channel.IdentityPub,
|
||||||
OurBalance: btcutil.Amount(500),
|
SettledBalance: btcutil.Amount(500),
|
||||||
|
TimeLockedBalance: btcutil.Amount(10000),
|
||||||
IsPending: false,
|
IsPending: false,
|
||||||
CloseType: ForceClose,
|
CloseType: ForceClose,
|
||||||
}
|
}
|
||||||
@@ -732,7 +734,8 @@ func TestFetchClosedChannels(t *testing.T) {
|
|||||||
ClosingTXID: rev,
|
ClosingTXID: rev,
|
||||||
RemotePub: state.IdentityPub,
|
RemotePub: state.IdentityPub,
|
||||||
Capacity: state.Capacity,
|
Capacity: state.Capacity,
|
||||||
OurBalance: state.OurBalance,
|
SettledBalance: state.OurBalance,
|
||||||
|
TimeLockedBalance: state.OurBalance + 10000,
|
||||||
CloseType: ForceClose,
|
CloseType: ForceClose,
|
||||||
IsPending: true,
|
IsPending: true,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user