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

Peer Protocol for Contract Negotiation Specification #59

Merged
merged 3 commits into from
Sep 8, 2020

Conversation

nkohen
Copy link
Contributor

@nkohen nkohen commented Aug 13, 2020

Re-wrote the Transactions specification to match the new adaptor signature based DLCs and to match the BOLT style.

It is not in its final state but it should be a good starting point to get merged in!

Related to #46

TODO:

  • Test Vectors

Comment on lines +51 to +52
* `contract_info`: ???
* `oracle_info`: ???
Copy link
Contributor

Choose a reason for hiding this comment

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

Can probably port over the way we do these in bitcoin-s?

Copy link
Member

Choose a reason for hiding this comment

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

I think it might depend on the discussion on oracle specifications. It could end up just being a URI.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to think about multi-oracle support here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I'm thinking that will be the version 0 of them but I actually want these to be true TLV types that can very between number of oracles, kinds of oracles (multi-R values for example) etc. Same with contract info and others

Copy link
Member

Choose a reason for hiding this comment

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

Tracked here if I'm not mistaken: #61

Protocol.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Show resolved Hide resolved
- MUST reject the contract.
- MUST NOT broadcast the funding transaction before receipt of a valid `sign_dlc`.
- on receipt of a valid `sign_dlc`:
- SHOULD broadcast the funding transaction.

Copy link
Contributor

@benthecarman benthecarman Aug 13, 2020

Choose a reason for hiding this comment

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

Maybe add something about if the Initiator doesn't see the funding tx in a timely manner, they can exit the DLC by self-spending one of their funding inputs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that should be specified but I believe it belongs in its own doc similar to BOLT 5

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should also include fee-bumping and such in that doc

Ichiro Kuwahara
Thibaut Le Guilly
Nadav Kohen
[ FIXME: Add Authors ]
Copy link
Contributor

@benthecarman benthecarman Aug 13, 2020

Choose a reason for hiding this comment

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

still need the FIXME?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, all the BOLTs have this so I figured in this case I would put it here as unlike the tx doc others have worked on this pretty extensively previously

Copy link
Member

@Tibo-lg Tibo-lg left a comment

Choose a reason for hiding this comment

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

Looks nice! Put quite some comments but maybe many things are just me being confused so sorry in advance if that's the case.

Messaging.md Outdated Show resolved Hide resolved
Messaging.md Show resolved Hide resolved
Messaging.md Show resolved Hide resolved
Comment on lines +51 to +52
* `contract_info`: ???
* `oracle_info`: ???
Copy link
Member

Choose a reason for hiding this comment

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

I think it might depend on the discussion on oracle specifications. It could end up just being a URI.

Messaging.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Show resolved Hide resolved
* [`u16`:`num_funding_inputs`]
* [`num_funding_inputs*funding_input`:`funding_inputs`]
* [`spk`:`change_spk`]
* [`cet_signatures`:`cet_signatures`]
Copy link
Member

Choose a reason for hiding this comment

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

again I feel here the type should be nb_cets*signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we need a label on each signature to point it to what outcome it signs for no? Or I guess we could use ordering explicitly (like copying the structure of the contract info) but this would need to be added to the specification if this were the case. I'll probably hold off judgement until the PR where cet_signatures as a TLV is defined.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I was assuming that the order of signatures and outcomes was corresponding, but I feel this is an acceptable assumption, as I can't think of a reason not to do that.

Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to decide something on this. One reason I can think of to follow your approach is that we might have to split them in several messages in which case having the index can be practical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#76

Protocol.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
* [`chain_hash`:`chain_hash`]
* [`contract_info`:`contract_info`]
* [`oracle_info`:`oracle_info`]
* [`point`:`funding_pubkey`]
Copy link
Contributor

@matthewjablack matthewjablack Aug 14, 2020

Choose a reason for hiding this comment

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

I'm guessing offer_dlc assumes counterparty has already been established (whether off-chain or through an orderbook) since counterparty pubkey is required to derive funding_pubkey

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure what you mean by

