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

revert #829 #830

Closed
ryanleecode opened this issue Mar 30, 2023 · 7 comments · Fixed by #833
Closed

revert #829 #830

ryanleecode opened this issue Mar 30, 2023 · 7 comments · Fixed by #833

Comments

@ryanleecode
Copy link
Contributor

Placeholder to revert #829 when this PR Is merged and released paritytech/substrate#13766

@tjjfvi
Copy link
Contributor

tjjfvi commented Mar 30, 2023

That PR fixes the estimation being too high, which isn't the problem here. The issue is that feeEstimate is using an old rpc api that only gives 1D of the 2D weight. It should be using the TransactionPaymentApi_query_info state_call API instead, which correctly gives both dimensions.

@ryanleecode
Copy link
Contributor Author

That PR fixes the estimation being too high, which isn't the problem here. The issue is that feeEstimate is using an old rpc api that only gives 1D of the 2D weight. It should be using the TransactionPaymentApi_query_info state_call API instead, which correctly gives both dimensions.

thats probably correct. how did you figure this out?

@tjjfvi
Copy link
Contributor

tjjfvi commented Mar 30, 2023

Looking through rpc/known/ + the rust source + playing with the apis in https://polkadot.js.org/apps/

@ryanleecode
Copy link
Contributor Author

ryanleecode commented Mar 31, 2023

Can't seem to get this to work. Always gives wasm error

  feeEstimate() {
    const queryInfoCallArgs = $.tuple($.uint8Array, $.u32)

    const encoded = this.encoded()
    const args = Rune.constant(queryInfoCallArgs)
      .into(CodecRune)
      .encoded(Rune.tuple([encoded, encoded.access("length")]))

    return this.chain.connection.call(
      "state_call",
      "TransactionPaymentApi_query_info",
      args.map(hex.encodePrefixed),
    )
      .dbg("TransactionPaymentApi_query_info")
      ...

I looked at these two.

https://polkadot.js.org/docs/substrate/runtime/#queryinfouxt-extrinsic-len-u32-runtimedispatchinfo

https://github.com/paritytech/substrate/blob/ee38a52d9ea643e4eec1e954b0b603aea4461416/frame/transaction-payment/src/tests.rs#L354


error: Uncaught (in promise) Unhandled {
  value: ServerError: Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x4afa28 - <unknown>!rust_begin_unwind
    1: 0x5371 - <unknown>!core::panicking::panic_fmt::hca80ede79c2b9c5b
    2: 0x16d6ed - <unknown>!TransactionPaymentApi_query_info
    at RunMap.fn (file:///workspaces/capi/fluent/ConnectionRune.ts:29:33)
    at async RunMap._evaluate (file:///workspaces/capi/rune/ValueRune.ts:162:29)
    at async RunMap.evaluate (file:///workspaces/capi/rune/Rune.ts:222:14)
    at async RunThrows._evaluate (file:///workspaces/capi/rune/ValueRune.ts:215:14)
    at async RunThrows.evaluate (file:///workspaces/capi/rune/Rune.ts:222:14)
    at async Promise.all (index 0)
    at async RunLs.evaluate (file:///workspaces/capi/rune/Rune.ts:222:14)
    at async RunMap._evaluate (file:///workspaces/capi/rune/ValueRune.ts:160:20)
    at async RunMap.evaluate (file:///workspaces/capi/rune/Rune.ts:222:14)
    at async RunMap._evaluate (file:///workspaces/capi/rune/ValueRune.ts:160:20)
Caused by Client error: Execution failed: Execution aborted due to trap: wasm trap: wasm `unreachable` instruction executed
WASM backtrace:
error while executing at wasm backtrace:
    0: 0x4afa28 - <unknown>!rust_begin_unwind
    1: 0x5371 - <unknown>!core::panicking::panic_fmt::hca80ede79c2b9c5b
    2: 0x16d6ed - <unknown>!TransactionPaymentApi_query_info
}
inner command exited with status code 1

@tjjfvi
Copy link
Contributor

tjjfvi commented Mar 31, 2023

    const queryInfoCallArgs = $.tuple($.uint8Array, $.u32)

This won't work like $.tuple($extrinsic, $.u32) because $.uint8Array encodes the length of the Uint8Array before inserting it.

@ryanleecode
Copy link
Contributor Author

nice i got it working

 encoded() {
    return Rune.fn($extrinsic)
      .call(this.chain.into(ValueRune).access("metadata"))
      .into(CodecRune)
      .encoded(Rune.rec({
        protocolVersion: 4,
        call: this,
      }))
  }

  feeEstimate() {
    const queryInfoCallArgs = Rune.fn($extrinsic)
      .call(this.chain.into(ValueRune).access("metadata"))
      .map((ext) => $.tuple(ext, $.u32))

    const args = queryInfoCallArgs
      .into(CodecRune)
      .encoded(Rune.tuple([
        Rune.rec({
          protocolVersion: 4,
          call: this,
        }),
        this.encoded().access("length"),
      ]))

    return this.chain.connection.call(
      "state_call",
      "TransactionPaymentApi_query_info",
      args.map(hex.encodePrefixed),
    )
      .dbg("TransactionPaymentApi_query_info")

@ryanleecode
Copy link
Contributor Author

It's working but the api call stills gives 0n for proof size

TransactionPaymentApi_query_info { weight: { refTime: 63845208260230n, proofSize: 0n } }

@ryanleecode ryanleecode changed the title Revert #829 revert #829 Apr 4, 2023
@github-project-automation github-project-automation bot moved this to Done in Capi Apr 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants