Skip to content

Commit d5aa4e9

Browse files
committed
wip
1 parent 819674d commit d5aa4e9

File tree

5 files changed

+315
-228
lines changed

5 files changed

+315
-228
lines changed

polkadot/node/network/availability-distribution/src/metrics.rs

Lines changed: 25 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,15 @@ struct MetricsInner {
5757
/// query further validators.
5858
retries: Counter<U64>,
5959

60-
/// Number of candidates for which we initiated early chunk fetching.
61-
early_candidates_fetched: Counter<U64>,
62-
/// Number of candidates for which we initiated on-time (slow path) chunk fetching.
63-
slow_candidates_fetched: Counter<U64>,
64-
/// Number of early-fetched candidates that never made it on-chain.
65-
early_candidates_never_onchain: Counter<U64>,
66-
67-
/// Number of candidates fetched early that later appeared on slow path, implying we skipped a
68-
/// duplicate fetch when they became occupied.
69-
early_candidates_skipped_on_slow: Counter<U64>,
60+
/// Number of candidates for which we initiated chunk fetching before getting backed on chain (early path).
61+
early_fetched_candidates: Counter<U64>,
62+
63+
/// Number of candidates for which we initiated chunk fetching after getting backed on chain (late path).
64+
late_fetched_candidates: Counter<U64>,
65+
66+
/// Number of early-fetched candidates that appeared on the occupied core as backed,
67+
/// avoiding redundant fetches by reusing existing data.
68+
early_candidates_backed_on_chain: Counter<U64>,
7069
}
7170

