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

BorshDeserialize errors in system_program.rs and idl.rs #2511

Closed
shirecoding opened this issue Jun 3, 2023 · 13 comments
Closed

BorshDeserialize errors in system_program.rs and idl.rs #2511

shirecoding opened this issue Jun 3, 2023 · 13 comments
Labels
compile error Issues related to compile errors

Comments

@shirecoding
Copy link

shirecoding commented Jun 3, 2023

I've tried anchor build for 0.26.0 and 0.27.0 and both give the following errors.
In addition i also had to add #![feature(trivial_bounds)] to lib.rs.
Anyone knows why? doesnt anchor build use its own rustc version? why then does it keep giving me nightly build errors

error[E0277]: the trait bound `Pubkey: BorshSerialize` is not satisfied                                                                                                                                                                              
   --> src/system_program.rs:289:10                                                                                                                                                                                                                  
    |                                                                                                                                                                                                                                                
289 | #[derive(Accounts)]                                                                                                                                                                                                                            
    |          ^^^^^^^^ the trait `BorshSerialize` is not implemented for `Pubkey`                                                                                                                                                                   
    |                                                                                                                                                                                                                                                
    = help: the following other types implement trait `BorshSerialize`:                                                                                                                                                                              
              &T                                                                                                                                                                                                                                     
              ()                                                                                                                                                                                                                                     
              (T0, T1)                                                                                                                                                                                                                               
              (T0, T1, T2)                                                                                                                                                                                                                           
              (T0, T1, T2, T3)                                                                                                                                                                                                                       
              (T0, T1, T2, T3, T4)                                                                                                                                                                                                                   
              (T0, T1, T2, T3, T4, T5)                                                                                                                                                                                                               
              (T0, T1, T2, T3, T4, T5, T6)                                                                                                                                                                                                           
            and 121 others                                                                                                                                                                                                                           
    = help: see issue #48214                                                                                                                                                                                                                         
    = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable                                                                                                                                                                      
    = note: this error originates in the derive macro `Accounts` (in Nightly builds, run with -Z macro-backtrace for more info)                                                                                                                      
                                                                                                                                          

adding #![feature(trivial_bounds)] to lib.rs makes the top error go away, however i still get another error

                                                                                                                                                                                                                  error[E0277]: the trait bound `Pubkey: BorshDeserialize` is not satisfied                                                                                                                                                                            
  --> src/idl.rs:95:1                                                                                                                                                                                                                                
   |                                                                                                                                                                                                                                                 
95 | #[account("internal")]                                                                                                                                                                                                                          
   | ^^^^^^^^^^^^^^^^^^^^^^ the trait `BorshDeserialize` is not implemented for `Pubkey`                                                                                                                                                             
   |                                                                                                                                                                                                                                                 
   = help: the following other types implement trait `BorshDeserialize`:                                                                                                                                                                             
             ()                                                                                                                                                                                                                                      
             (T0, T1)                                                                                                                                                                                                                                
             (T0, T1, T2)                                                                                                                                                                                                                            
             (T0, T1, T2, T3)                                                                                                                                                                                                                        
             (T0, T1, T2, T3, T4)                                                                                                                                                                                                                    
             (T0, T1, T2, T3, T4, T5)                                                                                                                                                                                                                
             (T0, T1, T2, T3, T4, T5, T6)                                                                                                                                                                                                            
             (T0, T1, T2, T3, T4, T5, T6, T7)                                                                                                                                                                                                        
           and 101 others                                                                                                                                                                                                                            
note: required for `IdlAccount` to implement `BorshDeserialize`   
@sultandilaram
Copy link

+1

1 similar comment
@ghulamMustafaRaza
Copy link

+1

@ghulamMustafaRaza
Copy link

@armaniferrante

@acheroncrypto
Copy link
Collaborator

This will be fixed by #2512.

@shirecoding
Copy link
Author

is there anything we can do to patch it in the meantime while waiting for the merge?

@acheroncrypto
Copy link
Collaborator

is there anything we can do to patch it in the meantime while waiting for the merge?

This currently works:

[dependencies]
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
getrandom = { version = "0.2.9", features = ["custom"] }
solana-program = "=1.14.17"
winnow = "=0.4.1"
toml_datetime = "=0.6.1"

@shirecoding
Copy link
Author

thanks @acheroncrypto

@shirecoding
Copy link
Author

i think something is still wrong though, it passes the dependencies however it seems to fail on any RPCs which creates an account

Error:

 Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Program failed to complete
#[derive(Accounts)]
pub struct CreateUser<'info> {
    #[account(
        init_if_needed,
        payer = signer,
        seeds = [b"user", signer.key().as_ref()],
        bump,
        space = User::len(),
    )]
    pub user_pda: Account<'info, User>,
    #[account(mut)]
    pub signer: Signer<'info>,
    pub system_program: Program<'info, System>,
}

#[account]
pub struct User {
    pub test: bool,
    pub bump: u8,
}
    const [pda, _] = web3.PublicKey.findProgramAddressSync(
      [Buffer.from(anchor.utils.bytes.utf8.encode("user"))],
      program.programId
    );

    // Create user
    const tx = await program.methods
      .createUser()
      .accounts({
        userPda: pda,
        signer: user.publicKey,
        systemProgram: web3.SystemProgram.programId,
      })
      .signers([user])
      .rpc();

@shirecoding
Copy link
Author

shirecoding commented Jun 7, 2023

ah nvm, it works after i also downgraded my solana CLI to 1.14.17

for those having issues you can try

sh -c "$(curl -sSfL https://release.solana.com/v1.14.17install)"

in addition to

[dependencies]
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
getrandom = { version = "0.2.9", features = ["custom"] }
solana-program = "=1.14.17"
winnow = "=0.4.1"
toml_datetime = "=0.6.1"

This was referenced Jun 7, 2023
@acheroncrypto acheroncrypto added the compile error Issues related to compile errors label Jun 12, 2023
@acheroncrypto
Copy link
Collaborator

This is fixed in 0.28.0.

@ChewingGlass
Copy link
Contributor

@acheroncrypto I still get this error around toml_datetime in 0.28.0

error: package `toml_datetime v0.6.2` cannot be built because it requires rustc 1.64.0 or newer, while the currently active rustc version is 1.62.0-dev

@ChewingGlass
Copy link
Contributor

ChewingGlass commented Jun 15, 2023

Note that if you use solana stable, you'll get this error:

   Compiling solana-sdk-macro v1.16.1
error[E0658]: `let...else` statements are unstable
   --> /Users/nprince/.cargo/registry/src/github.com-1ecc6299db9ec823/solana-frozen-abi-macro-1.16.1/src/lib.rs:422:5
    |
422 | /     let Some(expected_digest) = expected_digest else {
423 | |         return Error::new_spanned(
424 | |             TokenStream2::from(item),
425 | |             "the required \"digest\" = ... attribute is missing.",
...   |
428 | |         .into()
429 | |     };
    | |______^
    |
    = note: see issue #87335 <https://github.com/rust-lang/rust/issues/87335> for more information
    = help: add `#![feature(let_else)]` to the crate attributes to enable

So in order to use anchor 28 you have to be on solana beta, 1.17.0. Maybe an earlier version works, not sure the cutoff. But 1.14 definitely explodes.

@acheroncrypto
Copy link
Collaborator

@ChewingGlass you can use both 1.16 and 1.14(requires pinning versions of some crates) with Anchor 0.28.0 as explained in #2527 (comment) but 1.16 is recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compile error Issues related to compile errors
Projects
None yet
Development

No branches or pull requests

5 participants