Coder Social home page Coder Social logo

interledgerjs / settlement-lightning Goto Github PK

View Code? Open in Web Editor NEW
14.0 8.0 4.0 1.3 MB

⚡️ Settle Interledger payments using the Lightning Network

License: Apache License 2.0

JavaScript 3.10% TypeScript 96.90%
ilp interledger lightning lightning-network payment-channel streaming payments

settlement-lightning's Introduction

Interledger Lightning Plugin

NPM Package CircleCI Codecov Prettier Apache 2.0 License

🚨 Expect breaking changes while this plugin is in beta.

Overview

ilp-plugin-lightning enables settlements between Interledger peers using the Lightning Network on Bitcoin. Using the ILP/Stream protocol, payments are chunked down into small increments, which can facilitate faster and more relaible payments compared with native Lightning!

The integration requires an existing Lightning node with connectivity to the greater Lightning network. Note that speed within the Lightning network degrades as two peers have more degrees of separation, and opening a direct channel provides a much faster experience.

Additional information on the Lightning Network is available here.

Install

npm install ilp-plugin-lightning

Requires Node.js 10+.

API

Here are the available options to pass to the plugin. Additional configuration options are also inherited from ilp-plugin-btp if the plugin is a client, and ilp-plugin-mini-accounts if the plugin is a server.

Clients do not settle automatically. Sending Lightning payments can be triggered by invoking sendMoney on the plugin, and the money handler is called upon receipt of incoming payments (set using registerMoneyHandler).

The balance configuration has been simplified for servers. Clients must prefund before sending any packets through a server, and if a client fulfills packets sent to them through a server, the server will automatically settle such that they owe 0 to the client. This configuration was chosen as a default due to it's security and protection against deadlocks.

role

  • Type:
    • "client" to connect to a single counterparty
    • "server" enables multiple counterparties to connect
  • Default: "client"

lnd

  • Required
  • Type: LndOpts
  • Credentials to create a connection to the LND node, or an already constructed LND service

To have the plugin create the connection internally, provide an object with the following properties:

macaroon
  • Required
  • Type: string or Buffer
  • LND macaroon to used authenticate daemon requests as a Base64-encoded string or Buffer (e.g. using fs.readFile)
tlsCert
  • Required
  • Type: string or Buffer
  • TLS certificate to authenticate the connection to the Lightning daemon as a Base64-encoded string or Buffer (e.g. using fs.readFile)
hostname
  • Required
  • Type: string
  • Hostname of the Lightning node
grpcPort
  • Type: number
  • Default: 10009
  • Port of LND gRPC server

For example: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z2NxQ0cwcDFjM1IxYzNNdFRXRmpRbTl2YXkxUQpjbTh0TXk1c2IyTmhiSUlKYkc5allXeG9iM04wZ2dSMWJtbDRnZ3AxYm1sNGNHRmphMlYwaHdSL0FBQUJoeEFBCkFBQUFBQUFBQUFBQUFBQUFBQUFCaHhEK2dBQUFBQUFBQUFBQUFBQUFBQUFCaHhEK2dBQUFBQUFBQUF3bGM5WmMKazdiRGh3VEFxQUVFaHhEK2dBQUFBQUFBQUJpTnAvLytHeFhHaHhEK2dBQUFBQUFBQUtXSjV0bGlET1JqaHdRSwpEd0FDaHhEK2dBQUFBQUFBQUc2V3ovLyszYXRGaHhEOTJ0RFF5djRUQVFBQUFBQUFBQkFBTUFvR0NDcUdTTTQ5CkJBTUNBMGNBTUVRQ0lBOU85eHRhem1keENLajBNZmJGSFZCcTVJN0pNbk9GUHB3UlBKWFFmcllhQWlCZDVOeUoKUUN3bFN4NUVDblBPSDVzUnB2MjZUOGFVY1hibXlueDlDb0R1ZkE9PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg=='
}

maxPacketAmount

  • Type: BigNumber, number, or string
  • Default: Infinity
  • Maximum amount in satoshis above which an incoming ILP packet should be rejected

