-
Notifications
You must be signed in to change notification settings - Fork 28
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
Conversation
d5efcf9
to
939716e
Compare
NoteFile::NoteId
and NoteFile::NoteWith
NoteFile::NoteId
and NoteFile::NoteWithProof
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 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" |
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 be ok to move this to next
again, right?
bin/miden-cli/src/commands/import.rs
Outdated
client: &mut Client<N, R, S, A>, | ||
filename: PathBuf, | ||
) -> Result<NoteId, String> { | ||
pub async fn read_note_file(filename: PathBuf) -> Result<NoteFile, String> { |
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.
nit: Should we remove pub
from this?
async fn check_nullifiers_by_prefix( | ||
&mut self, | ||
prefixes: &[u16], | ||
) -> Result<Vec<(miden_objects::notes::Nullifier, u32)>, RpcError> { |
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.
Very minor nit: I'd import miden_objects::notes::Nullifier
in this mod in order to not make this return type too explicit here.
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
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.
Looks good! Thank you! Not a super-detailed review - but I did leave some comments inline.
939716e
to
1240721
Compare
crates/rust-client/src/sync/mod.rs
Outdated
@@ -614,3 +614,7 @@ impl<N: NodeRpcClient, R: FeltRng, S: Store, A: TransactionAuthenticator> Client | |||
Ok(()) | |||
} | |||
} | |||
|
|||
pub fn get_nullifier_prefix(nullifier: &Nullifier) -> u16 { |
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.
Does this need to be pub
?
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.
No, pub(crate)
should be enough
@@ -47,6 +47,7 @@ type SerializedInputNoteData = ( | |||
Option<String>, | |||
bool, | |||
Option<u32>, | |||
Option<u64>, |
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.
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 } |
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.
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, |
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.
Similar to the other comment, this should be u32
inclusion_details.merkle_path.clone(), | ||
)?; | ||
|
||
let tracked_note = maybe_await!(self.get_input_note(id)); |
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.
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( |
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.
nit: I'd rename this to get_nullifier_block_num()
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.
Looks good! Thank you. I left some comments inline.
7d76387
to
0791c27
Compare
.iter() | ||
.map(|nul| { | ||
let nullifier = nul.nullifier.clone().ok_or(RpcError::ExpectedFieldMissing( | ||
"CheckNullifiersByPrefix response should have a `nullifier`".to_string(), |
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.
nit: We usually just write the name of the missing field here
2e4100d
to
124e543
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, please address the comment tho.
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.
Looks good! Thank you! I left a few small comments/questions inline - but overall, I think this is good to merge.
685373f
to
9f15ac4
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
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
andNoteFile::NoteWithProof
is imported the client checks if the nullifier is consumed in the node. If that's the case then the note is stored asNoteStatus::Consumed
.