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 api to get ft balances for multiple accounts #905

Merged
merged 8 commits into from
Feb 27, 2024

Conversation

karim-en
Copy link
Contributor

@karim-en karim-en commented Feb 21, 2024

Description

The PR adds a public method to the engine/internal connector to get balances of multiple accounts. This is needed because we have changed the migration logic to migrate the balances based on the on-chain data, not off-chain.

Performance / NEAR gas cost considerations

The borsh is used instead of JSON to decrease gas usage and migrate more accounts in one batch.

Testing

Added a test to the crate aurora-engine-tests, not aurora-engine-tests-connector because the second one is enabled just for silo builds.

How should this be reviewed

Additional information

It's controversial whether to use HashMap<AccountId, Balance> or Vec<(AccountId, Balance)>; the HashMap prevents duplication, but on the other side, it increases gas usage.

@karim-en karim-en marked this pull request as ready for review February 23, 2024 22:38
@aleksuss
Copy link
Member

It's controversial whether to use HashMap<AccountId, Balance> or Vec<(AccountId, Balance)>; the HashMap prevents duplication, but on the other side, it increases gas usage.

I guess we can use the HashMap and don't care about the gas usage since it will be invoked only once.

aleksuss and others added 2 commits February 27, 2024 14:15
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
@aleksuss aleksuss added this pull request to the merge queue Feb 27, 2024
Merged via the queue into develop with commit 977823a Feb 27, 2024
24 checks passed
@aleksuss aleksuss deleted the balances-migration branch February 27, 2024 14:32
aleksuss added a commit that referenced this pull request Mar 27, 2024
<!--
Thanks for submitting a pull request! Here are some helpful tips:

* Always create branches on and target the `develop` branch.
* Run all the tests locally and ensure that they are passing.
* Run `make format` to ensure that the code is formatted.
* Run `make check` to ensure that all checks passed successfully.
* Small commits and contributions that attempt one single goal is
preferable.
* If the idea changes or adds anything functional which will affect
users, an
AIP discussion is required first on the Aurora forum: 

https://forum.aurora.dev/discussions/AIPs%20(Aurora%20Improvement%20Proposals).
* Avoid breaking the public API (namely in engine/src/lib.rs) unless
required.
* If your PR is a WIP, ensure that you enable "draft" mode.
* Your first PRs won't use the CI automatically unless a maintainer
starts.
If this is not your first PR, please do NOT abuse the CI resources.

Checklist:
- [ ] I have performed a self-review of my code
- [ ] I have documented my code, particularly in the hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests to prove my fix or new feature is effective and
works
- [ ] Any dependent changes have been merged
- [ ] The PR is targeting the `develop` branch and not `master`
- [ ] I have pre-squashed my commits into a single commit and rebased.
-->

## Description
The PR adds a public method to the engine/internal connector to get
balances of multiple accounts. This is needed because we have changed
the migration logic to migrate the balances based on the on-chain data,
not off-chain.
<!-- 
Provide a general summary of your changes. A clear overview along with
an
in-depth explanation is beneficial.

If this PR closes any issues, be sure to add "closes #<number>"
somewhere.
-->

## Performance / NEAR gas cost considerations
The borsh is used instead of JSON to decrease gas usage and migrate more
accounts in one batch.
<!--
Performance regressions are not ideal, though we welcome performance 
improvements. Any PR must be completely mindful of any gas cost
increases. The
CI will fail if the gas costs change at all. Do update these tests to 
accommodate for the new gas changes. It is good to explain 
this change, if necessary.
-->

## Testing
Added a test to the crate `aurora-engine-tests`, not
`aurora-engine-tests-connector` because the second one is enabled just
for silo builds.
<!--
Please describe the tests that you ran to verify your changes.
-->

## How should this be reviewed

<!--
Include any recommendations of areas to be careful of to ensure that the
reviewers use extra attention.
-->

## Additional information
It's controversial whether to use `HashMap<AccountId, Balance>` or
`Vec<(AccountId, Balance)>`; the `HashMap` prevents duplication, but on
the other side, it increases gas usage.
<!--
Include any additional information which you think should be in this PR,
such
as prior arts, future extensions, unresolved problems, or a TODO list
which
should be followed up.
-->

---------

Co-authored-by: Oleksandr Anyshchenko <oleksandr.anyshchenko@aurora.dev>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
@aleksuss aleksuss mentioned this pull request Mar 27, 2024
aleksuss added a commit that referenced this pull request Mar 27, 2024
### Additions

- Added a new view transaction `ft_balances_of` for getting balances for
multiple accounts by [@karim-en]. ([#905])

### Changes

- The `ft_resolve_transfer` callback doesn't require running the
contract to finish the `ft_transfer_call` correctly
  by [@aleksuss]. ([#906])
- Borsh has been bumped to 1.3 what allows to get rid of additional
feature `borsh-compat` by [@aleksuss]. ([#907])
- The `ExecutionProfile` has been extended with logs for tests by
[@mrLSD]. ([#910])
- The interface of the engine standalone storage has been extended with
a couple of methods for allowing set/get
  arbitrary data outside the crate by [@aleksuss]. ([#913])

### Fixes

- Minor improvements and fixes by [@raventid]. ([#916])

[#905]: #905
[#906]: #906
[#907]: #907
[#910]: #910
[#913]: #913
[#916]: #916

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Karim <karim@aurora.dev>
Co-authored-by: Michael Birch <michael.birch@aurora.dev>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Evgeny Ukhanov <evgeny@aurora.dev>
Co-authored-by: Julian Pokrovsky <raventid@users.noreply.github.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.

None yet

4 participants