Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
caffeinum opened this issue Apr 12, 2018 · 4 comments
Closed

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

caffeinum opened this issue Apr 12, 2018 · 4 comments

Comments

@caffeinum
Copy link

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
Copy link
Contributor

  • fork - could be emulated I suppose if your compiler converts straight C code to continuation-passing reactive Javascript, but I do not know how typical C-to-JS compilers do this.
  • file access - we read and write gossip_store, and the database has a file backing it.
  • socket - we not only use this to accept and create connections, but also to communicate between processes that we forked off.

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
Copy link
Author

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
Copy link
Author

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?

@rustyrussell
Copy link
Contributor

Closing as old.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants