lightningdevkit / rust-lightning

A highly modular Bitcoin Lightning library written in Rust. It's rust-lightning, not Rusty's Lightning!
Other
1.17k stars 368 forks source link

Non-tokio LDK Net #1493

Open TheBlueMatt opened 2 years ago

TheBlueMatt commented 2 years ago

@MaxFangX did a ton of work to build a non-tokio lightning-net crate in #1469, however, sadly, the constraints of the SGX environment he was targeted ended up forcing some decisions that probably don't make all that much sense for a more general-purpose one. That said, with a bit more work, we can probably still build a general lightnin-net crate that would support the SGX environment, just with a pretty different model.

In any case, we should have a lightning-net crate for those not using tokio, and it should be pretty trivial to do. I suggested a specific design for the interface at the end of https://github.com/lightningdevkit/rust-lightning/pull/1469#issuecomment-1133273025 that could support SGX, and we should probably do something that is dead-simple, basically a transliteration of https://github.com/lightningdevkit/ldk-c-bindings/blob/main/ldk-net/ldk_net.c to rust.

MaxFangX commented 2 years ago

FYI, we managed to get Tokio to run inside SGX. We had to patch 8 different libraries to get our node to even compile for SGX, but now it works! So we will continue using lightning-net-tokio.

TheBlueMatt commented 2 years ago

Oh, interesting. Is there a reason you didn't stick with the lightning-net crate you'd built?

MaxFangX commented 2 years ago

Well, since we can and are using Tokio, everything integrates a lot nicer if the networking stack uses Tokio too. We don't have to dynamically enter a runtime so that async code can run within a std::thread::spawn() closure. And if we can avoid the overhead of two threads per connection, why not.