mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-24 14:15:55 -04:00
feat (Bob): Buffer transfer proof to database when we are running a different swap (#1669)
This commit is contained in:
parent
4c9d1e8d8d
commit
23a27680a4
11 changed files with 193 additions and 51 deletions
|
@ -32,8 +32,7 @@ async fn concurrent_bobs_before_xmr_lock_proof_sent() {
|
|||
let alice_swap_2 = tokio::spawn(alice::run(alice_swap_2, FixedRate::default()));
|
||||
|
||||
// The 2nd swap ALWAYS finish successfully in this
|
||||
// scenario, but will receive an "unwanted" transfer proof that is ignored in
|
||||
// the event loop.
|
||||
// scenario, but will receive an "unwanted" transfer proof that is buffered until the 1st swap is resumed
|
||||
|
||||
let bob_state_2 = bob_swap_2.await??;
|
||||
assert!(matches!(bob_state_2, BobState::XmrRedeemed { .. }));
|
||||
|
@ -46,15 +45,13 @@ async fn concurrent_bobs_before_xmr_lock_proof_sent() {
|
|||
.await;
|
||||
assert!(matches!(bob_state_1, BobState::BtcLocked { .. }));
|
||||
|
||||
// The 1st (paused) swap is expected to refund, because the transfer
|
||||
// proof is delivered to the wrong swap, and we currently don't store it in the
|
||||
// database for the other swap.
|
||||
// The 1st (paused) swap is expected to finish successfully because the transfer proof is buffered when it is receives while another swap is running.
|
||||
|
||||
let bob_state_1 = bob::run(bob_swap_1).await?;
|
||||
assert!(matches!(bob_state_1, BobState::BtcRefunded { .. }));
|
||||
assert!(matches!(bob_state_1, BobState::XmrRedeemed { .. }));
|
||||
|
||||
let alice_state_1 = alice_swap_1.await??;
|
||||
assert!(matches!(alice_state_1, AliceState::XmrRefunded { .. }));
|
||||
assert!(matches!(alice_state_1, AliceState::BtcRedeemed { .. }));
|
||||
|
||||
Ok(())
|
||||
})
|
||||
|
|
|
@ -427,8 +427,6 @@ impl BobParams {
|
|||
}
|
||||
|
||||
pub async fn new_swap_from_db(&self, swap_id: Uuid) -> Result<(bob::Swap, cli::EventLoop)> {
|
||||
let (event_loop, handle) = self.new_eventloop(swap_id).await?;
|
||||
|
||||
if let Some(parent_dir) = self.db_path.parent() {
|
||||
ensure_directory_exists(parent_dir)?;
|
||||
}
|
||||
|
@ -437,8 +435,10 @@ impl BobParams {
|
|||
}
|
||||
let db = Arc::new(SqliteDatabase::open(&self.db_path).await?);
|
||||
|
||||
let (event_loop, handle) = self.new_eventloop(swap_id, db.clone()).await?;
|
||||
|
||||
let swap = bob::Swap::from_db(
|
||||
db,
|
||||
db.clone(),
|
||||
swap_id,
|
||||
self.bitcoin_wallet.clone(),
|
||||
self.monero_wallet.clone(),
|
||||
|
@ -457,8 +457,6 @@ impl BobParams {
|
|||
) -> Result<(bob::Swap, cli::EventLoop)> {
|
||||
let swap_id = Uuid::new_v4();
|
||||
|
||||
let (event_loop, handle) = self.new_eventloop(swap_id).await?;
|
||||
|
||||
if let Some(parent_dir) = self.db_path.parent() {
|
||||
ensure_directory_exists(parent_dir)?;
|
||||
}
|
||||
|
@ -467,6 +465,8 @@ impl BobParams {
|
|||
}
|
||||
let db = Arc::new(SqliteDatabase::open(&self.db_path).await?);
|
||||
|
||||
let (event_loop, handle) = self.new_eventloop(swap_id, db.clone()).await?;
|
||||
|
||||
db.insert_peer_id(swap_id, self.alice_peer_id).await?;
|
||||
|
||||
let swap = bob::Swap::new(
|
||||
|
@ -487,6 +487,7 @@ impl BobParams {
|
|||
pub async fn new_eventloop(
|
||||
&self,
|
||||
swap_id: Uuid,
|
||||
db: Arc<dyn Database + Send + Sync>,
|
||||
) -> Result<(cli::EventLoop, cli::EventLoopHandle)> {
|
||||
let tor_socks5_port = get_port()
|
||||
.expect("We don't care about Tor in the tests so we get a free port to disable it.");
|
||||
|
@ -503,7 +504,7 @@ impl BobParams {
|
|||
.behaviour_mut()
|
||||
.add_address(self.alice_peer_id, self.alice_address.clone());
|
||||
|
||||
cli::EventLoop::new(swap_id, swarm, self.alice_peer_id)
|
||||
cli::EventLoop::new(swap_id, swarm, self.alice_peer_id, db.clone())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue