Timeout Bob's execution-setup after 10 seconds

The execution setup is our only libp2p protocol that doesn't have
a timeout built-in. Hence, if anything fails on Alice's side, we
would wait here forever.

Wrapping the future in a timeout ensures that we fail eventually
if this protocol doesn't succeed.
This commit is contained in:
Thomas Eizinger 2021-03-29 15:52:53 +11:00
parent 5d75f1adba
commit dbe03ba1cf
No known key found for this signature in database
GPG Key ID: 651AC83A6C6C8B96

View File

@ -5,6 +5,7 @@ use anyhow::{Context, Error, Result};
use libp2p::PeerId;
use libp2p_async_await::BehaviourOutEvent;
use std::sync::Arc;
use std::time::Duration;
#[derive(Debug)]
pub enum OutEvent {
@ -42,8 +43,8 @@ impl Behaviour {
state0: State0,
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
) {
self.inner
.do_protocol_dialer(alice, move |mut substream| async move {
self.inner.do_protocol_dialer(alice, move |mut substream| {
let protocol = async move {
tracing::debug!("Starting execution setup with {}", alice);
substream
@ -78,6 +79,9 @@ impl Behaviour {
.await?;
Ok(state2)
})
};
async move { tokio::time::timeout(Duration::from_secs(10), protocol).await? }
})
}
}