19
19
#include <plugins/libplugin.h>
20
20
#include <stdint.h>
21
21
22
+
23
+ // FIXME: review this description still holds.
22
24
/* # Optimal payments
23
25
*
24
26
* In this module we reduce the routing optimization problem to a linear
47
49
*
48
50
* fee_msat = base_msat + floor(millionths*x_msat / 10^6)
49
51
*
50
- * We approximate this fee into a linear function by computing a slope `c_fee` such
51
- * that:
52
+ * We approximate this fee into a linear function plus a constant term:
53
+ *
54
+ * cost(x) = (k*base_msat) + (k*A_msat*millionths/10^6) * x
52
55
*
53
- * fee_microsat = c_fee * x_sat
56
+ * where A_msat is the accuracy of the flows, the smallest unit of flow, so that
57
+ * x_msat = x*A_msat, and k is an arbitrary constant.
54
58
*
55
59
* Function `linear_fee_cost` computes `c_fee` based on the base and
56
60
* proportional fees of a channel.
159
163
*
160
164
* */
161
165
162
- #define PARTS_BITS 2
166
+ /* Bits required to store all channel parts. */
167
+ #define PARTS_BITS 3
168
+ /* How many parts have a proportional cost. */
169
+ #define N_LINEAR_PARTS 5
170
+ /* The number of the channel part that holds the base fee. */
171
+ #define CHANNEL_BASE_PART 7
163
172
#define CHANNEL_PARTS (1 << PARTS_BITS)
164
173
165
174
// These are the probability intervals we use to decompose a channel into linear
166
175
// cost function arcs.
167
- static const double CHANNEL_PIVOTS []= {0 ,0.5 ,0.8 ,0.95 };
176
+ static const double CHANNEL_PIVOTS []= {0 ,0.5 ,0.8 ,0.95 , 0.99 };
168
177
169
178
static const s64 INFINITE = INT64_MAX ;
170
179
static const s64 MU_MAX = 100 ;
@@ -237,7 +246,7 @@ static const struct amount_msat SINGLE_PATH_THRESHOLD = AMOUNT_MSAT(1000000);
237
246
* we can't us a union, since bit order is implementation-defined and
238
247
* we want chanidx on the highest bits:
239
248
*
240
- * [ 0 1 2 3 4 5 6 ... 31 ]
249
+ * [ 0 1 2 3 4 5 6 ... 31 ]
241
250
* dual part chandir chanidx
242
251
*/
243
252
#define ARC_DUAL_BITOFF (0)
@@ -280,6 +289,13 @@ static inline struct arc arc_from_parts(u32 chanidx, int chandir, u32 part, bool
280
289
return arc ;
281
290
}
282
291
292
+ /* A fake node ID that we use to separate channel base costs from proportional
293
+ * costs. */
294
+ static u32 auxiliary_node (u32 chanidx , int chandir , u32 auxiliary_node_offset )
295
+ {
296
+ return auxiliary_node_offset + ((chanidx + 1 ) | chandir );
297
+ }
298
+
283
299
#define MAX (x , y ) (((x) > (y)) ? (x) : (y))
284
300
#define MIN (x , y ) (((x) < (y)) ? (x) : (y))
285
301
@@ -295,11 +311,18 @@ struct pay_parameters {
295
311
struct amount_msat accuracy ;
296
312
297
313
// channel linearization parameters
298
- double cap_fraction [CHANNEL_PARTS ],
299
- cost_fraction [CHANNEL_PARTS ];
314
+ double cap_fraction [N_LINEAR_PARTS ],
315
+ cost_fraction [N_LINEAR_PARTS ];
300
316
301
317
double delay_feefactor ;
302
318
double base_fee_penalty ;
319
+
320
+ /* FIXME: set this */
321
+ u32 auxiliary_node_offset ;
322
+
323
+ /* FIXME: our estimate of the constant probability of failure of any
324
+ * randomly chosen channel. */
325
+ double constant_fail_probability ;
303
326
};
304
327
305
328
/* Helper function.
@@ -553,11 +576,14 @@ static void init_linear_network(const tal_t *ctx,
553
576
s64 * * arc_fee_cost , s64 * * arc_capacity )
554
577
{
555
578
const struct gossmap * gossmap = params -> rq -> gossmap ;
556
- const size_t max_num_chans = gossmap_max_chan_idx ( gossmap );
557
- const size_t max_num_arcs = max_num_chans * ARCS_PER_CHANNEL ;
579
+ /* topology of the network */
580
+ const size_t max_num_chans = gossmap_max_chan_idx ( gossmap ) ;
558
581
const size_t max_num_nodes = gossmap_max_node_idx (gossmap );
582
+ /* topology of the MCF problem */
583
+ const size_t max_num_arcs = max_num_chans * ARCS_PER_CHANNEL ;
584
+ const size_t max_num_edges = max_num_nodes + max_num_chans * 2 ;
559
585
560
- * graph = graph_new (ctx , max_num_nodes , max_num_arcs , ARC_DUAL_BITOFF );
586
+ * graph = graph_new (ctx , max_num_edges , max_num_arcs , ARC_DUAL_BITOFF );
561
587
* arc_prob_cost = tal_arr (ctx , double , max_num_arcs );
562
588
for (size_t i = 0 ; i < max_num_arcs ; ++ i )
563
589
(* arc_prob_cost )[i ] = DBL_MAX ;
0 commit comments