Good morning Robert,

Since you want a delivery time within 3 blocks or it is free, the last hop has 
to be to your node from the pizza provider, meaning a direct channel between 
you.  And if you already have a channel between you, you probably will want to 
use that channel.  However in principle it would be possible to take multiple 
hops from you to the pizza provider and only require the last hop to be from 
the pizza provider to you.

AMP is probably feasible, if the pizza provider supports getting a list of 
hashes rather than just one, and the pizza delivery person demands all 
preimages before releasing the pizza.

In principle this is no different from any atomic exchange; one can claim this 
is a cross-chain atomic swap, although the so-called "real world" blockchain is 
very insecure and Turing complete and I do not advice transacting on it from a 
security perspective (they literally use manual labor to perform smart contract 
execution on that chain, would you believe that? plus their contracts are 
written in an opaque language that is hard to understand and has lots of 
gotchas; practically speaking only a language lawyer can hack through those).

(just to be clear: the payment algorithm I described is not intended to be 
practical, it merely provides a "3 blocks or it is free" offer that more 
practical payment algorithms do not. In particular the pizza provider will have 
to drop onchain if you send `update_fail_htlc`, automatically closing the 
channel to you, to ensure that the 3-blocks contract is enforced onchain if you 
discooperate)

Regards,
ZmnSCPxj

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On February 26, 2018 12:35 AM, Robert Olsson <rob...@robtex.com> wrote:

