Skip to content
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

macaroons: initial implementation of macaroon based accounting #2390

Closed
wants to merge 8 commits into from

Conversation

guggero
Copy link
Collaborator

@guggero guggero commented Dec 31, 2018

In this PR we add a new accounting system to the macaroons package.
This first implementation only partially satisfies the features requested in #291 but further PRs will follow.

As we introduce it in this first PR, an account is a simple construct that has a balance and an optional expiration date. The balance represents satoshis that can be spent by the "owner" of the account.
Every invoice that is paid from/with an account reduces the balance of that account by the payment amount plus fees.
Once the balance of an account is 0, further payments will be refused from/with that account.

Applying an account to a macaroon is a restriction. The bearer of a macaroon that is locked to an account will only be able to spend at most as many satoshis as the account's balance.
If a macaroon is not locked to an account, there is no restriction.

Accounts only assert a maximum amount spendable. Having a certain account balance does not guarantee that the node has the channel liquidity to actually spend that amount.

There are three commands in lncli that can be used to manage accounts:

  • createaccount balance [expiration_date] Creates a new account with the given balance and the optional expiration date.
  • listaccounts Lists all accounts that are currently stored in the account
    database.
  • removeaccount id Removes the account with the given ID.

Example output of listaccounts:

{
    "accounts": [
        {
            "id": "945ab38d3890c267",
            "initial_balance": "100",
            "current_balance": "100",
            "last_update": "1546254113",
            "expiration_date": "0"
        }
    ]
}

A new macaroon that is locked to an account can then be created using the delegatemacaroon command:
lncli --macaroonpath /some/dir/payment.macaroon delegatemacaroon --save_to /some/dir/account.macaroon --account_id abcdef01abcdef01
Of course this only makes sense if we can create a macaroon that is only allowed to pay invoices, once #1160 is merged.

With this first version there are several limitations that will be addressed in further PRs:

  • Accounts cannot be replenished.
  • Only payment methods (SendPayment, SendPaymentSync, SendToRoute and SendToRouteSync) are currently checked for the account constraint. It can be discussed if the ListAccounts method should only show the current account when the macaroon is locked to an account.
  • There is no link between accounts and the payments that have been paid from/with them.
  • There are no accounts with on-chain balance.
  • There are no accounts with a periodic balance (e.g. for subscription payments).

Depends on #1147 and #1152 (the first three commits of this PR will be removed as soon as these two PRs are merged to master).

@guggero guggero changed the title Initial implementation of macaroon based accounting macaroons: initial implementation of macaroon based accounting Dec 31, 2018
@guggero guggero force-pushed the macaroon-accounting branch 2 times, most recently from 1768f07 to faa09f9 Compare December 31, 2018 12:50
@Roasbeef Roasbeef added enhancement Improvements to existing features / behaviour macaroons P3 might get fixed, nice to have labels Jan 2, 2019
@guggero guggero force-pushed the macaroon-accounting branch from faa09f9 to 36d9124 Compare January 4, 2019 07:55
@aakselrod aakselrod self-assigned this Jan 15, 2019
@guggero guggero force-pushed the macaroon-accounting branch 2 times, most recently from 15901d4 to f23612e Compare February 22, 2019 11:03
@guggero guggero force-pushed the macaroon-accounting branch 2 times, most recently from e73261e to 40dd237 Compare April 17, 2019 13:27
@guggero guggero force-pushed the macaroon-accounting branch from 40dd237 to 0c59b43 Compare May 26, 2019 12:51
@guggero guggero force-pushed the macaroon-accounting branch from 0c59b43 to d062ebe Compare June 4, 2019 06:48
@guggero guggero force-pushed the macaroon-accounting branch from d062ebe to 4b550d7 Compare September 30, 2019 08:05
@guggero guggero force-pushed the macaroon-accounting branch from 4b550d7 to 5226a34 Compare January 27, 2020 09:15
@guggero
Copy link
Collaborator Author

guggero commented Mar 5, 2020

Realized this probably shouldn't be built into lnd itself but some kind of wrapper library. Will continue working on this in a different context.

@guggero guggero closed this Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvements to existing features / behaviour macaroons P3 might get fixed, nice to have
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants