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: check if note is consumed for NoteFile::NoteId and NoteFile::NoteWithProof #449

Merged
merged 22 commits into from
Aug 21, 2024

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented Jul 25, 2024

Deals with points 1 and 2 from this comment.

This PR uses the new CheckNullifiersByPrefix node endpoint to deal with imported notes that are already consumed.

When a note file of types NoteFile::NoteId and NoteFile::NoteWithProof is imported the client checks if the nullifier is consumed in the node. If that's the case then the note is stored as NoteStatus::Consumed.

@tomyrd tomyrd force-pushed the tomyrd-import-past-notes branch 3 times, most recently from d5efcf9 to 939716e Compare July 26, 2024 18:17
@tomyrd tomyrd marked this pull request as ready for review July 26, 2024 18:24
@tomyrd tomyrd changed the title feat: check if note is consumed for NoteFile::NoteId and NoteFile::NoteWith feat: check if note is consumed for NoteFile::NoteId and NoteFile::NoteWithProof Jul 26, 2024
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 some minor blocking comments.

Makefile Outdated
@@ -10,7 +10,7 @@ FEATURES_CLIENT="testing, concurrent"
FEATURES_CLI="testing, concurrent"
NODE_FEATURES_TESTING="testing"
WARNINGS=RUSTDOCFLAGS="-D warnings"
NODE_BRANCH="main"
NODE_BRANCH="tomyrd-get-nullifiers-by-prefix"
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 should be ok to move this to next again, right?

client: &mut Client<N, R, S, A>,
filename: PathBuf,
) -> Result<NoteId, String> {
pub async fn read_note_file(filename: PathBuf) -> Result<NoteFile, String> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Should we remove pub from this?

crates/rust-client/src/notes/mod.rs Outdated Show resolved Hide resolved
async fn check_nullifiers_by_prefix(
&mut self,
prefixes: &[u16],
) -> Result<Vec<(miden_objects::notes::Nullifier, u32)>, RpcError> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Very minor nit: I'd import miden_objects::notes::Nullifier in this mod in order to not make this return type too explicit here.

Copy link
Collaborator

@SantiagoPittella SantiagoPittella left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! Not a super-detailed review - but I did leave some comments inline.

crates/rust-client/Cargo.toml Outdated Show resolved Hide resolved
crates/rust-client/src/rpc/web_tonic_client/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/mod.rs Outdated Show resolved Hide resolved
@@ -614,3 +614,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client
Ok(())
}
}

pub fn get_nullifier_prefix(nullifier: &Nullifier) -> u16 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this need to be pub?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, pub(crate) should be enough

@@ -47,6 +47,7 @@ type SerializedInputNoteData = (
Option<String>,
bool,
Option<u32>,
Option<u64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Block number is u32 so this should likely be u32

block_height: inclusion_proof.location().block_num() as u64,
}
} else {
NoteStatus::Expected { created_at: 0 }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looking at this, probably the created_at field should be Option<u32> instead of u32

@@ -216,11 +216,19 @@ impl From<Note> for InputNoteRecord {

impl From<InputNote> for InputNoteRecord {
fn from(recorded_note: InputNote) -> Self {
let status = if let Some(inclusion_proof) = recorded_note.proof() {
NoteStatus::Committed {
block_height: inclusion_proof.location().block_num() as u64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Similar to the other comment, this should be u32

inclusion_details.merkle_path.clone(),
)?;

let tracked_note = maybe_await!(self.get_input_note(id));
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: This tracked_note sounds misleading now that we specifically say "tracked" notes to refer to notes that have a tag that the client is tracking, perhaps it should be store_note or similar

}
}

async fn nullifier_block_num(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: I'd rename this to get_nullifier_block_num()

@igamigo igamigo requested a review from bobbinth August 8, 2024 18:57
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you. I left some comments inline.

crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Show resolved Hide resolved
.iter()
.map(|nul| {
let nullifier = nul.nullifier.clone().ok_or(RpcError::ExpectedFieldMissing(
"CheckNullifiersByPrefix response should have a `nullifier`".to_string(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: We usually just write the name of the missing field here

Copy link
Collaborator

@SantiagoPittella SantiagoPittella left a comment

Choose a reason for hiding this comment

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

LGTM, please address the comment tho.

CHANGELOG.md Show resolved Hide resolved
Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you! I left a few small comments/questions inline - but overall, I think this is good to merge.

crates/rust-client/src/notes/import.rs Show resolved Hide resolved
crates/rust-client/src/rpc/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/sync/tags.rs Show resolved Hide resolved
crates/rust-client/src/store/note_record/mod.rs Outdated Show resolved Hide resolved
crates/rust-client/src/notes/import.rs Outdated Show resolved Hide resolved
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

@igamigo igamigo merged commit 7a6734e into next Aug 21, 2024
13 checks passed
@igamigo igamigo deleted the tomyrd-import-past-notes branch August 21, 2024 14:18
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.

4 participants