Git Product home page Git Product logo

rust-lightning's Introduction

Rust-Lightning

Crate Documentation Safety Dance Security Audit

LDK/rust-lightning is a highly performant and flexible implementation of the Lightning Network protocol.

The primary crate, lightning, is runtime-agnostic. Data persistence, chain interactions, and networking can be provided by LDK's sample modules, or you may provide your own custom implementations. More information is available in the About section.

Status

The project implements all of the BOLT specifications, and has been in production use since 2021. As with any Lightning implementation, care and attention to detail is important for safe deployment.

Communications for rust-lightning and Lightning Development Kit happen through our LDK Discord channels.

Crates

  1. lightning The core of the LDK library, implements the Lightning protocol, channel state machine, and on-chain logic. Supports no-std and exposes only relatively low-level interfaces.
  2. lightning-background-processor Utilities to perform required background tasks for Rust Lightning.
  3. lightning-block-sync Utilities to fetch the chain data from a block source and feed them into Rust Lightning.
  4. lightning-invoice Data structures to parse and serialize BOLT #11 Lightning invoices.
  5. lightning-net-tokio Implementation of the rust-lightning network stack using the Tokio async runtime. For rust-lightning clients which wish to make direct connections to Lightning P2P nodes, this is a simple alternative to implementing the required network stack, especially for those already using Tokio.
  6. lightning-persister Implements utilities to manage rust-lightning channel data persistence and retrieval. Persisting channel data is crucial to avoiding loss of channel funds.
  7. lightning-rapid-gossip-sync Client for rapid gossip graph syncing, aimed primarily at mobile clients.

About

LDK/rust-lightning is a generic library that allows you to build a Lightning node without needing to worry about getting all of the Lightning state machine, routing, and on-chain punishment code (and other chain interactions) exactly correct. Note that LDK isn't, in itself, a node. For an out-of-the-box Lightning node based on LDK, see LDK-sample. However, if you want to integrate Lightning with custom features such as your own chain sync, key management, data storage/backup logic, etc., LDK is likely your best option. Some rust-lightning utilities such as those in chan_utils are also suitable for use in non-LN Bitcoin applications such as Discreet Log Contracts (DLCs) and bulletin boards.

Also check out LDK-node library if you want to easily integrate lightning in your application without taking care of all the boiler plate code.

In general, rust-lightning does not provide (but LDK has implementations of):

  • on-disk storage - you can store the channel state any way you want - whether Google Drive/iCloud, a local disk, any key-value store/database/a remote server, or any combination of them - we provide a clean API that provides objects which can be serialized into simple binary blobs, and stored in any way you wish.
  • blockchain data - we provide a simple block_connected/block_disconnected API which you provide block headers and transaction information to. We also provide an API for getting information about transactions we wish to be informed of, which is compatible with Electrum server requests/neutrino filtering/etc.
  • UTXO management - RL/LDK owns on-chain funds as long as they are claimable as part of a Lightning output which can be contested - once a channel is closed and all on-chain outputs are spendable only by the user, we provide users notifications that a UTXO is "theirs" again and it is up to them to spend it as they wish. Additionally, channel funding is accomplished with a generic API which notifies users of the output which needs to appear on-chain, which they can then create a transaction for. Once a transaction is created, we handle the rest. This is a large part of our API's goals - making it easier to integrate Lightning into existing on-chain wallets which have their own on-chain logic - without needing to move funds in and out of a separate Lightning wallet with on-chain transactions and a separate private key system.
  • networking - to enable a user to run a full Lightning node on an embedded machine, we don't specify exactly how to connect to another node at all! We provide a default implementation which uses TCP sockets, but, e.g., if you wanted to run your full Lightning node on a hardware wallet, you could, by piping the Lightning network messages over USB/serial and then sending them in a TCP socket from another machine.
  • private keys - again we have "default implementations", but users can choose to provide private keys to RL/LDK in any way they wish following a simple API. We even support a generic API for signing transactions, allowing users to run RL/LDK without any private keys in memory/putting private keys only on hardware wallets.

