Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

feat: Indexing configs #1018

Merged
merged 73 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
11a34e8
initial index file
d-roak Aug 18, 2023
f7b2f15
rm unused assets at genesis
d-roak Aug 18, 2023
41eda2e
configs url
d-roak Aug 18, 2023
22111ca
Added fetching and file hash validation
d-roak Aug 22, 2023
c8eb583
adjust configs index and constants
d-roak Aug 22, 2023
440aaee
replace Proxy.json; adjust hashes; change chain spec fetching logic
d-roak Aug 22, 2023
2da78fe
Merge branch 'main' into feat/configs-index
d-roak Aug 22, 2023
91a97b4
readme; fix linters and formatters
d-roak Aug 22, 2023
af87342
change genesis paths
d-roak Aug 22, 2023
02643d9
add missing path
d-roak Aug 22, 2023
cd42a18
rm println; make file hash optional
d-roak Aug 22, 2023
15b2010
Update configs.md
d-roak Aug 22, 2023
1664ed5
reorder flags; force update on fetch and verify
d-roak Aug 22, 2023
5332221
prettier, linter and fmt
d-roak Aug 22, 2023
a4caf59
add logs to ci
d-roak Aug 22, 2023
30b7a06
fix genesis.json hash
d-roak Aug 22, 2023
7570e04
disable logging; bugfix on non madara-path genesis loading
d-roak Aug 22, 2023
12c8f53
update package-lock
d-roak Aug 22, 2023
24544bd
rm tmp TODO; working as supposed
d-roak Aug 23, 2023
8dde928
add verifiers in the ci; rm pr close workflow
d-roak Aug 23, 2023
8ebb405
specify origin/main
d-roak Aug 23, 2023
9bdb002
2nd try to fix git diff
d-roak Aug 23, 2023
655c52a
fetch whole git history
d-roak Aug 23, 2023
3217e83
rm head ref
d-roak Aug 23, 2023
06254eb
Merge branch 'main' into feat/configs-index
d-roak Aug 23, 2023
21e2921
fix merge conflict
d-roak Aug 24, 2023
361879c
add disable madara configs flag
d-roak Aug 25, 2023
300970c
comment unused stuff
d-roak Aug 25, 2023
905b9f2
new flag docs; improve code readability; refactor for build-spec
d-roak Aug 25, 2023
c130616
set chain spec with match
d-roak Aug 25, 2023
8d58d50
clippy
d-roak Aug 25, 2023
e7a3dde
review adjustments
d-roak Aug 25, 2023
b937fda
add early return
d-roak Aug 25, 2023
a8c1abc
applying changed requests
d-roak Aug 28, 2023
ff16036
rm configs docs; add default value to madara_path
d-roak Aug 29, 2023
03559d6
short base path assign
d-roak Aug 29, 2023
5b2469b
rm chain specs from the indexer; change the flow for `setup` and `run`
d-roak Sep 1, 2023
f4f5f76
better separation of the args for the subcommands
d-roak Sep 3, 2023
8f686d8
Merge branch 'main' into feat/configs-index
d-roak Sep 3, 2023
eec3cae
drop chain specs verification in the ci
d-roak Sep 3, 2023
8ac9a81
fix linting issues; add setup for ci flows
d-roak Sep 3, 2023
ece6b64
Merge branch 'main' into feat/configs-index
d-roak Sep 14, 2023
430edf4
adjustments to the merge with main; change docs to include setup and run
d-roak Sep 14, 2023
93f1dd5
make testnet and chain exclusive; rm clone from fetch_madara_configs
d-roak Sep 14, 2023
d284017
run prettier and fmt
d-roak Sep 14, 2023
5150e8c
replace match with if
d-roak Sep 14, 2023
0bd8cae
use if in the non conjuction
d-roak Sep 14, 2023
f984b90
clippy
d-roak Sep 14, 2023
d9bd2a3
fix bug while running flags
d-roak Sep 14, 2023
edd71e7
add setup and run on tests
d-roak Sep 14, 2023
2e373c9
ignore eslint
d-roak Sep 14, 2023
1eaa054
delete println
d-roak Sep 17, 2023
7a6666f
Merge branch 'main' into feat/configs-index
d-roak Sep 17, 2023
1555cc5
merge main
d-roak Sep 18, 2023
0c29e0b
merge pulled
d-roak Sep 18, 2023
f661388
fix genesis hash
d-roak Sep 18, 2023
7362d25
change from cairo-contracts to genesis assets
d-roak Sep 18, 2023
b5f3afd
fix genesis hash
d-roak Sep 18, 2023
b28f96d
readd coverage to workflows
d-roak Sep 18, 2023
b8d4b33
comment coverage while main doesnt have rust tests
d-roak Sep 18, 2023
3caebb0
Merge branch 'main' into feat/configs-index
d-roak Sep 20, 2023
02d0def
fix conversations about expect messages and functions inputs
d-roak Sep 22, 2023
1c2ee5e
fix merge conflicts
d-roak Sep 22, 2023
87f4e31
wrap madara path string in a function
d-roak Sep 22, 2023
b67ef98
Merge branch 'main' into feat/configs-index
d-roak Sep 22, 2023
0d7485b
changed conversion of madara path to string
d-roak Sep 25, 2023
87424cb
Merge branch 'feat/configs-index' of github.com:d-roak/madara into fe…
d-roak Sep 25, 2023
3b20480
fmt and cargo lock
d-roak Sep 25, 2023
0751eee
Update crates/node/src/command.rs
d-roak Sep 27, 2023
d789c39
merge main
d-roak Sep 27, 2023
21303a2
re-add flamegraph to readme
d-roak Sep 27, 2023
03927cb
rustdoc for get madara path str
d-roak Sep 27, 2023
32f33e4
rustdoc for get madara path str
d-roak Sep 27, 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
- ci: disable pr close workflow
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
- ci: add ci verification for detecting genesis changes and config hashes
- feat: better management of custom configurations for genesis assets
- feat: unification of the DA interface
- feat: use resolver 2 for cargo in the workspace
- upgrade: restructure code for rust latest version
- upgrade: bump rustc nightly version to 1.74 date
- feat: bump starknet-core to 0.6.0 and remove InvokeV0
- fix: estimate_fee should make sure all transaction have a version being
2^128 + 1 or 2^128+2 depending on the tx type
- fix: initial_gas set to max_fee and fixed fee not being charged when max_fee=0
Expand Down
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ clap = { version = "4.4.2", default-features = false }
futures = { version = "0.3.28", default-features = false }
futures-timer = { version = "3.0.2", default-features = false }
md5 = { version = "0.7.0", default-features = false }
reqwest = { version = "0.11.18", default-features = false }
serde = { version = "1.0.185", default-features = false }
serde_json = { version = "1.0.105", default-features = false }
reqwest = { version = "0.11.20", default-features = false }
serde = { version = "1.0.188", default-features = false }
serde_json = { version = "1.0.106", default-features = false }
serde_with = { version = "2.3.3", default-features = false }
bitvec = { version = "1", default-features = false }
thiserror = "1.0.48"
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,6 @@ production environment, the relative changes and trends over time are what we
focus on. This way, we can ensure that Madara is always improving, and that we
maintain a high standard of performance as the project evolves.

