channeldb: add HasChanStatus and ApplyChanState methods to OpenChannel
These methods allow callers to properly query if a channel is in a particular flag, and also modify the channel status in a thread safe manner.
This commit is contained in:
parent
a410262dda
commit
aaf6456e12
@ -316,8 +316,8 @@ var (
|
|||||||
// channel.
|
// channel.
|
||||||
ChanStatusLocalDataLoss ChannelStatus = 1 << 2
|
ChanStatusLocalDataLoss ChannelStatus = 1 << 2
|
||||||
|
|
||||||
// ChanStatusRestored is a status flag that signals that the chanel has
|
// ChanStatusRestored is a status flag that signals that the channel
|
||||||
// been restored, and doesn't have all the fields a typical channel
|
// has been restored, and doesn't have all the fields a typical channel
|
||||||
// will have.
|
// will have.
|
||||||
ChanStatusRestored ChannelStatus = 1 << 3
|
ChanStatusRestored ChannelStatus = 1 << 3
|
||||||
)
|
)
|
||||||
@ -531,6 +531,28 @@ func (c *OpenChannel) ChanStatus() ChannelStatus {
|
|||||||
return c.chanStatus
|
return c.chanStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ApplyChanStatus allows the caller to modify the internal channel state in a
|
||||||
|
// thead-safe manner.
|
||||||
|
func (c *OpenChannel) ApplyChanStatus(status ChannelStatus) error {
|
||||||
|
c.Lock()
|
||||||
|
defer c.Unlock()
|
||||||
|
|
||||||
|
return c.putChanStatus(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// HasChanStatus returns true if the internal bitfield channel status of the
|
||||||
|
// target channel has the specified status bit set.
|
||||||
|
func (c *OpenChannel) HasChanStatus(status ChannelStatus) bool {
|
||||||
|
c.RLock()
|
||||||
|
defer c.RUnlock()
|
||||||
|
|
||||||
|
return c.hasChanStatus(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *OpenChannel) hasChanStatus(status ChannelStatus) bool {
|
||||||
|
return c.chanStatus&status == status
|
||||||
|
}
|
||||||
|
|
||||||
// RefreshShortChanID updates the in-memory short channel ID using the latest
|
// RefreshShortChanID updates the in-memory short channel ID using the latest
|
||||||
// value observed on disk.
|
// value observed on disk.
|
||||||
func (c *OpenChannel) RefreshShortChanID() error {
|
func (c *OpenChannel) RefreshShortChanID() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user