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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
80ab0b7
Draft support for Moonriver
crystalin Dec 17, 2022
b028dbe
Merge branch 'master' into crystalin-moonriver
crystalin Dec 18, 2022
ed87ac2
Better storage modification for Moonriver
crystalin Dec 18, 2022
d0887e4
Merge branch 'master' into crystalin-moonriver
crystalin Dec 18, 2022
d9775a1
temp fix for default storage issue
crystalin Dec 18, 2022
cb8349c
Merge branch 'master' into crystalin-moonriver
crystalin Dec 19, 2022
3db2d02
removes notFirstBlock
crystalin Dec 19, 2022
8c276a7
remove unnecessary randomness storage modification
crystalin Dec 19, 2022
72fc9b3
Adds RT2100 Dev image in authorized upgrade
crystalin Dec 19, 2022
105c12e
Merge branch 'master' into crystalin-moonriver
crystalin Dec 19, 2022
c546ccf
Better support for nmbs engine
crystalin Dec 20, 2022
cad8131
Merge branch 'master' into crystalin-moonriver
crystalin Dec 20, 2022
2045c72
fix missing import
crystalin Dec 20, 2022
e80a133
lint
crystalin Dec 20, 2022
33d6f98
Merge branch 'master' into crystalin-moonriver
crystalin Dec 20, 2022
1c7bce6
Merge branch 'master' into crystalin-moonriver
crystalin Dec 21, 2022
da111ca
Update src/blockchain/txpool.ts
Dec 28, 2022
83e760b
Merge branch 'master' into crystalin-moonriver
crystalin Dec 28, 2022
c86d47a
Fix inherents
crystalin Dec 28, 2022
0d897fe
Removes extra storage push
crystalin Dec 29, 2022
4d77abf
Better file split
crystalin Dec 29, 2022
ec0772f
fix e2e imports
crystalin Dec 29, 2022
c917476
Merge branch 'master' into crystalin-moonriver
crystalin Jan 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions configs/moonbase-alpha.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
endpoint: wss://wss.api.moonbase.moonbeam.network
mock-signature-host: true
db: ./db.sqlite

import-storage:
System:
Account:
-
-
- "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"
- data:
free: "100000000000000000000000"
TechCommitteeCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
CouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
TreasuryCouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
Sudo:
Key: "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"
AuthorFilter:
EligibleRatio: 100
EligibleCount: 100



24 changes: 24 additions & 0 deletions configs/moonbeam.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
endpoint: wss://wss.api.moonbeam.network
mock-signature-host: true
db: ./db.sqlite

import-storage:
System:
Account:
-
-
- "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"
- data:
free: "100000000000000000000000"
TechCommitteeCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
CouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
TreasuryCouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
AuthorFilter:
EligibleRatio: 100
EligibleCount: 100



24 changes: 24 additions & 0 deletions configs/moonriver.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
endpoint: wss://wss.moonriver.moonbeam.network
mock-signature-host: true
db: ./db.sqlite

import-storage:
System:
Account:
-
-
- "0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"
- data:
free: "100000000000000000000000"
TechCommitteeCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
CouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
TreasuryCouncilCollective:
Members: ["0xf24FF3a9CF04c71Dbc94D0b566f7A27B94566cac"]
AuthorFilter:
EligibleRatio: 100
EligibleCount: 100



