mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-09-26 11:21:02 -04:00
Remove passing alice peer id
The usage of the peer id is incorrect as we do not even check it when dialing. For now, we can ignore it. We can then re-introduce it and use it properly at a later stage.
This commit is contained in:
parent
205b879967
commit
744fc625aa
3 changed files with 25 additions and 39 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::{bob::event_loop::EventLoopHandle, SwapAmounts};
|
||||
use anyhow::Result;
|
||||
use libp2p::core::Multiaddr;
|
||||
use libp2p::{core::Multiaddr, PeerId};
|
||||
use rand::{CryptoRng, RngCore};
|
||||
use std::sync::Arc;
|
||||
use xmr_btc::bob::State2;
|
||||
|
@ -12,32 +12,34 @@ pub async fn negotiate<R>(
|
|||
addr: Multiaddr,
|
||||
mut rng: R,
|
||||
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
|
||||
) -> Result<State2>
|
||||
) -> Result<(State2, PeerId)>
|
||||
where
|
||||
R: RngCore + CryptoRng + Send,
|
||||
{
|
||||
tracing::trace!("Starting negotiate");
|
||||
swarm.dial_alice(addr).await?;
|
||||
|
||||
let alice = swarm.recv_conn_established().await?;
|
||||
|
||||
swarm.request_amounts(alice.clone(), amounts.btc).await?;
|
||||
let alice_peer_id = swarm.recv_conn_established().await?;
|
||||
|
||||
swarm
|
||||
.send_message0(alice.clone(), state0.next_message(&mut rng))
|
||||
.request_amounts(alice_peer_id.clone(), amounts.btc)
|
||||
.await?;
|
||||
|
||||
swarm
|
||||
.send_message0(alice_peer_id.clone(), state0.next_message(&mut rng))
|
||||
.await?;
|
||||
let msg0 = swarm.recv_message0().await?;
|
||||
let state1 = state0.receive(bitcoin_wallet.as_ref(), msg0).await?;
|
||||
|
||||
swarm
|
||||
.send_message1(alice.clone(), state1.next_message())
|
||||
.send_message1(alice_peer_id.clone(), state1.next_message())
|
||||
.await?;
|
||||
let msg1 = swarm.recv_message1().await?;
|
||||
let state2 = state1.receive(msg1)?;
|
||||
|
||||
swarm
|
||||
.send_message2(alice.clone(), state2.next_message())
|
||||
.send_message2(alice_peer_id.clone(), state2.next_message())
|
||||
.await?;
|
||||
|
||||
Ok(state2)
|
||||
Ok((state2, alice_peer_id))
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ pub enum BobState {
|
|||
Started {
|
||||
state0: bob::State0,
|
||||
amounts: SwapAmounts,
|
||||
peer_id: PeerId,
|
||||
addr: Multiaddr,
|
||||
},
|
||||
Negotiated(bob::State2, PeerId),
|
||||
|
@ -118,10 +117,9 @@ where
|
|||
BobState::Started {
|
||||
state0,
|
||||
amounts,
|
||||
peer_id,
|
||||
addr,
|
||||
} => {
|
||||
let state2 = negotiate(
|
||||
let (state2, alice_peer_id) = negotiate(
|
||||
state0,
|
||||
amounts,
|
||||
&mut swarm,
|
||||
|
@ -131,7 +129,7 @@ where
|
|||
)
|
||||
.await?;
|
||||
run_until(
|
||||
BobState::Negotiated(state2, peer_id),
|
||||
BobState::Negotiated(state2, alice_peer_id),
|
||||
is_target_state,
|
||||
swarm,
|
||||
db,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use bitcoin_harness::Bitcoind;
|
||||
use futures::future::try_join;
|
||||
use libp2p::{Multiaddr, PeerId};
|
||||
use libp2p::Multiaddr;
|
||||
use monero_harness::Monero;
|
||||
use rand::rngs::OsRng;
|
||||
use std::sync::Arc;
|
||||
|
@ -51,7 +51,6 @@ async fn happy_path() {
|
|||
alice_swarm_handle,
|
||||
alice_btc_wallet,
|
||||
alice_xmr_wallet,
|
||||
alice_peer_id,
|
||||
) = init_alice(
|
||||
&bitcoind,
|
||||
&monero,
|
||||
|
@ -66,7 +65,6 @@ async fn happy_path() {
|
|||
let (bob_state, bob_swarm_driver, bob_swarm_handle, bob_btc_wallet, bob_xmr_wallet, bob_db) =
|
||||
init_bob(
|
||||
alice_multiaddr,
|
||||
alice_peer_id,
|
||||
&bitcoind,
|
||||
&monero,
|
||||
btc_to_swap,
|
||||
|
@ -149,28 +147,21 @@ async fn alice_punishes_if_bob_never_acts_after_fund() {
|
|||
.parse()
|
||||
.expect("failed to parse Alice's address");
|
||||
|
||||
let (
|
||||
alice_state,
|
||||
mut alice_swarm,
|
||||
alice_swarm_handle,
|
||||
alice_btc_wallet,
|
||||
alice_xmr_wallet,
|
||||
alice_peer_id,
|
||||
) = init_alice(
|
||||
&bitcoind,
|
||||
&monero,
|
||||
btc_to_swap,
|
||||
alice_btc_starting_balance,
|
||||
xmr_to_swap,
|
||||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
)
|
||||
.await;
|
||||
let (alice_state, mut alice_swarm, alice_swarm_handle, alice_btc_wallet, alice_xmr_wallet) =
|
||||
init_alice(
|
||||
&bitcoind,
|
||||
&monero,
|
||||
btc_to_swap,
|
||||
alice_btc_starting_balance,
|
||||
xmr_to_swap,
|
||||
alice_xmr_starting_balance,
|
||||
alice_multiaddr.clone(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let (bob_state, bob_swarm_driver, bob_swarm_handle, bob_btc_wallet, bob_xmr_wallet, bob_db) =
|
||||
init_bob(
|
||||
alice_multiaddr,
|
||||
alice_peer_id,
|
||||
&bitcoind,
|
||||
&monero,
|
||||
btc_to_swap,
|
||||
|
@ -226,7 +217,6 @@ async fn init_alice(
|
|||
alice::event_loop::EventLoopHandle,
|
||||
Arc<swap::bitcoin::Wallet>,
|
||||
Arc<swap::monero::Wallet>,
|
||||
PeerId,
|
||||
) {
|
||||
monero
|
||||
.init(vec![("alice", xmr_starting_balance.as_piconero())])
|
||||
|
@ -277,7 +267,6 @@ async fn init_alice(
|
|||
)
|
||||
};
|
||||
|
||||
let alice_peer_id = alice_behaviour.peer_id();
|
||||
let alice_transport = build(alice_behaviour.identity()).unwrap();
|
||||
|
||||
let (swarm_driver, handle) =
|
||||
|
@ -289,14 +278,12 @@ async fn init_alice(
|
|||
handle,
|
||||
alice_btc_wallet,
|
||||
alice_xmr_wallet,
|
||||
alice_peer_id,
|
||||
)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn init_bob(
|
||||
alice_multiaddr: Multiaddr,
|
||||
alice_peer_id: PeerId,
|
||||
bitcoind: &Bitcoind<'_>,
|
||||
monero: &Monero,
|
||||
btc_to_swap: bitcoin::Amount,
|
||||
|
@ -353,7 +340,6 @@ async fn init_bob(
|
|||
let bob_state = BobState::Started {
|
||||
state0,
|
||||
amounts,
|
||||
peer_id: alice_peer_id,
|
||||
addr: alice_multiaddr,
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue