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

chore(dlc_protocol): Track rollovers in dlc protocol table #2125

Merged
merged 8 commits into from
Mar 4, 2024

Conversation

holzeis
Copy link
Contributor

@holzeis holzeis commented Feb 29, 2024

Adds a dlc_protocol_type to the dlc_protocols table, allowing us to show what action triggered the dlc protocol. I opted to adding this enum, as it is helpful in deciding post processing actions, and the renew protocol is used for rollover and opening positions, so it would be ambiguous picking that information from the dlc_messages.

orderbook=# select protocol_type, previous_protocol_id, protocol_id, contract_id, channel_id, protocol_state from dlc_protocols where trader_pubkey='02e66db0280277b35f88b1a1fcf58f8b2208568b6c7ea9eb071d894836865bef63';
 protocol_type |         previous_protocol_id         |             protocol_id              |                           contract_id                            |                            channel_id                            | protocol_state 
---------------+--------------------------------------+--------------------------------------+------------------------------------------------------------------+------------------------------------------------------------------+----------------
 open          |                                      | 6d6a8ded-997e-4ed1-a390-d626f271eee0 | a02000f42e1bee780c81f4e13f4623c0db6b047a9e59b70cf079eedc45b20801 | 990afbeff87f7ef9cd68b7982f35174a2283005d301130c621e4ed15feb2a5e5 | Success
 settle        | 6d6a8ded-997e-4ed1-a390-d626f271eee0 | 47c03bc0-eb46-4edc-96ff-e993d9f382be | a02000f42e1bee780c81f4e13f4623c0db6b047a9e59b70cf079eedc45b20801 | 990afbeff87f7ef9cd68b7982f35174a2283005d301130c621e4ed15feb2a5e5 | Success
 renew         | 47c03bc0-eb46-4edc-96ff-e993d9f382be | 2fd477dd-9a1b-4bd9-a86a-91eda2624415 | f2ff62b546ed3b43cb0031be56c512e3f5b6e4fd8cae89311ecfd4c6f21a6daa | 990afbeff87f7ef9cd68b7982f35174a2283005d301130c621e4ed15feb2a5e5 | Success
 rollover      | 2fd477dd-9a1b-4bd9-a86a-91eda2624415 | ad913883-bda0-4ffd-934e-df25610c08ae | 3336fd8a8b07d88dd1e5ab39f7b356f32db8d17f78d65f0f7214fd73caafad8f | 990afbeff87f7ef9cd68b7982f35174a2283005d301130c621e4ed15feb2a5e5 | Success
 settle        | ad913883-bda0-4ffd-934e-df25610c08ae | c22adca5-cc5b-4e1d-9ef9-33bf5e4aeee5 | 3336fd8a8b07d88dd1e5ab39f7b356f32db8d17f78d65f0f7214fd73caafad8f | 990afbeff87f7ef9cd68b7982f35174a2283005d301130c621e4ed15feb2a5e5 | Success

@holzeis holzeis requested review from bonomat and luckysori February 29, 2024 15:26
@holzeis holzeis self-assigned this Feb 29, 2024
@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from a5fbfb1 to 8e79dac Compare February 29, 2024 15:27
@holzeis holzeis linked an issue Feb 29, 2024 that may be closed by this pull request
@luckysori
Copy link
Contributor

luckysori commented Mar 1, 2024

@holzeis: Can we close #2107 with this PR? It's not the same solution, but I think what you are doing here is what I suggested originally anyway.

@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from 4e5e736 to f3d91d6 Compare March 1, 2024 08:24
@holzeis
Copy link
Contributor Author

holzeis commented Mar 1, 2024

@holzeis: Can we close #2107 with this PR? It's not the same solution, but I think what you are doing here is what I suggested originally anyway.

Yes, although we might want to keep it as i think it could be useful to have a link from the dlc_protocol to the dlc_messages. But its definitely less of a priority with this now.

@holzeis holzeis linked an issue Mar 1, 2024 that may be closed by this pull request
@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from e30a9f8 to 9dc885d Compare March 1, 2024 11:24
@holzeis holzeis linked an issue Mar 4, 2024 that may be closed by this pull request
@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from 9dc885d to 744a63d Compare March 4, 2024 08:15
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 think this makes sense overall, but I would like to read your responses before approving explicitly.

coordinator/src/node.rs Outdated Show resolved Hide resolved
crates/ln-dlc-node/src/node/dlc_channel.rs Show resolved Hide resolved
coordinator/src/dlc_protocol.rs Show resolved Hide resolved
coordinator/src/db/positions.rs Show resolved Hide resolved
coordinator/src/dlc_protocol.rs Outdated Show resolved Hide resolved
coordinator/src/dlc_protocol.rs Outdated Show resolved Hide resolved
coordinator/src/dlc_protocol.rs Outdated Show resolved Hide resolved
coordinator/src/node.rs Show resolved Hide resolved

let protocol_executor =
dlc_protocol::DlcProtocolExecutor::new(self.pool.clone());
protocol_executor.finish_dlc_protocol(
protocol_id,
&node_id,
&contract_id,
channel.get_contract_id(),
Copy link
Contributor

Choose a reason for hiding this comment

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

🔧 Maybe we could just add a comment (and a named variable) for all these.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean. Do you want a separate variable for the contract_id?

@@ -89,6 +90,34 @@ async fn can_open_close_open_close_position() {
.unwrap();
tracing::info!(%app_off_chain_balance, "Opened second position");

// rolling over before closing the second position reproduces https://github.com/get10101/10101/issues/2126
Copy link
Contributor

Choose a reason for hiding this comment

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

🙃 Probably controversial, but could we add a dedicated test? I suppose the problem would happen with the first position too. It's a bit of an arbitrary spot to do this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think the test is no longer reproducing the issue because the issue is already fixed by now. Can you adapt the comment? I was a bit confused with the wording.

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 think this is fine after thinking a bit more about this thread: https://github.com/get10101/10101/pull/2125/files#r1511020380.

@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from 744a63d to 1d5388a Compare March 4, 2024 14:28
holzeis added 8 commits March 4, 2024 15:29
This allows us to track easily in the database what action triggered the dlc protocol.
chore(settle): Disregard additional check if contract is actually closed.

This is the responsibility of `rust-dlc`. Removing this check as it adds unnecessary complexity. We can assume that if `rust-dlc` successfully processed the `ChannelMessage::SettleFinalize` that the contract got closed.
@holzeis holzeis force-pushed the chore/add-rollover-to-protocols-table branch from 1d5388a to b2b0e3f Compare March 4, 2024 14:29
@holzeis holzeis added this pull request to the merge queue Mar 4, 2024
Merged via the queue into main with commit 87c8c0f Mar 4, 2024
20 checks passed
@holzeis holzeis deleted the chore/add-rollover-to-protocols-table branch March 4, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants