-
Notifications
You must be signed in to change notification settings - Fork 58
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
Random Number Generation #2053
Random Number Generation #2053
Conversation
86ffe89
to
15b7bc5
Compare
println!( | ||
"expected_ta_tx.tally: {}", | ||
hex::encode(&expected_ta_tx.tally) | ||
); |
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 removed
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.
why?
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 added it to help me write the tests, if the tests are done we don't need it.
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 had to modify several times the rng tests, so I think it could be useful in the future too
2db052b
to
d5bbf32
Compare
4659b63
to
58e5d0b
Compare
rad/src/lib.rs
Outdated
if is_rng { | ||
Ok(RadonReport::from_result( | ||
Ok(radon_types_vec[0].clone()), | ||
context, | ||
)) | ||
} else { |
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.
What is this doing?
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.
unwrap() :P
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.
In the rng case the request will usually have only one retrieval source. So this way we avoid the aggregation step, which is not needed. However I think that could apply to all kinds of requests, because you don't need aggregation if there is only one source. This would be a breaking change, but we can implement it with TAPI.
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 removed it and use the Mode instead, because the mode of a vector of one element is that element. To avoid strange cases
validations/src/validations.rs
Outdated
if path.url.is_empty() || path.script.is_empty() { | ||
is_rng = true; | ||
break; | ||
} else { | ||
return Err(DataRequestError::InvalidRngRequest.into()); | ||
} |
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 really follow the logic here hehehe.
- I can see why
url
must be empty (won't be used). - I have doubts on whether
script
should be allowed or not. - By reading this code, I understand that as long as
url
is empty,script
can be non-empty, but will it be used anyway?
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.
Some general but related comments:
RADTypes
only exist at the data source / retrieval level. We should avoid handling a data request differently only because one of the data sources is of a special kind.- There won't exist such thing as RNG requests, only requests with RNG sources.
- RNG and HttpGet sources should coexist in the same data request as long as they have the same output type.
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.
E.g. in the future we may have a data source type that performs general computation by running WASM bytecode in a sandbox.
And you may want to use that side by side with a classic HttpGet data source that triggers a similar computation on some cloud, or fetches similar outputs from some API.
My point is that you should perfectly be able to do so, and this part of the code should only care about routing the data source definitions to their "resolvers" (the resolver of HttpGet is our wrapper of the Surf library, the resolver of Rng is the RNG and the resolver of the hypothetical Wasm type would be a WASM virtual machine).
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.
Agree that is_rng
is a hack and we should find a way to avoid it.
validations/src/validations.rs
Outdated
if path.url.is_empty() { | ||
return Err(DataRequestError::NoRetrievalSources.into()); | ||
} |
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.
Won't this cause an early return for any retrieval path / data source of RADType::Rng that has both url
and script
being empty?
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.
In the rng case it does never reach this line because there is a break
in the previous condition. But that limits rng requests to one retrieval source, so we need to change this logic.
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.
If it is a RADType::Rng, it will always return earlier in the previous branchs (break or DataRequestError::InvalidRngRequest)
validations/src/validations.rs
Outdated
if is_rng && retrieval_paths.len() > 1 { | ||
return Err(DataRequestError::InvalidRngRequest.into()); | ||
} |
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.
As per my general comment above, this goes against the three points.
a928182
to
a334c8c
Compare
rad/src/script.rs
Outdated
| RadonReducers::Mode | ||
| RadonReducers::AverageMedian | ||
| RadonReducers::HashConcatenate | ||
| RadonReducers::Unwrap => {} |
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 function needs a context, the new operators can only be considered valid if the WIP is active.
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 is fixed in #2063, because it also affect to the median
e8b3537
to
fe14ad9
Compare
rad/src/reducers/mod.rs
Outdated
#[repr(u8)] | ||
pub enum RadonReducers { | ||
// Implemented | ||
Mode = 0x02, | ||
AverageMean = 0x03, | ||
AverageMedian = 0x05, | ||
DeviationStandard = 0x07, | ||
HashConcatenate = 0x0b, | ||
Unwrap = 0x0c, |
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.
Interesting. Where did this come from?
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.
We dont have a reducer to convert an array of 1 element in that element
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.
Deleted unwrap, using Mode instead of
rad/src/lib.rs
Outdated
let random_bytes: [u8; 32] = rand::random(); | ||
let random_bytes = RadonTypes::from(RadonBytes::from(random_bytes.to_vec())); | ||
|
||
Ok(RadonReport::from_result(Ok(random_bytes), context)) |
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 ignores the retrieval script, according to the WIP the script should be executed.
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.
Well actually I'm not sure if the retrieval script should be executed or not.
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.
Let's discuss here:
witnet/WIPs#70 (comment)
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.
What was the conclusion?
d248a53
to
fb70fcc
Compare
fe14ad9
to
0c4ffec
Compare
Using commit 0c4ffec and this data request:
An updated node accepts that as a valid request, while a not-updated node does not, leading to a fork. |
rad/src/lib.rs
Outdated
/// Auxiliary function that returns the current active wips and the WIPs in voting process as actived | ||
/// It is only used for testing | ||
pub fn all_wips_active() -> ActiveWips { | ||
let mut h = current_active_wips(); |
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.
Why h
? 🤣
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 stands for HashMap
, because the first version of ActiveWips
was just a HashMap
.
b54dd20
to
dca1c0f
Compare
dca1c0f
to
2ca0fe9
Compare
…tivation Co-authored-by: Tomasz Polaczyk <tmpolaczyk@gmail.com>
2ca0fe9
to
1b3176c
Compare
Close #2056