lightning network – How to compute the expected number of sats to arrive in a probabilistic payment flow?


Let’s review the definition of expected value.
The expected value of the random variable X given the state of the system O,
denoted as E(X,O) is computed as:

E(X,O) = \sum_i p_i(O) X_i

The sum is over all microstates (all ways in which liquidity could be allocated in the channels) or equivalently one can choose to sum over all possible observable outcomes. The p_i(O) is the probability of verifying i given the state O, and X_i is the value that X takes if i is verified.
Using this definition, one immediately sees that E(.,O) is a linear operator:

E(X+a*Y,O) = E(X,O) + a*E(Y,O)

That would be enough to answer your question.
You get different answers because you have constructed your observables differently.

Your observable is the sum of two flows x that goes through S-A-R with 1 sat and y that goes through S-B-R with 2 sat.

E(x+y,O) = E(x,O) + E(y,O)

Now, x either fails (prob. 1/3) getting us 0 sat or it succeeds giving us 1 sat (prob. 2/3).

E(x,O) = 0*1/3 + 1*2/3 = 2/3

Similarly with y

E(y,O) = 0*2/5 + 2*3/5 = 6/5

Adding up to

E(x+y,O) = 2/3 + 6/5 = 28/15

But be careful, that here we are assuming that x outcome is independent of the outcome of y. This is the case if you are sending two single path payments.

If you instead consider an atomic multi-path payment in which either both x and y succeed or none will, then the two outcomes for x are again 1 sat and 0 sat, but with probabilities 2/3*3/5=2/5 (both x and y succeed)
and 3/5 (all other cases) respectively:

E(x,O)= 1*2/5 + 0*3/5 = 2/5

similarly for y

E(y,O)= 2*2/5 + 0*3/5 = 4/5

Adding up to

E(x+y,O) = 2/5 + 4/5 = 6/5 = 18/15

You are building your observable as the sum of three single path flows (non-atomic):
x representing 1 sat over S-A-R, y representing 1 sat over S-B-R
and z representing 1 sat over S-B-R AFTER y. This is different from case B because y and z are not attached to each other, y might succeed and then z could fail.

Usual computations

E(x,O) = 0*1/3 + 1*2/3 = 2/3

for y

E(y,O) = 0*1/5 + 1*4/5 = 4/5

Then comes z, which will succeed only if there is enough liquidity for 2 sats on channel B-R, then

E(z,O) = 0*2/5 + 1*3/5= 3/5

Adding up:

E(x+y+z,O) = 2/3+4/5+3/5 = 31/15

Is similar to case D but the math is wrong.
You are correctly computing E(x,O)=2/3 and E(y,O)=4/5, but with
E(z,O) you are messing up with the conditional probability.

Let’s see all possible outcomes:

  • y fails, then also z fails, prob. 1/5, (having exactly 0 sat liquidity)
  • y succeeds, but z fails, prob. 1/5, (having exactly 1 sat of liquidity)
  • y succeeds, z succeeds, prob. 3/5, (all other cases which correspond to having enough liquidity for 2 sat)
    which is the same as the multiplication of y succeeding and the conditional prob. of z succeeding after y does (3/5 = 4/5 * 3/4).
E(z,O) = 0*1/5 + 0*1/5 + 1*3/5 = 3/5

It is important to state that z is tried after y or we get into race conditions.

  • Case A is right if you send a two flow atomic payment,
  • Case B is right if you send two single path payments,
  • Case C is wrong,
  • Case D is right if you send three single path payments.

I am confident that if you run the experiments you’ll confirm.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top