16 changes: 14 additions & 2 deletions e2e/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { Api } from '../src/api'
import { Blockchain } from '../src/blockchain'
import { BuildBlockMode } from '../src/blockchain/txpool'
import { GenesisProvider } from '../src/genesis-provider'
import { InherentProviders, ParaInherentEnter, SetTimestamp, SetValidationData } from '../src/blockchain/inherent'
import {
InherentProviders,
ParaInherentEnter,
SetBabeRandomness,
SetNimbusAuthorInherent,
SetTimestamp,
SetValidationData,
} from '../src/blockchain/inherent'
import { StorageValues } from '../src/utils/set-storage'
import { createServer } from '../src/server'
import { handler } from '../src/rpc'
Expand Down Expand Up @@ -52,7 +59,12 @@ export const setupAll = async ({

return {
async setup() {
const inherents = new InherentProviders(new SetTimestamp(), [new SetValidationData(), new ParaInherentEnter()])
const inherents = new InherentProviders(new SetTimestamp(), [
new SetValidationData(),
new ParaInherentEnter(),
new SetNimbusAuthorInherent(),
new SetBabeRandomness(),
])

const chain = new Blockchain({
api,
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"test:dev": "LOG_LEVEL=trace vitest --inspect",
"dev": "LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/dev.yml",
"dev:karura": "ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/karura.yml",
"dev:acala": "ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/acala.yml"
"dev:acala": "ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/acala.yml",
"dev:moonriver": "ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/moonriver.yml",
"dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/index.ts -- dev --config=configs/moonbeam.yml"
},
"dependencies": {
"@acala-network/chopsticks-executor": "workspace:*",
Expand Down
19 changes: 18 additions & 1 deletion src/blockchain/block-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Block, TaskCallResponse } from './block'
import { Header, RawBabePreDigest } from '@polkadot/types/interfaces'
import { HexString } from '@polkadot/util/types'
import { compactAddLength } from '@polkadot/util'
import { StorageValueKind } from './storage-layer'
import { compactAddLength, stringToHex } from '@polkadot/util'
import { compactHex } from '../utils'
import { defaultLogger, truncate, truncateStorageDiff } from '../logger'
import { getCurrentSlot } from '../utils/time-travel'

Expand Down Expand Up @@ -57,6 +59,21 @@ const newHeader = async (head: Block) => {
const digest = meta.registry.createType<RawBabePreDigest>('RawBabePreDigest', consensus.slot)
const newSlot = compactAddLength(meta.registry.createType('RawBabePreDigest', getNewSlot(digest, slot + 1)).toU8a())
newLogs = [{ PreRuntime: [consensus.consensusEngine, newSlot] }, ...consensus.rest]
} else if (consensus?.consensusEngine?.toString() == 'nmbs') {
const nmbsKey = stringToHex('nmbs')
newLogs = [
{
// Using previous block author
PreRuntime: [
consensus.consensusEngine,
parentHeader.digest.logs
.find((log) => log.isPreRuntime && log.asPreRuntime[0].toHex() == nmbsKey)
?.asPreRuntime[1].toHex(),
],
},
...consensus.rest,
head.pushStorageLayer().set(compactHex(meta.query.randomness.notFirstBlock()), StorageValueKind.Deleted),
]
}

const header = meta.registry.createType<Header>('Header', {
Expand Down
2 changes: 2 additions & 0 deletions src/blockchain/inherent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { getCurrentTimestamp, getSlotDuration } from '../../utils/time-travel'

export { SetValidationData } from './parachain/validation-data'
export { ParaInherentEnter } from './para-enter'
export { SetBabeRandomness } from './parachain/babe-randomness'
export { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent'

export interface CreateInherents {
createInherents(parent: Block, params?: BuildBlockParams['inherent']): Promise<HexString[]>
Expand Down
17 changes: 17 additions & 0 deletions src/blockchain/inherent/parachain/babe-randomness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GenericExtrinsic } from '@polkadot/types'
import { HexString } from '@polkadot/util/types'

import { Block } from '../../../blockchain/block'
import { BuildBlockParams } from '../../txpool'
import { CreateInherents } from '..'

// Support for Moonbeam pallet-randomness mandatory inherent
export class SetBabeRandomness implements CreateInherents {
async createInherents(parent: Block, _params?: BuildBlockParams['inherent']): Promise<HexString[]> {
const meta = await parent.meta
if (!meta.tx.randomness?.setBabeRandomnessResults) {
return []
}
return [new GenericExtrinsic(meta.registry, meta.tx.randomness.setBabeRandomnessResults()).toHex()]
}
}
17 changes: 17 additions & 0 deletions src/blockchain/inherent/parachain/nimbus-author-inherent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { GenericExtrinsic } from '@polkadot/types'
import { HexString } from '@polkadot/util/types'

import { Block } from '../../../blockchain/block'
import { BuildBlockParams } from '../../txpool'
import { CreateInherents } from '..'

// Support for Nimbus Author Inherent
export class SetNimbusAuthorInherent implements CreateInherents {
async createInherents(parent: Block, _params?: BuildBlockParams['inherent']): Promise<HexString[]> {
const meta = await parent.meta
if (!meta.tx.authorInherent?.kickOffAuthorshipValidation) {
return []
}
return [new GenericExtrinsic(meta.registry, meta.tx.authorInherent.kickOffAuthorshipValidation()).toHex()]
}
}
16 changes: 14 additions & 2 deletions src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ import { Api } from './api'
import { Blockchain } from './blockchain'
import { Config } from './schema'
import { GenesisProvider } from './genesis-provider'
import { InherentProviders, ParaInherentEnter, SetTimestamp, SetValidationData } from './blockchain/inherent'
import {
InherentProviders,
ParaInherentEnter,
SetBabeRandomness,
SetNimbusAuthorInherent,
SetTimestamp,
SetValidationData,
} from './blockchain/inherent'
import { defaultLogger } from './logger'
import { importStorage, overrideWasm } from './utils/import-storage'
import { openDb } from './db'
Expand Down Expand Up @@ -46,7 +53,12 @@ export const setup = async (argv: Config) => {

const header = await api.getHeader(blockHash)

const inherents = new InherentProviders(new SetTimestamp(), [new SetValidationData(), new ParaInherentEnter()])
const inherents = new InherentProviders(new SetTimestamp(), [
new SetValidationData(),
new ParaInherentEnter(),
new SetNimbusAuthorInherent(),
new SetBabeRandomness(),
])

const chain = new Blockchain({
api,
Expand Down