Skip to content
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

syn: relax entry 'info lifetime for compat. with solana-program-test #2711

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tilacog
Copy link

@tilacog tilacog commented Nov 23, 2023

This PR removes the 'info lifetime constraint from the AccountInfo slice.

This change was necessary for passing Anchor's program::entry to the solana-test-program's ProgramTest::add_program method.

Here's a sample of the lifetime mismatch, before this PR's changes:

error[E0308]: mismatched types
   --> my_program/tests/integration.rs:23:65
    |
23  |     program.add_program("test-program", my_program::ID, processor!(my_program::entry));
    |                                                      -----------^^^^^^^^^^^^^^-
    |                                                      |          |
    |                                                      |          one type is more general than the other
    |                                                      arguments to this function are incorrect
    |
    = note: expected fn pointer `for<'a, 'b, 'c, 'd> fn(&'a Pubkey, &'b [AccountInfo<'c>], &'d [u8]) -> Result<_, _>`
                  found fn item `for<'info, 'a, 'b> fn(&'a Pubkey, &'info [AccountInfo<'info>], &'b [u8]) -> Result<_, _> {entry}`
note: function defined here
   --> /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/solana-program-test-1.17.6/src/lib.rs:101:8
    |
101 | pub fn invoke_builtin_function(
    |    

Copy link

vercel bot commented Nov 23, 2023

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

A member of the Team first needs to authorize it.

@tilacog tilacog marked this pull request as draft November 23, 2023 17:23
@tilacog
Copy link
Author

tilacog commented Nov 23, 2023

The Anchor crates compile, but actual usage of #[program] breaks compilation.

Error from my project:

❯ cargo check
    Checking registry v0.1.0 (/home/tilacog/tiago/code/eiger/axelar/solana-axelar/solana/programs/registry)
error[E0621]: explicit lifetime required in the type of `accounts`
 --> programs/registry/src/lib.rs:8:1
  |
8 | #[program]
  | ^^^^^^^^^^
  | |
  | lifetime `'info` required
  | help: add explicit lifetime `'info` to the type of `accounts`: `&'info [anchor_lang::prelude::AccountInfo<'info>]`
  |
  = note: this error originates in the attribute macro `program` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0621`.
error: could not compile `registry` (lib) due to previous error

My familiarity with Anchor derive macros is limited, but I am open to discussing the problem further to refine this contribution.

@@ -47,14 +47,14 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
///
/// The `entry` function here, defines the standard entry to a Solana
/// program, where execution begins.
pub fn entry<'info>(program_id: &Pubkey, accounts: &'info [AccountInfo<'info>], data: &[u8]) -> anchor_lang::solana_program::entrypoint::ProgramResult {
pub fn entry<'info>(program_id: &Pubkey, accounts: &[AccountInfo<'info>], data: &[u8]) -> anchor_lang::solana_program::entrypoint::ProgramResult {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be much easier to fix by creating a new processor! macro with Anchor's current lifetimes because the same lifetime constraints exist in many places.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modifying the macro only is not enough. The issue comes from the signature expected by invoke_builtin_function itself. I think the changes to lifetime and references done in anchor need a bit more work to accommodate all the existing use cases.

dankelleher added a commit to sunrise-stake/beam that referenced this pull request Dec 5, 2023
NOTE - cargo test is broken pending resolution of this anchor issue: coral-xyz/anchor#2711
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.

None yet

3 participants