Closed nlok5923 closed 2 months ago
@nlok5923 - thank you for filing such a detailed report!
@Dominik1999 - could you check this? I thought we had some tests in miden-base
that tested account:set_item
procedure - but maybe there are some things we are not testing there.
Hi! Thanks for the detailed report.
I added a few more debug statements on the note script and the code:
set_item
is called the proper stack arguments are thereupdated_items: [
(
100,
[
1,
1,
0,
0,
],
),
(
101,
[
1,
2,
0,
0,
],
),
],
// check the store of player 1 account to see are the cards set properly
// ======== I ONLY ADDED THESE 2 LINES ==========
let (player_account, _) = client.get_account(player_account.id()).unwrap();
let player_account_storage = player_account.storage();
// for i in 0..102 {
// println!("Player account storage {:?} {:?}", i , player_account_storage.get_item(i));
// }
let after_acc_storage = player_account.storage().root();
println!("Player Card 1 {:?}", player_account_storage.get_item(100));
println!("Player Card 2 {:?}", player_account_storage.get_item(101));
println!("Prev acc storage root {:?}", prev_acc_storage);
println!("After txn acc storage root {:?}", after_acc_storage);
And I got the proper output (both the cards are correct and the storage root hash seems to have changed):
Player Card 1 RpoDigest([1, 1, 0, 0])
Player Card 2 RpoDigest([1, 2, 0, 0])
Prev acc storage root RpoDigest([691325485839961784, 18292302958153520671, 5992886236460359113, 743126542260494113])
After txn acc storage root RpoDigest([7246666647329329192, 14337335527969961969, 12753666777987838473, 5246371044914077319])
Let me know it it solves it for you @nlok5923 otherwise we'll figure it out
Thanks @mFragaBA for the help!
I think the issue is fixed now, Shouldn't we make Account api's such that it should always fetch the latest values from the client store ?
Thanks @mFragaBA for the help!
I think the issue is fixed now, Shouldn't we make Account api's such that it should always fetch the latest values from the client store ?
On the one hand, it would ease the developer using miden-client because they wouldn't have to worry on keeping the most up to date version of the account.
But on the other hand, Account
comes from miden-base and is used in other places which are not the client. We could make a wrapper type for account, but that would mean the account should have some sort of reference to either the store or the client. That would also in turn add more complexity. Plus you'd be forcing a request onto a db each time you want to access an element.
In any case it is possible for developers to write a wrapper type, something around this:
pub struct AccountWrapper<'s, N: NodeRpcClient, R: FeltRng, S: Store> {
client: &'s Client<N, R, S>,
account: Account,
}
impl<'s, N: NodeRpcClient, R: FeltRng, S: Store> AccountWrapper<'s, N, R, S> {
pub fn code(&self) -> &AccountCode {
todo!()
}
pub fn vault(&self) -> &AssetVault {
todo!()
}
pub fn storage(&mut self) -> &AccountStorage {
let (account, _seed) = self.client.get_account(self.account.id()).unwrap();
self.account = account;
self.account.storage()
}
}
you can also avoid going to the db. If you have an Account
and the TransactionResult
you can also do
// assuming you have mutable access to the account
account.apply_delta(transaction_result.account_delta()).unwrap(); // proper error handling missing
closing the issue as the original problem got solved.
What should be done?
I am using a custom notescript to store some information in a regular immutable account at particular slot index using
set_item
api.Note script Code:
Account Code where we want to store the card information
I am calling receive_cards procedure in notescripts to set custom information (cards informtion which is a word) in player account storage in slot 100 and 101.
How should it be done?
Even after setting the account storage using
set_item
api the storage root of the account doesn't changeWhen is this task done?
The storage root of account should change and we should be able to see card information on slot 100 and 101 of account storage.
Additional context
Steps to reproduce:
https://github.com/Rizelabs/aze-server
cd aze-server
git checkout feat/game-txn-call
cargo run --release
curl -X GET http://localhost:8000/v1/game/create-account
Notescript: https://github.com/RizeLabs/aze-server/blob/feat/game-txn-call/lib/contracts/notes/game/deal.masm