Bilateral Communication

This plugin uses the Bilateral Transfer Protocol over WebSockets to send messages between peers. Two subprotocols are supported:

peeringRequest

  • Format: [Identity public key], UTF-8 encoded
  • Used for sharing pubkey of our Lightning node with the peer
  • Only shares pubkey, does not attempt to peer over the Lightning network

paymentRequest

  • Format: BOLT11 encoded, then UTF-8 encoded
  • Used to send a invoice to the Interledger peer, so they have the ability to send payments to our instance
  • By default, peers send 20 invoices ahead of time, and share an additional invoice as each invoice expires or is paid

Known Issues

  • LND does not currently support pruning invoices (neither automatically nor manually). As this plugin may generate several invoices per second when a peer is actively streaming money, this can significantly increase the footprint of the LND database.
  • LND may soon support spontaneous payments, which would eliminate the overhead of frequently sharing invoices.
  • The plugin does not perform any accounting for Lightning Network fees.

settlement-lightning's People

Contributors

0xask avatar karzak avatar kincaidoneil avatar michielbdejong avatar roblav96 avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

settlement-lightning's Issues

Generated types fail linting

The generated proto service types rely on @types/long, which fails since it's not a dependency for packages that depend on this.

  • Fix this
  • Add the generated types to the tslint

Bundle LND & Neutrino light client

If no gRPC credentials are supplied, startup LND and Neutrino in the background and generate a new wallet.

Also requires:

  • Mechanism for the connector operator to fund the wallet
  • Way to open direct channels with peers (either automatically or manually)

Troubleshoot LND latency issues

Anecdotally, payments are very slow compared to the ETH/XRP implementations, even with a direct channel between two LND instances operating on the same machine.

  • More formally benchmark this; identify bottlenecks
  • How much does the 1.5 roundtrips when clearing HTLCs affect this?
  • How much latency is from gRPC/notifications of settled invoices?
  • How much does this PR, reducing roundtrips from 1.5 to 0.5 when settling HTLCs, reduce latency?

Retroactively credit incoming payments if notification failed

In the current implementation, the plugin must be online in order to credit an incoming Lightning payment. If the plugin is offline but the LND node is online, the sender may have sent a settlement, but it wouldn't be credited.

There should be a protocol or mechanism to retroactively credit settlements to get peers' balances back in sync if the receiver goes offline, then comes back online, or for some reason they fail to get the notification.

Clients cannot use non public lnd nodes

Description

The current client plugin almost works out of the box with Zap Wallet's bundled lnd node. But requires a small change.

Zap's lnd node doesn't have an external ip address set. This doesn't stop it sending or receiving payments. But causes the plugin to error on connect.

It fails here: https://github.com/interledgerjs/ilp-plugin-lightning/blob/9efe1886b90aed5236e97fbb3ee77a1ddbb82031/src/account.ts#L265
Because uris field of getInfo is empty: https://github.com/interledgerjs/ilp-plugin-lightning/blob/9efe1886b90aed5236e97fbb3ee77a1ddbb82031/src/index.ts#L222

Possible fix

If the external ip isn't known, send just the lnd node's pubKey on connect (instead of the full pubKey plus host ip). Then don't add the client plugin's node as a peer.

Current workaround

  1. Get credentials for Zap's bundled lnd (on macOS):

    <wallet name> is usually wallet-1

  2. Create a channel in zap to the connector's lnd node.

  3. Add a lnd.conf file here ~/Library/Application Support/Zap/lnd/bitcoin/testnet/<wallet name>/lnd.conf with the following:

    [Application Options]
    externalip=<any random ip address>
    

(restart zap)

Max. unsecured amount?

The plugin does not keep track of the unsecured balance. How do you enforce the peer to send a claim before the unsecured balance gets too large?

implement difference with -asym-client

I started this repo by copying some files from ilp-plugin-lnd-asym-client. Then, I changed the base class from ilp-plugin-btp to ilp-plugin-mini-accounts. That should be a good start towards making this a BTP server instead of a BTP client; some other things I will need to fix are:

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.