Skip to content
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

feat: various helper functions and fixes for platform contested resources PR #307

Merged
merged 45 commits into from
Jun 30, 2024

Conversation

QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Jun 25, 2024

Issue being fixed or feature implemented

What was done?

*Added helper methods to get element data more easily.
*If the query option is set to not error when parent paths are missing this will now work.
*Added some new conversions from return types from queries:
**to_last_path_to_keys_btree_map
**to_last_path_to_key_elements_btree_map
**to_last_path_to_elements_btree_map
**to_previous_of_last_path_to_keys_btree_map
*Added a new reference type: UpstreamRootHeightWithParentPathAdditionReference. This is very similar to the UpstreamRootHeightReference, however it appends to the absolute path when resolving the parent of the reference If the reference is stored at 15/9/80/7 then 80 will be appended to what we are referring to.

How Has This Been Tested?

Breaking Changes

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

@QuantumExplorer QuantumExplorer requested a review from fominok as a code owner June 25, 2024 07:29
@QuantumExplorer QuantumExplorer changed the title Feat/query sum tree feat: various helper functions and fixes for platform contested resources PR Jun 25, 2024
@QuantumExplorer QuantumExplorer changed the base branch from develop to master June 25, 2024 08:43
@QuantumExplorer QuantumExplorer changed the base branch from master to develop June 25, 2024 08:43
@fominok fominok force-pushed the feat/QuerySumTree branch from 8886695 to adb8fd1 Compare June 25, 2024 09:33
pub fn as_sum_item_value(&self) -> Result<i64, Error> {
match self {
Element::SumItem(value, _) => Ok(*value),
_ => Err(Error::WrongElementType("expected a sum item")),
}
}

#[cfg(any(feature = "full", feature = "verify"))]
/// Decoded the integer value in the SumItem element type
pub fn into_sum_item_value(self) -> Result<i64, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the purpose of this method? as_sum_item_value is just fine because i64 is Copy

Copy link
Member Author

Choose a reason for hiding this comment

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

still should be faster right as you are not copying memory. I agree it's not very important though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It returns from the function so the stack frame is cleared and memory will be copied from there anyways, we're not avoiding memory copies by using self unless we doing so to avoid doing explicit clonings

Copy link
Member Author

Choose a reason for hiding this comment

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

Look, it really doesn't matter, we have a lot of into and as. While I could remove this, I just don't think it matters, so I prefer to keep it.


#[cfg(any(feature = "full", feature = "verify"))]
/// Decoded the integer value in the SumTree element type
pub fn into_sum_tree_value(self) -> Result<i64, Error> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

as_sum_tree_value is fine

Copy link
Member Author

Choose a reason for hiding this comment

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

Same as above.

@@ -54,6 +54,12 @@ pub enum ReferencePathType {
/// path [p, q] result = [a, b, p, q]
UpstreamRootHeightReference(u8, Vec<Vec<u8>>),

/// This is very similar to the UpstreamRootHeightReference, however
Copy link
Collaborator

Choose a reason for hiding this comment

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

i guess it needs a better explanation at least how it's done at UpstreamRootHeightReference

Copy link
Member Author

Choose a reason for hiding this comment

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

added more info

)
.unwrap_add_cost(&mut cost)?;

match maybe_item {
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we shall stop with maybe_item there and reuse the following code intended for non-references, because it's the same and reference will be already resolved

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't understand this comment.

Err(e) => Err(e),
}
} else {
return Err(Error::CorruptedData(
Copy link
Collaborator

Choose a reason for hiding this comment

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

doesn't seem like corrupted data but a wrong arg to macro

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, since this is just copied code we should make a new PR to fix this in all places.

Copy link
Collaborator

@ogabrielides ogabrielides left a comment

Choose a reason for hiding this comment

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

LGTM in general

@QuantumExplorer QuantumExplorer merged commit a4326b7 into develop Jun 30, 2024
7 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/QuerySumTree branch June 30, 2024 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants