fundingmanager+lnwallet: ensure proposed channel reserve is above dust limit
This commit is contained in:
4 files changed
+57
-12
No files matched your search
+13
-1
@@ -284,7 +284,7 @@ func (r *ChannelReservation) SetNumConfsRequired(numConfs uint16) {
|
||||
// if the parameters are seemed unsound.
|
||||
func (r *ChannelReservation) CommitConstraints(csvDelay, maxHtlcs uint16,
|
||||
maxValueInFlight, minHtlc lnwire.MilliSatoshi,
|
||||
chanReserve btcutil.Amount) error {
|
||||
chanReserve, dustLimit btcutil.Amount) error {
|
||||
|
||||
r.Lock()
|
||||
defer r.Unlock()
|
||||
@@ -296,6 +296,12 @@ func (r *ChannelReservation) CommitConstraints(csvDelay, maxHtlcs uint16,
|
||||
return ErrCsvDelayTooLarge(csvDelay, maxDelay)
|
||||
}
|
||||
|
||||
// The dust limit should always be greater or equal to the channel
|
||||
// reserve. The reservation request should be denied if otherwise.
|
||||
if dustLimit > chanReserve {
|
||||
return ErrChanReserveTooSmall(chanReserve, dustLimit)
|
||||
}
|
||||
|
||||
// Fail if we consider the channel reserve to be too large. We
|
||||
// currently fail if it is greater than 20% of the channel capacity.
|
||||
maxChanReserve := r.partialState.Capacity / 5
|
||||
@@ -331,6 +337,12 @@ func (r *ChannelReservation) CommitConstraints(csvDelay, maxHtlcs uint16,
|
||||
minNumHtlc*minHtlc)
|
||||
}
|
||||
|
||||
// Our dust limit should always be less than or equal our proposed
|
||||
// channel reserve.
|
||||
if r.ourContribution.DustLimit > chanReserve {
|
||||
r.ourContribution.DustLimit = chanReserve
|
||||
}
|
||||
|
||||
r.ourContribution.ChannelConfig.CsvDelay = csvDelay
|
||||
r.ourContribution.ChannelConfig.ChanReserve = chanReserve
|
||||
r.ourContribution.ChannelConfig.MaxAcceptedHtlcs = maxHtlcs
|
||||
|
||||
Reference in new issue
Block a user