One can use flamegraph-rs to generate flamegraphs and look for the performance
d-roak marked this conversation as resolved.
Show resolved Hide resolved
bottlenecks of the system by running the following :

```bash
flamegraph --root --open -- ./target/release/madara --dev --pool-limit=100000 --pool-kbytes=500000 --rpc-methods=unsafe --rpc-cors=all --in-peers=0 --out-peers=1 --no-telemetry
```

In parallel to that, run `npm run test` within the `benchmarking` folder. Once
you stop the node, the flamegraph will open in your browser.

## 🌐 Connect to the dev webapp

Once your Madara node is up and running, you can connect to our Dev Frontend App
Expand Down
12 changes: 4 additions & 8 deletions crates/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ pub fn local_testnet_config(madara_path: PathBuf) -> Result<ChainSpec, String> {

fn load_genesis(madara_path: PathBuf) -> GenesisLoader {
let madara_path = madara_path.to_str().unwrap().to_string();
let genesis_path = madara_path.clone() + "/genesis-assets/genesis.json";
let genesis = utils::read_file_to_string(genesis_path).expect("Failed to read genesis file");
let genesis_path = madara_path.clone() + "/configs/genesis-assets/genesis.json";
let genesis = utils::read_file_to_string(genesis_path)
.expect("Failed to read genesis file. Please run `madara setup` before opening an issue.");
let mut genesis_loader: GenesisLoader = serde_json::from_str(&genesis).expect("Failed loading genesis");
genesis_loader.set_madara_path(madara_path);
genesis_loader
Expand All @@ -159,12 +160,7 @@ fn testnet_genesis(
initial_authorities: Vec<(AuraId, GrandpaId)>,
_enable_println: bool,
) -> GenesisConfig {
let genesis = madara_path.clone() + "/configs/genesis-assets/genesis.json";
let genesis = utils::read_file_to_string(genesis)
.expect("Failed to read genesis file. Please run `madara setup` before opening an issue.");
let mut genesis: GenesisLoader = serde_json::from_str(&genesis).expect("Failed loading genesis");
genesis.set_madara_path(madara_path);
let starknet_genesis: madara_runtime::pallet_starknet::GenesisConfig<_> = genesis.into();
let starknet_genesis_config: madara_runtime::pallet_starknet::GenesisConfig<_> = genesis_loader.into();

GenesisConfig {
system: SystemConfig {
Expand Down
16 changes: 10 additions & 6 deletions crates/node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ pub struct Cli {

#[clap(flatten)]
pub setup: SetupCmd,

/// Choose sealing method.
#[arg(long, value_enum, ignore_case = true)]
pub sealing: Option<Sealing>,
}

#[derive(Debug, clap::Args)]
#[derive(Clone, Debug, clap::Args)]
pub struct ExtendedRunCmd {
#[clap(flatten)]
pub run_cmd: RunCmd,

/// Choose a supported DA Layer
#[clap(long)]
pub da_layer: Option<DaLayer>,

/// Load a custom chain-spec from an url
/// If you want to load a chain spec that is present in your filesystem, use `--chain=<PATH>`
#[clap(long, conflicts_with = "testnet")]
Expand All @@ -58,9 +58,13 @@ pub struct ExtendedRunCmd {
#[clap(long, default_value = get_default_madara_path())]
pub madara_path: Option<PathBuf>,
d-roak marked this conversation as resolved.
Show resolved Hide resolved

/// Choose sealing method.
#[arg(long, value_enum, ignore_case = true)]
pub sealing: Option<Sealing>,

/// Choose a supported testnet chain which will load some default values
/// The testnets will allways be fetched when this flag is passed to search for updates
#[clap(long, conflicts_with = "fetch_chain_spec")]
#[clap(long, conflicts_with = "fetch_chain_spec", conflicts_with = "chain")]
pub testnet: Option<Testnet>,
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
75 changes: 35 additions & 40 deletions crates/node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"dev" => {
let enable_manual_seal = self.sealing.map(|_| true);
let enable_manual_seal = self.run.sealing.map(|_| true);
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
Box::new(chain_spec::development_config(
enable_manual_seal,
self.run.madara_path.clone().expect("Failed retrieving madara_path"),
Expand All @@ -56,6 +56,7 @@ impl SubstrateCli for Cli {
}

fn set_dev_environment(cli: &mut Cli) {
println!("Setting up dev environment");
d-roak marked this conversation as resolved.
Show resolved Hide resolved
// create a reproducible dev environment
cli.run.run_cmd.shared_params.dev = false;
cli.run.run_cmd.shared_params.chain = Some("dev".to_string());
Expand All @@ -74,13 +75,12 @@ fn set_testnet(cli: &mut Cli, testnet: Testnet) -> Result<(), String> {
let madara_path = cli.run.madara_path.clone().expect("Failed retrieving madara_path").to_str().unwrap().to_string();
d-roak marked this conversation as resolved.
Show resolved Hide resolved
let local_path = utils::get_project_path();

d-roak marked this conversation as resolved.
Show resolved Hide resolved
match (testnet, local_path) {
(Testnet::Sharingan, Ok(ref src_path)) => {
if testnet == Testnet::Sharingan {
if let Ok(ref src_path) = local_path {
let src_path = src_path.clone() + "/configs/chain-specs/testnet-sharingan-raw.json";
utils::copy_from_filesystem(src_path, madara_path.clone() + "/chain-specs")?;
cli.run.run_cmd.shared_params.chain = Some(madara_path + "/chain-specs/testnet-sharingan-raw.json");
}
(Testnet::Sharingan, _) => {
} else {
utils::fetch_from_url(
constants::SHARINGAN_CHAIN_SPEC_URL.to_string(),
madara_path.clone() + "/configs/chain-specs/",
Expand All @@ -107,40 +107,35 @@ fn set_chain_spec(cli: &mut Cli, chain_spec_url: String) -> Result<(), String> {
Ok(())
}

fn fetch_madara_configs(cli: &mut Cli) -> Result<(), String> {
fn fetch_madara_configs(cli: &Cli) -> Result<(), String> {
let madara_path = cli.run.madara_path.clone().expect("Failed retrieving madara_path").to_str().unwrap().to_string();
d-roak marked this conversation as resolved.
Show resolved Hide resolved
let local_path = utils::get_project_path();

match (cli.setup.fetch_madara_configs.clone(), local_path) {
// TODO match string for default configs value
(_, Ok(ref src_path)) => {
let index_path = src_path.clone() + "/configs/index.json";
utils::copy_from_filesystem(index_path, madara_path.clone() + "/configs")?;

let madara_configs: configs::Configs =
serde_json::from_str(&utils::read_file_to_string(madara_path.clone() + "/configs/index.json")?)
.expect("Failed to load madara configs");
for asset in madara_configs.genesis_assets {
let src_path = src_path.clone() + "/configs/genesis-assets/" + &asset.name;
utils::copy_from_filesystem(src_path, madara_path.clone() + "/configs/genesis-assets")?;
}
if let Ok(ref src_path) = local_path {
let index_path = src_path.clone() + "/configs/index.json";
utils::copy_from_filesystem(index_path, madara_path.clone() + "/configs")?;

let madara_configs: configs::Configs =
serde_json::from_str(&utils::read_file_to_string(madara_path.clone() + "/configs/index.json")?)
.expect("Failed to load madara configs");
d-roak marked this conversation as resolved.
Show resolved Hide resolved
for asset in madara_configs.genesis_assets {
let src_path = src_path.clone() + "/configs/genesis-assets/" + &asset.name;
utils::copy_from_filesystem(src_path, madara_path.clone() + "/configs/genesis-assets")?;
}
(Some(configs_url), _) => {
utils::fetch_from_url(configs_url, madara_path.clone() + "/configs")?;

let madara_configs: configs::Configs =
serde_json::from_str(&utils::read_file_to_string(madara_path.clone() + "/configs/index.json")?)
.expect("Failed to load madara configs");

for asset in madara_configs.genesis_assets {
configs::fetch_and_validate_file(
madara_configs.remote_base_path.clone(),
asset,
madara_path.clone() + "/configs/genesis-assets/",
)?;
}
} else if let Some(configs_url) = &cli.setup.fetch_madara_configs {
utils::fetch_from_url(configs_url.to_string(), madara_path.clone() + "/configs")?;

let madara_configs: configs::Configs =
serde_json::from_str(&utils::read_file_to_string(madara_path.clone() + "/configs/index.json")?)
.expect("Failed to load madara configs");
d-roak marked this conversation as resolved.
Show resolved Hide resolved

for asset in madara_configs.genesis_assets {
configs::fetch_and_validate_file(
madara_configs.remote_base_path.clone(),
asset,
madara_path.clone() + "/configs/genesis-assets/",
)?;
}
_ => {}
}

Ok(())
Expand Down Expand Up @@ -270,17 +265,17 @@ pub fn run() -> sc_cli::Result<()> {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run::<Block>(&config))
}
Some(Subcommand::Run(_)) => {
Some(Subcommand::Run(cmd)) => {
let madara_path =
cli.run.madara_path.clone().expect("Failed retrieving madara_path").to_str().unwrap().to_string();

// Set the node_key_file for substrate in the case that it was not manually setted
if cli.run.run_cmd.network_params.node_key_params.node_key_file.is_none() {
if cmd.run_cmd.network_params.node_key_params.node_key_file.is_none() {
cli.run.run_cmd.network_params.node_key_params.node_key_file =
Some((madara_path + "/p2p-key.ed25519").into());
Some((madara_path.clone() + "/p2p-key.ed25519").into());
}

if cli.run.run_cmd.shared_params.dev {
if cmd.run_cmd.shared_params.dev {
set_dev_environment(&mut cli);
}

Expand Down Expand Up @@ -310,11 +305,11 @@ pub fn run() -> sc_cli::Result<()> {

let runner = cli.create_runner(&cli.run.run_cmd)?;
runner.run_node_until_exit(|config| async move {
service::new_full(config, cli.sealing, da_config).map_err(sc_cli::Error::Service)
service::new_full(config, cli.run.sealing, da_config).map_err(sc_cli::Error::Service)
})
}
Some(Subcommand::Setup(_)) => {
fetch_madara_configs(&mut cli)?;
fetch_madara_configs(&cli)?;
Ok(())
}
_ => Err("You need to specify some subcommand. E.g. `madara run`".into()),
Expand Down
3 changes: 2 additions & 1 deletion docs/faucet-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ Follow the steps below to setup a faucet for your local build
Run an instance of your madara node locally

```bash
cargo run --release -- --dev
cargo run --release -- setup
cargo run --release -- run --dev
```

`--dev`: enforces a development environment needed to make testing easier for
Expand Down
16 changes: 9 additions & 7 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@ rustup show
Use Rust's native `cargo` command to build and launch the template node:

```sh
cargo run --release -- --dev
cargo run --release -- setup
cargo run --release -- run --dev
```

The node also supports to use manual seal (to produce block manually through
RPC). This is also used by the typescript tests:

```sh
$ cargo run --release -- --dev --sealing=manual
$ cargo run --release -- run --dev --sealing=manual
# Or
$ cargo run --release -- --dev --sealing=instant
$ cargo run --release -- run --dev --sealing=instant
```

Log level can be specified with `-l` flag. For example, `-ldebug` will show
debug logs. It can also be specified via the `RUST_LOG` environment variable.
For example:

```sh
RUSTLOG=runtime=info cargo run --release -- --dev
RUSTLOG=runtime=info cargo run --release -- run --dev
```

### Cargo Build
Expand Down Expand Up @@ -80,7 +81,8 @@ This command will start the single-node development chain with non-persistent
state:

```bash
./target/release/madara --dev
./target/release/madara setup
./target/release/madara run --dev
```

Purge the development chain's state:
Expand All @@ -92,7 +94,7 @@ Purge the development chain's state:
Start the development chain with detailed logging:

```bash
RUST_BACKTRACE=1 ./target/release/madara -ldebug --dev
RUST_BACKTRACE=1 ./target/release/madara run -ldebug --dev
```

> Development chain means that the state of our chain will be in a tmp folder
Expand All @@ -117,7 +119,7 @@ commands shows how to use a newly created folder as our db base path.
$ mkdir my-chain-state

// Use of that folder to store the chain state
$ ./target/release/madara --dev --base-path ./my-chain-state/
$ ./target/release/madara run --dev --base-path ./my-chain-state/

// Check the folder structure created inside the base path after running the chain
$ ls ./my-chain-state
Expand Down
5 changes: 3 additions & 2 deletions docs/rpc-contribution.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ First, go ahead and clone madara on the `main` branch from

There are two ways you can build madara to quickly test it:

1. `cargo build --release`, which will then allow us to start madara running
`./target/release/madara`. This will start the sequencer WITHOUT peers.
1. `cargo build --release`, which will then allow us to setup madara with
`./target/release/madara setup`, and then run it with
`./target/release/madara run`. This will start the sequencer WITHOUT peers.
That's not a problem if you just want to test that your RPC method is
accessible, and to test (de)serialization of your RPC parameters.

Expand Down
3 changes: 2 additions & 1 deletion docs/sharingan-starter-pack.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ If you prefer having Madara compiled locally, you must:
the root of Madara repository:

```bash
./target/release/madara --testnet sharingan --telemetry-url 'wss://telemetry.madara.zone/submit 0'
./target/release/madara setup
./target/release/madara run --testnet sharingan --telemetry-url 'wss://telemetry.madara.zone/submit 0'
```

This will store the data into `$HOME/.madara`.
Expand Down
3 changes: 3 additions & 0 deletions tests/util/dev-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export async function startMadaraDevNode(

const cmd = BINARY_PATH;
const args = [
"run",
withWasm ? "--execution=Wasm" : "--execution=Native", // Faster execution using native
process.env.FORCE_COMPILED_WASM
? "--wasm-execution=compiled"
Expand Down Expand Up @@ -110,6 +111,8 @@ export async function startMadaraDevNode(
let runningNode: ChildProcess = null;
process.once("exit", onProcessExit);
process.once("SIGINT", onProcessInterrupt);
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("child_process").execSync(cmd + " setup");
runningNode = spawn(cmd, args);

runningNode.once("exit", () => {
Expand Down
Loading