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

Database & Resume Swap #81

Closed
wants to merge 12 commits into from
Closed

Database & Resume Swap #81

wants to merge 12 commits into from

Conversation

rishflab
Copy link
Member

@rishflab rishflab commented Dec 14, 2020

Rebased @D4nte work on the database onto current master.
Update tests to use event-loop and properly restart.

Notable changes:

  • Refactored the e2e test to have re-usable building blocks to init containers, wallets, and initial state
  • Refactored the network behavior to be stateless (we finally did that 🎉) so we can overcome re-starting issues where the behaviour would need an initial state that is not available
  • Add [role]::recover function next to [role]::swap, (used in tests, to be plugged into CLI so we can recover :)

@da-kami da-kami changed the title Database Database & Recovery Dec 14, 2020
@da-kami da-kami marked this pull request as ready for review December 14, 2020 11:18
@da-kami
Copy link
Member

da-kami commented Dec 14, 2020

Database and recovery done :)
Will adapt the CLI in the morning as small follow-up PR, the recover functions are already in place and just have to be called with the correct params which includes the additional param to pass a db dir in.

For completion we should add balance checks to the happy_path_restart tests. @rishflab would be cool if you could tackle that in the morning. I expect the balances to be correct given that we basically end a happy_path scenario and that test passes with balance checks - but better add them :)

@da-kami
Copy link
Member

da-kami commented Dec 14, 2020

Let's not forget to squash the earlier commits on this branch 😬

@da-kami
Copy link
Member

da-kami commented Dec 14, 2020

The tests pass locally when run individually. When running in CI there was a failure when running the tests that are in same file. Previously those tests had already passed, when there was just one test per file. It could be an initialization issue with the containers, but needs more investigation. I split the tests into multiple files for now to see if that resolves the issue. Maybe @thomaseizinger has an idea what could cause this?

Given that it fails early:

---- given_alice_restarts_after_encsig_is_learned_resume_swap stdout ----
thread 'given_alice_restarts_after_encsig_is_learned_resume_swap' panicked at 'called `Result::unwrap()` on an `Err` value: Failed to receive dial connection from Bob

I would guess it is a setup issue, maybe related to using the same port for listening,

@thomaseizinger
Copy link
Contributor

Yeah you can't have them listen on the same port :)
I would suggest to use the MemoryTransport like we did in comit-rs to not run into this issue.
Alternatively you can listen on TCP port 0 to get one automatically assigned by the OS but that is a bit tricky because you have to get it out again of the NewListenAddress event before you can dial.

Note: I did not read any of the code :)

Copy link
Contributor

@D4nte D4nte left a comment

Choose a reason for hiding this comment

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

I don't think "recovery" is a good terminology because if possible, the swap will continue. I suggest "Resume" instead.

Also, my work was on #83 I will see if I can combine our changes.

Can you please clean-up your commit tree?

@@ -10,6 +10,7 @@ use futures::{
};
use libp2p::request_response::ResponseChannel;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the file name change? this does more than just negotiation.

Copy link
Member

Choose a reason for hiding this comment

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

Does it? I think negotiate is more accurate than execute. We can rename it again, but I think it is not the execution.

Copy link
Contributor

Choose a reason for hiding this comment

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

It provides an abstraction that allows to do one function call per step for the protocol execution.

Look at the functions present in the file, they are not related to "negotiation":

  • wait_for_locked_bitcoin
  • lock_xmr
  • etc

would steps.rs make more sense to you?


recover(bitcoin_wallet, monero_wallet, state).await?;
}
Options::Recover { .. } => todo!("implement this"),
Copy link
Contributor

Choose a reason for hiding this comment

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

What is recover for? Do you mean, resume?

Copy link
Member

Choose a reason for hiding this comment

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

This is the terminology that was previously used in the project. I am happy to rename both the CLI option and the function to resume.

Copy link
Contributor

Choose a reason for hiding this comment

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

The terminology previously used represented a different feature.

Copy link
Member Author

Choose a reason for hiding this comment

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

my vote goes for resume

@da-kami da-kami changed the title Database & Recovery Database & Resum Swap Dec 14, 2020
@da-kami da-kami changed the title Database & Resum Swap Database & Resume Swap Dec 14, 2020
// Bob locks btc and Alice locks xmr. Alice fails to act so Bob refunds. Alice
// then also refunds.
#[tokio::test]
async fn both_refund() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This only tests for Alice to restart and refund. We need a test for Bob to restart to ensure that database save/restore works as expected.

);
let t1_timeout = state3.wait_for_t1(bitcoin_wallet.as_ref());

tokio::select! {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my try I replaced this with futures::future::select. It allows to return a value, the state, removing the triplicate db save and run_until call.

@D4nte D4nte force-pushed the database branch 2 times, most recently from 38a1287 to 1d9aac9 Compare December 15, 2020 00:34
@da-kami
Copy link
Member

da-kami commented Dec 15, 2020

Closing this PR in favor of #85

@da-kami da-kami closed this Dec 15, 2020
@D4nte D4nte deleted the database branch December 18, 2020 01:10
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.

4 participants