LDK's customizability was presented about at Advancing Bitcoin in February 2020: https://vimeo.com/showcase/8372504/video/412818125

Design Goal

The goal is to provide a fully-featured and incredibly flexible Lightning implementation, allowing users to decide how they wish to use it. With that in mind, everything should be exposed via simple, composable APIs. More information about rust-lightning's flexibility is provided in the About section above.

For security reasons, do not add new dependencies. Really do not add new non-optional/non-test/non-library dependencies. Really really do not add dependencies with dependencies. Do convince Andrew to cut down dependency usage in rust-bitcoin.

Rust-Lightning vs. LDK (Lightning Development Kit)

rust-lightning refers to the core lightning crate within this repo, whereas LDK encompasses rust-lightning and all of its sample modules and crates (e.g. the lightning-persister crate), language bindings, sample node implementation(s), and other tools built around using rust-lightning for Lightning integration or building a Lightning node.

Tagline

"Rust-Lightning, not Rusty's Lightning!"

Contributing

Contributors are warmly welcome, see CONTRIBUTING.md.

Project Architecture

For a rust-lightning high-level API introduction, see ARCH.md.

License is either Apache-2.0 or MIT, at the option of the user (ie dual-license Apache-2.0 and MIT).

rust-lightning's People

Contributors

alecchendev avatar ariard avatar arik-so avatar benthecarman avatar bmancini55 avatar devrandom avatar dr-orlovsky avatar dunxen avatar evanfeenstra avatar g8xsu avatar henghonglee avatar jbesraa avatar jkczyz avatar johncantrell97 avatar jurvis avatar ksedgwic avatar moneyball avatar naumenkogs avatar optout21 avatar rrybarczyk avatar savil avatar shaavan avatar sr-gi avatar thebluematt avatar tnull avatar valentinewallace avatar viktortigerstrom avatar wpaulino avatar wvanlint avatar yuntai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rust-lightning's Issues

Key Management

...is almost entirely unhandled.

Generally, we need the final claim keys (ie channel_monitor_claim_key and channel_close_key) to be provided by the user (probably derived in some reliable way) and the rest are really our internal keys but should be generated from a secret the client gives us.

close_channel() API channel_id parameter

close_channel() expects channel_id, but channel_id is never reported to the client currently. If user_id is unique for each open_channel(), we can use it instead, but it doesn't apply to the fundee side as the user_id will always be zero. I think we can make another API event, ChannelEstablisehd { user_id, channel_id }.

Investigate dropping Arcs for references

We should see if we can take advantage of the borrow checker to drop a bunch of Arcs and hold references in a number of places, may require #80, though. Should also look into nice things like dropping the secp_ctx in Channels and holding a reference to the ChannelManager one, too.

Finish ChannelMonitor case handling and add more testing

There's one or two TODOs in ChannelMonitor to handle all the listed cases, plus some TODOs in channel-force-close in ChannelManager to update ChannelMonitor, and the test in ChannelManager which construct networks, do various things to them, and then check monitor validity should be fleshed out way way more.

try! instead of ?

I see a lot of try! in the code, is there a reason to prefer it over ?

Failure Messages in Onion

Additional payloads for some failure codes are not reported back (e.g. htlc_msat for amount_below_minimum)
And some error checkings are missing - amount_below_msat, expiry_too_soon, expiy_too_far .

Implementation goals or list of TODOs

Hello @TheBlueMatt et al.,

Nice project, I really wanna see the LN daemon written in Rust happen and I wondering if there's a some kind of list of long- and short-term goals (or TODOs) for this particular project so new contributors (and me, hopefully) who know Rust and something about Bitcoin/Cryptography/Distributed would put their hands on and make a contribution.

On the first glance it's kinda hard to see what is already implemented and what should be (for example, list of BOLT's and subsequent tasks/challenges that are implemented/done already and what aren't).

How should `ConfirmationTarget` be used?

The bitcoind's estimatesmartfee method needs a conf_target parameter describing the numbers of blocks the TX should wait, it's the same with btcd's "getinfo" method. Shouldn't ConfirmationTarget have a method called to retrieve the number of blocks desired to wait?

cleanup TODOs in transaction_utils.rs

I was looking into doing this as an easy starter task, but had some questions. https://github.com/rust-bitcoin/rust-lightning/blob/master/src/util/transaction_utils.rs

  1. re: the TODO to make static and put in utils (+ sort inputs).
  • not sure what "make static" would mean for a standalone function? I'm new to rust so probably overlooking some concept.
  • it seems to already be in a utils file, and is called as transaction_utils::sort_outputs. Is there anything else to do (except implement sort_inputs)?
  1. re: the TODO for ordering of scripts shouldn't be len-based.
  • If not len-based, then what should the ordering be based on?
  • I can poke around at other implementations to see what they do, but figured I'd ask first.

Fix [u8; 32]/Sha256dHash/Uint256 type mess

Right now all three are used interchangably in a few places, which is nonsense and just leads to confusion. Probably switch to Sha256dHash when things are actually Sha256dHashes (mostly block hashes and txids) and use our own types for most other things, or just [u8; 32] when it makes sense.

Error message deserialization/handling

We currently drop all error messages, which we (a) shouldn't do (we need to log them) and (b) shouldn't do (need to close the channel referenced in the error message).

ChainWatchInterface incompatible with proposed BIP158 filters

ChainWatchInterface offers filter by spent outpoint. These are no longer available in proposed BIP158 base filter. Instead only filter by spent script possible. Please change interface otherwise the lightning node will depend on full nodes not using filters.

BOLT 10 DNS

Need to investigate exposing enough to let clients implement DNS querying for address bootstrap without tracking all the details of BOLT 10.

Explore DoS banning

I presume this would be a HandleError action specific to particularly-bad peers, but may need some kind of tracking of how much a peer is doing something bad, and also need to keep score by remote address, not just pubkey.

Make network bootstrapping smarter

Right now we just download a full route db dump from the first few nodes we connect to. This works but is really, really bad. We should be way smarter, as well as persist route db to disk.

Add API to change HTLC relay parameters

I wonder we need user-facing API to update relay parameter for

  • cltv_expiry_delta
  • htlc_minimum_msat
  • fee_base_msat
  • fee_proportional_millionths

