MCPcopy Create free account
hub / github.com/ElementsProject/lightning / check_dust_limit

Function check_dust_limit

openingd/common.c:170–229  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170bool check_dust_limit(const tal_t *ctx,
171 const struct channel_config *remoteconf,
172 const struct channel_config *localconf,
173 bool allow_dust_reserve,
174 char **err_reason)
175{
176 /* BOLT #2:
177 *
178 * The receiving node MUST fail the channel if:
179 *...
180 * - `dust_limit_satoshis` is smaller than `354 satoshis` (see [BOLT 3](03-transactions.md#dust-limits)).
181 */
182 if (amount_sat_less(remoteconf->dust_limit, MIN_REMOTE_DUST_LIMIT)) {
183 *err_reason = tal_fmt(ctx,
184 "dust_limit_satoshis %s too small"
185 " (minimum %s)",
186 fmt_amount_sat(ctx, remoteconf->dust_limit),
187 fmt_amount_sat(ctx, MIN_REMOTE_DUST_LIMIT));
188 return false;
189 }
190
191 /* Everything we hold below their dust limit is trimmed from
192 * *their* commitment transaction and goes to miners when they
193 * force close. When they open, we derive the reserve from their
194 * dust limit, so without an absolute ceiling a peer could set it
195 * to half the channel, pay us up to just under it, and burn (or,
196 * with a miner, steal) our whole balance. */
197 /* BOLT #2:
198 *
199 * The receiving node MAY fail the channel if:
200 *...
201 * - it considers `dust_limit_satoshis` too large (see [BOLT 3](03-transactions.md#dust-limits)).
202 */
203 if (amount_sat_greater(remoteconf->dust_limit, MAX_REMOTE_DUST_LIMIT)) {
204 *err_reason = tal_fmt(ctx,
205 "dust_limit_satoshis %s too large"
206 " (maximum %s)",
207 fmt_amount_sat(ctx, remoteconf->dust_limit),
208 fmt_amount_sat(ctx, MAX_REMOTE_DUST_LIMIT));
209 return false;
210 }
211
212 /* BOLT #2:
213 *
214 * The receiving node MUST fail the channel if:
215 *...
216 * - `dust_limit_satoshis` is greater than `channel_reserve_satoshis`.
217 */
218 if (!allow_dust_reserve
219 && amount_sat_greater(remoteconf->dust_limit,
220 localconf->channel_reserve)) {
221 *err_reason = tal_fmt(ctx,
222 "dust_limit_satoshis %s"
223 " would be above our reserve %s",
224 fmt_amount_sat(ctx, remoteconf->dust_limit),
225 fmt_amount_sat(ctx, localconf->channel_reserve));
226 return false;
227 }

Callers 6

funder_channel_startFunction · 0.85
fundee_channelFunction · 0.85
accepter_startFunction · 0.85
opener_startFunction · 0.85
rbf_local_startFunction · 0.85
rbf_remote_startFunction · 0.85

Calls 3

amount_sat_lessFunction · 0.85
amount_sat_greaterFunction · 0.85
fmt_amount_satFunction · 0.50

Tested by

no test coverage detected