Closed ranchalp closed 5 years ago
I don't consider this an issue with lnd
and more an issue with the dev site tutorials. As a result, I think this issue belongs at https://github.com/lightninglabs/lightning-dev-site. It may even be an issue with the library itself as well (or just the way it's using async I/O in python).
Perhaps I did not express properly. Even when not following the documentation, and using generators the only way they are supposed to be used in python (to the best of my knowledge), the code works. It might be a problem with python but it impacts in the usage of the gRPC. In any case, I found the dodgy workaround that I mentioned so until further notice I will use that.
Background
The lnd gRPC reference website does not show an example that works for for
SendPayment
andSendToRoute
using python'sgRPC
. Consequently, there is no valid example. The tutorials are also not showing examples for streaming objects using python's RPC in the case ofSendPayment
andSendToRoute
, while it is recommended to use the streaming functions rather than the sync ones. Seems to me as though the line that invokesyield [...]
should suspend execution until called again(which would fix the whole thing), but it is not what happens in reality.Your environment
lnd
lnd version 0.5.1-beta commit=v0.5.1-betauname -a
on *Nix) Linux despatx 4.13.0-36-generic Ubuntubtcd
,bitcoind
, or other backend btcd version 0.12.0-betaSteps to reproduce
Following the example, created the following code on a simnet with only 4 nodes and 3 channels: Alice-Bob-Charlie-Dave. The purpose is to test payments from Dave to Alice:
Bear in mind that I changed
for response in stub...
forfor i in range (0,10)
and then making use ofnext
in order to prevent an infinite loop. This code, while working, seems to call too many times to the generator for what I believe should be just one call per iteration in thefor
(see here).If I, however, remove the
while True
, and just perform one call:the result is then incorrect:
However, if I make this one call last longer by, for example, putting it to sleep for a few mins, then the result is correct (at least during the first call, but users typically only want to call once):
result:
Seems like one needs to .lock() the
request_iterable
untilresponse.running()==False
, but it is not said anywhere throughout the tutorials and documentation. Why isyield
called more than once per call toSendPayment
? Also, why doestime.sleep(4*60)
(or lock()) have any impact on the outcome of the execution outside of it?. Why does the documentation have aWhile True:
andfor response in
stub.SendPayment(...)`?.Actual behaviour
This is straight-forward in javascript with the
on(...)
methods, and the example for javascript shows it very well, but in python, either it is not as straight-forward, or it is not shown as straight-forward in the tutorial, or both (I personally do not know so I am currently just adding time.sleep(...) after yield to guaranteeing getting the proper value). As far as I know,yield
should suspend, but it is not the case.