-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove cache from validation #646
base: validate_clvm_and_sigs
Are you sure you want to change the base?
Conversation
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.
looks good. just a few comments
) -> Result<(OwnedSpendBundleConditions, Vec<PairingInfo>, Duration), ErrorCode> { | ||
let start_time = Instant::now(); | ||
let mut a = make_allocator(LIMIT_HEAP); | ||
let sbc = get_conditions_from_spendbundle(&mut a, spend_bundle, max_cost, height, constants) | ||
.map_err(|e| e.1)?; | ||
let npcresult = OwnedSpendBundleConditions::from(&a, sbc); | ||
let iter = npcresult.spends.iter().flat_map(|spend| { | ||
let spends = npcresult.spends.clone(); |
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.
I don't think you need to clone the spends 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.
There's an unfortunate move that happens which means we can't return npcresult
unless we clone it earlier
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.
I would expect you the lambda to take the entry by reference, and return a reference
let mut hasher = Sha256::new(); | ||
hasher.update(pk.to_bytes()); | ||
hasher.update(msg.as_slice()); | ||
let hash: [u8; 32] = hasher.finalize(); |
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.
it would probably make sense to factor this out as a separate function, as this code is repeated.
@@ -46,32 +46,54 @@ pub fn validate_clvm_and_signature( | |||
.flat_map(move |(condition, items)| { | |||
let spend_clone = spend.clone(); | |||
items.iter().map(move |(pk, msg)| { |
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.
is there a good reason to move the spends into this lambda function? That's probably why you have to clone the spends in the first place.
.agg_sig_unsafe | ||
.iter() | ||
.map(|(pk, msg)| (pk, msg.as_slice().to_vec())); | ||
let unsafes = npcresult.agg_sig_unsafe.clone(); |
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.
I don't think you should clone this either
.aggregate_verify(iter, &spend_bundle.aggregated_signature); | ||
let result = aggregate_verify_gt( | ||
&spend_bundle.aggregated_signature, | ||
iter.clone().map(|tuple| tuple.1), |
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.
Cloning the iterator here probably means you'll perform the work in the lambda twice, each time you iterate over it. It might be a good reason to collect()
the GTElement
s first. Alternatively, build the return vector as part of this lambda function. That would be the most efficient.
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.
looks good. I would think the &
allows you to not make GTElement
derive from Copy
though
@@ -13,7 +13,7 @@ use std::ops::{Mul, MulAssign}; | |||
pyo3::pyclass, | |||
derive(chia_py_streamable_macro::PyStreamable) | |||
)] | |||
#[derive(Clone)] | |||
#[derive(Clone, Copy)] |
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.
I believe the GTElement
is more than 500 bytes large. I think it's pretty good to require explicit cloning, to see where we pay that cost.
|
||
// Verify aggregated signature | ||
let result = aggregate_verify_gt( | ||
&spend_bundle.aggregated_signature, | ||
iter.clone().map(|tuple| tuple.1), | ||
pairs.iter().map(|tuple| tuple.1), |
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.
pairs.iter().map(|tuple| tuple.1), | |
pairs.iter().map(|tuple| &tuple.1), |
does this work?
Creating a new branch and PRing into
validate_clvm_and_sigs
as this change is rather big.