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

fix: Create trade after finished dlc protocol #2084

Merged
merged 4 commits into from Feb 28, 2024

Conversation

holzeis
Copy link
Contributor

@holzeis holzeis commented Feb 22, 2024

This patch introduces the contract transaction, which reflects the state of the dlc protocol.

A contract transaction starts with one of the following dlc protocols

  • offer channel
  • offer collaborative settle
  • renew offer
  • offer collaborative close
  • force closure

The contract txid is used as a reference id for the offer channel, offer collaborative settle and renew offer protocols. Once the final message of the protocol is received, the contract transaction gets updated with the latest dlc ids and creates the corresponding trade.

orderbook=# select id, previous_txid, contract_txid, channel_id, contract_id, transaction_state from contract_transactions;
 id |            previous_txid             |            contract_txid             |                            channel_id                            |                           contract_id                            | transaction_state
----+--------------------------------------+--------------------------------------+------------------------------------------------------------------+------------------------------------------------------------------+-------------------
  1 |                                      | 996ef088-f30c-4b9a-b386-9dd502416777 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eba735ded90d3db6516d8260a1361d69f32da484b1b3b0a8e7612ae42f8768fe | Success
  2 | 996ef088-f30c-4b9a-b386-9dd502416777 | caf1335c-be7f-478e-aadb-e996055a8668 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eba735ded90d3db6516d8260a1361d69f32da484b1b3b0a8e7612ae42f8768fe | Success
  3 | caf1335c-be7f-478e-aadb-e996055a8668 | 06d443f1-17e7-4536-8640-e4ff7ac79b91 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | 402ac89527d6aa15c26fc550c21390b5d603e645b37358c3dd8e1c22230de826 | Success
  4 | 06d443f1-17e7-4536-8640-e4ff7ac79b91 | 322f3e46-4817-4c57-b8a6-3f641f800988 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | 402ac89527d6aa15c26fc550c21390b5d603e645b37358c3dd8e1c22230de826 | Success
  5 | 322f3e46-4817-4c57-b8a6-3f641f800988 | 535303e3-d00f-4a13-9cab-6998b629be42 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eceef4e5a6a3b7c81500f70379a807c66d61468496850b1b06a74884f5be7395 | Success

Note, the trade params are temporarily stored to the trade_params table so that the trade can be created correctly.

Depends on the following rust-dlc changes

@holzeis holzeis self-assigned this Feb 22, 2024
@holzeis holzeis linked an issue Feb 22, 2024 that may be closed by this pull request
@holzeis holzeis force-pushed the chore/record-contract-transactions branch from 8a58950 to e80b8cc Compare February 22, 2024 11:52
@holzeis
Copy link
Contributor Author

holzeis commented Feb 26, 2024

Note, rollovers will change the contract but are currently not get captured in a contract transaction. I will work on that once I got an approval on this change.

@holzeis holzeis requested a review from bonomat February 26, 2024 09:36
@holzeis holzeis force-pushed the chore/record-contract-transactions branch from 8f2c78a to c344472 Compare February 26, 2024 09:36
@holzeis
Copy link
Contributor Author

holzeis commented Feb 26, 2024

Note, this change will add the reference id to the dlc messages, thus affecting the hash of the dlc message. Any last dlc messages will those get processed again. In my testing this didn't lead to any issues, however, we might want to consider reverting adding the reference id to the dlc message for now, since it is not really needed at the moment.

Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

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

I like it! With some new names and a ProtocolId type I would be very happy.

coordinator/src/contract.rs Outdated Show resolved Hide resolved
crates/ln-dlc-node/src/util.rs Outdated Show resolved Hide resolved
crates/ln-dlc-node/src/util.rs Outdated Show resolved Hide resolved
crates/ln-dlc-node/src/util.rs Outdated Show resolved Hide resolved
crates/ln-dlc-node/src/util.rs Outdated Show resolved Hide resolved
@luckysori
Copy link
Contributor

Note, this change will add the reference id to the dlc messages, thus affecting the hash of the dlc message. Any last dlc messages will those get processed again. In my testing this didn't lead to any issues, however, we might want to consider reverting adding the reference id to the dlc message for now, since it is not really needed at the moment.

Let's keep the change, as discussed 🙏

@holzeis
Copy link
Contributor Author

holzeis commented Feb 27, 2024

@luckysori please have another look, I've addressed your remarks.

Copy link
Contributor

@luckysori luckysori left a comment

Choose a reason for hiding this comment

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

Looks great! Thanks for taking the time to address my comments ♥️

This patch introduces the contract transaction, which reflects the state of the dlc protocol.

A contract transaction starts with one of the following dlc protocols

- offer channel
- offer collaborative settle
- renew offer
- offer collaborative close
- force closure

The contract txid is used as a reference id for the offer channel, offer collaborative settle and renew offer protocols. Once the final message of the protocol is received, the contract transaction gets updated with the latest dlc ids and creates the corresponding trade.

```
orderbook=# select id, previous_txid, contract_txid, channel_id, contract_id, transaction_state from contract_transactions;
 id |            previous_txid             |            contract_txid             |                            channel_id                            |                           contract_id                            | transaction_state
----+--------------------------------------+--------------------------------------+------------------------------------------------------------------+------------------------------------------------------------------+-------------------
  1 |                                      | 996ef088-f30c-4b9a-b386-9dd502416777 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eba735ded90d3db6516d8260a1361d69f32da484b1b3b0a8e7612ae42f8768fe | Success
  2 | 996ef088-f30c-4b9a-b386-9dd502416777 | caf1335c-be7f-478e-aadb-e996055a8668 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eba735ded90d3db6516d8260a1361d69f32da484b1b3b0a8e7612ae42f8768fe | Success
  3 | caf1335c-be7f-478e-aadb-e996055a8668 | 06d443f1-17e7-4536-8640-e4ff7ac79b91 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | 402ac89527d6aa15c26fc550c21390b5d603e645b37358c3dd8e1c22230de826 | Success
  4 | 06d443f1-17e7-4536-8640-e4ff7ac79b91 | 322f3e46-4817-4c57-b8a6-3f641f800988 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | 402ac89527d6aa15c26fc550c21390b5d603e645b37358c3dd8e1c22230de826 | Success
  5 | 322f3e46-4817-4c57-b8a6-3f641f800988 | 535303e3-d00f-4a13-9cab-6998b629be42 | bfd333e680af603b52340c4e84335c6b9b2fb950363db8a4c77589d494bc8d1e | eceef4e5a6a3b7c81500f70379a807c66d61468496850b1b06a74884f5be7395 | Success
```

Note, the trade params are temporarily stored to the `trade_params` table so that the trade can be created correctly.
@holzeis holzeis force-pushed the chore/record-contract-transactions branch from 37c7d83 to 3c58a99 Compare February 28, 2024 10:14
@holzeis holzeis added this pull request to the merge queue Feb 28, 2024
Merged via the queue into main with commit 7933a96 Feb 28, 2024
20 checks passed
@holzeis holzeis deleted the chore/record-contract-transactions branch February 28, 2024 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The trade record should only be created if the trade was successful
3 participants