-
Notifications
You must be signed in to change notification settings - Fork 32
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: verify imported note existance in the chain #297
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.
Not a final review
CHANGELOG.md
Outdated
@@ -1,5 +1,6 @@ | |||
# Changelog | |||
|
|||
* Added an option to verify note existance in the chain before importing. |
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.
* Added an option to verify note existance in the chain before importing. | |
* Added an option to verify note existence in the chain before importing. |
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.
Nice catch. The error name was also wrong so I fixed it everywhere.
@@ -29,7 +29,57 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store> Client<N, R, S> { | |||
// -------------------------------------------------------------------------------------------- | |||
|
|||
/// Imports a new input note into the client's store. | |||
pub fn import_input_note(&mut self, note: InputNoteRecord) -> Result<(), ClientError> { | |||
pub async fn import_input_note( |
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.
The method doc comment should Also mention posible errors and explain the verify flag
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.
Done.
src/client/sync.rs
Outdated
let uncommited_note_tags: Vec<NoteTag> = self | ||
.store | ||
.get_input_notes(NoteFilter::Pending)? | ||
.iter() | ||
.filter(|note| note.metadata().is_some()) | ||
.map(|note| note.metadata().expect("Notes should have metadata after filter").tag()) | ||
.collect(); | ||
|
||
let note_tags = [account_note_tags, stored_note_tags, uncommited_note_tags].concat(); |
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'm wondering whether we should pass this through a map to remove possible duplicates
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.
Added a temporary fix using HashMap
. Will change it to BTreeSet
when NoteTag
implements Ord
.
#[tokio::test] | ||
async fn test_import_pending_notes() { |
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 think we should also try consuming the created notes to make sure the inclusion proofs paths are usable
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.
Done. Added a line that consumes the note. The test doesn't panic so the inclusion proof is usable.
29d8800
to
8a24a67
Compare
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.
LGTM. Left a couple comments that should be simple to address
src/client/sync.rs
Outdated
@@ -1,4 +1,4 @@ | |||
use alloc::collections::BTreeSet; | |||
use std::collections::{BTreeSet, HashMap}; |
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 collections (BTreeSet
and BTreeMap
) should come from alloc
to not depend on std
types.
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.
Done
//TODO: Use BTreeSet to remove duplicates more efficiently once `Ord` is implemented for `NoteTag` | ||
let note_tags: Vec<NoteTag> = [account_note_tags, stored_note_tags, uncommited_note_tags] | ||
.concat() | ||
.into_iter() | ||
.map(|tag| (tag.to_string(), tag)) | ||
.collect::<HashMap<String, NoteTag>>() | ||
.values() | ||
.cloned() | ||
.collect(); |
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.
now that the related PR from base got merged, will we do this in a follow-up PR?
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 discussed offline, we'll do this on the branch that we'll use as a base for the release (that will point to base's next)
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.
Added an issue for this change (#320).
Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Martin Fraga <[email protected]>
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.
LGTM! Tested locally, no issues found.
* feat: export notes from output notes table (converted to input notes) * refactor: rewrite test to display new behavior * Add note details command when importing note * Add account details command when creating new account * Erase TODO, fixed in PR #297 * Add more feedback to `tx new` command * feat: search both input and output notes when looking for notes * refactor: rename input_notes file to notes * Add more information to `SyncStatus` * Add tests for new sync details * Add changes to CHANGELOG * Rename `SyncNewDetails` and add docs * address review comments * fix: handle corner cases on show command * Fix suggestions * Remove unnecessary message * Move binary name to constant * Move binary name inline * Change `add` to `combine_with` * Change transaction output notes message --------- Co-authored-by: Martin Fraga <[email protected]>
* Add verify flag to import note command * Add inclusion proof to note if possible * Include uncommited notes tags to sync * Add tests for * Add change to CHANGELOG * Fix typo in error name * Change flag to be `no_verify` instead of `verify` * Improve doc comment for `import_input_note` * Remove note tag duplicates before request * Combine `filter` and `map` for uncommited note tags * Add explanation for inclusion proof check * Consume note in integration test to check proof validity * Fix typo in documentation Co-authored-by: igamigo <[email protected]> * Use BTreeSet from alloc * Remove git artifacts * Fix cli-reference doc Co-authored-by: Martin Fraga <[email protected]> * Fix comment in testing Co-authored-by: Martin Fraga <[email protected]> --------- Co-authored-by: igamigo <[email protected]> Co-authored-by: Martin Fraga <[email protected]>
* feat: export notes from output notes table (converted to input notes) * refactor: rewrite test to display new behavior * Add note details command when importing note * Add account details command when creating new account * Erase TODO, fixed in PR #297 * Add more feedback to `tx new` command * feat: search both input and output notes when looking for notes * refactor: rename input_notes file to notes * Add more information to `SyncStatus` * Add tests for new sync details * Add changes to CHANGELOG * Rename `SyncNewDetails` and add docs * address review comments * fix: handle corner cases on show command * Fix suggestions * Remove unnecessary message * Move binary name to constant * Move binary name inline * Change `add` to `combine_with` * Change transaction output notes message --------- Co-authored-by: Martin Fraga <[email protected]>
closes #277
Added the option to verify a note when importing it to the client. If the verification passes we try to add an inclusion proof to the imported note if possible.
Also we now check for local uncommited notes in every sync. So if the note was imported but it's not relevant for tracked account it can also be updated.