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

Add caching to HeaderChain struct #5403

Merged
merged 12 commits into from
Apr 10, 2017

Conversation

adrianbrink
Copy link

This is the initial PR for adding caching to the HeaderChain struct.

  • spelling fixes in ethcore-light
  • add reference to docs for LRU cache
  • add member variable cache on HeaderChain

Left todo:

  • use the cache in the methods

#5398

@parity-cla-bot
Copy link

It looks like @adrianbrink hasn'signed our Contributor License Agreement, yet.

The purpose of a CLA is to ensure that the guardian of a project's outputs has the necessary ownership or grants of rights over all contributions to allow them to distribute under the chosen licence.
Wikipedia

You can read and sign our full Contributor License Agreement at the following URL: https://cla.ethcore.io

Once you've signed, plesae reply to this thread with [clabot:check] to prove it.

Many thanks,

Parity Technologies CLA Bot

@@ -408,7 +414,7 @@ impl HeaderChain {
}
}

/// Get the nth CHT root, if it's been computed.
/// Get the nth CHT root, if it has been computed.
Copy link
Contributor

Choose a reason for hiding this comment

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

technically not wrong before but reads better here :)

Copy link
Author

Choose a reason for hiding this comment

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

Reversed

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

//! PIP Protocol Version 1 implementation.
//! PLP Protocol Version 1 implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

No, it really is PIP...

maybe I'll just change the name if it's really confusing :)

Copy link
Author

Choose a reason for hiding this comment

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

But isn't it Parity Lightlient Protocol? I have to say that I find it pretty confusing :-)

Copy link
Author

Choose a reason for hiding this comment

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

Also reversed.

@rphmeier rphmeier added A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. M4-core ⛓ Core client code / Rust. labels Apr 5, 2017
@rphmeier
Copy link
Contributor

rphmeier commented Apr 5, 2017

Thanks! The key method to look at is block_header for utilizing the cache.

return cached
} else {
match self.db.get(self.col, &hash) {
Ok(val) => val.map(|x| x.to_vec()).map(encoded::Header::new),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should write the encoded header into the cache on success.
You can have a different match arm for Ok(Some(header_bytes)) and Ok(None) to handle this cleanly

@rphmeier rphmeier added A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. and removed A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. labels Apr 6, 2017
@adrianbrink
Copy link
Author

I've rebased and now update the cache.

It looks a build verbose due to the fact that insert_block_header() doesn't return the inserted item and hence the extended function block in and_then().

None => {
match self.db.get(self.col, &hash) {
Ok(dbValue) => {
dbValue.map(|x| x.to_vec()).map(encoded::Header::new)
Copy link
Contributor

Choose a reason for hiding this comment

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

last thing: in Rust we usually use snake_case style. So dbValue should be db_value

@rphmeier
Copy link
Contributor

rphmeier commented Apr 6, 2017

Okay, LGTM except for the capitalization issue

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A5-grumble 🔥 Pull request has minor issues that must be addressed before merging. labels Apr 6, 2017
@@ -56,6 +60,8 @@ pub struct Service {
impl Service {
/// Start the service: initialize I/O workers and client itself.
pub fn start(config: ClientConfig, spec: &Spec, path: &Path) -> Result<Self, Error> {
let cache = Arc::new(Mutex::new(Cache::new(Default::default(), Duration::hours(6))));
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be given a cache, which should be the same one given to OnDemand and RPC in parity/run.rs

@rphmeier rphmeier 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 7, 2017
@adrianbrink
Copy link
Author

@rphmeier Rebased and fixed up parity/run.rs to now use the same Cache. However, currently we are passing the cache size down but I don't think it is used. I can try and fix that in another PR.

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

rphmeier commented Apr 7, 2017

Thanks!

LGTM, seems like some random other changes have gotten mixed into the diff, though.
Also, the CI doesn't appear to have run...

@adrianbrink
Copy link
Author

Anything that I should fix? Aren't those other changes from me rebasing?

@gavofyork
Copy link
Contributor

will push this as a branch in our repo to get the fire

@gavofyork
Copy link
Contributor

see #5428

@rphmeier rphmeier added A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. and removed A8-looksgood 🦄 Pull request is reviewed well. labels Apr 7, 2017
@rphmeier
Copy link
Contributor

rphmeier commented Apr 7, 2017

Looks like there are some test build failures.
Can you make changes so running test.sh builds and completes successfully? Maybe set CARGO_INCREMENTAL=1 for faster compilation.

@adrianbrink
Copy link
Author

Just noticed. I'll fix it now and then I'll update the PR. And also, I'll run the test script. Before I only ran the tests for the light_client crate.

@adrianbrink adrianbrink force-pushed the adrian-lightclientcache branch from f954818 to 144d6c2 Compare April 7, 2017 19:38
@adrianbrink
Copy link
Author

adrianbrink commented Apr 7, 2017

@gavofyork @rphmeier
The tests in ./test.sh are all passing now locally. Could you trigger a 2nd CI build.

Also, do any of you have a good guide on how to handle rebasing when using a forking approach to git? I have rebased again but it is always messy to rebase against the upstream(parity)/master and then follow that with a rebase against origin/adrian-lightclientcache.

@adrianbrink
Copy link
Author

Also, is there a way to speed up the tests for the entire parity build?

I'm running them with CARGO_INCREMENTAL=1 ./test.sh on a MBP 13" and it takes around 5 min. :-)

@rphmeier
Copy link
Contributor

rphmeier commented Apr 7, 2017

Usually we just git merge against the latest master rather than rebase because it's clean.

And that's about as fast as the tests get :)

@adrianbrink
Copy link
Author

Okay, that's good to know. I'll switch to git merge next time :-)

@rphmeier rphmeier added A8-looksgood 🦄 Pull request is reviewed well. and removed A7-looksgoodtestsfail 🤖 Pull request is reviewed well, but cannot be merged due to tests failing. labels Apr 10, 2017
@rphmeier rphmeier merged commit 95808f5 into openethereum:master Apr 10, 2017
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