AcalaNetwork/chopsticks

Unable to use custom rpcs with chopsticks

distributedstatemachine opened this issue · 2 comments

Description

We are currently try to integrate chopsticks in our dev flow an need to implement these custom rpcs. As we current use 0.9.36 version of the sdk , we compile the node and use the wasm overide flag as advised here.

Unfortunately , chopsticks crashes.

Steps to Reproduce

  • clone this repo.
  • build the wasm target , `cargo build --release --features "runtime-benchmarks"
  • run chopsticks with the following commands : node packages/chopsticks/chopsticks.cjs --config=configs/bittensor.yml --wasm-override=../subtensor/target/release/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.wasm
  • execute this script
const { ApiPromise, WsProvider } = require('@polkadot/api');
const { decodeAddress, encodeAddress } = require('@polkadot/util-crypto');
const {Address} = require('@polkadot/types/interfaces');

// const provider = new WsProvider('wss://dev.chain.opentensor.ai:443');

const provider = new WsProvider('ws://127.0.0.1:8000');
const customConfig = {
  provider,
  types: {
    Balance: 'u64',
    DelegateInfo: {
      delegate_ss58: 'AccountId',
      take: 'Compact<u16>',
      nominators: 'Vec<(AccountId, Compact<u64>)>',
      owner_ss58: 'AccountId',
      registrations: 'Vec<Compact<u16>>',
      validator_permits: 'Vec<Compact<u16>>',
      return_per_1000: 'Compact<u64>',
      total_daily_return: 'Compact<u64>',
    },
    SubnetStakeInfo: {
      hotkey: 'AccountId',
      netuid: 'u16',
      stake: 'Compact<u64>',
    },
  },
  rpc: {
    delegateInfo: {
      getDelegates: {
        description: 'Get delegates info',
        params: [],
        type: 'Vec<u8>',
      },
    },
    subnetInfo: {
      getAllStakeInfoForColdKey: {
        description: 'Get all stake info for a given coldkey',
        params: [
          {
            name: 'coldkeyAccountVec',
            type: 'Vec<u8>'
          },
          {
            name: 'at',
            type: 'Option<BlockHash>',
            isOptional: true
          }
        ],
        type: 'Vec<u8>',
      },
    getTotalSubnetStake: {
      description: 'Get total subnet stake',
      params: [
        {
          name: 'netuid',
          type: 'u16'
        },
        {
          name: 'at',
          type: 'Option<BlockHash>',
          isOptional: true
        }
      ],
      type: 'Vec<u8>',
    },
  },
}
};

async function main() {

    const serializedData = await api.rpc.delegateInfo.getDelegates();

    const delegateInfos = api.registry.createType('Vec<DelegateInfo>', serializedData);
  
    console.log(delegateInfos.toJSON());

}

main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });

bitsensor.yml

endpoint:
 - wss://entrypoint-finney.opentensor.ai
 - wss://archive.chain.opentensor.ai
  # - wss://dev.chain.opentensor.ai:443
mock-signature-host: true
block: ${env.BITTENSOR_BLOCK_NUMBER}
db: ./db.sqlite
runtime-log-level: 5

import-storage:
  Sudo:
    Key: 5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx
  System:
    Account:
      -
        -
          - 5GpzQgpiAKHMWNSH3RN4GLf96GVTDct9QxYEFAY7LWcVzTbx
        - providers: 1
          data:
            free: 100000000000
        -
          - 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY // Alice
        - providers: 1
          data:
            free: 100000000000

Actual Behaviour

[12:48:40.794] INFO: Bittensor RPC listening on port 8000
    app: "chopsticks"
panicked at src/task.rs:144:10:
called `Result::unwrap()` on an `Err` value: (VirtualMachine(FunctionNotFound), HostVmPrototype)

Stack:

Error
    at imports.wbg.__wbg_new_abda76e883ba8a5f (/Users/samueldare/code/samtvlabs/bittensor/chopsticks/executor/dist/cjs/chopsticks_executor.js:751:19)
    at wasm://wasm/00b1d246:wasm-function[1106]:0x1907d4
    at wasm://wasm/00b1d246:wasm-function[1335]:0x19913c
    at wasm://wasm/00b1d246:wasm-function[1221]:0x1960bf
    at wasm://wasm/00b1d246:wasm-function[115]:0xc4bf5
    at wasm://wasm/00b1d246:wasm-function[633]:0x16aeae
    at wasm://wasm/00b1d246:wasm-function[1479]:0x19a85e
    at __wbg_adapter_48 (/Users/samueldare/code/samtvlabs/bittensor/chopsticks/executor/dist/cjs/chopsticks_executor.js:419:10)
    at real (bittensor/chopsticks/executor/dist/cjs/chopsticks_executor.js:401:22)
    at node:internal/process/task_queues:140:7



node:internal/event_target:1100
  process.nextTick(() => { throw err; });
                           ^
Error [RuntimeError]: unreachable
    at wasm://wasm/00b1d246:wasm-function[1106]:0x1908ea
    at wasm://wasm/00b1d246:wasm-function[1335]:0x19913c
    at wasm://wasm/00b1d246:wasm-function[1221]:0x1960bf
    at wasm://wasm/00b1d246:wasm-function[115]:0xc4bf5
    at wasm://wasm/00b1d246:wasm-function[633]:0x16aeae
    at wasm://wasm/00b1d246:wasm-function[1479]:0x19a85e
    at __wbg_adapter_48 (/Users/samueldare/code/samtvlabs/bittensor/chopsticks/executor/dist/cjs/chopsticks_executor.js:419:10)
    at real (/bittensor/chopsticks/executor/dist/cjs/chopsticks_executor.js:401:22)
    at node:internal/process/task_queues:140:7
    at AsyncResource.runInAsyncScope (node:async_hooks:206:9)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:826:20)
    at exports.emitMessage (node:internal/per_context/messageport:23:28)

Node.js v20.11.1

Excepted Behaviour

Calls succeeds.

you can't use runtime with benchmarking feature. it will have benchmark host functions (unresolved method)

Also your custom rpcs are part of your client and not runtime. You can't use them with chopsticks. Chopsticks itself implements only the base rpcs. You can only use runtime apis from chopsticks.