refactor(swap): Upgrade libp2p to 0.53.2, reliable retry mechanisms (#109)

Our libp2p version is out of date, and we need to tackle the upgrade even though it's a significant undertaking. This'll also fix some other [issues](https://github.com/UnstoppableSwap/core/issues/95).

## This PR includes the following changes:
- Breaking network protocol change: The libp2p version has been upgraded to 0.53 which includes breaking network protocol changes. ASBs and CLIs will not be able to swap if one of them is on the old version.
- ASB: Transfer proofs will be repeatedly sent until they are acknowledged by the other party. This fixes a bug where it'd seem to Bob as if the Alice never locked the Monero. Forcing the swap to be refunded.
- CLI: Encrypted signatures will be repeatedly sent until they are acknowledged by the other party
- CLI+ASB: Libp2p network errors in request-response protocols are now propagated throught the event loop channels. This allows the caller to retry if an error occurs (e.g timeout)

Closes https://github.com/UnstoppableSwap/core/issues/101, https://github.com/UnstoppableSwap/core/issues/95
This commit is contained in:
binarybaron 2024-11-11 00:14:42 +01:00 committed by GitHub
parent a116c27785
commit c027e51087
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
41 changed files with 4197 additions and 7643 deletions

View file

@ -626,7 +626,7 @@ pub async fn buy_xmr(
)
.await?;
swarm.behaviour_mut().add_address(seller_peer_id, seller);
swarm.add_peer_address(seller_peer_id, seller);
context
.db
@ -816,9 +816,7 @@ pub async fn resume_swap(
// Fetch the seller's addresses from the database and add them to the swarm
for seller_address in seller_addresses {
swarm
.behaviour_mut()
.add_address(seller_peer_id, seller_address);
swarm.add_peer_address(seller_peer_id, seller_address);
}
let (event_loop, event_loop_handle) =
@ -1222,9 +1220,17 @@ where
}
loop {
println!("max_giveable: {}", max_giveable);
println!("bid_quote.min_quantity: {}", bid_quote.min_quantity);
let min_outstanding = bid_quote.min_quantity - max_giveable;
println!("min_outstanding: {}", min_outstanding);
let min_bitcoin_lock_tx_fee = estimate_fee(min_outstanding).await?;
println!("min_bitcoin_lock_tx_fee: {}", min_bitcoin_lock_tx_fee);
let min_deposit_until_swap_will_start = min_outstanding + min_bitcoin_lock_tx_fee;
println!(
"min_deposit_until_swap_will_start: {}",
min_deposit_until_swap_will_start
);
let max_deposit_until_maximum_amount_is_reached =
maximum_amount - max_giveable + min_bitcoin_lock_tx_fee;