Lightning Network is preferably a scaling solution to the blockchain. It is a routed network of bidirectional payment channels which are connected to each other. Means any user can rout the payment from channel to channel without trusting the intermediate parties and the intermediate parties can earn a small fee for letting the routing of payment through them. However the process will remain trustless.
Suppose there are 5 users: Eoin, Alex, Shepherd, Chris, Robert and there are different channel that connects Eoin to Alex, Alex to Shepherd, Shepherd to Chris, Chris to Robert.
Eoin wants to send 1 BTC to Robert, but he is not connected to Robert directly and he does not want to open a direct channel either, as they may cost more money to open a LN channel. Eoin’s lightning node is connected with Alex’s node and Alex’s node is connected with Shepherd’s node and similarly Shepherd is connected to Chris and Chris is connected to Robert.
So Robert will generate a secret R which only he knows and he hashes it and sends the hash H to Eoin’s node.
Now Eoin will create an HTLC payable to the person who can solve the hash H with a 10 block refund timeout and for an amount 1.003 BTC. The extra amount 0.003 BTC will be used to pay the intermediaries in the LN channel for routing the payment from Eoin to Robert.
So Eoin sends the HTLC to Alex, So if Alex knows the secret to solve the hash H within a timeout of 10 blocks then it will consume 1.003 BTC of Eoin. Alex does not know the secret, so what he will do is that, he will create another HTLC on his payment channel to Shepherd with a commitment of 1.002 BTC who can solve the hash H for 9 blocks. Similarly Shepherd will create another HTLC on his payment channel to Chris with a commitment of 1.001 BTC who can solve the hash for 8 blocks and this process continues and similarly Chris creates another HTLC on his payment channel to Robert with a commitment of 1 BTC who can solve it for 7 blocks.
Now Robert knows the secret value R to solve the hash H, so he can claim the HTLC from Chris. So he sends the secret R to Chris and gets 1 BTC. So now Chris can claim the HTLC committed by Shepherd and earn 0.001 BTC and in similar fashion Shepherd and Alex both can get 0.001 BTC. So in this example, the intermediaries put their lightning channel at stake for routing the payment from Eoin to Robert and for that they earned incentives of 0.001 BTC each. This is how the lightning channel works. So if the secret is known the intermediate nodes can claim back their channel balance along with a fee and if it will not be known then after the timeout, they will get their channel balance. So the nodes have nothing to lose and if they successfully rout a payment through their nodes they can earn an incentive.
"Time Lock" & "hash Lock" verifications in a combination is known as "HTLC"(Hashed Timelock Contract) protocol.
Funds can only be spent after a certain time period. It could be 1 day or 2 days or 7 days etc.
Funds can only be spent after a question hidden by hash is discovered.