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

Remove client dependency from faucet #368

Merged
merged 33 commits into from
Jun 7, 2024
Merged

Conversation

tomyrd
Copy link
Collaborator

@tomyrd tomyrd commented May 27, 2024

closes #343

This PR removes almost all of the functionality implemented by the miden-client and replaces it with it's own implementation that doesn't depend on the crate. The new FaucetClient is stored in the state and wrapped with a mutex to allow concurrency (a feature that was removed in the previous version).

Some caveats:

  • We still have a small dependency. The InputNoteRecord type is needed in order to be serialized and imported by the user. We could change the miden-client to accept the Note type as it's import or move the InputNoteRecord to miden-base.
  • There's a small issue where if multiple transactions are sent at the same time, the node accepts the first one and rejects all others. This happens because of this verification.

@tomyrd tomyrd marked this pull request as ready for review May 28, 2024 18:45
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.

Looking good! Left some comments

bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

  • We still have a small dependency. The InputNoteRecord type is needed in order to be serialized and imported by the user. We could change the miden-client to accept the Note type as it's import or move the InputNoteRecord to miden-base.

I didn't see where in the code we are currently using InputNoteRecord, but if we need it, my preference would be to create a struct in miden-objects (e.g., maybe something like NoteFile which is used specifically for serializing different note variants.

@tomyrd
Copy link
Collaborator Author

tomyrd commented May 29, 2024

I didn't see where in the code we are currently using InputNoteRecord

Here. It's needed because the client can only import serialized InputNoteRecord files.

maybe something like NoteFile which is used specifically for serializing different note variants.

Created an issue for this in miden-base.

@tomyrd tomyrd requested review from igamigo and bobbinth May 29, 2024 15:36
Copy link
Contributor

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

Not a final review, In general looks good though. I'll continue with testing these changes locally.

One thing I noticed while reviewing this is that we never store the faucet state. This means that if by any reason the server crashes I lost the faucet forever. It might be worth considering storing it somewhere, but it's a separate issue than this one.


#[derive(Clone)]
pub struct FaucetDataStore {
faucet_account: Rc<RefCell<Account>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

If we changed Rc<RefCell<Account>> for Arc<<Mutex<Account>> (maybe even Arc<RwLock<Account>>) would we still need the unsafe impl Send and unsafe impl Sync from above?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes because the TransactionExecutor still wouldn't be Send+Sync


struct FaucetAuthenticator {
secret_key: AuthSecretKey,
rng: RefCell<ChaCha20Rng>,
Copy link
Contributor

Choose a reason for hiding this comment

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

as for what was said above, what happens if we wrap this with a Mutex/ RwLock instead of a RefCell?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was suggested to remove this struct in favor of the BasicAuthenticator which currently also uses a RefCell. In the future this may change and we could remove the unsafe impl Send+Sync.

bin/faucet/src/handlers.rs Show resolved Hide resolved
Copy link
Contributor

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

Tested locally with the dockerized node, worked like a charm. In fact, it feels faster than before (it's still restricted by block time since we can only do one tx per block.

Again unrelated to the PR, but could it be possible to do a mint for multiple accounts at a time by "aggregating" many mint requests into a single Tx that generates all mint notes? It would probably change the flow a bit since we'd need to switch to a polling scheme or similar, but it would allow the faucet to mint for several accounts per block.

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 couple of small comments inline.

Also, I think as a part of this PR we should get rid of the miden-client dependency entirely. So, before merging this, we should probably address 0xPolygonMiden/miden-base#715 and propagate the changes here and to miden-client.

bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Show resolved Hide resolved
@tomyrd tomyrd force-pushed the tomyrd-remove-client-from-faucet branch from 2dc9fc9 to cb9e735 Compare May 31, 2024 15:57
@tomyrd
Copy link
Collaborator Author

tomyrd commented May 31, 2024

So, before merging this, we should probably address 0xPolygonMiden/miden-base#715 and propagate the changes here and to miden-client.

Creted a PR adding the new NoteFile object. Drafting this PR until that one is merged so as to not merge it by accident.

We will also need to update the client to use the new serialized file but it's not a blocking change for the faucet.

@tomyrd tomyrd marked this pull request as draft May 31, 2024 16:17
@tomyrd tomyrd requested review from mFragaBA and bobbinth May 31, 2024 16:17
@tomyrd tomyrd force-pushed the tomyrd-remove-client-from-faucet branch from 0a2aff6 to b0e9116 Compare June 3, 2024 19:43
@tomyrd tomyrd changed the base branch from next to mFragaBA-next-0.4 June 3, 2024 19:45
@tomyrd tomyrd force-pushed the tomyrd-remove-client-from-faucet branch from b0e9116 to 0a2aff6 Compare June 3, 2024 19:48
@tomyrd tomyrd force-pushed the tomyrd-remove-client-from-faucet branch from 0a2aff6 to a176307 Compare June 3, 2024 20:08
@tomyrd tomyrd marked this pull request as ready for review June 3, 2024 21:59
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.

Thank you! Not a very in-depth review - but overall everything looks good (only a couple of inline comments from my end).

bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

bobbinth commented Jun 4, 2024

@tomyrd - thank you!

@igamigo, @mFragaBA - could one of you take another look and then we can merge?

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 a couple of comments but nothing blocking.

bin/faucet/src/client.rs Outdated Show resolved Hide resolved
bin/faucet/src/client.rs Outdated Show resolved Hide resolved
@bobbinth
Copy link
Contributor

bobbinth commented Jun 6, 2024

I see that this was merged into mFragaBA-next-0.4. Should we merge it into next?

bin/faucet/Cargo.toml Outdated Show resolved Hide resolved
@mFragaBA
Copy link
Contributor

mFragaBA commented Jun 6, 2024

I see that this was merged into mFragaBA-next-0.4. Should we merge it into next?

it will change the miden-base dependencies to point to the next branch since it was merged into mFragaBA-next-0.4, if we're ok with that then sure (we'll need to change it before release)

@bobbinth
Copy link
Contributor

bobbinth commented Jun 6, 2024

it will change the miden-base dependencies to point to the next branch since it was merged into mFragaBA-next-0.4, if we're ok with that then sure (we'll need to change it before release)

Yes - I think it is fine to have next branch here point to the next branch in miden-base.

@tomyrd tomyrd changed the base branch from mFragaBA-next-0.4 to next June 6, 2024 19:16
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 one comment inline.

crates/store/src/state.rs Show resolved Hide resolved
Copy link
Contributor

@mFragaBA mFragaBA left a comment

Choose a reason for hiding this comment

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

LGTM! (tested locally with a dockerized node + faucet and an account from a local client. Created multiple public notes and was able to consume them). We'd still need 0xPolygonMiden/miden-client#375 for private ones to import private notes into the client

@bobbinth bobbinth merged commit 0bd0ee4 into next Jun 7, 2024
6 checks passed
@bobbinth bobbinth deleted the tomyrd-remove-client-from-faucet branch June 7, 2024 06:38
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