Skip to content
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

[WIP] Add support for Moonriver #95

Merged
merged 23 commits into from
Jan 11, 2023

Conversation

crystalin
Copy link
Contributor

@crystalin crystalin commented Dec 17, 2022

Status: Working, missing better fix for Randomness pallet VRF

It adds:

  • Inherent => Nimbus - Author Inherent
  • Inherent => Pallet Randomness - Babe Randomness Result
  • Consensus => nmbs pre-digest
  • Config => Moonriver, Moonbeam, Moonbase Alpha

Broken:

  • The Randomness verification is not passing (temp solution, delete NotFirstBlock at each block)

@crystalin
Copy link
Contributor Author

@xlc is there an easy way to troubleshoot the block produced, including changes in the storage (maybe debug logs level ?)?

@xlc
Copy link
Member

xlc commented Dec 18, 2022

"dev": "LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/dev.yml",

with trace level logging you will see storage changes

logger.trace(resp.storageDiff, 'Applied inherent')

configs/moonriver.yml Outdated Show resolved Hide resolved
@crystalin
Copy link
Contributor Author

Currently; it is possible to create 1 block with extrinsic (transfer) but fails for the following block:

[14:15:22.124] ERROR (rpc-author/6439): ExtrinsicFailed
    error: {
      "code": 1,
      "message": "Extrinsic is invalid: {\"invalid\":{\"badProof\":null}}"
    }

@ermalkaleci
Copy link
Collaborator

Screenshot 2022-12-19 at 1 43 12 PM

@crystalin I was able to produce new blocks for moonriver and did 2 trasfers but I had to delete randomness.notfirstblock before and after block creation to bypass randomness validation.

Add this before this.#chain.newTempBlock(head, header)

head.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), StorageValueKind.Deleted)

Add this after BlockBuilder_finalize_block

if (meta.query.randomness?.notFirstBlock) {
      newBlock.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), StorageValueKind.Deleted)
    }

@ermalkaleci
Copy link
Collaborator

@crystalin also I used your config.yml but without block number

@crystalin
Copy link
Contributor Author

@ermalkaleci thanks, it seems to work for me too. Howerver it only support Runtime 2000 (which wasn't the one used initially but Moonriver has been upgraded since).

Concerning the hard coded changes, do you have an idea how to include them better ?

@ermalkaleci
Copy link
Collaborator

ermalkaleci commented Dec 19, 2022

@ermalkaleci thanks, it seems to work for me too. Howerver it only support Runtime 2000 (which wasn't the one used initially but Moonriver has been upgraded since).

Concerning the hard coded changes, do you have an idea how to include them better ?

because smoldot job is to sync with current state of chains, it doesn't support old tx version.
we also added support for genesis config meaning you can start the chain with genesis without an endpoint but it will not work if genesis is too old, smoldot will p will throw invalid transaction. See configs/mandala-genesis.yml

regarding hard coded changes I am not sure, maybe it can be inside consensus closure. I didn't spend much time, just tried to cheat, not sure if we can modify digest logs to make it valid

@crystalin
Copy link
Contributor Author

@ermalkaleci Thank you.

I also tested a runtime upgrade and it worked, but it can't produce blocks anymore after that (same issue I believe):

    prevHash: "0x3e6f92d000000000000000000000000000000000000000000000000000000000"
[15:53:23.132] ERROR (rpc-author/25217): ExtrinsicFailed
    error: {
      "code": 1,
      "message": "Extrinsic is invalid: {\"invalid\":{\"badProof\":null}}"
    }
[15:56:16.554] INFO (txpool/25217): Building block
    hash: "0x87cbcbcdc5ab007599e148ad4e0f02b24072fd096285b8266ab5bc0cbad0587d"
    number: 3222725
    extrinsicsCount: 1
    tempHash: "0x521197e000000000000000000000000000000000000000000000000000000000"
    timeValue: 1671461506894
    expectedSlot: 835730753447
createInherents kickOffAuthorshipValidation 3222726
createInherents SetBabeRandomness 3222726
[15:56:18.951] WARN (txpool/25217): Failed to apply inherents {} Error: Error while executing Wasm VM: Trap: Unreachable
"panicked at 'Bad input data provided to apply_extrinsic: Codec error', /home/crystalin/projects/moonbeam/runtime/moonriver/src/lib.rs:1298:1"
/home/crystalin/projects/chopsticks/src/blockchain/txpool.ts:144
        throw new ResponseError(1, 'Failed to apply inherents')
              ^
ResponseError: Failed to apply inherents
    at TxPool.#buildBlock (/home/crystalin/projects/chopsticks/src/blockchain/txpool.ts:144:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async TxPool.buildBlock (/home/crystalin/projects/chopsticks/src/blockchain/txpool.ts:64:5) {
  code: 1
}

@ermalkaleci
Copy link
Collaborator

@crystalin can you try refreshing polkadotjs app after the upgrade? upgrade subscription isn't implemented yet

@crystalin
Copy link
Contributor Author

I did, as otherwise I can't send transaction. It showed the new version and supported to send the transaction but chopsticks failed.
(I tried twice)

@crystalin
Copy link
Contributor Author

Here is a RT2100 for Moonriver. You need to "enactAuthorizedUpgrade" (I added the authorization in the genesis of moonriver.yml): https://drive.google.com/file/d/1vVVR-YosRspnUEIHg9iLmI4nrBBffEXy/view?usp=sharing

@ermalkaleci
Copy link
Collaborator

@crystalin ok I think I know the reason. We're not updating metadata when upgrade happens. Fixing it

@ermalkaleci
Copy link
Collaborator

@crystalin fixed

@crystalin
Copy link
Contributor Author

@ermalkaleci I merged master and still get the same issue

@ermalkaleci
Copy link
Collaborator

@ermalkaleci I merged master and still get the same issue

Did you rebuilt wasm?

@crystalin
Copy link
Contributor Author

Yes I did (otherwise it doesn't even restart)

@crystalin
Copy link
Contributor Author

Ok so I think it might be due to a transaction that stays in the pool during the runtime upgrade. and then fails to be applied at the following block.
I tried to use manual (but api.rpc.engine.createBlock didn't exist it seems) or instant (this one never produces a block event with txs in the pool)

@ermalkaleci
Copy link
Collaborator

Ok so I think it might be due to a transaction that stays in the pool during the runtime upgrade. and then fails to be applied at the following block.

I tried to use manual (but api.rpc.engine.createBlock didn't exist it seems) or instant (this one never produces a block event with txs in the pool)

You can go to js section and do api.rpc("dev_newBlock")

@ermalkaleci
Copy link
Collaborator

#91 (comment)

@ermalkaleci
Copy link
Collaborator

I tested your runtime. Upgrade was successfully but I got the error trying to build new blocks. Is this runtime compatible with smoldot?

@crystalin
Copy link
Contributor Author

You are right, the runtime might have been broken. I didn't really check with commit I built it from.
I took the previous runtime and simply changed the version and it seems to work fine now !!! :)

@xlc
Copy link
Member

xlc commented Dec 19, 2022

You may want to add tests like this to avoid accidentally breaks the compatibility

https://github.com/AcalaNetwork/chopsticks/blob/master/e2e/relaychain.test.ts

@@ -97,6 +112,7 @@ export class TxPool {
},
})

head.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), StorageValueKind.Deleted)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xlc not sure what we could do here. Ideally, the signature should be mocked too but quickly looking at the randomness pallet I don't see much how this could be done.
A temporary solution is to remove the NotFirstBlock but it needs to be pallet specific and also break support for randomness.
Any idea ?

