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

Poc query balance #21

Merged
merged 6 commits into from
May 23, 2024
Merged

Poc query balance #21

merged 6 commits into from
May 23, 2024

Conversation

indirection42
Copy link
Contributor

@indirection42 indirection42 commented May 22, 2024

poc-guest-query-balance is working, close #2

Bugs:

The previous way of returning value via guest's stack is not working. Specifically, PR #17 has bug, which produce 40 instead of 42 for variant 1. In addition, return RO value is ok for variant 0.
I roughly looked over the assembly code, and it does seem a bit off. I need to take a closer look later.
For now, I use return value via heap instead, it works.

@indirection42 indirection42 marked this pull request as ready for review May 22, 2024 04:52
// variant 0 means free balance
// variant 1 means reserved balance
// variant 2 means free+reserved
let mut sum = 0u64;
Copy link
Member

Choose a reason for hiding this comment

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

the sum logic should happen in guest program. the host only does the query

Copy link
Contributor Author

@indirection42 indirection42 May 22, 2024

Choose a reason for hiding this comment

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

I'm thinking making host call:

  1. query_balances(variant, account_ids_ptr, bytes_len)(which make host decode Vec<AccountId>'s length) and return slices of balance (write to guest as return values)
  2. or let guest has the type information to decode bytes, then do query_balance(variant, account_id)

I think the latter will be more general and make the host call api simple.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the prefixed compact-encoded length in SCALE encoding with Vec<T> just for size hint to preallocate appropriate memory? We still need to specify the encoded bytes length when doing decoding, right?

Copy link
Member

Choose a reason for hiding this comment

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

host function should be minimal
it should be query one account id at a time so and we know the size of AccountId and can just hardcode it here

@indirection42 indirection42 requested a review from xlc May 23, 2024 06:27
@indirection42 indirection42 merged commit 0fb3a86 into master May 23, 2024
2 checks passed
@indirection42 indirection42 deleted the poc-query-balance branch May 23, 2024 07:56
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.

E2E PoC
2 participants