-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the #[interface]
attribute for overriding the default discriminator
#2728
Introduce the #[interface]
attribute for overriding the default discriminator
#2728
Conversation
@buffalojoec is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
@acheroncrypto A couple of flags:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for taking an interest in contributing to Anchor!
- I can't think of an idiomatic way to add support for this in the instruction coder's
decode
function. Are you open to changing how the layouts are stored?
If the current way doesn't allow for it then sure.
- When the
interface-instructions
feature is enabled, Anchor throws the below warning trace on build. Have you seen this before? (Note this is even if I start frommaster
and just add the feature with no new code)Error: Function _ZN106_$LT$core..iter..adapters..GenericShunt$LT$I$C$R$GT$$u20$as$u20$core..iter..traits..iterator..Iterator$GT$4next17h7adef51f44f8e442E Stack offset of 30848 exceeded max offset of 4096 by 26752 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn7codegen8accounts11constraints9linearize17h92d75d9d4dd862feE Stack offset of 22624 exceeded max offset of 4096 by 18528 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn7codegen8accounts8generics17he85b1e7c96261c3eE Stack offset of 4504 exceeded max offset of 4096 by 408 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn6parser8accounts11constraints5parse17h9c1a9fbf1ca518f7E Stack offset of 29856 exceeded max offset of 4096 by 25760 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn6parser8accounts11constraints22ConstraintGroupBuilder5build17hfc3c764227ad11e0E Stack offset of 30848 exceeded max offset of 4096 by 26752 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn6parser8accounts5parse17h7cbbe77d97239a5aE Stack offset of 14448 exceeded max offset of 4096 by 10352 bytes, please minimize large stack variables Error: Function _ZN10anchor_syn6parser8accounts19parse_account_field17h49818181fa8cf20aE Stack offset of 36368 exceeded max offset of 4096 by 32272 bytes, please minimize large stack variables
This is because you've included anchor-syn
as a dependency to anchor-lang
but anchor-syn
is mainly used for creating the macros so it doesn't/shouldn't run in BPF:
Lines 47 to 48 in c402972
# `anchor-syn` should only be included with `idl-build` feature | |
anchor-syn = { path = "./syn", version = "0.29.0", optional = true } |
Thanks! This did the trick. I've also resolved your other comments. Last piece is the decoder. |
bae8c52
to
3f71931
Compare
Ok @acheroncrypto the last commit is the decoder implementation. Actually came out much smoother than I thought. Lmk any thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok @acheroncrypto the last commit is the decoder implementation. Actually came out much smoother than I thought. Lmk any thoughts.
Only minimal changes and it's looking great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!
Before we get this in, could you note this change in the CHANGELOG?
b4eed4e
to
37a87dc
Compare
37a87dc
to
b7172ee
Compare
This looks ready to merge but before we do so, let me know if you have thoughts on the following:
I think it's best to merge this right now since people have already been asking for this feature. |
I'm willing to rename the macro and the builder method to With that being said, I think it might be a little confusing for people if they can use I guess it's completely up to you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
This PR introduces the
#[interface]
attribute for instruction functions in Anchor programs.When a function is annotated with
#[interface(..)]
, a particular instruction from an SPL interface - such as SPL Transfer Hook - can be provided as an argument. This argument will instruct Anchor to override the default discriminator (a hash of"global"
and the function name) to instead use the interface instruction's discriminator, as defined in the interface crate.Here's a snippet of a Transfer Hook program written in Anchor:
With these annotations in place, these will be the new discriminators, respectively:
spl_transfer_hook_interface::instruction::InitializeExtraAccountMetaListInstruction::SPL_DISCRIMINATOR
spl_transfer_hook_interface::instruction::ExecuteInstruction::SPL_DISCRIMINATOR
Accounts context is unchanged.
Closes #2723