WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 69928cb

Browse files
Fix P2P restarts
* implement command channel draining in event loop * remove redundant shutdown controller * Remove events drain until needed --------- Co-authored-by: Aleksandar Terentić <[email protected]>
1 parent 8164f5e commit 69928cb

File tree

6 files changed

+21
-7
lines changed

6 files changed

+21
-7
lines changed

client/src/cli.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use avail_light_core::{
22
network::{Network, ServiceMode},
3-
types::NetworkMode,
3+
types::{KademliaMode, NetworkMode},
44
};
55
use clap::{command, ArgAction, Parser};
66
use tracing::Level;
@@ -85,4 +85,8 @@ pub struct CliOpts {
8585
/// AutoNAT behaviour mode: client, server, or disabled
8686
#[arg(long, value_enum, default_value = "server")]
8787
pub auto_nat_mode: ServiceMode,
88+
89+
/// Kademlia operation mode: client or server
90+
#[arg(long, value_enum, default_value = "client")]
91+
pub operation_mode: Option<KademliaMode>,
8892
}

client/src/main.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,10 @@ pub fn load_runtime_config(opts: &CliOpts) -> Result<RuntimeConfig> {
529529
));
530530
}
531531

532+
if let Some(operation_mode) = opts.operation_mode {
533+
cfg.libp2p.kademlia.operation_mode = operation_mode;
534+
}
535+
532536
Ok(cfg)
533537
}
534538

core/src/network/p2p/client.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[cfg(not(feature = "multiproof"))]
22
use avail_core::kate::{CHUNK_SIZE, COMMITMENT_SIZE};
33
use color_eyre::{
4-
eyre::{eyre, OptionExt, WrapErr},
4+
eyre::{eyre, OptionExt},
55
Result,
66
};
77
use futures::future::join_all;
@@ -112,9 +112,13 @@ impl Client {
112112
}
113113
})?;
114114

115-
response_receiver
116-
.await
117-
.wrap_err("sender should not be dropped")?
115+
response_receiver.await.map_err(|_| {
116+
if self.command_sender.is_closed() {
117+
eyre!("Event loop shut down before command could be processed")
118+
} else {
119+
eyre!("Command handler failed to send response")
120+
}
121+
})?
118122
}
119123

120124
/// Starts listening on provided multiaddresses and saves the listener IDs

core/src/network/p2p/event_loop.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ impl EventLoop {
148148
}
149149

150150
pub async fn run(mut self) {
151+
info!("Running P2P event loop");
151152
// shutdown will wait as long as this token is not dropped
152153
let _delay_token = self
153154
.shutdown
@@ -223,6 +224,7 @@ impl EventLoop {
223224
}
224225
}
225226
self.disconnect_peers();
227+
info!("Exiting P2P event loop");
226228
}
227229

228230
fn disconnect_peers(&mut self) {

core/src/network/p2p/restart.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub async fn init_and_start_p2p_client(
4545
.await?;
4646

4747
// Start the new event loop
48-
spawn_in_span(shutdown.with_cancel(p2p_event_loop.run()));
48+
spawn_in_span(p2p_event_loop.run());
4949

5050
let addrs = vec![libp2p_cfg.tcp_multiaddress()];
5151

core/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl TryFrom<(&AvailHeader, Option<f64>)> for BlockVerified {
127127
}
128128
}
129129

130-
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
130+
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
131131
#[serde(try_from = "String")]
132132
pub enum KademliaMode {
133133
Client,

0 commit comments

Comments
 (0)