7271
impl Metrics {
@@ -111,30 +110,23 @@ impl Metrics {
111110
}
112111

113112
/// Increment early candidates fetched counter.
114-
pub fn on_early_candidate_fetched(&self) {
115-
if let Some(metrics) = &self.0 {
116-
metrics.early_candidates_fetched.inc()
117-
}
118-
}
119-
120-
/// Increment slow candidates fetched counter.
121-
pub fn on_slow_candidate_fetched(&self) {
113+
pub fn on_early_fetched_candidate(&self) {
122114
if let Some(metrics) = &self.0 {
123-
metrics.slow_candidates_fetched.inc()
115+
metrics.early_fetched_candidates.inc()
124116
}
125117
}
126118

127-
/// Increment early candidates that never made it on-chain counter.
128-
pub fn on_early_candidate_never_onchain(&self) {
119+
/// Increment late candidates fetched counter.
120+
pub fn on_late_fetched_candidate(&self) {
129121
if let Some(metrics) = &self.0 {
130-
metrics.early_candidates_never_onchain.inc()
122+
metrics.late_fetched_candidates.inc()
131123
}
132124
}
133125

134-
/// Increment early candidates that later appeared on slow path (duplicate fetch skipped).
135-
pub fn on_early_candidate_skipped_on_slow(&self) {
126+
/// Increment early fetched candidates that later got backed on chain counter.(skipped duplicate fetch)
127+
pub fn on_early_candidate_backed_on_chain(&self) {
136128
if let Some(metrics) = &self.0 {
137-
metrics.early_candidates_skipped_on_slow.inc()
129+
metrics.early_candidates_backed_on_chain.inc()
138130
}
139131
}
140132
}
@@ -189,31 +181,24 @@ impl metrics::Metrics for Metrics {
189181
)?,
190182
registry,
191183
)?,
192-
early_candidates_fetched: prometheus::register(
184+
early_fetched_candidates: prometheus::register(
193185
Counter::new(
194186
"polkadot_parachain_early_candidates_fetched_total",
195-
"Number of candidates for which we initiated early chunk fetching.",
196-
)?,
197-
registry,
198-
)?,
199-
slow_candidates_fetched: prometheus::register(
200-
Counter::new(
201-
"polkadot_parachain_slow_candidates_fetched_total",
202-
"Number of candidates for which we initiated on-time (slow path) chunk fetching.",
187+
"Number of candidates for which we initiated chunk fetching before getting backed on chain (early path).",
203188
)?,
204189
registry,
205190
)?,
206-
early_candidates_never_onchain: prometheus::register(
191+
late_fetched_candidates: prometheus::register(
207192
Counter::new(
208-
"polkadot_parachain_early_candidates_never_onchain_total",
209-
"Number of early-fetched candidates that never made it on-chain.",
193+
"polkadot_parachain_late_fetched_candidates_total",
194+
"Number of candidates for which we initiated chunk fetching after getting backed on chain (late path).",
210195
)?,
211196
registry,
212197
)?,
213-
early_candidates_skipped_on_slow: prometheus::register(
198+
early_candidates_backed_on_chain: prometheus::register(
214199
Counter::new(
215-
"polkadot_parachain_early_candidates_skipped_on_slow_total",
216-
"Number of early-fetched candidates that later appeared on the slow path (duplicate fetch skipped).",
200+
"polkadot_parachain_early_candidates_backed_on_chain_total",
201+
"Number of early-fetched candidates that later got backed on chain (duplicate fetch skipped).",
217202
)?,
218203
registry,
219204
)?,

polkadot/node/network/availability-distribution/src/requester/fetch_task/mod.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,24 @@ mod tests;
6060
pub struct FetchTaskConfig {
6161
prepared_running: Option<RunningTask>,
6262
live_in: HashSet<Hash>,
63+
fetch_type: FetchType,
64+
}
65+
66+
pub enum FetchType {
67+
/// Early fetched erasure coded chunk, before it was backed on-chain.
68+
Early,
69+
/// The candidate successfully got backed on-chain for which we already fetched the chunk
70+
/// early.
71+
EarlyOnChain,
72+
/// Late fetched erasure coded chunk, after it was backed on-chain.
73+
/// The hash represents the block hash where the candidate was backed on chain.
74+
Late(Hash),
6375
}
6476

6577
/// Information about a task fetching an erasure chunk.
6678
pub struct FetchTask {
79+
pub fetch_type: FetchType,
80+
6781
/// For what relay parents this task is relevant.
6882
///
6983
/// In other words, for which relay chain parents this candidate is considered live.
@@ -147,7 +161,7 @@ impl FetchTaskConfig {
147161
///
148162
/// The result of this function can be passed into [`FetchTask::start`].
149163
pub fn new(
150-
leaf: Hash,
164+
fetch_type: FetchType,
151165
core: &CoreInfo,
152166
sender: mpsc::Sender<FromFetchTask>,
153167
metrics: Metrics,
@@ -156,11 +170,14 @@ impl FetchTaskConfig {
156170
req_v1_protocol_name: ProtocolName,
157171
req_v2_protocol_name: ProtocolName,
158172
) -> Self {
159-
let live_in = vec![leaf].into_iter().collect();
173+
let live_in = match fetch_type {
174+
FetchType::Late(block_hash) => vec![block_hash].into_iter().collect(),
175+
_ => vec![].into_iter().collect(),
176+
};
160177

161178
// Don't run tasks for our backing group:
162179
if session_info.our_group == Some(core.group_responsible) {
163-
return FetchTaskConfig { live_in, prepared_running: None };
180+
return FetchTaskConfig { fetch_type, live_in, prepared_running: None };
164181
}
165182

166183
let prepared_running = RunningTask {
@@ -181,7 +198,7 @@ impl FetchTaskConfig {
181198
req_v1_protocol_name,
182199
req_v2_protocol_name
183200
};
184-
FetchTaskConfig { live_in, prepared_running: Some(prepared_running) }
201+
FetchTaskConfig { fetch_type, live_in, prepared_running: Some(prepared_running) }
185202
}
186203
}
187204

@@ -191,17 +208,17 @@ impl FetchTask {
191208
///
192209
/// A task handling the fetching of the configured chunk will be spawned.
193210
pub async fn start<Context>(config: FetchTaskConfig, ctx: &mut Context) -> Result<Self> {
194-
let FetchTaskConfig { prepared_running, live_in } = config;
211+
let FetchTaskConfig { prepared_running, live_in, fetch_type } = config;
195212

196213
if let Some(running) = prepared_running {
197214
let (handle, kill) = oneshot::channel();
198215

199216
ctx.spawn("chunk-fetcher", running.run(kill).boxed())
200217
.map_err(|e| FatalError::SpawnTask(e))?;
201218

202-
Ok(FetchTask { live_in, state: FetchedState::Started(handle) })
219+
Ok(FetchTask { fetch_type, live_in, state: FetchedState::Started(handle) })
203220
} else {
204-
Ok(FetchTask { live_in, state: FetchedState::Canceled })
221+
Ok(FetchTask { fetch_type, live_in, state: FetchedState::Canceled })
205222
}
206223
}
207224

0 commit comments

Comments
 (0)