channeldb/channel: adds IsBorked to OpenChannel
This commit is contained in:
parent
20f4c61c8b
commit
1d69526874
@ -305,6 +305,11 @@ type OpenChannel struct {
|
|||||||
// negotiate fees, or close the channel.
|
// negotiate fees, or close the channel.
|
||||||
IsInitiator bool
|
IsInitiator bool
|
||||||
|
|
||||||
|
// IsBorked indicates that the channel has entered an irreconcilable
|
||||||
|
// state, triggered by a state desynchronization or channel breach.
|
||||||
|
// Channels in this state should never be added to the htlc switch.
|
||||||
|
IsBorked bool
|
||||||
|
|
||||||
// FundingBroadcastHeight is the height in which the funding
|
// FundingBroadcastHeight is the height in which the funding
|
||||||
// transaction was broadcast. This value can be used by higher level
|
// transaction was broadcast. This value can be used by higher level
|
||||||
// sub-systems to determine if a channel is stale and/or should have
|
// sub-systems to determine if a channel is stale and/or should have
|
||||||
@ -522,6 +527,37 @@ func (c *OpenChannel) MarkAsOpen(openLoc lnwire.ShortChannelID) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarkBorked marks the event when the channel as reached an irreconcilable
|
||||||
|
// state, such as a channel breach or state desynchronization. Borked channels
|
||||||
|
// should never be added to the switch.
|
||||||
|
func (c *OpenChannel) MarkBorked() error {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
if err := c.Db.Update(func(tx *bolt.Tx) error {
|
||||||
|
chanBucket, err := updateChanBucket(tx, c.IdentityPub,
|
||||||
|
&c.FundingOutpoint, c.ChainHash)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
channel, err := fetchOpenChannel(chanBucket, &c.FundingOutpoint)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
channel.IsBorked = true
|
||||||
|
|
||||||
|
return putOpenChannel(chanBucket, channel)
|
||||||
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
c.IsBorked = true
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// putChannel serializes, and stores the current state of the channel in its
|
// putChannel serializes, and stores the current state of the channel in its
|
||||||
// entirety.
|
// entirety.
|
||||||
func putOpenChannel(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
func putOpenChannel(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
||||||
@ -1217,6 +1253,9 @@ 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
|
||||||
|
|
||||||
|
// CloseHeight is the height at which the funding transaction was spent.
|
||||||
|
CloseHeight uint32
|
||||||
|
|
||||||
// SettledBalance is our total balance settled balance at the time of
|
// SettledBalance is our total balance settled balance at the time of
|
||||||
// channel closure. This _does not_ include the sum of any outputs that
|
// channel closure. This _does not_ include the sum of any outputs that
|
||||||
// have been time-locked as a result of the unilateral channel closure.
|
// have been time-locked as a result of the unilateral channel closure.
|
||||||
@ -1402,9 +1441,9 @@ func putChannelCloseSummary(tx *bolt.Tx, chanID []byte,
|
|||||||
|
|
||||||
func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error {
|
func serializeChannelCloseSummary(w io.Writer, cs *ChannelCloseSummary) error {
|
||||||
return writeElements(w,
|
return writeElements(w,
|
||||||
cs.ChanPoint, cs.ChainHash, cs.ClosingTXID, cs.RemotePub, cs.Capacity,
|
cs.ChanPoint, cs.ChainHash, cs.ClosingTXID, cs.CloseHeight,
|
||||||
cs.SettledBalance, cs.TimeLockedBalance, cs.CloseType,
|
cs.RemotePub, cs.Capacity, cs.SettledBalance,
|
||||||
cs.IsPending,
|
cs.TimeLockedBalance, cs.CloseType, cs.IsPending,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1429,9 +1468,9 @@ func deserializeCloseChannelSummary(r io.Reader) (*ChannelCloseSummary, error) {
|
|||||||
c := &ChannelCloseSummary{}
|
c := &ChannelCloseSummary{}
|
||||||
|
|
||||||
err := readElements(r,
|
err := readElements(r,
|
||||||
&c.ChanPoint, &c.ChainHash, &c.ClosingTXID, &c.RemotePub, &c.Capacity,
|
&c.ChanPoint, &c.ChainHash, &c.ClosingTXID, &c.CloseHeight,
|
||||||
&c.SettledBalance, &c.TimeLockedBalance, &c.CloseType,
|
&c.RemotePub, &c.Capacity, &c.SettledBalance,
|
||||||
&c.IsPending,
|
&c.TimeLockedBalance, &c.CloseType, &c.IsPending,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -1445,9 +1484,10 @@ func putChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
|||||||
if err := writeElements(&w,
|
if err := writeElements(&w,
|
||||||
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
|
channel.ChanType, channel.ChainHash, channel.FundingOutpoint,
|
||||||
channel.ShortChanID, channel.IsPending, channel.IsInitiator,
|
channel.ShortChanID, channel.IsPending, channel.IsInitiator,
|
||||||
channel.FundingBroadcastHeight, channel.NumConfsRequired,
|
channel.IsBorked, channel.FundingBroadcastHeight,
|
||||||
channel.ChannelFlags, channel.IdentityPub, channel.Capacity,
|
channel.NumConfsRequired, channel.ChannelFlags,
|
||||||
channel.TotalMSatSent, channel.TotalMSatReceived,
|
channel.IdentityPub, channel.Capacity, channel.TotalMSatSent,
|
||||||
|
channel.TotalMSatReceived,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -1545,9 +1585,10 @@ func fetchChanInfo(chanBucket *bolt.Bucket, channel *OpenChannel) error {
|
|||||||
if err := readElements(r,
|
if err := readElements(r,
|
||||||
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
|
&channel.ChanType, &channel.ChainHash, &channel.FundingOutpoint,
|
||||||
&channel.ShortChanID, &channel.IsPending, &channel.IsInitiator,
|
&channel.ShortChanID, &channel.IsPending, &channel.IsInitiator,
|
||||||
&channel.FundingBroadcastHeight, &channel.NumConfsRequired,
|
&channel.IsBorked, &channel.FundingBroadcastHeight,
|
||||||
&channel.ChannelFlags, &channel.IdentityPub, &channel.Capacity,
|
&channel.NumConfsRequired, &channel.ChannelFlags,
|
||||||
&channel.TotalMSatSent, &channel.TotalMSatReceived,
|
&channel.IdentityPub, &channel.Capacity, &channel.TotalMSatSent,
|
||||||
|
&channel.TotalMSatReceived,
|
||||||
); err != nil {
|
); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user