and fire channel_update message (if there is actual update). (related to #169?)

While writing test code for #157, I found that it'd be much easier (and more realistic) to actually change channel config to simulate error condition.

Do not claim/reject all inbound HTLCs at once based on preimage/hash

As of #167 we track HTLCs separately as required by BOLT 2 for privacy. However, we currently reject/accept all to-us HTLCs at once when the user gives us a preimage/no-such-preimage callback. This allows an attacker to (in a really race-y way) query us if we are the intended recipient of a payment that was routed through them by simply sending us a small value HTLC with the same hash as the one they saw. This will likely require an API change, and users may end up needing to do something like tracking the expected value of a payment and only fulfilling HTLCs that match the expected value (to the single-msat level).

Redo local channel tracking for route generation

Currently we require users to interrogate ChannelManager for info on non-public local channels, which makes it particularly hard to comply with BOLT 7 "SHOULD accept channel_updates for its own channels (even if non-public), in order to learn the associated origin nodes' forwarding parameters." I think the obvious solution is to track local channels in Router.

Tagging 0.1 so I can call BOLT 7 completed in #129 "with the exception of other 0.1-tagged issues"

Check Bolt 9 specs

This issue tracks BOLT #9: Assigned Feature Flags, this here so we can check all requirements.

  • option_data_loss_protect
  • initial_routing_sync
  • option_upfront_shutdown_script
  • gossip_querie

Some kind of channel autopilot

Probably needs at least #58 so we can bootstrap, but once we have a node db, figuring out some "suggested channels" for clients would be really cool.

Implement a Config interface

Was thinking of the new TODO in channel about optional additional constraints, the user should be able to configure them easily if not opting for default policy. So need a Config interface we can pass everywhere, with a lock, and that can be updated on-fly

Prune old ChannelMonitor in SimpleManyChannelMonitor

Problem is ChannelMonitor become out-of-date due to different reasons (reorg, revocations, close, ...). We should get them out of SimpleManyChannelMonitor when it's accurate.

I'm afraid that we need to keep all previous state until channel close, I mean that's a good component of LN security model..

just sharing a dump-out

https://gist.github.com/yuntai/9ddc6349df50fcb63c4f4a4dbf5f9484

Not sure it's okay to push this here in the issue list, but wanted to share this dump-out I created for HTLC switching in the payment process across three nodes.
The transcript shows events, messages exchanged and commitment txs. Message() shows the sighash of commitment txs.

At least it was very helpful for me to understand things so I thought it might be so also to other new-comers.

ChainInterface is easy to misuse

In writing https://github.com/TheBlueMatt/rust-lightning-bitcoinrpc I almost misused ChainWatchInterface, almost calling ChannelManager::block_connected and PeerHandler::block_connected instead of only calling ChainWatchInterfaceUtil::block_connected (which will call the others for you).

I'm not actually sure what a better interface looks like. I played around a bit with making some things pub(crate) in chaininterface but couldn't come up with anything I actually liked, sadly.

PaymentSent/PaymentFailed events can be duplicative

This was discovered (and documented) in #208, but its a really terrible API, so should be fixed. I suppose the easy way to do so is to generate these events in response to the commitment_signed dance instead of the initial update_fulfill_htlc message, which I guess is OK, though would be nice to tell the user faster.

Implement update_fee commitment dance and sending

We currently implement update_fee by just updating the local fee, but it needs to do a full commitment dance to get updated (ie we need to store a previous one and a commitment sate of the new one). We also need to implement sending update_fees.

Work through each BOLT and fill out error conditions

Need to make sure we're compliant with all the various actions we're supposed to take as specified in the BOLTs, as well as ensure ErrorActions are always Some() in HandleError. Some of these should be pretty easy, some will be way more involved.

  • BOLT 1
  • BOLT 2
  • BOLT 3
  • BOLT 4
  • BOLT 5
  • BOLT 7
  • BOLT 8
  • BOLT 9

BOLT 10 we don't have any implementation of yet (#58), and BOLT 11 is in rust-lightning-invoice.

Logging Interface

We need to convert the few printlns we have to some kind of user-provided logging interface, as well as add a ton of additional logs. I think its fine if we just make it another Arc<trait> that gets passed around everywhere and we call it directly with lines. Would be nice to avoid the format!() overhead when we dont need it, so maybe we can provide build options to turn off debug logging and avoid most of it?

Handle the Err return in ChannelManager.

It should fail the channel when message handling routines return Err and optionally send an error message to the peer, but it currently doesn't.

//TODO: Handle errors and close channel (or so)

block_connected panic if channel failed open_channel (or waiting on response to open_channel)

We panic in the channe.rs:1814 panic after failing the self.channel_state < ChannelState::FundingCreated as u32 check in channel_monitor(&self) when called from channelmanager's block_connected if channel.channel_monitor().would_broadcast_at_height(height) { line. Just filing an issue and not fixing yet (which is an obvious fix) cause I want to wait and see if the new fuzz testing changes I have pending will catch this first (they should, pretty trivially).

Hardening the Logger interface against DoS

Add RemoteDOSError and maybe others kind of log levels for logs which can be triggered in an infinite quantity by a remote peer. Add also warning comments for logger implementers on how to avoid (rate-limit it, ring-buffer)
#rust-bitcoin 16 Aug 2018 22:52

channel_reserve_satoshis variable names confusing

In the spec,

channel_reserve_satoshis is the minimum amount that the other node is to keep as a direct payment.

And, as my understanding, this means it's the value that the node receiving Open/AcceptChannel should keep.

We do channel.thier_channel_reserve_satoshis = msg.channel_reserve_satoshis
So channel.their_channel_reserve_satoshis is used when checking conditions for our channel reserve and I found it pretty confusing.

Perhaps,
channel.our_channel_reserve_satoshis = msg.channel_reserve_satoshis
and
Channel::get_their_channel_reserve_satoshis is better?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.