1

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?

3 Answers 3

3

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.

1

Your program can declare instructions to do whatever you want within the constraints of the transaction deserialization and compute-budget limits

1

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.

3
  • But the size of this global account will be fixed right? How do we workaround that?
    – itsfarseen
    Commented Jul 20, 2022 at 9:39
  • The size of the global account doesn't need to change, you just store your scalar there. Presumably, there is math in your program that looks like: 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).
    – HelmetFace
    Commented Jul 27, 2022 at 21:51
  • Oh that way. Unfortunately, my scaling parameter is different for each user. The scaling parameter for someone who staked two weeks ago would be different for someone who staked four weeks ago.
    – itsfarseen
    Commented Jul 28, 2022 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.