Main
Main
1 Introduction
Payments in the Lightning Network are performed along shortest path on the network that
try to minimize the transfer fees. Because the participating nodes have incomplete information
about the balance of the individual channels, it is not always possible to perform the payments
along the shortest path, and the back-end of lightning has to work out alternative routes until
one is found with enough liquidity to process the payment.
[2] proposes an alternative algorithm for payments, by introducing the following novel ideas:
1. Each payment can be routed through a combination of different paths, in what is called
a Mult-Part Payment (MPP). The transfer of money on each channel is bounded by the
channel’s capacity (in one specific direction) and the sum of the inbound and outbound
payments for the nodes satisfy balance constraints, the MPP problem can be solved with
the algorithms that find maximum flows on a directed network.
2. The arcs of the network can be characterized by a probability distribution function for
the realization of the transfer (the value of the flow on the arc that can be processed).
The probability of success of the MPP becomes the multiplication of the probability of
success of every non-trivial flow on the network.
3. By defining a new function of the MPP flow, which is the negative logarithm of that
probability of success, one has that the probability of an MPP payment is maximized
when this new cost function is minimized. And since the logarithm of the product is the
sum of logarithms, this cost function is separable in the sum of the cost for the individual
costs of the flow through the arcs of the network. Thus the problem of maximizing the
probability of success of a MPP payment becomes a Min Cost Flow problem with non-
linear costs on arcs.
4. By assuming some constraint in the probability function of the arcs, one can reduce to a
particular class of problems for which the cost of the flow is a convex function. For this
class of problem efficient polynomial algorithms are known.
2 Proposal
This Summer of Bitcoin project, proposes the design and implementation of a C++ mini-library
with no external dependencies for solving the min cost flow problem (MCF) with convex costs
that can be used to optimize the probability of success of multipart payments in the Lightning
Network.
1
Some time of the project will be allocated to study of the state of the art of the problem.
At the present we are aware of two algorithms that can be used to solve the MCF with convex
costs. One that transforms approximates the cost function to a piecewise linear function and
splits the arc into several linear cost arcs accordingly (section 14.4 of [1]). And the so called
Capacity algorithm described in section 14.5 of [1], which is a generalization of a Excess Scaling
solver for the linear MCF problem. During the course of this project duration, we will evaluate
which algorithm will be best suited for the problem domain.
Parallelization of the algorithms will be considered and discussed during the development of
the back-end. We will propose to use standard library tools for that purpose which are available
in C++17.
For the preparation of this Summer of Bitcoin project proposal, we have been working on a
proof-of-concept MCF C++ library1 publicly available on Github. The API of this MCF library
permits the representation of a directed graph digraph in a space efficient data structure. It also
allows for the computation shortest paths on a weighted network using Dijsktra’s and Breadth-
First-Search algorithms, which serve as building blocks for flow solvers. There are two different
back-ends for the solution of the Max Flow problem: using Edmond-Karp’s Augmenting Paths
and Dinic’s Push-Relabel. Also these constitute building blocks for the Min Cost Flow solvers.
The library contains a MCF solver based on the Successive Shortest Path algorithm presented
in section 9.7 on [1].
In the library’s respository we provide examples of applications that we have also used as
test for correctedness and efficiency of our implementation. These examples actually solve two
problems from the online judge Kattis: maxflow2 and mincostmaxflow3 , and they do pass the
test cases within the time and memory constraints.
3 Timeline
Before May 9
Meet the mentors, discuss with them the proposed timeline, deliverables and share ideas.
May 9 – May 23
Search in the literature for algorithms that solve the min-cost flow problem with convex cost
functions. Follow the bitcoin and lightning seminars.
May 23 – June 6
Design of a standalone C++ library for solving the min-cost flow problem. Implementation of
a textbook efficient solution to the linear min-cost flow problem, the Excess Scaling algorithm
described in [1] section 7.9. This linear MCF solver can be used to solve convex cost problems
with a tuneable linear approximation by decomposing the non-linear cost arcs into several linear
cost arcs. Set up a simple set of unit tests for correctedness and CI for the library repository.
June 6 – June 20
Use the code to reproduce the results of Pickhardt’s Payment Simulation Jupyter Notebook.
Implementation of a textbook solution: the capacity scaling algorithm described in [1] section
14.5. This algorithm is a generalization of the Excess Scaling, hence it shouldn’t be too difficult
to adapt the linear MCF already implemented to the general convex cost case.
1
https://github.com/Lagrang3/mincostflow
2
https://open.kattis.com/problems/maxflow
3
https://open.kattis.com/problems/mincostmaxflow
2
June 20 – July 4
Benchmark the canditate solutions. Optimize the code to find a good tradeoff of runtimes and
probability of success. Parallelization of the time critical routines.
July 4 – July 18
Implementation of a small C-lightning plugin to demonstrate the use of the library.
July 18 – August 1
Document the library and buffer time for unfinished issues.
August 1 – August 15
Preparation of the final report and draft the research article.
August 15 – August 22
Submission of the final project report.
References
[1] R.K. Ahuja, T.L. Magnanti, and J.B. Orlin. Network Flows: Theory, Algorithms, and
Applications. Prentice Hall, 1993.
[2] Rene Pickhardt and Stefan Richter. Optimally reliable & cheap payment flows on the
lightning network, 2021.
A Biographical Information
Personal details
Name: Eduardo Quintana Miranda
Affiliation: University of Trieste, Astronomical Observatory of Trieste
Course: Astrophysics
Degree Program: PhD
Country: Italy
E-mail: [email protected]
Github: github.com/Lagrang3
Discord: eduardo-qm
Educational background.
• 2008–2013. BSc. Nuclear Physics, University of Havana,
3
Programming background.
My main programming language is C++, but I am also profiecient in C and python.
I started programming back in 2009 during my 2nd year of BSc. The main drivers were
physics simulations and programming competitions. From 2009 until 2013 I’ve participated
intensively in those kind of competitions, the most important were the ACM-ICPC4 competi-
tions held every year, my team managed to classify many times to the regional phase, which
in our geographical context where named Caribbean Finals of the ICPC. Until this date I par-
ticipate once in a while on codeforces.com rounds by the username Lagrang35 . I have a fair
knowledge of a variety of classical algorithms somewhat seasoned by my participation on pro-
gramming competitions. I am familiar with shortest path, max-flow and linear min-cost flow
graph problems and textbook algorithms for solving them.
I’ve acquired some professional programming skills during the Master in High Performance
Computing. Advanced C++, Python, bash, git, and parallel programming in OpenMP, MPI
and Cuda where among the topics taught in that curriculum.
In 2021 I’ve succesfully completed a Google Summer of Code project for the proposal of
FFT utilities in Boost Math library6 .
Today, I am doing a PhD in astrophysics working on the developement of a simulation code
to study the effects of general relativity in the formation of cosmological structures.7
4
icpc.global
5
https://codeforces.com/profile/Lagrang3
6
https://github.com/BoostGSoC21/math-fft-report/releases/download/v1.1/gsoc-report.pdf
7
https://github.com/Lagrang3/gevolution-1.2/tree/gev-api