Copy link
Member

Choose a reason for hiding this comment

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

how does the randomness pallet verify the VRF? if that's using host function than we can mock it. otherwise I can see few options:

  • modify randomness pallet to make it mock friendly. e.g. if a particular storage exists or not exists, switch to mock mode
  • refactor chopsticks to support plugins so we can better manage pallet specific code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@crystalin
Copy link
Contributor Author

@ermalkaleci latest master seems broken (I tried to update submodule run yarn and ....)

Error: Cannot find module '@chopsticks/logger'
Require stack:
- /home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts
- /home/crystalin/projects/chopsticks/src/blockchain/block.ts
- /home/crystalin/projects/chopsticks/src/blockchain/txpool.ts
- /home/crystalin/projects/chopsticks/src/index.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/home/crystalin/projects/chopsticks/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Module.m._compile (/home/crystalin/projects/chopsticks/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Object.require.extensions.<computed> [as .ts] (/home/crystalin/projects/chopsticks/node_modules/ts-node/src/index.ts:1621:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts',
    '/home/crystalin/projects/chopsticks/src/blockchain/block.ts',
    '/home/crystalin/projects/chopsticks/src/blockchain/txpool.ts',
    '/home/crystalin/projects/chopsticks/src/index.ts'
  ]
}

@ermalkaleci
Copy link
Collaborator

@ermalkaleci latest master seems broken (I tried to update submodule run yarn and ....)

Error: Cannot find module '@chopsticks/logger'
Require stack:
- /home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts
- /home/crystalin/projects/chopsticks/src/blockchain/block.ts
- /home/crystalin/projects/chopsticks/src/blockchain/txpool.ts
- /home/crystalin/projects/chopsticks/src/index.ts
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/home/crystalin/projects/chopsticks/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._load (node:internal/modules/cjs/loader:833:27)
    at Module.require (node:internal/modules/cjs/loader:1057:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at Object.<anonymous> (/home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts:5:1)
    at Module._compile (node:internal/modules/cjs/loader:1155:14)
    at Module.m._compile (/home/crystalin/projects/chopsticks/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
    at Object.require.extensions.<computed> [as .ts] (/home/crystalin/projects/chopsticks/node_modules/ts-node/src/index.ts:1621:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/crystalin/projects/chopsticks/src/blockchain/storage-layer.ts',
    '/home/crystalin/projects/chopsticks/src/blockchain/block.ts',
    '/home/crystalin/projects/chopsticks/src/blockchain/txpool.ts',
    '/home/crystalin/projects/chopsticks/src/index.ts'
  ]
}

yeah forgot ts-node registrer-ts-paths. fixing

@crystalin
Copy link
Contributor Author

@ermalkaleci: Done, it seems to work well with current code

@xlc
Copy link
Member

xlc commented Jan 10, 2023

Is this ready for merge @crystalin ?

@crystalin
Copy link
Contributor Author

@xlc it is yes

@crystalin
Copy link
Contributor Author

I merged master but is now failing the test :(

@xlc xlc merged commit a279b9f into AcalaNetwork:master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants