Skip to content
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

fix: Use correct registry when creating calls; Remove usage of derive.chain.getBlock #391

Merged
merged 3 commits into from
Jan 15, 2021

Conversation

emostov
Copy link
Contributor

@emostov emostov commented Jan 15, 2021

Closes #384

In #351, I removed the querys api.query.session.validators & api.rpc.getBlock. Additionally I removed BlocksService. extractAuthor. I replaced all of them with api.derive.chain.getBlock, which neatly gave us the authorId in addition to the block. (Opposed to having to use the validators and digest logs to extract the authorId)

However, for some reason none of the Codec objects returned from the derive call have a type registry dated to the call, instead they have what seems to be the most recent type registry. The effect of this is that when we try to create Calls that are not in the most recent metadata we get a call not found error. To solver this issue I have brought back the aforementioned code that I removed and use the type registry attached to the block

I experimented with other options like using the type registry on the block hash passed down from the controller, but that had the same issue. We also can't use the events because we do not guarantee that those will be retrieved (e.g. a non-archive node)

@emostov emostov added the P2 - ASAP Get fixed ASAP label Jan 15, 2021
Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

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

However, for some reason none of the Codec objects returned from the derive call have a type registry dated to the call

Should we open an issue here (or on pd.js?) to dig into this further?

Comment on lines +71 to +73
const authorId = sessionValidators
? this.extractAuthor(sessionValidators, digest)
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does extractAuthor return? If it returns undefined this ternary isn't needed.

Suggested change
const authorId = sessionValidators
? this.extractAuthor(sessionValidators, digest)
: undefined;
const authorId = this.extractAuthor(sessionValidators, digest);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We just need something so TS does not complain since it knows sessionValidators may be undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

eew, so you're saying we must do like const authorId = this.extractAuthor(sessionValidators, digest) || undefined; just to appease the compiler? :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but we need to check before we call extractAuthor, because extractAuthor requires that the type of the sessionValidators param be Array<AccountId>. I agree with the compiler here because sending down undefined where only an array is expected could lead to issues at runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you mean. But is it not an error if sessionValidators is undefined (or an empty array)? Like, shouldn't we bail before we get here if that's the case?

Copy link
Member

@TarikGul TarikGul left a comment

Choose a reason for hiding this comment

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

LGTM!

@emostov emostov merged commit f961cae into master Jan 15, 2021
@emostov emostov deleted the zeke-decode-finality-track branch January 15, 2021 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 - ASAP Get fixed ASAP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Westend: Error: createType(Call):: findMetaCall: Unable to find Call with index 0x0900/[9,0]
4 participants