-
Notifications
You must be signed in to change notification settings - Fork 354
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
Update contract' gas to Weight type #5324
Conversation
4db1d78
to
856ecf3
Compare
3b5b29a
to
856ecf3
Compare
this is great! thanks @jasl |
I make a new commit for this, check 3bbb6c0 |
@jacogr what does the |
5761c90
to
3bbb6c0
Compare
ops it seems I force pushed too many times the CI refuse to run ... |
https://github.com/polkadot-js/api/pull/5324/files#diff-e923378b0f9524ff3bcbc37be8010d0f81c271e98fceabc6cc9641adb08de09bR58 |
d9b74f0
to
250db93
Compare
understood, thank you, now the latest commit should pass |
CI PASSED !!! |
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.
The Weight
is optional in runtime APIs now. It allows you to let the runtime choose a default value in case you don't care (you usually don't care if you use it to estimate gas_required
).
@@ -24,7 +24,7 @@ export const runtime: DefinitionsCall = { | |||
}, | |||
{ | |||
name: 'gasLimit', | |||
type: 'u64' | |||
type: 'Weight' |
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.
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.
Changed to Option<Weight>
@@ -64,7 +64,7 @@ export const runtime: DefinitionsCall = { | |||
}, | |||
{ | |||
name: 'gasLimit', | |||
type: 'u64' | |||
type: 'Weight' |
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.
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.
Changed to Option<Weight>
@@ -45,7 +45,7 @@ export default { | |||
origin: 'AccountId', | |||
dest: 'AccountId', | |||
value: 'Balance', | |||
gasLimit: 'u64', | |||
gasLimit: 'Weight', |
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.
Is optional.
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.
Changed to Option<Weight>
Changed your mentioned fields to |
Don't you also need to adapt some code in the contracts api that uses those, now changed, signatures? |
Sorry, I'm not familier with |
I do unit test in local, they're all passed, you mean I need to add unit tests for WeightV2? |
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 am literally not sure about these Option<Weight>
changes - there seems to have been a breaking update to the runtime interfaces without a version update. This is hugely problematic, there is a reason why the runtime interfaces have versions.
EDIT: Indeed. This PR broke the world without updating the runtime api version. paritytech/substrate#12429 - not sure how that passed reviews. It is creating huge (unsolvable) issues here now.
packages/api-contract/src/types.ts
Outdated
@@ -55,8 +55,8 @@ export interface InterfaceContractCalls { | |||
|
|||
export interface ContractCallOutcome { | |||
debugMessage: Text; | |||
gasConsumed: u64; | |||
gasRequired: u64; | |||
gasConsumed: u64 | WeightV2; |
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.
This should just be Weight
- this is a bit tricky, but the runtime will inject the correct type.
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.
Changed
@@ -45,7 +45,7 @@ export default { | |||
origin: 'AccountId', | |||
dest: 'AccountId', | |||
value: 'Balance', | |||
gasLimit: 'u64', | |||
gasLimit: 'Option<Weight>', |
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.
This is going to be problematic - there is now old and new, we need to cater for both.
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.
does u64 | Option<Weight>
work?
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.
For his one we need a runtime result for V1 as well - that keeps as it. For v2, we have a new version that gets returned. So basically rename the existing to ContractCallRequestV1
(to be returned for v1 runtime) and the change the above version for Option<Weight>
.
Basically (until we finally have all this info on the metadata), we need to have old and new types available. Yes, it is a bitch.
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 already created ContractCallRequestV1
, on line 44
@@ -24,7 +24,7 @@ export const runtime: DefinitionsCall = { | |||
}, | |||
{ | |||
name: 'gasLimit', | |||
type: 'u64' | |||
type: 'Option<Weight>' |
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.
This can't be - the runtime is supposed to be versioned, i.e. there should not be a breaking change without updating versions. (This is the same as above, this is breaking for users)
EDIT: See my comment with the problematic PR linked - no idea how to solve this at all.
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.
IMO, Option<Weight>
can be treated as 0u64
? and 0u64
can be treated as None
?
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.
There is a difference in SCALE encoding Option<u64>
vs u64
. The former would be 9 bytes in length, the later would be 8 bytes. So it breaks the structure decoding if wrong.
Do you have idea @athei ? |
What exactly do you mean by "broke the world"? Do you mean existing code which didn't update to a new polkadot.js version or is new code also affected? |
The issue is that the This is the great thing about using The nightmare here is that the result encoding has completely changed - since none of this information is in the metadata (there is a Substrate issue to expose it), there is no way to know how to decode it, i.e. what is the format. This would have been solved with adding the So atm - the runtime calls for V1 will work against older deployed chains. If they upgrade to this new v1 interface, it cannot be decoded. If the definitions are changed to match the "new v1 interfaces" the results from deployed "old v1" interfaces will break. So some chains will break since we just don't know. Hence - "breaking the world", since somebody is going to be unhappy with 2-same-versioned-yet-different |
Here is an example of a change made to the result of a runtime api declaration where the version was bumped, https://github.com/paritytech/substrate/blob/38a955ba4a0c967659e6c944c56c664fce0f8f23/primitives/consensus/babe/src/lib.rs#L363-L372 With the above, anybody can always know which one of these interfaces are in operation - so either can be used (and is defined as such). This is all based on the info returned from the So literally what is missing is the |
So in order to unblock this PR it would be fine if I just flag the new version as
How do you detect the version (given that I add the version attribute in substrate)? There is no indication in metadata. |
So we need to do these things:
Am I understanding correct? |
Sorry I think I need more clear instructions, |
29a3213
to
1da7ffa
Compare
I rebased master |
Try my best to understanding your means... I'm dizzy, sorry 😓 |
(Basically on the generated types it uses the chain metadata - this means that all chains supply their metadata and it tweaks the generated types based on that) TL;DR The joys of having statically generated types based on something dynamic like runtimes... |
Yeah, I rebased master and specify deprecated Contracts RPC to use V1 struct, then |
@@ -145,7 +145,7 @@ declare module '@polkadot/rpc-core/types/jsonrpc' { | |||
* @deprecated Use the runtime interface `api.call.contractsApi.call` instead | |||
* Executes a call to a contract | |||
**/ | |||
call: AugmentedRpc<(callRequest: ContractCallRequest | { origin?: any; dest?: any; value?: any; gasLimit?: any; storageDepositLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<ContractExecResult>>; | |||
call: AugmentedRpc<(callRequest: ContractCallRequestV1 | { origin?: any; dest?: any; value?: any; gasLimit?: any; storageDepositLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<ContractExecResult>>; |
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.
If you run yarn build:metadata
now, it should actually pull in the latest V2 stuff (assuming there is a version: 2 definition available in contracts/runtime.ts)
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 ran yarn build:metadata
seems no file changes
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.
Ensure you have master merged in - just did a quick (5 mins, literally), ContractsApi/2
in here and it generates the new interfaces - #5330
(No idea if it is fully correct in regards to ContractsApi
definitions)
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 rebased master and it has the new metadata commit...
I see you open a new PR for Contracts V2, do you wanna take it?
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.
Happy if you take it - you have done the hard work. But either way ok. (Just wanted to show that the runtime apis does get updated, once defined, on master, in the above PR)
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 believe your issues (reading below), is that your u64 -> Option changes are on the v1 APIs, which are not being generated. My PR adds for v2 (and keeps v1 as-is, with some small historic-types-now updates), hence being generated.
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 miss the head of the file yarn polkadot-types-from-chain
, so I should build a latest Substrate node, and run yarn polkadot-types-from-chain --endpoint ws://127.0.0.1:9944 --output packages/rpc-augment/src/augment/jsonrpc.ts
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.
We do include the latest static metadata, so yarn build:metadata
will pick it up. (Well, "latest" as of this morning - it gets updated once weekly)
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 port your PR's changes, and rerun yarn build:metadata
, Doe it look correct now?
Just made another batch of changes, ran |
Nice. I can see the v2 apis popping up now. Will get it in in the morning. |
Thank you for your patience mentoring, if possible, could you make a new release after this PR merged? our team is blocked by the issue |
Releases go on weekends. (Generally Sundays, each week, but I have been known to push on Saturday as well) The next is scheduled for tomorrow. |
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.
Thank you. Seems spot-on.
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I don't have confidence I'm doing right.
Starting from
polkadot v0.9.31
, the gas relates fields has changed toWeight
(V2, https://github.com/paritytech/substrate/blob/polkadot-v0.9.31/frame/contracts/primitives/src/lib.rs#L35-L71 ),but it looks polkadot.js still define them
u64