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: verify imported note existance in the chain #297

Merged
merged 20 commits into from
May 3, 2024

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented Apr 25, 2024

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.

@tomyrd tomyrd linked an issue Apr 25, 2024 that may be closed by this pull request
@tomyrd tomyrd marked this pull request as ready for review April 25, 2024 17:17
Copy link
Contributor

@mFragaBA mFragaBA left a 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.
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
* Added an option to verify note existance in the chain before importing.
* Added an option to verify note existence in the chain before importing.

Copy link
Collaborator Author

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.

src/cli/input_notes.rs Show resolved Hide resolved
@@ -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(
Copy link
Contributor

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 162 to 170
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();
Copy link
Contributor

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

Copy link
Collaborator Author

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.

src/client/sync.rs Outdated Show resolved Hide resolved
src/client/notes.rs Show resolved Hide resolved
src/client/notes.rs Show resolved Hide resolved
Comment on lines +1024 to +1025
#[tokio::test]
async fn test_import_pending_notes() {
Copy link
Contributor

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

Copy link
Collaborator Author

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.

@tomyrd tomyrd force-pushed the tomyrd-import-note-existance-check branch from 29d8800 to 8a24a67 Compare April 29, 2024 21:27
@tomyrd tomyrd requested a review from mFragaBA April 29, 2024 21:33
Copy link
Collaborator

@igamigo igamigo left a 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/notes.rs Outdated Show resolved Hide resolved
@@ -1,4 +1,4 @@
use alloc::collections::BTreeSet;
use std::collections::{BTreeSet, HashMap};
Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Comment on lines +171 to +179
//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();
Copy link
Contributor

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?

Copy link
Contributor

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)

Copy link
Collaborator Author

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).

tests/integration/main.rs Outdated Show resolved Hide resolved
docs/cli-reference.md Outdated Show resolved Hide resolved
tomyrd and others added 2 commits May 3, 2024 16:05
Co-authored-by: Martin Fraga <[email protected]>
Co-authored-by: Martin Fraga <[email protected]>
Copy link
Contributor

@mFragaBA mFragaBA left a 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.

@igamigo igamigo merged commit 99c1721 into next May 3, 2024
6 checks passed
@igamigo igamigo deleted the tomyrd-import-note-existance-check branch May 3, 2024 19:23
tomyrd added a commit that referenced this pull request May 6, 2024
igamigo pushed a commit that referenced this pull request May 9, 2024
* 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]>
bobbinth pushed a commit that referenced this pull request May 15, 2024
* 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]>
bobbinth pushed a commit that referenced this pull request May 15, 2024
* 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]>
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.

Verify a note exists when importing
3 participants