coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.68k stars 1.35k forks source link

Bug: anchor rpc name of 29 characters fails erroneuosly. #1448

Open mgild opened 2 years ago

mgild commented 2 years ago

Upon calling an RPC of the name:

oracle_queue_set_vrf_settings

I receive:

ProgramError: 101: Fallback functions are not supported
    at Function.parse (/Users/mgild/projects/v2-setup/node_modules/@project-serum/anchor/src/error.ts:41:14)
    at Object.rpc [as oracleQueueSetVrfSettings] (/Users/mgild/projects/v2-setup/node_modules/@project-serum/anchor/src/program/namespace/rpc.ts:28:42)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async OracleQueueAccount.setVrfSettings (/Users/mgild/projects/v2-setup/node_modules/@switchboard-xyz/switchboard-v2/src/sbv2.ts:1841:12)
    at async main (/Users/mgild/projects/v2-setup/main.ts:601:5) {
  code: 101,
  msg: 'Fallback functions are not supported'
}

Shortening the rpc name to oracle_queue_vrf_config resolves the issue.

NBNARADHYA commented 2 years ago

@mgild I couldn't really reproduce this issue! I used the exact same instruction name and it works without a glitch

schwarzbi3r commented 2 years ago

@mgild I also could reproduce with the same instruction name. Could you provide more details/code?

Further exploration notes: This error, 101, only seems to come back from https://github.com/project-serum/anchor/blob/master/lang/syn/src/codegen/program/dispatch.rs#L117 and so is likely the result of a of the sighash not matching at https://github.com/project-serum/anchor/blob/master/lang/syn/src/codegen/program/dispatch.rs#L171

Not sure what's happening, but somewhere along the line it would imply a mismatch either on the Solana Hasher side, or on the client side where it takes in the RPC name, snake cases it and hashes the <namespace>::<snake_case_name>. I can't find anywhere in either of those places where a longer string would be an issue (or a 29 character string). I did try some extremely long strings as a sanity check and found no issues.

However, I was able to cause this error by using the name "oracle_queue_vrfconfig", which through a CamelCase to snake_case conversion will drop the trailing underscore, throwing off the 8 byte hash id and thereby causing the Error: 101: Fallback functions are not supported. Which I don't think is your issue, but demonstrates that it is possible to generate an IDL with RPC names that won't hash to their proper counterparts and cause this error.

More code would be helpful to debug this.

mgild commented 2 years ago

Hm, the namespace name is switchboard_v2 but the rpc was empty at the time of testing this:

anchor-cli 0.19.0 solana-program = "=1.9.6" anchor-lang = "0.19.0"