You actually can resize accounts.
How can I increase an existing account size?
Solana uses a Vec<(String, String)>
for the additional_metadata
of the TokenMetadata token22 token-metadata interface.
Link to the code:
solana token-metadata interface additional_metadata github
It is recommended to put a dynamic sized data at the end of the account struct so any other data can be easily filtered, because once you get to vector data you have to do more work for filtering since the size will be dynamic.
I don't know how your Post
account data looks, but including a vector of dynamic data every time you fetch a post doesn't feel like a great way to handle this. Instead I would add a couple more accounts PostLikes
and PostDislikes
which will be PDA's derived with ['post-likes', post.key()]
. The likes and dislikes can be a counter stored in the post so you can still quickly get the amount of likes and dislikes without needing to get all of the pubkeys of the likers/dislikers. Then inside of PostLikes
and PostDislikes
you can have the Vec<Pubkey>
.
Now if you want to get the number of likes/dislikes, just get the post data. If you want to get the pubkeys of the likes/dislikes, use the post to get the pda for the PostLikes
/PostDislikes
account.
Keep in mind account size and rent costs. A Pubkey is 32 bytes. 100,000 likes would be at least 3,200,000 bytes which is about 22 sol at current rent prices, which could be paid for and expanded by you as needed, or paid for by the user when they like the post.
Edit: Also note that accounts actually do have a max limit still. So if you really need 100,000 all in one account to be checked on-chain, you won't be able to use a PDA.
If you don't need them all in one account, you can chunk them up and still use PDA's as well as another account keeping track of which chunk a likers/dislikers Pubkey is in. Just brainstorming here though, as it really comes down to what exactly you are trying to do.
At the time of this writing:
- Accounts have a max size of 10MB (10 Mega Bytes)
- PDA accounts have a max size of 10KB (10 Kilo Bytes)
solana cookbook account facts