Replies: 3 comments 20 replies
-
This is great! Thank you for putting it together! I think this is kind of related to #489 in that we need to understand what states a note can be in and which actions can move a note from one state to another. I'm trying to think about this as if it was a finite-state machine. For example, Let's say we get a nullifier for a note during state sync. The action here would be "note nullified" (or something like that) and then almost any state we apply this action to would mean that the note moves into "consumed" state (unless it is already in the "consumed" state, and then we get an error?). |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
Once #520 gets merged we should continue working on how output notes will be reworked. Will they use the same state as input notes? If this is the case should we add separate transitions for output notes? Some other options I can think of:
|
Beta Was this translation helpful? Give feedback.
-
The client's
import
andsync
functions changed considerably in the last weeks, the idea of this post is to document and discuss the current client behavior in each case. We can use this as a base point to see if this is the desired state or if we want to make some changes.Current behavior
Import
The import behavior depends mainly on the
NoteFile
variant being imported.NoteFile::NoteId(id)
The client will use the
GetNotesById
endpoint to request information about the note the note with the given ID. If the note is public and is tracked by the node, the client will import it, otherwise it will return an error.If the note imported is already tracked by the client, the client will update the note's inclusion proof and metadata.
The client then uses the
CheckNullifiers
endpoint to determine if the note is consumed or not. If the note is consumed, the client will import it asConsumed
, otherwise it will be imported asCommitted
along with its inclusion proof and metadata.If the note is imported as
Committed
and its in the past relative to the client, the block headers and MMR data for the note is also stored.NoteFile::NoteWithProof(note, inclusion_proof)
The client then uses the
CheckNullifiers
endpoint to determine if the note is consumed or not. If the note is consumed, the client will import the note asConsumed
, otherwise it will be imported asCommitted
along with its inclusion proof and metadata.If the note is imported as
Committed
and its in the past relative to the client, the block headers and MMR data for the note is also stored.NoteFile::NoteDetails{details, after_block_num, tag}
The imported note will be marked as ignored if the tag is
None
or if it'sSome(tag)
and the tag is not currently tracked by the client (ie, it's stored as a persistent tag).The import process uses the
SyncNotes
endpoint to determine was committed in the past relative to the client's current block number. If the note is tracked by the node and it was committed in the past, the note is imported asCommitted
. If this doesn't happen or if the tag isNone
, the note is imported asExpected
.If the note is imported as
Committed
, its inclusion proof and metadata is also stored, with the addition of the block headers and MMR data for the block in which the note was committed.Sync
The way a note is updated on sync depends on two factors:
Expected + Tracked Notes
The tags used in the sync request to update expected notes are:
The node returns a list of note inclusions which are notes tracked by the node that match the provided tags. Expected notes that are included in this list are turned into committed notes without changing its ignored status. The block headers and MMR changes for these notes are also added to the client.
Expected + Ignored Notes
As mentioned, only tags from non-ignored notes are added to the sync request. This means that ignored notes are not returned in the note inclusions list and will not be updated through the sync process.
The client offers a separate
update_ignored_notes
method that uses the GetNotesById node endpoint to specifically request information about ignored notes. Returned notes are known to be tracked by the node and can be changed from expected to committed. The client also updates the note's inclusion proof and metadata.The
update_ignored_notes
method is not called during the sync process, it must be called manually by the user.Committed/Processing + Tracked Notes
The client needs to know which committed notes have been consumed. On every sync, a list of nullifiers is sent. The requested nullifiers are:
The node returns a list of nullifiers that have been recorded. This means that notes that match these nullifiers need to be updated to consumed.
Additionally, after every sync, the client will request the block headers and MMR data for all committed notes that don't have them tracked.
Processing + Tracked Notes
Just like committed notes, these notes will be updated to consumed if they are included in the list of nullifiers returned by the node.
Processing + Ignored Notes
This case is currently not handled.
Consumed Notes
Once a note is set as consumed it is no longer updated.
Beta Was this translation helpful? Give feedback.
All reactions