metaplex-foundation / metaplex-program-library

Smart contracts maintained by the Metaplex team
Other
587 stars 512 forks source link

[Bug]: Can't deserialize metadata using latest lib #428

Closed ilmoi closed 2 years ago

ilmoi commented 2 years ago

Which package is this bug report for?

token-metadata

Issue description

Trying to deserialize a bunch of PDAs for Boryoku Dragonz that I got from gPA:

creator = DRGNjvBvnXNiQz9dTppGk1tAsVxtJsvhEmojEfBU3ezf

const rawMetadatas = await conn.getProgramAccounts(new PublicKey(METADATA_PROGRAM_ID), {
  filters: [
    ...baseFilters,
    {
      memcmp: {
        offset: programs.metadata.computeCreatorOffset(0),
        bytes: creator.toBase58(),
      },
    },
  ],
});

using the latest metdata js lib (@metaplex-foundation/mpl-token-metadata):

const deserializeMetadata = (rawMetadata: any): Metadata | undefined => {
  try {
    return Metadata.fromAccountInfo(rawMetadata.account)[0];
    // @ts-ignore
  } catch (e: any) {
    console.log("Failed to deserialize on-chain metadata:", e);
  }
};

For some of them works fine (about 100 out of 1100), but for the rest it fails with the following error:

Failed to deserialize on-chain metadata: AssertionError [ERR_ASSERTION]: Expected ��� ����F~��I��*�Țg�?D4�/�Ą͝!�o�mB!̺e0�Yy��3���S�d�c� Boryoku Dragonz #618
BORYOKU�https://arweave.net/3y40kWLZHh1LV6sKCMUV0UKG2MK-HQ45EN5lRL1kuVk���� ����F~��I��*�Țg�?D4�/�Ąd��~z�.R�c���|����~��^�7NĄd� to hold a COption
    at Object.toFixedFromData (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/beet/src/beets/composites.ts:141:15)
    at fixBeetFromData (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/beet/src/beet.fixable.ts:22:17)
    at FixableBeetStruct.toFixedFromData (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/beet/src/struct.fixable.ts:85:40)
    at FixableBeetStruct.deserialize (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/beet/src/struct.fixable.ts:59:17)
    at Function.deserialize (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/mpl-token-metadata/src/generated/accounts/Metadata.ts:103:25)
    at Function.fromAccountInfo (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/node_modules/@metaplex-foundation/mpl-token-metadata/src/generated/accounts/Metadata.ts:78:21)
    at deserializeMetadata (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/metadata/solana-api.ts:34:21)
    at /Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/metadata/solana-api.ts:99:17
    at Array.map (<anonymous>)
    at fetchMetadatasByCreator (/Users/ilmoi/Dropbox/crypto_bc/tensor/tensor-infra/etl/sol/src/metadata/solana-api.ts:99:6) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

Any advice? 🙏

Relevant log output

No response

Priority this issue should have

High (immediate attention needed)

samuelvanderwaal commented 2 years ago

@lorisleiva @thlorenz this is due to corrupted metadata. The fix is on devnet currently and should go to mainnet this week. Once it's on mainnet folks will be able to fix their metadata by running update_metadata_accounts_v2 on it. I also added a custom implementation of the Borsh deserialize trait that checks for the metadata issues and uses sane defaults when it finds it. I'm not sure how the JS lib does deserialization but if you want to explore adding something similar, let me know.

ilmoi commented 2 years ago

Is this a common problem? v 1.x.x lib was able to deserialize, so wondering if I need to bite the bullet and downgrade to 1.x.x... or if it's a one off

thlorenz commented 2 years ago

The Metadata de/serialization is derived from the Rust account struct (annotated with shank). So just re-running the SDK generator might do the trick.

Is the fix on master?

samuelvanderwaal commented 2 years ago

The Metadata de/serialization is derived from the Rust account struct (annotated with shank). So just re-running the SDK generator might do the trick.

Is the fix on master?

It is now, yes.

thlorenz commented 2 years ago

We basically need to replicate the custom Rust de/serialization function in the SDK and add an option to solita to override the generic one it generates.

I'm going to look into this ASAP.

thlorenz commented 2 years ago

@ilmoi I'm trying to reproduce your issue exactly, but the code snippet isn't complete (missing baseFilters and programs.metadata and such). Could you link me to a repo that has everything ready to run so I can repro this quickly?

I wanna reproduce to make 100% sure this is fixed when I'm done.

thlorenz commented 2 years ago

OK. no longer need the above .. was able to find some accounts that have exactly the issue you described ... from that same creator

thlorenz commented 2 years ago

@ilmoi please confirm that the issue is fixed for you now. Thanks!

ilmoi commented 2 years ago

works flawlessly, thx for fixing guys