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

Implement Flash Layer with multi-hop payments #1610

Merged
merged 15 commits into from
Feb 8, 2021

Conversation

AndrejMitrovic
Copy link
Contributor

Revival of #1415 with additional features.

As discussed with @omerfirmak there's still some wrong assumptions made in the code. These will have to be fixed, either in this PR or in a fixup later.

Also there is an occasional test failure, there's some timing assumptions that fail sometimes.

I plan to move the stuff out of test/Flash.d and into a separate class. My goal is for a FullNode / ValidatorNode to also be a FlashNode if they have any funding transactions on the blockchain for which they are a part of. In this way we get some free features like getting the latest gossiped block, transaction validation, etc.

But I want to focus on the internals first before it's capable to run it in release mode.

It's useful for other routines.
It will be needed for non-agora nodes to
be able to connect to agora nodes in the
Flash layer tests.
This class is responsible for maintaining a
single 2-party channel. There may be multiple
channels open between two parties, but the Channel
class only cares about a single channel instance.

The channel's ID is derived from the funding transaction's
UTXO hash. The channel becomes open once the funding
transaction is externalized in the blockchain. The channel
becomes closed once the closing transaction is externalized,
or may alternatively become closed after the externalization
of the trigger / update and settlement transactions.
This `UpdateSigner` class is responsible for
safely signing & collecting settlement and update
transaction pairs.

The settlement multisig must be validated before
the update transaction signature is revealed,
otherwise the node risks having their funds locked
in the channel if this was the first (trigger)
transaction pair.
Some of these may be replaced in the future as HTLC
support is added. Each API endpoint which is expected
to return a value may also return an error code with a
diagonstical message.
The `Scripts` module contains the ability to create
lock scripts for trigger / update transactions,
as well as key-derivation methods for signing &
validating the update & settlement transactions.
These types are used in the API.

They contain the `ChannelState`, the various update / settlement
transaction types, the nonce types used for signing,
balance types for various balance requests and updates,
and a `Result` struct to have a consistent error-handling mechanism.
These are the various error codes which may be
returned by a call to a Flash API endpoint.

Some errors are recoverable, while others signal
that something went wrong. The errors typically
come with an extra diagnostical message.
The `ChannelConfig` contains all of the information necessary
to open a new channel with a peer.

It contains only public information, leaking this data cannot
cause a loss of funds - although it may cause privacy issues.
The invoice is used to route HTLC payments
across the network. The node shares the hash
of a preimage to the party which intends to
pay for the invoice.

The destination node can redeem the payment
if the reveal the secret to the counter-party
of the channel through which the payment
was routed.

The secrets are then revealed in the reverse
path of the payment, thereby updating all
the balances and collecting fees.
These packets ensure that each hop node in
the payment route only knows to decrypt
their own information and may only
route the payment to the next channel.

Note: Currently the size of the onion is not static.
This should be improved for privacy / censorship
reasons (See LN RFC spec).
Currently there are no routing algorithms.
Only the path definition is implemented.
This class takes care of most book-keeping.
A separate control class will be defined
which allows client code to explicitly
create or pay for invoices.
This API can be used to control the flash node,
for example creating new invoices or paying
for existing ones.
Added a bunch of tests. Some of this code
needs to be folded into base classes later.
@omerfirmak
Copy link
Contributor

My goal is for a FullNode / ValidatorNode to also be a FlashNode if they have any funding transactions on the blockchain for which they are a part of

Do we have any intentions to have thin Lightning Nodes as well, in the future?

@AndrejMitrovic
Copy link
Contributor Author

Do we have any intentions to have thin Lightning Nodes as well, in the future?

I suppose that's not a bad idea. There could be an abstract flash node class, with implementations in the LightFlashNode and FullNode / Validator classes. Maybe like that..

@codecov
Copy link

codecov bot commented Feb 8, 2021

Codecov Report

Merging #1610 (92140c1) into flash-layer (f925cd7) will decrease coverage by 50.18%.
The diff coverage is 22.59%.

Impacted file tree graph

@@               Coverage Diff                @@
##           flash-layer    #1610       +/-   ##
================================================
- Coverage        78.71%   28.53%   -50.19%     
================================================
  Files              120       92       -28     
  Lines            10608     6687     -3921     
================================================
- Hits              8350     1908     -6442     
- Misses            2258     4779     +2521     
Flag Coverage Δ
integration 24.75% <22.06%> (?)
unittests 17.46% <31.36%> (-61.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
source/agora/common/BitField.d 75.00% <0.00%> (-22.60%) ⬇️
source/agora/common/Serializer.d 77.27% <ø> (-18.03%) ⬇️
source/agora/consensus/EnrollmentPool.d 20.00% <0.00%> (-65.85%) ⬇️
source/agora/consensus/data/ValidatorBlockSig.d 0.00% <0.00%> (ø)
source/agora/consensus/state/UTXODB.d 73.68% <ø> (-15.21%) ⬇️
source/agora/flash/Channel.d 0.00% <0.00%> (ø)
source/agora/flash/Invoice.d 0.00% <0.00%> (ø)
source/agora/flash/Node.d 0.00% <0.00%> (ø)
source/agora/flash/OnionPacket.d 0.00% <0.00%> (ø)
source/agora/flash/Scripts.d 0.00% <0.00%> (ø)
... and 154 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f21f066...92140c1. Read the comment docs.

Copy link
Contributor

@omerfirmak omerfirmak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets just merge these.

@omerfirmak omerfirmak merged commit bf4abab into bosagora:flash-layer Feb 8, 2021
@AndrejMitrovic
Copy link
Contributor Author

Fastest review in the west.

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

Successfully merging this pull request may close these issues.

2 participants