swap_setup instead of spot_price and execution_setup

Having `spot_price` and `execution_setup` as separate protocols did not bring any advantages, but was problematic because we had to ensure that `execution_setup` would be triggered after `spot_price`. Because of this dependency it is better to combine the protocols into one.

Combining the protocols also allows a refactoring to get rid of the `libp2p-async-await` dependency.

Alice always listens for the `swap_setup` protocol. When Bob opens a substream on that protocol the spot price is communicated, and then all execution setup messages (swap-id and signature exchange).
This commit is contained in:
Daniel Karzel 2021-06-24 13:54:26 +10:00
parent ada5acb2b5
commit 818147a629
No known key found for this signature in database
GPG key ID: 30C3FC2E438ADB6E
30 changed files with 1063 additions and 1563 deletions

View file

@ -224,8 +224,6 @@ async fn start_alice(
) -> (AliceApplicationHandle, Receiver<alice::Swap>) {
let db = Arc::new(Database::open(db_path.as_path()).unwrap());
let current_balance = monero_wallet.get_balance().await.unwrap();
let lock_fee = monero_wallet.static_tx_fee_estimate();
let min_buy = bitcoin::Amount::from_sat(u64::MIN);
let max_buy = bitcoin::Amount::from_sat(u64::MAX);
let latest_rate = FixedRate::default();
@ -233,8 +231,6 @@ async fn start_alice(
let mut swarm = swarm::asb(
&seed,
current_balance,
lock_fee,
min_buy,
max_buy,
latest_rate,
@ -449,18 +445,19 @@ impl BobParams {
) -> Result<(bob::EventLoop, bob::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.");
let mut swarm = swarm::cli(&self.seed, self.alice_peer_id, tor_socks5_port).await?;
let mut swarm = swarm::cli(
&self.seed,
self.alice_peer_id,
tor_socks5_port,
self.env_config,
self.bitcoin_wallet.clone(),
)
.await?;
swarm
.behaviour_mut()
.add_address(self.alice_peer_id, self.alice_address.clone());
bob::EventLoop::new(
swap_id,
swarm,
self.alice_peer_id,
self.bitcoin_wallet.clone(),
self.env_config,
)
bob::EventLoop::new(swap_id, swarm, self.alice_peer_id, self.env_config)
}
}