Skip to content

Commit 1161b08

Browse files
committed
add new av store message type, send message for early fetches
1 parent e7785b3 commit 1161b08

File tree

3 files changed

+70
-0
lines changed
  • polkadot/node

3 files changed

+70
-0
lines changed

polkadot/node/core/av-store/src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,6 +1232,24 @@ fn process_message(
12321232
},
12331233
}
12341234
},
1235+
AvailabilityStoreMessage::NoteBackableCandidate{ candidate_hash, tx } => {
1236+
let res = note_backable_candidate(
1237+
&subsystem.db,
1238+
&subsystem.config,
1239+
candidate_hash,
1240+
subsystem,
1241+
);
1242+
1243+
match res {
1244+
Ok(_) => {
1245+
let _ = tx.send(Ok(()));
1246+
},
1247+
Err(e) => {
1248+
let _ = tx.send(Err(()));
1249+
return Err(e)
1250+
},
1251+
}
1252+
},
12351253
}
12361254

12371255
Ok(())
@@ -1430,3 +1448,29 @@ fn prune_all(db: &Arc<dyn Database>, config: &Config, now: Duration) -> Result<(
14301448
db.write(tx)?;
14311449
Ok(())
14321450
}
1451+
1452+
fn note_backable_candidate(
1453+
db: &Arc<dyn Database>,
1454+
config: &Config,
1455+
candidate_hash: CandidateHash,
1456+
subsystem: &AvailabilityStoreSubsystem,
1457+
) -> Result<(), Error> {
1458+
let mut tx = DBTransaction::new();
1459+
1460+
if load_meta(db, config, &candidate_hash)?.is_none() {
1461+
let now = subsystem.clock.now()?;
1462+
let meta = CandidateMeta {
1463+
state: State::Unavailable(now.into()),
1464+
data_available: false,
1465+
chunks_stored: bitvec::bitvec![u8, BitOrderLsb0; 0; 12],
1466+
};
1467+
1468+
let prune_at = now + KEEP_UNAVAILABLE_FOR;
1469+
1470+
write_pruning_key(&mut tx, config, prune_at, &candidate_hash);
1471+
write_meta(&mut tx, config, &candidate_hash, &meta);
1472+
}
1473+
1474+
db.write(tx)?;
1475+
Ok(())
1476+
}

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ use futures::{
3131

3232
use polkadot_node_network_protocol::request_response::{v1, v2, IsRequest, ReqProtocolNames};
3333
use polkadot_node_subsystem::{
34+
<<<<<<< Updated upstream
3435
messages::{ChainApiMessage, RuntimeApiMessage, CandidateBackingMessage},
36+
=======
37+
messages::{ChainApiMessage, RuntimeApiMessage, CandidateBackingMessage, AvailabilityStoreMessage},
38+
>>>>>>> Stashed changes
3539
overseer, ActivatedLeaf, ActiveLeavesUpdate,
3640
SubsystemSender,
3741
};
@@ -307,6 +311,19 @@ impl Requester {
307311
?scheduled_cores,
308312
"Adding scheduled cores"
309313
);
314+
let sender = &mut ctx.sender().clone();
315+
for (core_index, core_info) in &scheduled_cores {
316+
let (tx, rx) = oneshot::channel();
317+
sender
318+
.send_message(
319+
AvailabilityStoreMessage::NoteBackableCandidate{ candidate_hash: core_info.candidate_hash, tx },
320+
)
321+
.await;
322+
if let Err(err) = rx.await {
323+
gum::error!(target: LOG_TARGET, "Sending NoteBackableCandidate message failed: {:?}", err);
324+
}
325+
326+
}
310327
self.add_cores(ctx, runtime, leaf, leaf_session_index, scheduled_cores).await?;
311328
}
312329

polkadot/node/subsystem-types/src/messages.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,15 @@ pub enum AvailabilityStoreMessage {
572572
tx: oneshot::Sender<Result<(), ()>>,
573573
},
574574

575+
/// Note that a candidate is backable. Only used by Speculative Availability to signal to Availability Store
576+
/// that it should keep track of this candidate and it is highly likely the candidate will be backed.
577+
NoteBackableCandidate{
578+
/// A hash of the backable candidate.
579+
candidate_hash: CandidateHash,
580+
/// Sending side of the channel to send result to.
581+
tx: oneshot::Sender<Result<(), ()>>,
582+
},
583+
575584
/// Computes and checks the erasure root of `AvailableData` before storing all of its chunks in
576585
/// the AV store.
577586
///

0 commit comments

Comments
 (0)