> Thank you ZmnSCPxj
>
> `all time is measured in terms of blocks; "minutes" is just a shared human 
> delusion`  goes into by book of quotes
>
> Before I explain this pizza ordering procedure to my grandmum, I must get 
> this straight: do you mean this approach will *not* work on multihop and AMP 
> routes, or were you just simplifying the explanation to make it slightly more 
> probable that I would understand? I do not yet understand every single bit of 
> the workings of lightning, i'm afraid, but I can't see why it wouldn't work :)
>
> Regards
> Robert Olsson
>
> On Sun, Feb 25, 2018 at 5:30 PM, ZmnSCPxj <zmnsc...@protonmail.com> wrote:
>
>> Good morning Robert,
>>
>> Assuming you have a direct channel with the pizza provider, build a route 
>> from you to pizza provider to you.  You route the pizza price + 546 satoshi 
>> (the minimum for a nondust output) to the pizza provider, and the hop from 
>> the pizza provider to you is the 546 satoshi (so that the pizza provider 
>> gets paid the pizza price in total as the "routing fee").
>>
>> You inform the pizza provider the hash of the preimage, which the pizza 
>> provider can check with their node exists as an incoming HTLC and an 
>> outgoing HTLC, with the difference being the pizza price.
>>
>> Further, you set things up so that the HTLC to you expires in 3 blocks, 
>> which means that the pizza provider has to provide the pizza in three blocks 
>> or it is free.  This is the Bitcoin universe and all time is measured in 
>> terms of blocks; "minutes" is just a shared human delusion that is less real 
>> than blockchains.
>>
>> When the pizza is delivered, your provide the preimage to the pizza provider 
>> via standard LN protocol, and when the pizza provider confirms to the 
>> delivery person that the pizza is paid for, the pizza is released to you.
>>
>> Regards,
>> ZmnSCPxj
>>
>> Sent with [ProtonMail](https://protonmail.com) Secure Email.
>>
>> ‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
>> On February 25, 2018 4:19 PM, Robert Olsson <rob...@robtex.com> wrote:
>>
>>> First of all, Laszlo, that was awesome!
>>>
>>> Instead of the part where you proved you had opened a channel, it would be 
>>> awesome to add some escrow-functionality. Such as you get the invoice, and 
>>> then you have a function to *almost* pay it, to verify it works thru the 
>>> network with AMP and all. At that stage they start to make the pizza. And 
>>> when you actually receive your pizza, you just somehow confirm the 
>>> transaction, releasing the funds.
>>> Not sure you would have to prove anything with the preimage to the delivery 
>>> guy. He should get some notification in his phone from his lightningnode 
>>> that it is paid.
>>> If he never shows up you revert it somehow. Not sure how to do that 
>>> technically, but we probably have most things in place for it already.
>>> Start your brains, guys! Things are getting serious, there is pizza at 
>>> stake!
>>>
>>> Best regards
>>> Robert Olsson
>>>
>>> On Sun, Feb 25, 2018 at 3:29 AM, Laszlo Hanyecz <las...@heliacal.net> wrote:
>>>
>>>> I wanted to try out a real trade using lightning network.  I don't know of 
>>>> any pizza places near me that accept lightning bitcoin yet but a friend 
>>>> from London agreed to do it and he sub contracted out the pizza delivery 
>>>> to a local shop.
>>>> In short, I paid bitcoin using the lightning network and he arranged for 
>>>> pizza to be delivered to me.  In this trade my friend is just a middle man 
>>>> that is taking the risk on accepting lightning payments, but it 
>>>> demonstrates the basic premise of how this works for everyday 
>>>> transactions.  It could just as well be the pizza shop accepting the 
>>>> payment directly with their own lightning node.
>>>> I wanted two pizzas and to try to do it as close to atomically as 
>>>> possible.  I didn't want to prepay and end up with no pizza.  As far as I 
>>>> know we don't yet have pizza/bitcoin atomic swap software but we 
>>>> improvised and decided that I would need to provide the payment hash 
>>>> preimage to the delivery driver in order to claim my pizza.  If I can't 
>>>> produce the preimage, proving that I paid, then the pizza would not be 
>>>> handed over and it would be destroyed.  This works because I can't get the 
>>>> preimage without paying the invoice.  I agreed to open a channel and fund 
>>>> it with a sufficient amount for what we estimated the cost would end up 
>>>> being.  After we agreed to these terms my friend was able to verify that I 
>>>> funded a channel on the blockchain, which shows that I at least have the 
>>>> money (bitcoin).  He is taking on some entrepreneurial risk and prepaying 
>>>> his sub contractor to prepare and deliver the pizza to me, but at this 
>>>> point I have not risked my bitcoins, they're just committed to a channel.  
>>>> I was given a bolt11 invoice which I decoded with the c-lightning cli to 
>>>> verify everything was as agreed:
>>>>
>>>> $ ./lightning-cli decodepay lnbc6490u1pdfrjhcpp5jyxuuskqw5
>>>>
>>>> 3apgqvtxa7emcrz5vs0qr2sxjayxv7
>>>>
>>>> jj70jznnl94sdp5x9vycgzrdpjk2um
>>>>
>>>> eypgxj7n6vykzqvfqg3jkcatcv5s9q
>>>>
>>>> 6t60fssxqyzx2qcqpgaue37x27yp3p
>>>>
>>>> n4cr6wuprvwedncz4kavqh83cp3l0v
>>>>
>>>> wfrprj0xj8cedkfmjdzea0xpp0jazf
>>>>
>>>> cyy77cq37ej6d3xvmujmgu56pe56kt
>>>>
>>>> cqa3vcys
>>>> { "currency" : "bc", "timestamp" : 1519504120, "created_at" : 1519504120, 
>>>> "expiry" : 72000, "payee" : "0397b318c5e0d09b16e6229ec5074
>>>>
>>>> 4c8a7a8452b2d7c6d9855c826ff14b
>>>>
>>>> 8fa8b27", "msatoshi" : 649000000, "description" : "1XL Cheesy Pizza, 1 
>>>> Deluxe Pizza", "min_final_cltv_expiry" : 8, "payment_hash" : 
>>>> "910dce42c07523d0a00c59bbecef0
>>>>
>>>> 3151907806a81a5d2199e94bcf90a7
>>>>
>>>> 3f96b", "signature" : "3045022100ef331f195e206219d70
>>>>
>>>> 3d3b811b1d96cf02adbac05cf1c063
>>>>
>>>> f7b1c91847279a402207c65b64ee4d
>>>>
>>>> 167af3042f97449c109ef6011f665a
>>>>
>>>> 6c4ccdf25b4729a0e69ab2f" }
>>>>
>>>> When the pizza delivery arrived, I was asked "What is the preimage?" by 
>>>> the driver.  At this point I paid the invoice and instantly received the 
>>>> preimage in return.
>>>>
>>>> $ ./lightning-cli pay lnbc6490u1pdfrjhcpp5jyxuuskqw5
>>>>
>>>> 3apgqvtxa7emcrz5vs0qr2sxjayxv7
>>>>
>>>> jj70jznnl94sdp5x9vycgzrdpjk2um
>>>>
>>>> eypgxj7n6vykzqvfqg3jkcatcv5s9q
>>>>
>>>> 6t60fssxqyzx2qcqpgaue37x27yp3p
>>>>
>>>> n4cr6wuprvwedncz4kavqh83cp3l0v
>>>>
>>>> wfrprj0xj8cedkfmjdzea0xpp0jazf
>>>>
>>>> cyy77cq37ej6d3xvmujmgu56pe56kt
>>>>
>>>> cqa3vcys
>>>> { "preimage" : "7241e3f185148625894b8887ad459
>>>>
>>>> babd26540fc12124c3a7a96c937d89
>>>>
>>>> da8c1", "tries" : 1 }
>>>>
>>>> In the interest of keeping it simple we agreed that the preimage would 
>>>> just be the first and last 4 characters of the hex string.  So my answer 
>>>> was 7241-a8c1.  I wrote this on a notepad and presented it to the driver 
>>>> who compared it to his own notepad, at which point I was given the pizza.  
>>>> It's probably not a good practice to share the preimage.  The delivery 
>>>> driver didn't have the full string, only enough to verify that I had it.
>>>> How do you get the preimage for your invoice?  In c-lightning you can do 
>>>> it like this:
>>>> $ ./lightning-cli invoice 12345 label description
>>>> { "payment_hash" : "e04dfbd4adc634779b560c8e7072f
>>>>
>>>> 883d5f17a3e32a33603bfc90a86828
>>>>
>>>> 73d44", "expiry_time" : 1519523498, "expires_at" : 1519523498, "bolt11" : 
>>>> "lnbc123450p1pdfyzy6pp5upxlh49
>>>>
>>>> dcc680x6kpj88quhcs02lz737x23nv
>>>>
>>>> qaley9gdq5884zqdqjv3jhxcmjd9c8
>>>>
>>>> g6t0dccqpg802ys4s4z3rpm6d8zvdg
>>>>
>>>> q397wewh5kaz527hnglz9xsmjxfjrh
>>>>
>>>> e3mxq9pp7pqm0pwcwm748tav4am97g
>>>>
>>>> qrvnzxnlw5uxxawgw4vcywgphj26nf
>>>>
>>>> " }
>>>> $ sqlite3 ~/.lightning/lightningd.sqlite
>>>>
>>>> 3 "SELECT quote(payment_key) FROM invoices ORDER BY id DESC LIMIT 1"
>>>> X'D3BE7E68D8B38B15A5194AEA131A
>>>>
>>>> 21429A1987085C95A0631273273546
>>>>
>>>> FF5ED8'
>>>> Then you can verify that it's indeed the correct preimage by hashing it 
>>>> again and comparing it to the payment_hash in the invoice above:
>>>> $ echo "D3BE7E68D8B38B15A5194AEA131A2
>>>>
>>>> 1429A1987085C95A0631273273546F
>>>>
>>>> F5ED8" | xxd -r -p | sha256sum
>>>> e04dfbd4adc634779b560c8e7072f8
>>>>
>>>> 83d5f17a3e32a33603bfc90a868287
>>>>
>>>> 3d44  -
>>>> Note that you should not share the preimage with anyone.
>>>>
>>>> So is there any point to doing this instead of an on chain transaction?  
>>>> For what I described here, probably not.  The goal was just to play around 
>>>> with c-lightning and do something more than shuffling a few satoshi back 
>>>> and forth.  Maybe eventually pizza shops will have their own lightning 
>>>> nodes and I can open channels to them directly.
>>>>
>>>> Some pics of my family enjoying the pizza here:
>>>> [http://eclipse.heliacal.net/~s
>>>>
>>>> olar/bitcoin/lightning-pizza/](http://eclipse.heliacal.net/~solar/bitcoin/lightning-pizza/)
>>>> -Laszlo
>>>>
>>>> _______________________________________________
>>>> Lightning-dev mailing list
>>>> Lightning-dev@lists.linuxfoundation.org
>>>> https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev
_______________________________________________
Lightning-dev mailing list
Lightning-dev@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/lightning-dev

Reply via email to