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

Snapshot chunks packed by size #5318

Merged
merged 3 commits into from
Apr 7, 2017
Merged

Snapshot chunks packed by size #5318

merged 3 commits into from
Apr 7, 2017

Conversation

arkpar
Copy link
Collaborator

@arkpar arkpar commented Mar 28, 2017

No description provided.

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. B0-patch M4-core ⛓ Core client code / Rust. labels Mar 28, 2017
@arkpar arkpar requested a review from rphmeier March 31, 2017 13:34
},
}

// return chainable self
self
}


/// Declare appending the list of unknown size, chainable.
pub fn begin_unbound_list(&mut self) -> &mut RlpStream {
Copy link
Contributor

Choose a reason for hiding this comment

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

"unbounded"

Copy link
Collaborator

@debris debris left a comment

Choose a reason for hiding this comment

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

lgtm

imo, only one assert is needed. The rest of my comments are only suggestions

}

if let Some(pair) = leftover.take() {
account_stream.append_raw_checked(&pair, 1, target_chunk_size);
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you put an assert here?

let len = self.buffer.len() - list.position;
self.encoder().insert_list_payload(len, list.position);
self.note_appended(1);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe not in this pr, but what do you think about moving this logic to a new structure - UnboundedRlpStream? imo, it would reduce complexity

Copy link
Contributor

Choose a reason for hiding this comment

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

It would only make sense if we forced each list to be a separate stream. What would it mean to call begin_list(X) on an UnboundedRlpStream or begin_list_unbounded() on a regular Stream?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a use case when both bounded and unbounded lists are added to the same stream. I'd redesign RlpStream to accept tuples instead of fixed size begin_list()/end_list() and add a variant of append() that accepts an iterator. But that's out of the scope of this PR

}

loop {
match db_iter.next() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

one of those loops could be moved to a new structure -> RlpChunkedStream which returns vec of chunks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Chunking implemented here is too snapshot specific. Itertools::chunks can be used in simpler cases.

@debris debris added A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 5, 2017
@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A6-mustntgrumble 💦 Pull request has areas for improvement. The author need not address them before merging. labels Apr 5, 2017
@debris debris added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 5, 2017

if let Some(pair) = leftover.take() {
let leftover_appended = account_stream.append_raw_checked(&pair, 1, target_chunk_size);
assert!(leftover_appended);
Copy link
Contributor

Choose a reason for hiding this comment

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

prove or remove.

@gavofyork gavofyork added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Apr 5, 2017
@gavofyork
Copy link
Contributor

assert! can panic, can't it?

@arkpar
Copy link
Collaborator Author

arkpar commented Apr 5, 2017

Assert here indicates that this function is used incorrectly (max_chunk_size < ~300 bytes)

@gavofyork
Copy link
Contributor

feel free to keep the assert, but just ensure you prove why it can never happen :)

@arkpar
Copy link
Collaborator Author

arkpar commented Apr 5, 2017

Since this is a public function and the max_chunk_size constant is defined elsewhere the proof would include assumptions external to this module.

@arkpar arkpar added A0-pleasereview 🤓 Pull request needs code review. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Apr 5, 2017
@gavofyork
Copy link
Contributor

if a public function can be called with invalid data such that it'll end up returning meaningless results (or worse having arbitrary side-effects), then it should be detecting such invalid input and failing fast with a Result (invalid input -> Result.Err...).

@rphmeier
Copy link
Contributor

rphmeier commented Apr 6, 2017

@gavofyork

That is now the behavior. Also, I'm not sure it really counts as a "public" function since it's only accessible from the module where the target chunk size constant is declared (and this is what the assertion depends on).

I think either way is fine, either as an assert!(checked_append, "leftover only pushed directly after beginning fresh chunk; qed") or to return an error.

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Apr 7, 2017
@rphmeier rphmeier merged commit 50886fc into master Apr 7, 2017
@arkpar arkpar deleted the snapshot-v2 branch April 7, 2017 12:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants