I have a question regarding lightning network. It's a bit of a long question so please bear with me.
If have 1 bitcoin in my wallet and buy an item costing that amount from a shop. I leave the shop before they have a confirmation (before it's put into a block).
It's my understanding this would put the shop at risk as i still have the 1 bitcoin technically in my wallet as the transaction with the shop is still floating around in the meme pool.
I could at this point create a new transaction sending the 1 bitcoin to another wallet owned by myself. I could attach a relatively large miner fee to this transaction.
This transaction would probably then get put into a block before the shop transaction. If this happened the shop transaction would now be considered invalid as according to the block chain i now have 0 bitcoin in my wallet.
This is why the shop needs to wait for 1 confirmation before allowing me to walk out of the shop with the purchased item.
The problem here is i could potentially be waiting for around 10 minutes before confirmation is received. Bitcoin isn't exactly user friendly from the shops point of view.
I have heard lightning network solves this issue but i don't fully understand why.
My understanding is to open a LN channel with the shop a transaction is created on the main bitcoin block chain.
This transaction would be saying to take 1 btc from my wallet and 0 btc from the shop's wallet and open a multi sig wallet. My understanding being the multi sig wallet is a temporary address which will remain active until the LN channel is closed. When it's closed a new transaction would be created distributing the funds to my wallet and the shop's wallet depending on where the funds were in the LN channel when the channel was closed.
My question is how do confirmations work with regards to the initial transaction which opened the LN channel? When the LN channel is opened presumably this transaction is in the meme pool.
Can i send the 1 btc to the shop in the LN channel while that transaction is still in the meme pool? If yes then surely it's the same situation as before where i could then create another transaction on the main blockchain for 1 btc and if that transaction gets put into a block before the LN transaction is put into a block then the LN transaction would now be invalid.
Basically i don't understand how LN allows instant payment in a shop while maintaining security of that payment from the shops point of view.
I know i must be not fully understanding how this process works. Can anyone shed some light on this?