-
Notifications
You must be signed in to change notification settings - Fork 150
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: historical queries for account balances #653
Conversation
I need to confirm that this works for all runtimes before block ~1500000 (Kusama), currently they all work except when querying block 1400000's runtime. |
All historical runtimes are now covered. The initial issue was present in two cases: For example, when querying Kusama, the following 2 groups of runtimes have different storage formats. v1054 --> v1050 Presently we use 2 formats to get account storage information: a) But for runtime v1054 --> v1050 the api requires a historicalApi via
And for runtime v1049 --> ...(earliest runtime) also requires a historicalApi
|
height: header.number.toNumber().toString(10), | ||
}; | ||
|
||
if (locks && free && reserved && nonce) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is necessary, could we just do null if one of these fields doesn't exist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When you say 'do null' do you mean a null
response for the key value pair? Or do you mean just check one value and then throw the error.
Here I am just mimicking the error response logic that is in the existing service to keep it consistent with what response/errors it reports. So if we change this to something different it might be worth updating the rest as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, I think I see what you are saying, It only makes sense to really check for one value. Will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % a few questions where we might be able to improve performance. Also, if these derives https://github.com/polkadot-js/api/blob/master/packages/api-derive/src/balances/account.ts start supporting .at
I wonder if it would be more robust to start using them in parts of this service in the future
Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
…ritytech/substrate-api-sidecar into tarik-fix-historical-account-balances
Yea I totally agree with this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There is a bunch of places where you mock an async function by chaining a Promise.resolve
with no value, and I'm not sure it's necessary when a regular async function could be used?
freeBalance: () => | ||
Promise.resolve().then(() => { | ||
return polkadotRegistry.createType('Balance', 123456789); | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that be easier?
freeBalance: () => | |
Promise.resolve().then(() => { | |
return polkadotRegistry.createType('Balance', 123456789); | |
}), | |
freeBalance: async () => polkadotRegistry.createType('Balance', 123456789), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, yea I definitely agree, will fix it up now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
closes: #634
This fixes historical queries for
/accounts/{accountId}/balance-info
.