Open mikemaccana opened 4 weeks ago
- Include an
ANCHOR_DISCRIMINATOR
const out of the box?
There are plans to support dynamic discriminator length which would make this redundant. This is also one of the main reasons why the new IDL spec have required discriminator
field.
- Have something like
INIT_SPACE
that included the discriminator size, egTOTAL_SPACE
or similar?
Yeah, tbh I think InitSpace
should have included the discriminator by default since it's pretty much only being used in init
contexts anyway. That being said, making that change now would be a breaking change, and it's likely many people will keep adding the discriminator size if we were to make changes to InitSpace
. Instead, we can deprecate InitSpace
, and have a new one TotalSpace
(or Space
for simplicity) like you've suggested.
I also think it's possible to completely hide the discriminator logic from the user's POV.
Heya! @nickfrosty and I were talking and wondering what you think here.
Right now when teaching Anchor we avoid magic numbers by getting people to add
pub const ANCHOR_DISCRIMINATOR: usize = 8;
to almost every new project, and get people to write......when they need to initialize new accounts. I'm wondering what a better solution would be:
ANCHOR_DISCRIMINATOR
const out of the box?Have something like
INIT_SPACE
that included the discriminator size, egTOTAL_SPACE
or similar?I'm happy to send a PR. Just LMK what you think.