-
Notifications
You must be signed in to change notification settings - Fork 44
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
Implement get_notes_by_id
endpoint
#298
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.
LGTM. I'm guessing the changes to the storage (for supporting on-chain note data) will also imply a couple of changes in the endpoint.
/// Select Note's matching the NoteId using the given [Connection]. | ||
/// | ||
/// # Returns | ||
/// | ||
/// - Empty vector if no matching `note`. | ||
/// - Otherwise, notes which `note_hash` matches the `NoteId` as bytes. |
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.
Should this include a description of how off-chain and on-chain notes are different in terms of the response? (or perhaps when the storage changes are made)
store/src/db/sql.rs
Outdated
|
||
let placeholders = note_ids.iter().map(|_| "?").collect::<Vec<&str>>().join(", "); | ||
|
||
let query = &format!("SELECT * FROM notes WHERE note_hash IN ({})", placeholders); |
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 note_hash
column name should likely be updated to note_id
but not for this set of changes
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.
Instead of formatting the SQL statement, this should use the rarray
extension. Here is an example:
miden-node/store/src/db/sql.rs
Lines 83 to 96 in 0335339
let mut stmt = conn.prepare( | |
" | |
SELECT | |
account_id, account_hash, block_num | |
FROM | |
accounts | |
WHERE | |
block_num > ?1 AND | |
block_num <= ?2 AND | |
account_id IN rarray(?3) | |
ORDER BY | |
block_num ASC | |
", | |
)?; |
In general I'm against formatting SQL statements, for two reasons:
- It is an easy way to get into a SQL injection vulnerability
- It makes it harder to have caches of prepared statements
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.
Fixed it using the rarray
method.
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
note_hash
column name should likely be updated tonote_id
but not for this set of changes
Opening an issue here: #301
@@ -99,6 +99,11 @@ message GetTransactionInputsResponse { | |||
|
|||
message SubmitProvenTransactionResponse {} | |||
|
|||
message GetNotesByIdResponse { | |||
// Lists Note's returned by the database | |||
repeated note.Note notes = 1; |
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.
It seems these are missing the details (i.e. the note's script/inputs/etc.):
miden-node/proto/proto/note.proto
Lines 8 to 15 in 0335339
message Note { | |
fixed32 block_num = 1; | |
uint32 note_index = 2; | |
digest.Digest note_id = 3; | |
account.AccountId sender = 4; | |
fixed64 tag = 5; | |
merkle.MerklePath merkle_path = 7; | |
} |
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 don't think that this message is missing a details
field.
This message represents getting a list of notes. Each note will have their own details
field indeed. But the GetNoteById
message should not return details but only a list of notes.
If you want to see the Note
message with a details field, then see this PR when I make the modification to the db: #300
store/src/db/sql.rs
Outdated
|
||
let placeholders = note_ids.iter().map(|_| "?").collect::<Vec<&str>>().join(", "); | ||
|
||
let query = &format!("SELECT * FROM notes WHERE note_hash IN ({})", placeholders); |
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.
Instead of formatting the SQL statement, this should use the rarray
extension. Here is an example:
miden-node/store/src/db/sql.rs
Lines 83 to 96 in 0335339
let mut stmt = conn.prepare( | |
" | |
SELECT | |
account_id, account_hash, block_num | |
FROM | |
accounts | |
WHERE | |
block_num > ?1 AND | |
block_num <= ?2 AND | |
account_id IN rarray(?3) | |
ORDER BY | |
block_num ASC | |
", | |
)?; |
In general I'm against formatting SQL statements, for two reasons:
- It is an easy way to get into a SQL injection vulnerability
- It makes it harder to have caches of prepared statements
merge? |
Hey, yes soon. Still working on making sure that everything works correctly and addressing the small nits from the other teammates. |
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 couple of doc-related comments inline. Other than that, we should also resolve the merge conflicts (hopefully, shouldn't be too difficult) and then we can merge.
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.
All looks good! Thank you!
* Getting notes by id works * lint and test * Improved comments + Added conversion from digest::Digest to NoteId * Added rpc validation for NoteId's * Added documentation to Readmes * Lint * Fixed ci problems * Added test for endpoint + refactored sql query + improved documentation * Fixed lint * Order rpc and store endpoints alphabitically * Improved documentation with gh comments
In this PR I propose the addition of the
get_notes_by_id
endpoint on the RPC and Store of the Miden nodeCloses: #286
Now making this request to the RPC:
Returns this response:
Proving the functionality of the endpoint.