counterparty pubkey is required to derive funding_pubkey

as I don't believe this is true.

Regardless though, yes this entire document assumes the existence of some kind of communication layer as is stated at the top of the Messaging doc

Copy link
Contributor

@matthewjablack matthewjablack Aug 18, 2020

Choose a reason for hiding this comment

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

funding_pubkey is a 2-of-2 multisig Script right? So don't you need pubkey of both alice and bob to derive funding_pubkey?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

funding_pubkey is just one party's public key (which is one of the two that goes into the funding script public key)

@nkohen
Copy link
Contributor Author

nkohen commented Aug 14, 2020

Note to self: This was just updated: niftynei/lightning-rfc#1


Various fundamental types are referred to in the message specifications:

* `byte`: an 8-bit byte
Copy link
Contributor

Choose a reason for hiding this comment

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

signed or unsigned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this question doesn't apply to byte, it isn't a number, just 8 bits.

Messaging.md Outdated Show resolved Hide resolved
Messaging.md Outdated Show resolved Hide resolved
2. data:
* [`byte`:`contract_flags`]
* [`chain_hash`:`chain_hash`]
* [`contract_info`:`contract_info`]
Copy link
Contributor

Choose a reason for hiding this comment

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

So how/where is "contract_info" specified? There is an assumption here that peers know how to parse/interpret contract_info? Do we need a similar spec for this just like we are talking about oracles in #55 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Protocol.md Outdated
Comment on lines 78 to 79
* [`u32`:`contract_maturity_cltv`]
* [`u32`:`contract_timeout_cltv`]
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, Matt does have a good point. It might be nice to invalidate refund transactions when contract terms are updated. Perhaps we can use the Lightning penalty mechanism?

- the `chain_hash` value is set to a hash of a chain that is unknown to the receiver.
- the `contract_info` refers to events unknown to the receiver.
- the `oracle_info` refers to an oracle unknown to the receiver.
- it considers `feerate_per_vb` too small for timely processing or unreasonably large.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is implied here, but if the number of funding_inputs is something ridiculous you should reject as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The only time this would lead to a rejection is if the resulting funding transaction would not be valid so I'm not sure I need to say this? Will double check against Lisa's spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

I should have been more specific about what I meant by "valid". In this case I meant valid in terms of relay policy on the bitcoin p2p network. If you want more background on this you look at the AcceptToMemoryPool (ATMP) logic in bitcoin core.

and you should definitely checkout this excellent discussion from @ariard about relay policies on the bitcoin network in the future

bitcoin/bitcoin#14895 (comment)

Protocol.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated

## Validation
This message gives all of the initiator's the signatures, which allows the receiver
Copy link
Contributor

Choose a reason for hiding this comment

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

nit,: initiator -> offerer/maker etc

* B fund amount: confirm that the fund amount matches what was agreed upon.
- if any `signature` is incorrect:
- MUST reject the contract.
- MUST NOT broadcast the funding transaction before receipt of a valid `sign_dlc`.
Copy link
Contributor

Choose a reason for hiding this comment

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

what happens if this is not followed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A free option


#### CET CSV Delay
The number to use as input to the CSV in the [CETs](Transactions.md#outputs-1).
- set undefined bits in `contract_flags` to 0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Above you say they should be ignored, here you say they should be set to 0. Maybe change above to say that it should expect 0 and fail otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that in the current state it is easiest to implement this way but it should change before we have an official v0.1: #74

Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
Messaging.md Outdated Show resolved Hide resolved
Protocol.md Show resolved Hide resolved
Protocol.md Outdated Show resolved Hide resolved
@nkohen
Copy link
Contributor Author

nkohen commented Sep 8, 2020

Relevant open issues:

#76
#74
#73
#72
#69
#62
#61
#60
#53

@nkohen nkohen merged commit b0cbed2 into discreetlogcontracts:master Sep 8, 2020
@Tibo-lg Tibo-lg mentioned this pull request Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants