metaplex-foundation / mpl-token-metadata

Program to attach additional data to Fungible or Non-Fungible tokens on Solana.
https://developers.metaplex.com/token-metadata
Other
99 stars 42 forks source link

Borsh version in Anchor & Metaplex #31

Closed saberistic closed 11 months ago

saberistic commented 11 months ago

So today I got into this situation that after adding mpl-metadata-program as a dependency to my anchor program(0.28)I faced a compilation issue.

  --> src/state/reservation.rs:56:26                                                                                                                                            [1169/1600]
   |                                                                                                                                                                                       
56 | #[derive(BorshSerialize, BorshDeserialize, PartialEq, Eq, Debug, Clone, ShankAccount)]                                                                                                
   |                          ^^^^^^^^^^^^^^^^ the trait `borsh::BorshDeserialize` is not implemented for `solana_program::pubkey::Pubkey`                                                 
   |                                                                                                                                                                                       
   = help: the following other types implement trait `borsh::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)                                                                                                                                              kGAQQBaGooaivchrEpZgrzW7peUU
           and 160 others                                                                                                                                                                  
   = help: see issue #48214                                                                                                                                                                
   = help: add `#![feature(trivial_bounds)]` to the crate attributes to enable                                                                                                             
   = note: this error originates in the derive macro `BorshDeserialize` (in Nightly builds, run with -Z macro-backtrace for more info) 

searching web told me it's about borsh version and have to set dependencies as precise with cargo so that it gets resolved. cargo update -p solana-zk-token-sdk --precise 1.14.22 So I did.

Then accounts serializations(too large) popped up on my local cluster (v1.16) logs that was indication of some incompatibility with this precising. So attempted to downgrade cluster and another can of worm got popped open with anchor versions.

Long story short eventually I found a workaround by cloning this repo, set Borsh version to 0.10.3 and mocking a missing implementation of deserialize_reader and locally patch cargo dependency to my local version of this repo.

Anyone could advise on what should be the right move from here?

febo commented 11 months ago

You can use the 2.0.0-beta.1 version of the crate: https://crates.io/crates/mpl-token-metadata/2.0.0-beta.1

The code base is in the PR #29

saberistic commented 11 months ago

Oh thanks, I missed that tag. Is there a breaking change there? Noticing a major version bump, exciting

febo commented 11 months ago

The change from borsh 0.9.x to 0.10.x is a breaking change, since borsh changed one of its traits. There can be dependency issues if you have a library that needs 0.9.x.

saberistic commented 11 months ago

Compiler still complains about the trait `borsh::BorshSerialize` is not implemented for `mpl_token_auth_rules::payload::Payload when switched to 2.0.0-beta.1

tushar-sahoo commented 10 months ago

@saberistic First try anchor build with version 1.13.1 you will get an error. Then change it in Cargo.toml to version 2.0.0-beta.1 and do anchor clean and anchor build again. This worked for me.

Make sure your Rust CLI is v1.68.0 or above; worked fine for me in v1.71.0. Solana CLI must be v1.16.5 or above; I used v1.16.8. And ofc Anchor CLI must be v0.28.0

saberistic commented 10 months ago

Thanks, tried downgrading to 1.13.2 and it got resolved, not sure if this is something specific to my machine or expected in 1.13.2