Bitcoin Forum
May 12, 2024, 05:06:35 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Lightning - Question to understand atomic transactions over the network  (Read 257 times)
Kogs (OP)
Member
**
Offline Offline

Activity: 86
Merit: 26


View Profile
March 07, 2018, 02:35:24 PM
 #1


Hi,

I'm trying to deeply understand how the lightning network is working.

I understand how a payment channel between two nodes works, but I did not find out yet, how a more complex multi hop transaction is working in terms of an atomic transaction.

How does the network make sure, that all nodes are doing the transaction if everything is fine, or that no node is doing the transaction if any problem occurs (for example one of the selected nodes in the route is down).

I understand the network like this.

1) Sender is searching the best route through all nodes to reach the target.
2) Sender is encrypting the selected route node by node (onion routing)
3) Sender send coins to the first node using a payment channel between sender and first node
4) The next node decrypts the follow up node and continue sending coins to the next node over the next payment channel
5) continue with 4 until the target node is reached.

In my understanding, whenever I send something over the payment channel, this transaction is completed and not reversible (this is maybe the point where I'm wrong).
So, when I have 10 nodes in my selected route, and node 5 in my list is down. How does the network make sure, that the 4 nodes before are doing a rollback to give back the coins to the sender, so the sender can try a different route.

An explanation about this missing link I have would be great.

Thank you in advanced.
1715533595
Hero Member
*
Offline Offline

Posts: 1715533595

View Profile Personal Message (Offline)

Ignore
1715533595
Reply with quote  #2

1715533595
Report to moderator
Transactions must be included in a block to be properly completed. When you send a transaction, it is broadcast to miners. Miners can then optionally include it in their next blocks. Miners will be more inclined to include your transaction if it has a higher transaction fee.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715533595
Hero Member
*
Offline Offline

Posts: 1715533595

View Profile Personal Message (Offline)

Ignore
1715533595
Reply with quote  #2

1715533595
Report to moderator
Anti-Cen
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 07, 2018, 07:28:09 PM
 #2

2) Sender is encrypting the selected route node by node (onion routing)

You could be right but how does the sender know what channels are open between each of the banking nodes
to be in a position to plan the route ?

The number of hops needed seems to be about six but the network is not fluid, more like snooker balls
bumping into each other with your money remaining inside the first ledger and this is the reason you end
up having to borrow money in effect to send payments across the network.

Bob and Alice models are never going to work here because the number of hops required would be
measured in hundreds and the Alice's of this world don't have $1m to finance hundreds of channels.

DO Please correct me if I am wrong here because that is my understanding.

Here is the current map if that helps you https://lnmainnet.gaben.win/

Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
Kogs (OP)
Member
**
Offline Offline

Activity: 86
Merit: 26


View Profile
March 08, 2018, 05:36:06 AM
 #3

2) Sender is encrypting the selected route node by node (onion routing)

You could be right but how does the sender know what channels are open between each of the banking nodes
to be in a position to plan the route ?
...
Here is the current map if that helps you https://lnmainnet.gaben.win/

You answer your question by yourself.
With the link you provided you see the complete network. Each node has information about the exact same info like this site has. You know each node in the network with each capacity of every payment channel between two nodes. So by knowing this, the source can make whatever route it wants to reach the target (I think there is a limit of maximum 20 hops).

Different implementations may focus on different strategies to route to the target. But I guess the most will try to find the cheapest route which has enough capacity to send the coins.
achow101
Moderator
Legendary
*
expert
Offline Offline

Activity: 3388
Merit: 6635


Just writing some code


View Profile WWW
March 09, 2018, 01:23:26 AM
Merited by ABCbits (3), DooMAD (2)
 #4

I understand the network like this.

1) Sender is searching the best route through all nodes to reach the target.
2) Sender is encrypting the selected route node by node (onion routing)
3) Sender send coins to the first node using a payment channel between sender and first node
4) The next node decrypts the follow up node and continue sending coins to the next node over the next payment channel
5) continue with 4 until the target node is reached.

In my understanding, whenever I send something over the payment channel, this transaction is completed and not reversible (this is maybe the point where I'm wrong).
So, when I have 10 nodes in my selected route, and node 5 in my list is down. How does the network make sure, that the 4 nodes before are doing a rollback to give back the coins to the sender, so the sender can try a different route.
That's not how payment routing actually works. That's just the messaging protocol to transmit some information between nodes.

The actual payment part works through Hashed Time Locked Contracts (HTLCs). So node A offers a HTLC output to node B. In order for node B to spend from that HTLC (thus being paid by node A), he needs to provide the preimage to some hash in addition to his own signature. After some timeout, node A can take the money back with a signature of his own.

In LN, the HTLCs are used to make the payments between the nodes. They use the same hash so they all have the same hash pre-image required. So if any one HTLC is spent, all HTLCs in the route can be spent since the hash pre-image is revealed during the spend. If the hash preimage is never revealed, then the coins are never sent to the other party. This makes it atomic.

As a shortcut (to avoid on chain transactions for each HTLC) LN uses the onion routing method you described. The hash preimage is given to the recipient by the sender and that is transmitted to each node in the route so that they all have the hash preimage. Once both nodes in the channel have the hash preimage, they resolve the HTLC off chain. If some nodes are not able to transmit the hash preimage to settle the HTLC off chain, then the node that was able to settle with one peer but not the other can settle on-chain, and in doing so, reveals the hash preimage for the remaining nodes to settle (either on chain or off chain, as necessary). That node is incentivized to settle on chain because he would actually be losing money by not settling.

Kogs (OP)
Member
**
Offline Offline

Activity: 86
Merit: 26


View Profile
March 09, 2018, 06:24:20 AM
 #5

That's not how payment routing actually works. That's just the messaging protocol to transmit some information between nodes.

The actual payment part works through Hashed Time Locked Contracts (HTLCs). So node A offers a HTLC output to node B. In order for node B to spend from that HTLC (thus being paid by node A), he needs to provide the preimage to some hash in addition to his own signature. After some timeout, node A can take the money back with a signature of his own.

In LN, the HTLCs are used to make the payments between the nodes. They use the same hash so they all have the same hash pre-image required. So if any one HTLC is spent, all HTLCs in the route can be spent since the hash pre-image is revealed during the spend. If the hash preimage is never revealed, then the coins are never sent to the other party. This makes it atomic.

As a shortcut (to avoid on chain transactions for each HTLC) LN uses the onion routing method you described. The hash preimage is given to the recipient by the sender and that is transmitted to each node in the route so that they all have the hash preimage. Once both nodes in the channel have the hash preimage, they resolve the HTLC off chain. If some nodes are not able to transmit the hash preimage to settle the HTLC off chain, then the node that was able to settle with one peer but not the other can settle on-chain, and in doing so, reveals the hash preimage for the remaining nodes to settle (either on chain or off chain, as necessary). That node is incentivized to settle on chain because he would actually be losing money by not settling.

Thank you for your great answer. This was the missing link I had.
It's now clear for me and I can dig deeper into the details of the lightning protocol/network.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!