-
Notifications
You must be signed in to change notification settings - Fork 79
feat: miden client service #1434
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
base: next
Are you sure you want to change the base?
Conversation
4791fda to
6e77927
Compare
| /// Syncs the client's state with the current state of the Miden network and returns a | ||
| /// [`SyncSummary`] corresponding to the local state update. | ||
| /// Performs a sync against the network and returns the raw [`StateSyncUpdate`]. | ||
| /// | ||
| /// The sync process is done in multiple steps: | ||
| /// 1. A request is sent to the node to get the state updates. This request includes tracked | ||
| /// account IDs and the tags of notes that might have changed or that might be of interest to | ||
| /// the client. | ||
| /// 2. A response is received with the current state of the network. The response includes | ||
| /// information about new/committed/consumed notes, updated accounts, and committed | ||
| /// transactions. | ||
| /// 3. Tracked notes are updated with their new states. | ||
| /// 4. New notes are checked, and only relevant ones are stored. Relevant notes are those that | ||
| /// can be consumed by accounts the client is tracking (this is checked by the | ||
| /// [`crate::note::NoteScreener`]) | ||
| /// 5. Transactions are updated with their new states. | ||
| /// 6. Tracked public accounts are updated and private accounts are validated against the node | ||
| /// state. | ||
| /// 7. The MMR is updated with the new peaks and authentication nodes. | ||
| /// 8. All updates are applied to the store to be persisted. |
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.
Would be good to keep the detailed description somewhere
| /// Configuration for the background client service. | ||
| #[derive(Debug, Clone)] | ||
| pub struct ServiceConfig { | ||
| /// Interval at which the client should attempt to sync with the chain. | ||
| pub sync_interval: Duration, | ||
| /// Whether the service should automatically sync on the configured interval. | ||
| pub auto_sync: bool, | ||
| /// Capacity for the internal command channel. | ||
| pub command_buffer: usize, | ||
| } |
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.
👍🏼
| .map_err(|_| ServiceError::ChannelClosed) | ||
| } | ||
|
|
||
| /// Runs a one-shot function with mutalbe access to the client. |
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.
| /// Runs a one-shot function with mutalbe access to the client. | |
| /// Runs a one-shot function with mutable access to the client. |
| /// }).await?; | ||
| /// # Ok(()) } | ||
| /// ``` | ||
| pub async fn run_with_client<F, Fut>(&self, f: F) -> Result<(), ServiceError> |
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.
a handle always "runs with client", right? Maybe a rename to just run would be cleaner
| } | ||
| } | ||
|
|
||
| // TODO: Run these in parallel? |
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.
IIUC, the tasks will go in the background, it's just the spawning itself which is done sequentially?
If so, then I think the sync work done inside this loop is minimal enough.
| Command::SubmitTransaction { account_id, tx_request, resp_tx } => { | ||
| let result = self | ||
| .client | ||
| .submit_new_transaction(account_id, tx_request) | ||
| .await | ||
| .map_err(ServiceError::from); | ||
| let _ = resp_tx.send(result); | ||
| }, | ||
| Command::AddBlockingHandler(handler) => self.registered_blocking_handlers.push(handler), | ||
| Command::AddAsyncHandler(handler) => self.registered_async_handlers.push(handler), | ||
| Command::RunWithClient { mut f, resp_tx } => { |
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.
ATM the commands are mixing client functionality (submit tx) with runtime functionality (add handler / stop). Is there a way to de-couple these?
(I'm not sure decoupling is a net positive, just curious)
No description provided.