ElementsProject / lightning

Core Lightning — Lightning Network implementation focusing on spec compliance and performance
Other
2.81k stars 887 forks source link

Compiling c-lightning via WebAssembly to run in browser #1370

Open caffeinum opened 6 years ago

caffeinum commented 6 years ago

That is not an issue, that is mostly a proposal/ask for help. I am not sure what would be the best place to ask such question.

I am looking for a way to run a LN node inside the browser. One way would be to implement BOLT protocol from scratch in JS, but I am thinking of an easy way.

Has anyone succeed in compiling this project under WebAssembly? http://webassembly.org/getting-started/developers-guide/. WebAssembly is a C/C++ compiler into browser-compatible byte-code. It can use JS-API, but can also work with low-level C functions.

What are specific things c-lighting does that would stop from running it inside browser? e.g. my main concern are sockets, because for WebAssembly you should use special wrappers given by Emscripten lib.

So, my question is what should I look for when trying to run that, and also I want to hear your general feedback on the idea.

P.S. If here's not the place for this, can you please point me to where I can get such feedback?

ZmnSCPxj commented 6 years ago

I think fork is the big one here; to my understanding C-to-JS compiler tend to target something like asm.js and converts straight-line C to straight-line asm.js, but our design implicitly assumes that multiple processes running straight-line C code will run simultaneously; I am uncertain how, or if, this is possible in a typical C-to-JS setup.

caffeinum commented 6 years ago

As I have read up, Emscripten with BINARYEN enabled should support concurrency, pthreads etc.

Currently I have tried to build project under Emscripten, and stuck at first step, configure:

macbook-caffeinum-921:lightning caffeinum$ emconfigure ./configure
-n Compiling ccan/tools/configurator/configurator...
error: unresolved symbol: popen
Aborting compilation due to previous errors | undefined
Traceback (most recent call last):
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emcc.py", line 3015, in <module>
    sys.exit(run())
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emcc.py", line 1759, in run
    final = shared.Building.emscripten(final, append_ext=False, extra_args=extra_args)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/tools/shared.py", line 2282, in emscripten
    emscripten._main(cmdline)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 2222, in _main
    return temp_files.run_and_clean(lambda: main(
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/tools/tempfiles.py", line 93, in run_and_clean
    return func()
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 2227, in <lambda>
    DEBUG=DEBUG,
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 2153, in main
    temp_files=temp_files, DEBUG=DEBUG)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 86, in emscript
    glue, forwarded_data = compiler_glue(metadata, libraries, compiler_engine, temp_files, DEBUG)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 218, in compiler_glue
    glue, forwarded_data = compile_settings(compiler_engine, libraries, temp_files)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/emscripten.py", line 530, in compile_settings
    cwd=path_from_root('src'), error_limit=300)
  File "/Users/caffeinum/emsdk/emscripten/1.38.10/tools/jsrun.py", line 132, in run_js
    raise Exception('Expected the command ' + str(command) + ' to finish with return code ' + str(assert_returncode) + ', but it returned with code ' + str(proc.returncode) + ' instead! Output: ' + str(ret)[:error_limit])
Exception: Expected the command ['/Users/caffeinum/emsdk/node/8.9.1_64bit/bin/node', '/Users/caffeinum/emsdk/emscripten/1.38.10/src/compiler.js', '/tmp/tmpZl49aX.txt', '/Users/caffeinum/emsdk/emscripten/1.38.10/src/library_pthread_stub.js'] to finish with return code 0, but it returned with code 1 instead! Output: // The Module object: Our interface to the outside world. We import
// and export values on it. There are various ways Module can be used:
// 1. Not defined. We create it here
// 2. A function parameter, function(Module) { ..generated code.. }
// 3. pre-run appended it, var Module = {}; ..generated 
ERROR:root:Configure step failed with non-zero return code: 1.  Command line: ./configure at /Users/caffeinum/lightning
caffeinum commented 6 years ago

This link target issues in the make and configure files:

https://kripken.github.io/emscripten-site/docs/compiling/Building-Projects.html#build-system-issues

I am not sure if any of that applies to this project, can someone guide me?