405: Concurrent swaps with same peer r=da-kami a=da-kami

Fixes #367 

- [x] Concurrent swaps with same peer

Not sure how much more time I should invest into this. We could just merge the current state and then do improvements on top...?

Improvements:

- [x] Think `// TODO: Remove unnecessary swap-id check` through and remove it
- [x] Add concurrent swap test, multiple swaps with same Bob
- [ ] Save swap messages without matching swap in execution in the database
- [ ] Assert the balances in the new concurrent swap tests
- [ ] ~~Add concurrent swap test, multiple swaps with different Bobs~~
- [ ] ~~Send swap-id in separate message, not on top of `Message0`~~

Co-authored-by: Daniel Karzel <daniel@comit.network>
This commit is contained in:
bors[bot] 2021-04-13 08:50:44 +00:00 committed by GitHub
commit 19766b9759
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 456 additions and 127 deletions

View file

@ -68,6 +68,7 @@ async fn next_state(
let bitcoin_refund_address = bitcoin_wallet.new_address().await?;
let state2 = request_price_and_setup(
swap_id,
btc_amount,
event_loop_handle,
env_config,
@ -106,7 +107,7 @@ async fn next_state(
select! {
transfer_proof = transfer_proof_watcher => {
let transfer_proof = transfer_proof?.tx_lock_proof;
let transfer_proof = transfer_proof?;
tracing::info!(txid = %transfer_proof.tx_hash(), "Alice locked Monero");
@ -259,6 +260,7 @@ async fn next_state(
}
pub async fn request_price_and_setup(
swap_id: Uuid,
btc: bitcoin::Amount,
event_loop_handle: &mut EventLoopHandle,
env_config: &Config,
@ -269,6 +271,7 @@ pub async fn request_price_and_setup(
tracing::info!("Spot price for {} is {}", btc, xmr);
let state0 = State0::new(
swap_id,
&mut OsRng,
btc,
xmr,