Skip to content

Commit

Permalink
Development Genesis Config has Mainnet Schemas (#2057)
Browse files Browse the repository at this point in the history
# Goal
The goal of this PR is to add the Schemas in at Genesis from Mainnet
when on a development chain

Closes #2041

# Discussion
- Adds a tool `tools/genesis-schemas` that downloads the schemas from
mainnet and stuffs them into a json file
- GenesisConfig for Schemas Pallet that loads from a json file schemas
to start with at genesis

## How to Test
- You can test the pulling yourself with:
- `cd tools/genesis-data && npm i && npm run schemas` or use `make
genesis-schemas`
- Otherwise just run `make start` and see that it has the same schemas
as mainnet with the same names.

# Checklist
- [x] Tests added
  • Loading branch information
wilwade authored Jul 11, 2024
1 parent 3ebbb71 commit c8b60fb
Show file tree
Hide file tree
Showing 27 changed files with 2,161 additions and 172 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -891,16 +891,12 @@ jobs:
fail-fast: true
matrix:
arch: [amd64]
node: [collator-node-local, instant-seal-node, standalone-node]
node: [collator-node-local, standalone-node]
include:
- node: collator-node-local
network: local
build-profile: release
release-file-name-prefix: frequency-local
- node: instant-seal-node
network: dev
build-profile: release
release-file-name-prefix: frequency-dev
- node: standalone-node
network: dev
build-profile: release
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/verify-pr-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -475,14 +475,6 @@ jobs:
platforms: "amd64"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build collator image in instant seal mode
env:
IMAGE_NAME: instant-seal-node
uses: docker/build-push-action@v5
with:
context: .
push: false
file: ./docker/${{env.IMAGE_NAME}}.dockerfile
- name: Build collator standalone
env:
IMAGE_NAME: standalone-node
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -345,3 +345,9 @@ endif
.PHONY: version-reset
version-reset:
find ./ -type f -name 'Cargo.toml' -exec sed -i '' 's/^version = \".*+polkadot.*\"/version = \"0.0.0\"/g' {} \;

.PHONY: genesis-schemas
genesis-schemas:
cd tools/genesis-data && \
npm i && \
npm run --silent schemas > ../../resources/genesis-schemas.json
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ _Note, Running Frequency via following options does not require binary to be bui
This option runs just one collator node without the need for a relay chain.
This preloads into genesis all the schemas from mainnet.
Use `make genesis-schemas` if the genesis is out of date.
### Manual Sealing
a. Blocks can be triggered by calling the `engine_createBlock` RPC
Expand Down Expand Up @@ -187,17 +190,17 @@ Great for most testing.
make start
```
Also available as a Docker image: [`frequencychain/instant-seal-node`](https://hub.docker.com/r/frequencychain/instant-seal-node)
Also available as a Docker image: [`frequencychain/standalone-node`](https://hub.docker.com/r/frequencychain/standalone-node)
```sh
docker run --rm -p 9944:9944 -p 30333:30333 frequencychain/instant-seal-node
docker run --rm -p 9944:9944 frequencychain/standalone-node
```
To stop running chain hit [Ctrl+C] in terminal where the chain was started.
| **Node** | **Ports** | **Explorer URL** |
| ----------------------- | :----------------------------: | ----------------------------------------------------------------------------------------- |
| Frequency Collator Node | ws and rpc:`9944`, p2p:`30333` | [127.0.0.1:9944](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer) |
| **Node** | **Ports** | **Explorer URL** |
| ----------------------- | :---------------: | ----------------------------------------------------------------------------------------- |
| Frequency Collator Node | ws and rpc:`9944` | [127.0.0.1:9944](https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1%3A9944#/explorer) |
### Interval Sealing
Expand Down
1 change: 1 addition & 0 deletions common/primitives/src/handles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::utils::*;
use frame_support::BoundedVec;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_core::ConstU32;
use sp_std::vec::Vec;
Expand Down
46 changes: 39 additions & 7 deletions common/primitives/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::utils;
use enumflags2::{bitflags, BitFlags};
use parity_scale_codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
use scale_info::{build::Fields, meta_type, Path, Type, TypeInfo, TypeParameter};
#[cfg(feature = "std")]
use serde::{Deserialize, Serialize};
use sp_runtime::RuntimeDebug;
use sp_std::prelude::*;
Expand All @@ -18,8 +17,19 @@ pub type SchemaId = u16;
pub type SchemaVersion = u8;

/// Types of modeling in which a message payload may be defined
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq, MaxEncodedLen)]
#[derive(
Copy,
Clone,
Encode,
Decode,
PartialEq,
Debug,
TypeInfo,
Eq,
MaxEncodedLen,
Serialize,
Deserialize,
)]
pub enum ModelType {
/// Message payload modeled with Apache Avro: <https://avro.apache.org/docs/current/spec.html>
AvroBinary,
Expand All @@ -28,8 +38,19 @@ pub enum ModelType {
}

/// Types of payload locations
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Encode, Decode, PartialEq, Debug, TypeInfo, Eq, MaxEncodedLen)]
#[derive(
Copy,
Clone,
Encode,
Decode,
PartialEq,
Debug,
TypeInfo,
Eq,
MaxEncodedLen,
Serialize,
Deserialize,
)]
pub enum PayloadLocation {
/// Message payload is located on chain
OnChain,
Expand All @@ -44,8 +65,19 @@ pub enum PayloadLocation {
/// Support for up to 16 user-enabled features on a collection.
#[bitflags]
#[repr(u16)]
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, RuntimeDebug, PartialEq, Eq, Encode, Decode, MaxEncodedLen, TypeInfo)]
#[derive(
Copy,
Clone,
RuntimeDebug,
PartialEq,
Eq,
Encode,
Decode,
MaxEncodedLen,
TypeInfo,
Serialize,
Deserialize,
)]
pub enum SchemaSetting {
/// Schema setting to enforce append-only behavior on payload.
/// Applied to schemas of type `PayloadLocation::Itemized`.
Expand Down
56 changes: 0 additions & 56 deletions docker/instant-seal-node.dockerfile

This file was deleted.

64 changes: 0 additions & 64 deletions docker/instant-seal-node.overview.md

This file was deleted.

8 changes: 0 additions & 8 deletions node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ pub struct Cli {
#[clap(raw = true)]
pub relay_chain_args: Vec<String>,

#[cfg(feature = "frequency-no-relay")]
#[clap(long = "instant-sealing", help = "Deprecated. Use --sealing=instant instead.")]
pub instant_sealing: bool,

#[cfg(feature = "frequency-no-relay")]
#[clap(long = "manual-sealing", help = "Deprecated. Use --sealing=manual instead.")]
pub manual_sealing: bool,

/// Instant block sealing
/// Blocks are triggered to be formed each time a transaction hits the validated transaction pool
/// Empty blocks can also be formed using the `engine_createBlock` RPC
Expand Down
12 changes: 0 additions & 12 deletions node/cli/src/run_as_localchain.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
use crate::cli::Cli;
use frequency_service::block_sealing::frequency_dev_sealing;
use sc_cli::SubstrateCli;
use std::process;

pub fn run_as_localchain(cli: Cli) -> sc_service::Result<(), sc_cli::Error> {
let runner = cli.create_runner(&cli.run.normalize())?;

runner.run_node_until_exit(|config| async move {
if cli.instant_sealing {
log::error!(
"The --instant-sealing option is deprecated. Use --sealing=instant instead."
);
process::exit(1);
} else if cli.manual_sealing {
log::error!(
"The --manual-sealing option is deprecated. Use --sealing=manual instead."
);
process::exit(1);
}
frequency_dev_sealing(
config,
cli.sealing,
Expand Down
10 changes: 9 additions & 1 deletion node/service/src/chain_spec/frequency_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ fn template_session_keys(keys: AuraId) -> frequency_runtime::SessionKeys {
frequency_runtime::SessionKeys { aura: keys }
}

#[allow(clippy::unwrap_used)]
fn load_genesis_schemas() -> Vec<frequency_runtime::pallet_schemas::GenesisSchema> {
serde_json::from_slice(include_bytes!("../../../../resources/genesis-schemas.json")).unwrap()
}

#[allow(clippy::unwrap_used)]
fn development_genesis(
invulnerables: Vec<(AccountId, AuraId)>,
Expand Down Expand Up @@ -131,7 +136,10 @@ fn development_genesis(
// Assign network admin rights.
key: root_key,
},
schemas: Default::default(),
schemas: frequency_runtime::pallet_schemas::GenesisConfig {
initial_schemas: load_genesis_schemas(),
..Default::default()
},
time_release: Default::default(),
democracy: Default::default(),
treasury: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion pallets/passkey/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub type PasskeyAuthenticatorData = BoundedVec<u8, ConstU32<128>>;
/// Passkey ClientDataJson type
/// Note: The `challenge` field inside this json MUST be replaced with `CHALLENGE_PLACEHOLDER`
/// before submission to the chain
/// https://w3c.github.io/webauthn/#dictdef-collectedclientdata
/// <https://w3c.github.io/webauthn/#dictdef-collectedclientdata>
pub type PasskeyClientDataJson = BoundedVec<u8, ConstU32<256>>;
/// PassKey Public Key type in compressed encoded point format
/// the first byte is the tag indicating compressed format
Expand Down
1 change: 1 addition & 0 deletions pallets/schemas/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ frame-support = { workspace = true }
frame-system = { workspace = true }
numtoa = { workspace = true, optional = true }
scale-info = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true, features = ["alloc"] }
smallvec = { workspace = true }
sp-core = { workspace = true }
Expand Down
Loading

0 comments on commit c8b60fb

Please sign in to comment.