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

feat: Add account details endpoint #248

Merged
merged 20 commits into from
Apr 11, 2024

Conversation

mFragaBA
Copy link
Contributor

@mFragaBA mFragaBA commented Apr 9, 2024

This PR introduces a few things:

  • Adds a new param to the CLI for the account new command, --storage-mode=onchain,offchain(default) that enables the creation of onchain accounts
  • Adds to the node rpc client a get_account_updates trait function. This function takes an account ID and fetches the GetAccountDetails endpoint on the node added on #294 from miden-node (and previous PRs)
  • Updates the sync behavior
    • When doing a sync we check the account updates in two ways (always doing so for tracked accounts).
      • First, validating that the updated offchain account hashes match the ones of our client
      • Second, checking the updated onchain accounts, if the hash does not match ours that means it's outdated and thus we'll use the get_account_updates function to fetch the most up to date account

@mFragaBA mFragaBA force-pushed the mFragaBA-add-account-details-endpoint branch 2 times, most recently from 27288fc to eaa7dd6 Compare April 9, 2024 20:34
Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.
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.

Left some comments for now, please disregard if you were already planning changes for any of them (since it's still a draft)

let updated_onchain_accounts = self
.get_updated_onchain_accounts(&response.account_hash_updates, &onchain_accounts)
.await?;
self.check_local_account_hashes(&response.account_hash_updates, &offchain_accounts)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's take the opportunity of the refactor to rename this to validate_local_account_hashes

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I would leave the comment that was taken out (or something similar that takes your changes into account)

@mFragaBA mFragaBA force-pushed the mFragaBA-add-account-details-endpoint branch from eaa7dd6 to 8d9c31d Compare April 10, 2024 18:08
@igamigo igamigo changed the title add account details endpoint feat: Add account details endpoint Apr 10, 2024
@igamigo igamigo marked this pull request as ready for review April 10, 2024 22:43
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. Fixed the CI issue I believe seems I didn't. I left some comments which should be simple to address, but in any case they can be deferred to a follow up PR or issue.

There are also a couple of TODOs that need addressing but I'm guessing those were planned

NonFungibleFaucet,
NonFungibleFaucet {
#[clap(short, long, value_enum, default_value_t = AccountStorageMode::OffChain)]
storage_mode: AccountStorageMode,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can add this to the AccountCmd::New since it's common to all variants.

Comment on lines +92 to +109
pub enum AccountStorageMode {
OffChain,
OnChain,
}

impl From<AccountStorageMode> for accounts::AccountStorageMode {
fn from(value: AccountStorageMode) -> Self {
match value {
AccountStorageMode::OffChain => accounts::AccountStorageMode::Local,
AccountStorageMode::OnChain => accounts::AccountStorageMode::OnChain,
}
}
}

impl From<&AccountStorageMode> for accounts::AccountStorageMode {
fn from(value: &AccountStorageMode) -> Self {
accounts::AccountStorageMode::from(*value)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add a TODO to review these struct's names (and maybe the local vs offchain terms)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes! added it here and in the client/accounts.rs one

&mut self,
account_id: AccountId,
) -> Result<Option<Account>, NodeRpcClientError> {
debug_assert!(account_id.is_on_chain());
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should probably be an error instead of a panic

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed!

Comment on lines 60 to 63
async fn get_account_update(
&mut self,
account_id: AccountId,
) -> Result<Option<Account>, NodeRpcClientError>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems that the return type should be Account instead of Option<Account> for this. I believe the node will return an error if the account is not found so an Account is always expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went for Option since it's what the response comes with so I expected that there will eventually be some use for the summary but no details case. In any way we can take another look at it in the future and keep it simple for now

@igamigo igamigo merged commit e298357 into igamigo-use-next Apr 11, 2024
4 of 5 checks passed
@igamigo igamigo deleted the mFragaBA-add-account-details-endpoint branch April 11, 2024 14:44
igamigo added a commit that referenced this pull request Apr 12, 2024
* feat: add GetAccountDetails endpoint to tonic rpc client

* feat: update CLI to provide account storage mode as cli args

* feat: handle updated onchain accounts during sync and refactor

Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.

* use updated create_basic_wallet and faucet

* use next for miden node proto

* update order of create_basic_fungible_faucet

* add small integration test for onchain accounts transactions

* address comments

* add missing sync

* fix: read Account instead of AccountDetails from get_account_details response

* remove dbg statement

* re-enable other integration tests

* extend mint integration test to reuse same on-chain account in two clients

* Test fix

* Test fix

* Test fix

* Update Makefile.toml

* address review

* extend onchain integration test to do transfer between accounts

* update missing documentation

* fix test

* Follow ups

* Stop test execution before transfer

We stop the onchain accounts test before running the p2id transaction because there's an error on how inputs are inserted/extracted on the vm, so until that gets fixed we'll leave the test code but do an early return so the test still passes.

* add rpc endpoints to trait functions' documentation

* split test helper in two functions

* fix tests

* Update main.rs

* dep version

* re-add assert

* remove unnecessary sleeps

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>
igamigo added a commit that referenced this pull request Apr 12, 2024
* Use next branches

* Fix integration test build (still doesnt work accordingly)

* Fix advice inputs?

* Fix and fmt

* Update script

* Update script properly

* fix integration test

* point to next instead of custom branch

* fix falcon seed size

* update note script root

* temp: clone the node on next branch

* run tests in parallel

* Fix path creation

* Fix tests and small refactors

* test

* Fix tests's account id

* Several refactors after updates

* Tests fix

* Mint script fix

* Fix integration

* Make compatible with newer ref

* Fix test

* feat: Add account details endpoint (#248)

* feat: add GetAccountDetails endpoint to tonic rpc client

* feat: update CLI to provide account storage mode as cli args

* feat: handle updated onchain accounts during sync and refactor

Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.

* use updated create_basic_wallet and faucet

* use next for miden node proto

* update order of create_basic_fungible_faucet

* add small integration test for onchain accounts transactions

* address comments

* add missing sync

* fix: read Account instead of AccountDetails from get_account_details response

* remove dbg statement

* re-enable other integration tests

* extend mint integration test to reuse same on-chain account in two clients

* Test fix

* Test fix

* Test fix

* Update Makefile.toml

* address review

* fix compilation errors

* add onchain accounts to docs

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>

* feat: Implement `GetNotesById` RPC endpoint (#247)

* On-chain note support.

* Merge conflicts

* Fixes

* Update main.rs

* Update sync.rs

* Use correct dependencies

* Remove underscore

* Follow ups

* Docs and fixes

* doc&refactor: missing changes from #248  (#249)

* feat: add GetAccountDetails endpoint to tonic rpc client

* feat: update CLI to provide account storage mode as cli args

* feat: handle updated onchain accounts during sync and refactor

Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.

* use updated create_basic_wallet and faucet

* use next for miden node proto

* update order of create_basic_fungible_faucet

* add small integration test for onchain accounts transactions

* address comments

* add missing sync

* fix: read Account instead of AccountDetails from get_account_details response

* remove dbg statement

* re-enable other integration tests

* extend mint integration test to reuse same on-chain account in two clients

* Test fix

* Test fix

* Test fix

* Update Makefile.toml

* address review

* extend onchain integration test to do transfer between accounts

* update missing documentation

* fix test

* Follow ups

* Stop test execution before transfer

We stop the onchain accounts test before running the p2id transaction because there's an error on how inputs are inserted/extracted on the vm, so until that gets fixed we'll leave the test code but do an early return so the test still passes.

* add rpc endpoints to trait functions' documentation

* split test helper in two functions

* fix tests

* Update main.rs

* dep version

* re-add assert

* remove unnecessary sleeps

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>

* Cargo toml

* Address reviews

---------

Co-authored-by: Martin Fraga <martin.fraga@lambdaclass.com>
Co-authored-by: Martin Fraga <fragamartine@gmail.com>
bobbinth pushed a commit that referenced this pull request Apr 13, 2024
* Use next branches

* Fix integration test build (still doesnt work accordingly)

* Fix advice inputs?

* Fix and fmt

* Update script

* Update script properly

* fix integration test

* point to next instead of custom branch

* fix falcon seed size

* update note script root

* temp: clone the node on next branch

* run tests in parallel

* Fix path creation

* Fix tests and small refactors

* test

* Fix tests's account id

* Several refactors after updates

* Tests fix

* Mint script fix

* Fix integration

* Make compatible with newer ref

* Fix test

* feat: Add account details endpoint (#248)

* feat: add GetAccountDetails endpoint to tonic rpc client

* feat: update CLI to provide account storage mode as cli args

* feat: handle updated onchain accounts during sync and refactor

Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.

* use updated create_basic_wallet and faucet

* use next for miden node proto

* update order of create_basic_fungible_faucet

* add small integration test for onchain accounts transactions

* address comments

* add missing sync

* fix: read Account instead of AccountDetails from get_account_details response

* remove dbg statement

* re-enable other integration tests

* extend mint integration test to reuse same on-chain account in two clients

* Test fix

* Test fix

* Test fix

* Update Makefile.toml

* address review

* fix compilation errors

* add onchain accounts to docs

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>

* feat: Implement `GetNotesById` RPC endpoint (#247)

* On-chain note support.

* Merge conflicts

* Fixes

* Update main.rs

* Update sync.rs

* Use correct dependencies

* Remove underscore

* Follow ups

* Docs and fixes

* doc&refactor: missing changes from #248  (#249)

* feat: add GetAccountDetails endpoint to tonic rpc client

* feat: update CLI to provide account storage mode as cli args

* feat: handle updated onchain accounts during sync and refactor

Now during the state sync we check the updated account hashes for onchain
accoints. if they don't match, then we fetch the current state from the node.
The old validation for offchain accounts is left unchanged but I refactored it
so the logic looks similar to the one for onchain accoints. I also left a few
TODO's and panics that'll be removed in follow-up commits.

* use updated create_basic_wallet and faucet

* use next for miden node proto

* update order of create_basic_fungible_faucet

* add small integration test for onchain accounts transactions

* address comments

* add missing sync

* fix: read Account instead of AccountDetails from get_account_details response

* remove dbg statement

* re-enable other integration tests

* extend mint integration test to reuse same on-chain account in two clients

* Test fix

* Test fix

* Test fix

* Update Makefile.toml

* address review

* extend onchain integration test to do transfer between accounts

* update missing documentation

* fix test

* Follow ups

* Stop test execution before transfer

We stop the onchain accounts test before running the p2id transaction because there's an error on how inputs are inserted/extracted on the vm, so until that gets fixed we'll leave the test code but do an early return so the test still passes.

* add rpc endpoints to trait functions' documentation

* split test helper in two functions

* fix tests

* Update main.rs

* dep version

* re-add assert

* remove unnecessary sleeps

---------

Co-authored-by: Ignacio Amigo <ignacio.amigo@lambdaclass.com>

* Cargo toml

* Address reviews

---------

Co-authored-by: Martin Fraga <martin.fraga@lambdaclass.com>
Co-authored-by: Martin Fraga <fragamartine@gmail.com>
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.

2 participants