Skip to content

Commit 7b85674

Browse files
authored
Merge pull request #3862 from autonomys/ageorge95-farmer-hardening
Farmer hardening: ban disconnect, sector download timeout, log colors
2 parents 3ebae62 + 2b0759e commit 7b85674

7 files changed

Lines changed: 29 additions & 2 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ bytesize = "2.3.1"
5353
cc = "1.2.62"
5454
chacha20 = { version = "0.10.0", default-features = false }
5555
clap = "4.6.1"
56+
console = "0.15.11"
5657
core_affinity = "0.8.1"
5758
cpufeatures = "0.3.0"
5859
criterion = { version = "0.8.2", default-features = false }

crates/subspace-farmer-components/src/plotting.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ use tracing::{debug, trace, warn};
4040

4141
const RECONSTRUCTION_CONCURRENCY_LIMIT: usize = 1;
4242

43+
/// Maximum time allowed for a sector download before giving up (retry will continue at the farm level).
44+
const SECTOR_DOWNLOAD_MAX_ELAPSED_TIME: Duration = Duration::from_secs(30 * 60); // 30 minutes
45+
4346
fn default_backoff() -> ExponentialBackoff {
4447
ExponentialBackoff {
4548
initial_interval: Duration::from_secs(15),
4649
max_interval: Duration::from_secs(10 * 60),
47-
// Try until we get a valid piece
48-
max_elapsed_time: None,
50+
max_elapsed_time: Some(SECTOR_DOWNLOAD_MAX_ELAPSED_TIME),
4951
..ExponentialBackoff::default()
5052
}
5153
}

crates/subspace-networking/src/node_runner.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,9 @@ impl NodeRunner {
15421542
self.swarm.behaviour_mut().kademlia.remove_peer(&peer_id);
15431543
self.known_peers_registry
15441544
.remove_all_known_peer_addresses(peer_id);
1545+
1546+
// Immediately disconnect the peer to cancel any in-flight requests.
1547+
let _ = self.swarm.disconnect_peer_id(peer_id);
15451548
}
15461549

15471550
fn register_event_metrics(&mut self, swarm_event: &SwarmEvent<Event>) {

shared/subspace-process/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ include = [
1111
]
1212

1313
[dependencies]
14+
console.workspace = true
1415
fdlimit.workspace = true
1516
futures.workspace = true
1617
supports-color.workspace = true

shared/subspace-process/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ use tracing_subscriber::{EnvFilter, Layer, fmt};
2020
mod tests;
2121

2222
pub fn init_logger() {
23+
// sc_informant and other substrate crates colorize log content via `console`;
24+
// tracing-subscriber 0.3.20+ escapes those embedded ANSI codes into literal `\x1b[`
25+
// text in the message. Turn console color off at the source so nothing is emitted.
26+
console::set_colors_enabled(false);
27+
console::set_colors_enabled_stderr(false);
28+
2329
// TODO: Workaround for https://github.com/tokio-rs/tracing/issues/2214, also on
2430
// Windows terminal doesn't support the same colors as bash does
2531
let enable_color = if cfg!(windows) {

shared/subspace-process/src/tests.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ use crate::run_future_in_dedicated_thread;
44
use std::future;
55
use tokio::sync::oneshot;
66

7+
// Runs on every CI platform (Linux/macOS/Windows). `init_logger` disables console colors so
8+
// substrate's `console`-styled log content is not escaped into literal `\x1b[` text in messages.
9+
#[test]
10+
fn init_logger_disables_console_ansi() {
11+
crate::init_logger();
12+
13+
let styled = format!("{}", console::style("x").white().bold());
14+
assert_eq!(
15+
styled, "x",
16+
"console emitted ANSI after init_logger: {styled:?}"
17+
);
18+
}
19+
720
#[tokio::test]
821
async fn run_future_in_dedicated_thread_ready() {
922
let value = run_future_in_dedicated_thread(|| future::ready(1), "ready".to_string())

0 commit comments

Comments
 (0)