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

Function calculate_our_funding

plugins/funder_policy.c:207–326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

205}
206
207const char *
208calculate_our_funding(struct funder_policy *policy,
209 struct node_id id,
210 struct amount_sat their_funding,
211 struct amount_sat available_funds,
212 struct amount_sat channel_max,
213 struct amount_sat requested_lease,
214 struct amount_sat *our_funding)
215{
216 struct amount_sat avail_channel_space, net_available_funds;
217
218 /* Are we only funding lease requests ? */
219 if (policy->leases_only && amount_sat_zero(requested_lease)) {
220 *our_funding = AMOUNT_SAT(0);
221 return tal_fmt(tmpctx,
222 "Skipping funding open; leases-only=true"
223 " and this open isn't asking for a lease");
224 }
225
226 /* Are we skipping this one? */
227 if (pseudorand(100) >= policy->fund_probability
228 /* We don't skip lease requests */
229 && amount_sat_zero(requested_lease)) {
230 *our_funding = AMOUNT_SAT(0);
231 return tal_fmt(tmpctx,
232 "Skipping, failed fund_probability test");
233 }
234
235 /* Figure out amount of actual headroom we have */
236 if (!amount_sat_sub(&avail_channel_space, channel_max, their_funding)
237 || amount_sat_zero(avail_channel_space)) {
238 *our_funding = AMOUNT_SAT(0);
239 return tal_fmt(tmpctx, "No space available in channel."
240 " channel_max %s, their_funding %s",
241 type_to_string(tmpctx, struct amount_sat,
242 &channel_max),
243 type_to_string(tmpctx, struct amount_sat,
244 &their_funding));
245 }
246
247 /* Figure out actual available funds, given our requested
248 * 'reserve_tank' */
249 if (!amount_sat_sub(&net_available_funds, available_funds,
250 policy->reserve_tank)
251 || amount_sat_zero(net_available_funds)) {
252 *our_funding = AMOUNT_SAT(0);
253 return tal_fmt(tmpctx, "Reserve tank too low."
254 " available_funds %s, reserve_tank requires %s",
255 type_to_string(tmpctx, struct amount_sat,
256 &available_funds),
257 type_to_string(tmpctx, struct amount_sat,
258 &policy->reserve_tank));
259 }
260
261 /* Are they funding enough ? */
262 if (amount_sat_less(their_funding, policy->min_their_funding)) {
263 *our_funding = AMOUNT_SAT(0);
264 return tal_fmt(tmpctx, "Peer's funding too little."

Callers 3

listfunds_successFunction · 0.85
check_fuzzingFunction · 0.85
mainFunction · 0.85

Calls 8

amount_sat_zeroFunction · 0.85
amount_sat_lessFunction · 0.85
amount_sat_greaterFunction · 0.85
apply_policyFunction · 0.85
apply_fuzzFunction · 0.85
pseudorandFunction · 0.50
amount_sat_subFunction · 0.50
type_to_stringClass · 0.50

Tested by 2

check_fuzzingFunction · 0.68
mainFunction · 0.68