hicommonwealth / edgeware-node-types

Typescript bindings for our node modules.
9 stars 7 forks source link

polkadot/api fails to fetch very early blocks with the latest type definitions #32

Open dzhelezov opened 3 years ago

dzhelezov commented 3 years ago

I'm using the latest type definitions and polkadot/api v4.17.1 and edgeware type definitions from master. When trying to fetch the blocks of height 1 and later, with API, I get

Failed to execute "get signed block by hash 0xb106f23a8e0900855ab2d6cad2bdfb12bdc19c0afc8d917d910287357bde86de" 
2021-07-06 16:26:48             VEC: Unable to decode on index 1 createType(ExtrinsicV4):: createType(Call):: Call: failed decoding imOnline.heartbeat:: Struct: failed on args: {"heartbeat":"Heartbeat","_signature":"Signature"}:: decodeU8a: failed at 0x42c59312af11636c… on _signature: H512:: Expected at least 64 bytes (512 bits), found 60 bytes
2021-07-06 16:26:48        RPC-CORE: getBlock(hash?: BlockHash): SignedBlock:: createType(SignedBlock):: Struct: failed on block: {"header":"Header","extrinsics":"Vec<Extrinsic>"}:: Struct: failed on extrinsics: Vec<Extrinsic>:: createType(ExtrinsicV4):: createType(Call):: Call: failed decoding imOnline.heartbeat:: Struct: failed on args: {"heartbeat":"Heartbeat","_signature":"Signature"}:: decodeU8a: failed at 0x42c59312af11636c… on _signature: H512:: Expected at least 64 bytes (512 bits), found 60 bytes

Fetching blocks with height > 1M seems to work fine

wliyongfeng commented 3 years ago

Hi, we have the same issue. My code:

const blockHash = await api.rpc.chain.getBlockHash(1);
const block = await api.rpc.chain.getBlock(blockHash);
const allEvents = await api.query.system.events.at(blockHash);

It produced following errors:

2021-11-14 20:36:16        REGISTRY: Unable to resolve type RewardDestinationTo257, it will fail on construction
2021-11-14 20:36:16        REGISTRY: Error: Call: failed decoding staking.bond:: Struct: failed on args: :: Cannot construct unknown type RewardDestinationTo257
    at new GenericCall (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/generic/Call.cjs:147:13)
    at new Type (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/registry.cjs:349:16)
    at initType (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/createType.cjs:44:19)
    at createTypeUnsafe (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/createType.cjs:63:12)
    at createType (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/createType.cjs:78:10)
    at TypeRegistry.createType (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/registry.cjs:306:39)
    at Function.decodeExtrinsic (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/extrinsic/v4/Extrinsic.cjs:47:31)
    at new GenericExtrinsicV4 (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/extrinsic/v4/Extrinsic.cjs:30:27)
    at new Type (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/registry.cjs:349:16)
    at initType (/Users/mac/work/os/play/edg/node_modules/@polkadot/types/create/createType.cjs:44:19)
wliyongfeng commented 3 years ago

I tried @polkadot/api 3.4.1, and it works.

Asmadek commented 2 years ago

Is there any solution to fix it in @polkadot/api ^6 version?

polkadot js has troubles with started blocks https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Fmainnet.edgewa.re#/explorer/query/0xecfe590f070b93fef6bfc5620c3f9b925afd0b1c8ca3182e9af206110d3e7b31

But subscan show it correctly https://edgeware.subscan.io/block/0xecfe590f070b93fef6bfc5620c3f9b925afd0b1c8ca3182e9af206110d3e7b31?tab=log

Asmadek commented 2 years ago

We made some research and find some bugs and solutions for edgeware types. But one of this bugs (number 3) we can't fix on our side.

  1. Unable to retrieve the specified block details. createType(SignedBlock):: Struct: failed on block: {"header":"Header","extrinsics":"Vec<Extrinsic>"}:: Struct: failed on extrinsics: Vec<Extrinsic>:: createType(ExtrinsicV4):: createType(Call):: Call: failed decoding staking.bond:: Struct: failed on args: :: decodeU8a: failed at 0x00… on payee:: DoNotConstruct: Cannot construct unknown type RewardDestinationTo257

Can be fixed by add custom type

types: {
    RewardDestinationTo257: {
        "_enum": ["Staked", "Stashed", "Controller"]
    }
}
  1. ERROR failed to fetch block Error: createType(SignedBlock):: Struct: failed on block: {"header":"Header","extrinsics":"Vec<Extrinsic>"}:: Struct: failed on extrinsics: Vec<Extrinsic>:: createType(ExtrinsicV4):: createType(Call):: Call: failed decoding imOnline.heartbeat:: Struct: failed on args: {"heartbeat":"Heartbeat","_signature":"Signature"}:: decodeU8a: failed at 0x42c59312af11636cb36475277cfeb800… on _signature: H512:: Expected at least 64 bytes (512 bits), found 60 bytes

Can be fixed by add custom type

types: {
    Signature: '[u8; 60]'
}
  1. ERROR failed to fetch block Error: createType(SignedBlock):: Struct: failed on block: {"header":"Header","extrinsics":"Vec<Extrinsic>"}:: Struct: failed on extrinsics: Vec<Extrinsic>:: createType(ExtrinsicV4):: createType(Call):: Call: failed decoding utility.batch:: Struct: failed on args: {"calls":"Vec<Call>"}:: decodeU8a: failed at 0x100600ff32d7e231759c2a47d0fbce0e… on calls: Vec<Call>:: decodeU8a: failed at 0x08ff6ea12c8193339b2a058cbe43dc12…: Call:: findMetaCall: Unable to find Call with index [8, 255]/[8,255]

Repeates on different blocks (e.g. 1632627, 4310374). Problem meets in batch transactions with set_controller function. This is specific for the spec version under 45.

UPD: Issue number 3 can be fixed with custom type

types: {
    ValidatorPrefs: {
      commission: "Compact<Perbill>",
    },
}
flipchan commented 2 years ago

@Asmadek seems to be an on-chain migration issue, here, keep in mind that this repo is about to be decomissioned very soon: The official edgeware repo's you can always find here: https://github.com/edgeware-network

flipchan commented 2 years ago

This looks like a storage migration issue, I will look deeper into this