smol-dot / smoldot

Lightweight client for Substrate-based chains, such as Polkadot and Kusama.
GNU General Public License v3.0
189 stars 50 forks source link

Panic while compiling Moonbeam runtime #1152

Open mfornos opened 1 year ago

mfornos commented 1 year ago

We are trying to use the light client to connect to the Moonbeam network.

But it panics while compiling the runtime.

panicked at 'called `Result::unwrap()` on an `Err` value: InvalidRuntime(InvalidHeapPages(TooLarge))', /__w/smoldot/smoldot/light-base/src/json_rpc_service/background.rs:1282:14
file:///home/marc/Development/ocelloids/node_modules/smoldot/dist/mjs/instance/raw-instance.js:36
                throw new Error();
                      ^
Error
    at Object.onPanic (file:///home/marc/Development/ocelloids/node_modules/smoldot/dist/mjs/instance/raw-instance.js:36:23)
    at panic (file:///home/marc/Development/ocelloids/node_modules/smoldot/dist/mjs/instance/bindings-smoldot-light.js:52:20)
    at wasm://wasm/00fc8eb6:wasm-function[2764]:0xa0317
    at wasm://wasm/00fc8eb6:wasm-function[12523]:0x282f48
    at wasm://wasm/00fc8eb6:wasm-function[12513]:0x2823d5
    at wasm://wasm/00fc8eb6:wasm-function[12518]:0x282a47
    at wasm://wasm/00fc8eb6:wasm-function[12590]:0x2888ed
    at wasm://wasm/00fc8eb6:wasm-function[12621]:0x28ddce
    at wasm://wasm/00fc8eb6:wasm-function[1994]:0x83a4b
    at wasm://wasm/00fc8eb6:wasm-function[1497]:0x5492c

Context:

[smoldot] Chain initialization complete for polkadot. Name: "Polkadot". Genesis hash: 0x91b1…90c3. State root hash: 0x29d0d972cd27cbc511e9589fcb7a4506d5eb6a9e8df205f00472e5ab354a4e17. Network identity: 12D3KooWLvwb4xoELUUpFuohYGdEnZtdYuikJXKWA5mUyTtYiCCB. Chain specification or database starting at: 0xcbd8…793f (#16637440)
[smoldot] Parachain initialization complete for moonbeam. Name: "Moonbeam". Genesis hash: 0xfe58…b76d. State root hash: 0x74e54bafcf1ecdce51867078fa16f2902751d11473628ac19e89a5be20df3262. Network identity: 12D3KooWPnCpjre36yqeW9m151stms11FwnnTrCmjPCgMAMzAe8h. Relay chain: polkadot (id: 2004)
[sync-service-polkadot] GrandPa warp sync finished to #17272223 (0xdbf2…3f3b)
[runtime-polkadot] Finalized block runtime ready. Spec version: 9430. Size of `:code`: 1.4 MiB.
[runtime-moonbeam] Failed to compile runtime. Size of `:code`: 1.6 MiB.
Error: Failed to parse `:heappages` storage value: TooLarge
This indicates an incompatibility between smoldot and the chain.

It there anything that we can do to make it work with Moonbeam?

Thank you very much!

tomaka commented 1 year ago

The value at the storage key :heappages (0x3a686561707061676573) for Moonbeam is 0xed5c416273747261 (queried through a JSON-RPC server).

tomaka commented 1 year ago

cc https://github.com/paritytech/polkadot-sdk/issues/71

mfornos commented 1 year ago

Well... seemingly it is really set to "7021802807942536429" pages. A "solution" could be to limit the max heap pages number to a reasonable one. Maybe 65536 as in the fix of the linked issue? I was checking other networks and didn't found other network specifying ':heappages' so 2048 is being used.

Btw, i'm not aware of the implications for smoldot and how the pages are actually allocated. Will take a look just out of curiosity :D

tomaka commented 1 year ago

A "solution" could be to limit the max heap pages number to a reasonable one. Maybe 65536 as in the fix of the linked issue?

Smoldot needs to match the behavior of Substrate.

As far as I understand, Moonbeam made some modifications to their fork of Substrate so that it ignores the number of heap pages. It's unclear to me why they don't fix the on-chain value instead. If that's the case, then Moonbeam is incompatible with smoldot.

XY-Wang commented 1 year ago

Seems that the ignore_onchain_heap_pages flag was merged into Substrate.

References: https://github.com/paritytech/polkadot-sdk/blob/771c3fbde7ba3849298d6fc7df390fc6b5a04d2f/substrate/client/executor/src/executor.rs#L145 https://github.com/paritytech/polkadot-sdk/blob/771c3fbde7ba3849298d6fc7df390fc6b5a04d2f/substrate/client/executor/src/executor.rs#L657 https://github.com/paritytech/polkadot-sdk/blob/771c3fbde7ba3849298d6fc7df390fc6b5a04d2f/substrate/client/executor/src/executor.rs#L663

tomaka commented 1 year ago

If you want to move this issue forward, please find someone from Moonbeam and ask them for an explanation about this.

tomaka commented 10 months ago

The panic has been fixed in https://github.com/smol-dot/smoldot/pull/1570