Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

feat: compute max_weight for multisig example #402

Merged
merged 2 commits into from
Nov 15, 2022

Conversation

kratico
Copy link
Contributor

@kratico kratico commented Nov 14, 2022

Use extrinsic.feeEstimation to compute multisig max_weight

@kratico kratico force-pushed the feat/multisig-example-fee-estimation branch from b64ed4d to 5b80ea6 Compare November 14, 2022 19:59
Comment on lines +104 to +109
.next((weight) => {
return {
ref_time: BigInt(weight.ref_time),
proof_size: BigInt(weight.proof_size),
}
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tjjfvi Would you know if this is codec related?

ref_time and proof_size are u64 but they are not decoded as biging

See https://github.com/paritytech/substrate/blob/59da38b3a07b4ddf380ff9b01a5874fd883138a9/primitives/weights/src/weight_v2.rs#L29-L35

Copy link
Contributor

@tjjfvi tjjfvi Nov 14, 2022

Choose a reason for hiding this comment

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

That weight seems to come from the RPC, which – being JSON – can only send numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right

It might be a good DX to have the codec convert number to bigint when it's needed, WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

Having any implicit coercion legitimizes implicit coercion in other cases, which could quickly get out of hand (c.f. @polkadot/types, which is a rat's nest of implicit coercion).

Additionally, all codecs from scale-ts currently roundtrip exactly for every valid input (that is,

!$.is($foo, value) || deepEqual(value, $foo.decode($foo.encode(value)))

is always true), and I'd like to preserve this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would probably make the most sense for the .feeEstimate effect to do this BigInt coercion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if we do it in the effect, as soon as the weight shape changes, the effect will need to be refactored (like it happened with recent polkadot updates).

that's why I believe that implicit coercion from number to bigint will scale better for this case.

Comment on lines 111 to 127
sender: C.compat.multiAddressFromKeypair(pair),
palletName: "Multisig",
methodName: "as_multi",
args: C.Z.rec({
threshold: THRESHOLD,
call: {
type: "Balances",
value: {
type: "transfer_keep_alive",
dest: C.compat.multiAddressFromKeypair(T.dave),
value: 1_230_000_000_000n,
},
},
other_signatories: signatories.filter((value) => value !== pair.publicKey),
store_call: false,
max_weight: maxWeight,
maybe_timepoint: maybeTimepoint as Rest[0],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@harrysolovay the extrinsic data is almost the same but the spread operator doesn't work well with C.Z.rec

Would you know a better alternative?

I could factor out the args within Z.rec, WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or, given that it's an example, code duplication might be fine

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you want to calculate the weight for the Balances.transfer_keep_alive call, not the Multisig.as_multi, which would solve this duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, I believe you'll be able to get the appropriate weight using the encoded inner extrinsic.

On a more general note though...

  • A bit of redundancy in examples can definitely help with reader comprehension
  • In this particular case, I suppose we could extract the common fields –– another way we'll make this example nicer: @tjjfvi is working on feat: next-gen codegen #368, which will enable us to generate/use narrow call data types (and their factory fns)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'll resolve the duplication in the codegen branch using the call factories once this is merged – no need to address it now.

@kratico kratico marked this pull request as ready for review November 14, 2022 20:05
@kratico kratico requested a review from tjjfvi November 14, 2022 23:12
@@ -38,7 +38,6 @@
"test:update": "deno task test -- -- --update",
"mdbook:watch": "mdbook watch -o",
"bench": "deno bench -A --no-check=remote --unstable",
"multisig": "deno task run test_util/ctx.ts -- deno task run examples/multisig_transfer.ts",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I committed the multisig example, I forgot to remove this task

@kratico kratico merged commit 2692c9a into main Nov 15, 2022
@kratico kratico deleted the feat/multisig-example-fee-estimation branch November 15, 2022 13:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants