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

Add proof type #245

Merged
merged 89 commits into from
Feb 22, 2023
Merged

Add proof type #245

merged 89 commits into from
Feb 22, 2023

Conversation

MavenRain
Copy link
Contributor

@MavenRain MavenRain commented Jan 19, 2023

The proof type will be used to construct the response attribute arguments for proofs in many-framework where proofs are requested (via attribute 3).

Notes:

  • I hit snags trying to add context parameters to the idstore and event endpoints (weird compiler errors complaining about not implementing the Decode trait).
  • events.list will require implementing construction of proofs from key ranges.
  • Key retrieval for proofs is still bespoke by endpoint. It would be nice to find a way of pushing key collection to the background.
  • Migration work related to hash scheme is out of scope for this PR.

@@ -554,7 +554,6 @@ impl<'a, T, E, IDX: AsRef<str>> Index<IDX> for MigrationSet<'a, T, E> {
}

/// Kept for backward compatibility.
#[deprecated = "Should use MigrationSet::load() instead."]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These warnings were triggering on builds. Either these should be removed, or they should be re-added along with the remedies for the places where they are currently being used.

@codecov-commenter
Copy link

codecov-commenter commented Jan 24, 2023

Codecov Report

Merging #245 (09842be) into main (37e273b) will decrease coverage by 0.16%.
The diff coverage is 75.35%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
- Coverage   73.33%   73.17%   -0.16%     
==========================================
  Files         175      177       +2     
  Lines       22715    23171     +456     
==========================================
+ Hits        16657    16956     +299     
- Misses       6058     6215     +157     
Impacted Files Coverage Δ
src/many-error/src/error.rs 46.24% <ø> (ø)
src/many-ledger/src/module/ledger_mintburn.rs 0.00% <0.00%> (ø)
src/many-ledger/src/storage/ledger_mintburn.rs 0.00% <0.00%> (ø)
src/many-macros/src/lib.rs 0.21% <0.00%> (-0.03%) ⬇️
src/many-modules/src/_5_data.rs 92.52% <0.00%> (-0.88%) ⬇️
src/many-protocol/src/lib.rs 96.80% <ø> (ø)
src/many-protocol/src/response.rs 88.46% <0.00%> (-1.99%) ⬇️
src/many-types/src/attributes.rs 88.20% <0.00%> (+0.20%) ⬆️
src/many-types/src/lib.rs 75.06% <ø> (ø)
src/many/src/main.rs 0.24% <0.00%> (-0.02%) ⬇️
... and 49 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

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

First round of reviews.

Can you also add an issue where we have proper Proof tree algebra and can just pass the context around and collect keys as we go instead of returning them everywhere? Should simplify the code.

src/many/src/main.rs Outdated Show resolved Hide resolved
}
}

impl From<Context> for Cow<'_, Context> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Cow should support Into or From already, no? Also, why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hansl I'm going to remove this because I thought I would need this flexibility at the beginning of writing this PR but then quickly discovered that I only needed to ever move a single Context object between calls. For the record, though, I don't believe that Cow comes with automatic From/Into support except for a few specific cases. For user-defined types, one must define From for Cow support.

src/many-kvstore/Cargo.toml Outdated Show resolved Hide resolved
src/many-ledger/src/storage/ledger.rs Outdated Show resolved Hide resolved
})
.collect::<Result<Vec<_>, _>>()
})
.map_err(|error| ManyError::unknown(error.to_string()))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.map_err(|error| ManyError::unknown(error.to_string()))
.map_err(ManyError::unknown)

src/many-ledger/src/storage/ledger.rs Outdated Show resolved Hide resolved
)?;
Ok(())
self.module_impl
.send(
Copy link
Contributor

Choose a reason for hiding this comment

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

Proofs on a command (like send or mint) are senseless as they are executed in order and the root hash is being updated as we go through the block. So you can't actually use the proof for anything, really.

We should just return proofs on queries, wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this makes sense. I can remove proof functionality from send and mint.

Comment on lines 134 to 139
self.storage
.prove_state(context, keys)
.map(|error| ManyError::unknown(error.to_string()))
.map(Err)
.unwrap_or(Ok(()))
.map(|_| account::CreateReturn { id })
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 simplify with the other changes to prove_state below to:

Suggested change
self.storage
.prove_state(context, keys)
.map(|error| ManyError::unknown(error.to_string()))
.map(Err)
.unwrap_or(Ok(()))
.map(|_| account::CreateReturn { id })
self.storage.prove_state(context, keys)?;
Ok(account::CreateReturn { id })

Here and everywhere.

src/many-types/src/proof.rs Show resolved Hide resolved
@@ -464,50 +465,55 @@ pub type AddFeaturesReturn = EmptyReturn;
#[cfg_attr(test, mockall::automock)]
pub trait AccountModuleBackend: Send {
/// Create an account.
fn create(&mut self, sender: &Address, args: CreateArgs) -> Result<CreateReturn, ManyError>;
fn create(&mut self, sender: &Address, args: CreateArgs, context: Context) -> Result<CreateReturn, ManyError>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Commands (that have mut self) don't need to return a proof and cannot actually build a usable one.

}
}

impl From<(RequestMessage, Sender<ProofResult>)> for Context {
Copy link
Contributor

Choose a reason for hiding this comment

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

Additional; Can you make a proper new method instead of Into?

@MavenRain
Copy link
Contributor Author

First round of reviews.

Can you also add an issue where we have proper Proof tree algebra and can just pass the context around and collect keys as we go instead of returning them everywhere? Should simplify the code.

#310

@MavenRain MavenRain requested a review from hansl February 21, 2023 20:41
@@ -200,7 +200,7 @@ struct MessageOpt {
data: Option<String>,

#[clap(long)]
attribute: Option<u32>,
proof: Option<bool>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't have to be Option<bool>, just set default value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I can make a suggestion :) I was going quick through the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Also noted that there's a missing description for this flag.

    /// Request a proof of the value. This may cause an error if the server
    /// does not support proofs, and might not work on all endpoints. Consult
    /// the specification for more information.
    #[clap(long, default_value = "false")]
    proof: bool,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah . . . I hadn't done it this way, but will now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

@hansl hansl left a comment

Choose a reason for hiding this comment

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

Assuming the proof flag is properly updated, LGTM.

@MavenRain MavenRain merged commit 3c641d8 into liftedinit:main Feb 22, 2023
@MavenRain MavenRain deleted the oobi/proof branch February 22, 2023 19:54
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