mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-12 22:59:38 +02:00
htlcswitch: implement flush api for channelLink
This commit is contained in:
@@ -367,6 +367,14 @@ type channelLink struct {
|
|||||||
// log is a link-specific logging instance.
|
// log is a link-specific logging instance.
|
||||||
log btclog.Logger
|
log btclog.Logger
|
||||||
|
|
||||||
|
// isOutgoingAddBlocked tracks whether the channelLink can send an
|
||||||
|
// UpdateAddHTLC.
|
||||||
|
isOutgoingAddBlocked atomic.Bool
|
||||||
|
|
||||||
|
// isIncomingAddBlocked tracks whether the channelLink can receive an
|
||||||
|
// UpdateAddHTLC.
|
||||||
|
isIncomingAddBlocked atomic.Bool
|
||||||
|
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
quit chan struct{}
|
quit chan struct{}
|
||||||
}
|
}
|
||||||
@@ -559,24 +567,49 @@ func (l *channelLink) EligibleToUpdate() bool {
|
|||||||
// EnableAdds sets the ChannelUpdateHandler state to allow UpdateAddHtlc's in
|
// EnableAdds sets the ChannelUpdateHandler state to allow UpdateAddHtlc's in
|
||||||
// the specified direction. It returns an error if the state already allowed
|
// the specified direction. It returns an error if the state already allowed
|
||||||
// those adds.
|
// those adds.
|
||||||
func (l *channelLink) EnableAdds(LinkDirection) error {
|
func (l *channelLink) EnableAdds(linkDirection LinkDirection) error {
|
||||||
// TODO(proofofkeags): Implement
|
if linkDirection == Outgoing {
|
||||||
|
if !l.isOutgoingAddBlocked.Swap(false) {
|
||||||
|
return errors.New("outgoing adds already enabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if linkDirection == Incoming {
|
||||||
|
if !l.isIncomingAddBlocked.Swap(false) {
|
||||||
|
return errors.New("incoming adds already enabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// DiableAdds sets the ChannelUpdateHandler state to allow UpdateAddHtlc's in
|
// DiableAdds sets the ChannelUpdateHandler state to allow UpdateAddHtlc's in
|
||||||
// the specified direction. It returns an error if the state already disallowed
|
// the specified direction. It returns an error if the state already disallowed
|
||||||
// those adds.
|
// those adds.
|
||||||
func (l *channelLink) DisableAdds(LinkDirection) error {
|
func (l *channelLink) DisableAdds(linkDirection LinkDirection) error {
|
||||||
// TODO(proofofkeags): Implement
|
if linkDirection == Outgoing {
|
||||||
|
if l.isOutgoingAddBlocked.Swap(true) {
|
||||||
|
return errors.New("outgoing adds already disabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if linkDirection == Incoming {
|
||||||
|
if l.isIncomingAddBlocked.Swap(true) {
|
||||||
|
return errors.New("incoming adds already disabled")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsFlushing returns true when UpdateAddHtlc's are disabled in the direction of
|
// IsFlushing returns true when UpdateAddHtlc's are disabled in the direction of
|
||||||
// the argument.
|
// the argument.
|
||||||
func (l *channelLink) IsFlushing(LinkDirection) bool {
|
func (l *channelLink) IsFlushing(linkDirection LinkDirection) bool {
|
||||||
// TODO(proofofkeags): Implement
|
if linkDirection == Outgoing {
|
||||||
return false
|
return l.isOutgoingAddBlocked.Load()
|
||||||
|
}
|
||||||
|
|
||||||
|
return l.isIncomingAddBlocked.Load()
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnFlushedOnce adds a hook that will be called the next time the
|
// OnFlushedOnce adds a hook that will be called the next time the
|
||||||
|
Reference in New Issue
Block a user