Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Availability store subsystem #1404

Merged
merged 12 commits into from
Jul 27, 2020
Merged

Availability store subsystem #1404

merged 12 commits into from
Jul 27, 2020

Conversation

montekki
Copy link
Contributor

@montekki montekki commented Jul 14, 2020

No description provided.

@montekki montekki added A3-in_progress Pull request is in progress. No review needed at this stage. B0-silent Changes should not be mentioned in any release notes labels Jul 14, 2020
@montekki montekki changed the title Fs availability store subsystem Availability store subsystem Jul 15, 2020
@montekki montekki added C1-low PR touches the given topic and has a low impact on builders. A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Jul 21, 2020
@montekki montekki marked this pull request as ready for review July 21, 2020 18:13
@montekki montekki requested a review from rphmeier July 21, 2020 18:13
@rphmeier
Copy link
Contributor

@ordian This is the only subsystem that does storage, and all storage updates are atomic.

@montekki montekki requested a review from rphmeier July 24, 2020 05:17
Copy link
Contributor

@coriolinus coriolinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nits, but overall, looks good to me.

// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.

//! Implements a `AvailabilityStoreSubsystem`.
//!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing empty comment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be expanded a bit (:

use AvailabilityStoreMessage::*;
match msg {
QueryAvailableData(hash, tx) => {
let _ = tx.send(available_data(db, &hash).map(|d| d.data));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to swallow send errors? Why not just propagate them?

Comment on lines 666 to 668
Ok(Signal(BlockFinalized(_))) => {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ok(Signal(BlockFinalized(_))) => {
return false;
}
Ok(Signal(BlockFinalized(_))) => {}

We can just let the operation fall through in this case.

let mut db_config = DatabaseConfig::with_columns(columns::NUM_COLUMNS);

if let Some(cache_size) = config.cache_size {
let mut memory_budget = HashMap::new();
Copy link
Contributor

@drahnr drahnr Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let mut memory_budget = HashMap::new();
let mut memory_budget = HashMap::with_capacity(columns::NUM_COLUMNS);

Comment on lines +93 to +96
let mut memory_budget = HashMap::new();

for i in 0..columns::NUM_COLUMNS {
memory_budget.insert(i, cache_size / columns::NUM_COLUMNS as usize);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

Suggested change
let mut memory_budget = HashMap::new();
for i in 0..columns::NUM_COLUMNS {
memory_budget.insert(i, cache_size / columns::NUM_COLUMNS as usize);
}
let val = cache_size / columns::NUM_COLUMNS;
let memory_budget = 0..columns::NUM_COLUMNS.into_iter().map(|i| (i, val) ).collect::<HashMap>();

fn query_inner<D: Decode>(db: &Arc<dyn KeyValueDB>, column: u32, key: &[u8]) -> Option<D> {
match db.get(column, key) {
Ok(Some(raw)) => {
let res = D::decode(&mut &raw[..]).expect("all stored data serialized correctly; qed");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely convinced this is a good idea, should we not rather warn and return a None?

if let Some(data) = available_data(db, candidate_hash) {
let mut chunks = get_chunks(&data.data, data.n_validators as usize)?;
let chunk = chunks.get(index as usize).cloned();
for chunk in chunks.drain(..) {
Copy link
Contributor

@drahnr drahnr Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit cryptic, it uses IntoIterator of Option and the for loop really only does one iteration.

I .map() or .and_then() might be more idiomatic, or did you mean to avoid the closure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, changed the naming of the var; you see here the Option is chunk var and we are draining chunks which are Vec.

futures::pin_mut!(test_fut);
futures::pin_mut!(subsystem);

executor::block_on(future::select(test_fut, subsystem));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is way simpler than I anticipated! 👍

@@ -60,13 +60,16 @@ Messages to and from the availability store.
```rust
enum AvailabilityStoreMessage {
/// Query the PoV of a candidate by hash.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find it a bit unclear what AvailableData here means? The description still refers to the PoV, a bit of elaboration would be helpful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's defined in availability.md

Copy link
Contributor

@drahnr drahnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing big here, looks good! Mostly a code check, not a functional review.

@coriolinus coriolinus mentioned this pull request Jul 24, 2020
Copy link
Member

@ordian ordian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some comments about kvdb usage

node/core/av-store/src/lib.rs Outdated Show resolved Hide resolved
node/core/av-store/src/lib.rs Outdated Show resolved Hide resolved
}

#[cfg(test)]
fn new_in_memory(inner: Arc<dyn KeyValueDB>) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why doesn't it create in_memory db inside the function, I don't see the store used outside?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used in testing so the main idea is that it could be useful to have a handle to the db outside of the store so the test could look into it directly; though it is not used at the moment

@rphmeier
Copy link
Contributor

Needs a rebase. There are 3 PRs worth of commits in here.

@rphmeier rphmeier closed this Jul 24, 2020
@rphmeier rphmeier reopened this Jul 24, 2020
@montekki montekki merged commit b838b38 into paritytech:master Jul 27, 2020
ghost pushed a commit that referenced this pull request Jul 29, 2020
* Apply suggestions from #1364 code review

- use CoreState, not CoreOccupied
- query for availability chunks, not the whole PoV
- create a stub `fn availability_cores`

* link to issue documenting unimplemented

* implement get_availability_cores by adding a new runtime api request

* back out an unrelated change properly part of #1404

* av-store: handle QueryChunkAvailability

* simplify QueryDataAvailability

* remove extraneous whitespace

* compact primitive imports
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants