Skip to content

lang: Replace hardcoded discriminators with Discriminator::DISCRIMINATOR#3578

Merged
acheroncrypto merged 3 commits intosolana-foundation:masterfrom
acheroncrypto:lang-replace-hardcoded-discriminators
Mar 4, 2025
Merged

lang: Replace hardcoded discriminators with Discriminator::DISCRIMINATOR#3578
acheroncrypto merged 3 commits intosolana-foundation:masterfrom
acheroncrypto:lang-replace-hardcoded-discriminators

Conversation

@acheroncrypto
Copy link
Copy Markdown
Collaborator

Problem

There are some places where we're using hardcoded discriminators instead of the associated Discriminator::DISCRIMINATOR constant in codegen.

For example the following section:

https://github.com/coral-xyz/anchor/blob/c869e11a83173355123c4109d3f37add1b3bd69d/lang/attribute/program/src/declare_program/mods/cpi.rs#L76

expands to something like:

data.extend_from_slice(&[142u8, 128u8, 47u8, 77u8, 15u8, 152u8, 240u8, 42u8]);

when we could just use the associated constant to make it simpler and less error-prone:

data.extend_from_slice(MyInstruction::DISCRIMINATOR);

Summary of changes

Replace hardcoded discriminators in declare_program! with Discriminator::DISCRIMINATOR.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 4, 2025

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto merged commit 8b391aa into solana-foundation:master Mar 4, 2025
52 of 53 checks passed
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant