Is there a way to update a field on all the accounts owned by a program at once?
Say I have a bunch of PDAs Stake { amount: usize }
.
Is it possible to do amount = amount * 1.1
for multiple accounts in one go?
You need to add each PDA as mutable account to the instructions. Therefore the limiting factor will be transaction size, which is currently 1232 bytes of serialized transaction data.
If this proposal is implemented in the future this limit will most likely increase.
Your program can declare instructions to do whatever you want within the constraints of the transaction deserialization and compute-budget limits
Given transaction size limits, this can't be done atomically "at scale".
The "simpler" approach is probably to store some global state on an account somewhere that you update instead of all user accounts' values, and during calculation where you need those users' values scaled, you just reference that global state.
let some_value = do_some_math(user_account.foo);
Instead of relying on applying a scalar to each user_account.foo
, store one global u64
and do_some_math(user_account.foo * global_account.scalar)
.
Commented
Jul 27, 2022 at 21:51