-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add caching to HeaderChain struct #5403
Add caching to HeaderChain struct #5403
Conversation
It looks like @adrianbrink hasn'signed our Contributor License Agreement, yet.
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 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. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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 :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also reversed.
Thanks! The key method to look at is |
return cached | ||
} else { | ||
match self.db.get(self.col, &hash) { | ||
Ok(val) => val.map(|x| x.to_vec()).map(encoded::Header::new), |
There was a problem hiding this comment.
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
I've rebased and now update the cache. It looks a build verbose due to the fact that |
None => { | ||
match self.db.get(self.col, &hash) { | ||
Ok(dbValue) => { | ||
dbValue.map(|x| x.to_vec()).map(encoded::Header::new) |
There was a problem hiding this comment.
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
Okay, LGTM except for the capitalization issue |
ethcore/light/src/client/service.rs
Outdated
@@ -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)))); |
There was a problem hiding this comment.
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 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. |
Thanks! LGTM, seems like some random other changes have gotten mixed into the diff, though. |
Anything that I should fix? Aren't those other changes from me rebasing? |
will push this as a branch in our repo to get the fire |
see #5428 |
Looks like there are some test build failures. |
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. |
f954818
to
144d6c2
Compare
@gavofyork @rphmeier 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. |
Also, is there a way to speed up the tests for the entire parity build? I'm running them with |
Usually we just And that's about as fast as the tests get :) |
Okay, that's good to know. I'll switch to |
This is the initial PR for adding caching to the HeaderChain struct.
cache
on HeaderChainLeft todo:
#5398