Skip to content

Update block failed message #2418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/node-core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Update index block failed message (#2414)

## [10.3.2] - 2024-05-27
### Changed
Expand Down
19 changes: 19 additions & 0 deletions packages/node/src/utils/substrate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
fetchBlocksArray,
fetchBlocksBatches,
filterExtrinsic,
getBlockByHeight,
} from './substrate';

const ENDPOINT_POLKADOT = 'wss://rpc.polkadot.io';
Expand Down Expand Up @@ -65,4 +66,22 @@ describe('substrate utils', () => {
filterExtrinsic(block.extrinsics[2], { isSigned: false }),
).toBeFalsy();
});

it('decode fail message', async () => {
const provider = new WsProvider(ENDPOINT_KARURA);
const api = await ApiPromise.create({ provider });

await expect(getBlockByHeight(api, 86614)).rejects.toThrow(
/Unable to decode|failed decoding|unknown type/,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to test that it throws an error with our message and not the underlying error that we wrap

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both are needed.

);
await api.disconnect();
});

it('decode normal message', async () => {
const provider = new WsProvider(ENDPOINT_KARURA);
const api = await ApiPromise.create({ provider });

expect(await getBlockByHeight(api, 50710)).toBeTruthy();
await api.disconnect();
});
});
29 changes: 27 additions & 2 deletions packages/node/src/utils/substrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ export async function getBlockByHeight(

const block = await api.rpc.chain.getBlock(blockHash).catch((e) => {
logger.error(
`failed to fetch Block hash="${blockHash}" height="${height}"`,
`failed to fetch Block hash="${blockHash}" height="${height}"${getApiDecodeErrMsg(
e.message,
)}`,
);
throw ApiPromiseConnection.handleError(e);
});
Expand Down Expand Up @@ -330,7 +332,11 @@ export async function fetchEventsRange(
return Promise.all(
hashs.map((hash) =>
api.query.system.events.at(hash).catch((e) => {
logger.error(`failed to fetch events at block ${hash}`);
logger.error(
`failed to fetch events at block ${hash}${getApiDecodeErrMsg(
e.message,
)}`,
);
throw ApiPromiseConnection.handleError(e);
}),
),
Expand Down Expand Up @@ -448,3 +454,22 @@ export function calcInterval(api: ApiPromise): BN {
: DEFAULT_TIME),
);
}

function getApiDecodeErrMsg(errMsg: string): string {
const decodedErrMsgs = [
'Unable to decode',
'failed decoding',
'unknown type',
];

if (!decodedErrMsgs.find((decodedErrMsg) => errMsg.includes(decodedErrMsg))) {
return '';
}

return (
`\nThis is because the block cannot be decoded. To solve this you can either:` +
'\n* Skip the block' +
'\n* Update the chain types. You can test this by viewing the block with https://polkadot.js.org/apps/' +
'\nFor further information please read the docs: https://academy.subquery.network/'
);
}
Loading