Skip to content

Commit

Permalink
Merge pull request #87 from Cerebellum-Network/feature/ddc-validator-cli
Browse files Browse the repository at this point in the history
DAC DataModel HTTP endpoint from CLI
  • Loading branch information
khssnv authored Sep 21, 2023
2 parents d557ae2 + 6ae8504 commit 28fe7af
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument. It will only work on the nodes with validation and offchain workers enabled as well.
- [D] New `pallet-ddc-validator` which implements DDC CDN nodes validation and rewarding. You can enable DDC validation providing `--enable-ddc-validation` argument and `--dac-url` argument to specify DAC endpoint. It will only work on the nodes with validation and offchain workers enabled as well.
- [D] Several calls for `pallet-ddc-staking` to distribute rewards.
- [D] DDC cluster managers access control list in `pallet-ddc-staking` managed by governance.
- [Zombienet](https://github.com/paritytech/zombienet) configurations to test block building and spawn a network for DDC validation debugging.
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@ zombienet -p native test zombienet/0000-block-building/block-building.zndsl

#### Spawn 5 DDC validation nodes

The following command spawns 5 validator nodes with DDC validation enabled as well as 1 non-validator node to check it is not affected.
The following command spawns 5 validator nodes with DDC validation enabled as well as 1 non-validator node to check it is not affected. Set `DAC_URL` environment variable with an address to [webdis](https://webd.is/) which will proxy validator's requests for DDC activity data to DAC DataModel Redis.

```console
export DAC_URL=http://localhost:7379/
zombienet -p native test zombienet/0001-ddc-validation/ddc-validation.toml
```

Expand Down
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ sc-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrat
sc-service = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" }
frame-benchmarking-cli = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate", optional = true, branch = "polkadot-v0.9.30" }
try-runtime-cli = { version = "0.10.0-dev", git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.30" }
url = "2.4.1"

# Local
cere-service = { path = "../node/service", default-features = false, optional = true }
Expand Down
6 changes: 5 additions & 1 deletion cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ pub struct RunCmd {

/// Enable DDC validation (disabled by default). Works only on validator nodes with enabled
/// offchain workers.
#[clap(long)]
#[clap(long, requires = "dac-url")]
pub enable_ddc_validation: bool,

/// DAC DataModel HTTP endpoint to retrieve DDC activity data for validation.
#[clap(long, requires = "enable-ddc-validation", validator = url::Url::parse)]
pub dac_url: Option<String>,

/// Force using Cere Dev runtime.
#[clap(long = "force-cere-dev")]
pub force_cere_dev: bool,
Expand Down
1 change: 1 addition & 0 deletions cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub fn run() -> sc_cli::Result<()> {
config,
cli.run.no_hardware_benchmarks,
cli.run.enable_ddc_validation,
cli.run.dac_url,
)
.map(|full| full.task_manager)
.map_err(Error::Service)
Expand Down
22 changes: 15 additions & 7 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,15 @@ pub fn build_full(
config: Configuration,
disable_hardware_benchmarks: bool,
enable_ddc_validation: bool,
dac_url: Option<String>,
) -> Result<NewFull<Client>, ServiceError> {
#[cfg(feature = "cere-dev-native")]
if config.chain_spec.is_cere_dev() {
return new_full::<cere_dev_runtime::RuntimeApi, CereDevExecutorDispatch>(
config,
disable_hardware_benchmarks,
enable_ddc_validation,
dac_url,
|_, _| (),
)
.map(|full| full.with_client(Client::CereDev))
Expand All @@ -289,6 +291,7 @@ pub fn build_full(
config,
disable_hardware_benchmarks,
enable_ddc_validation,
dac_url,
|_, _| (),
)
.map(|full| full.with_client(Client::Cere))
Expand Down Expand Up @@ -323,6 +326,7 @@ pub fn new_full<RuntimeApi, ExecutorDispatch>(
mut config: Configuration,
disable_hardware_benchmarks: bool,
enable_ddc_validation: bool,
dac_url: Option<String>,
with_startup_data: impl FnOnce(
&sc_consensus_babe::BabeBlockImport<
Block,
Expand Down Expand Up @@ -352,15 +356,19 @@ where

let basics = new_partial_basics::<RuntimeApi, ExecutorDispatch>(&config)?;

basics
let mut offchain_storage = basics
.backend
.offchain_storage()
.expect("no off-chain storage, DDC validation is not possible")
.set(
sp_core::offchain::STORAGE_PREFIX,
b"enable-ddc-validation",
if enable_ddc_validation { &[1] } else { &[0] },
);
.expect("no off-chain storage, DDC validation is not possible");

offchain_storage.set(
sp_core::offchain::STORAGE_PREFIX,
b"enable-ddc-validation",
if enable_ddc_validation { &[1] } else { &[0] },
);
if let Some(dac_url) = dac_url {
offchain_storage.set(sp_core::offchain::STORAGE_PREFIX, b"dac-url", dac_url.as_bytes());
};

let sc_service::PartialComponents {
client,
Expand Down
2 changes: 1 addition & 1 deletion pallets/ddc-validator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub const KEY_TYPE: KeyTypeId = KeyTypeId(*b"dacv");
/// Webdis in experimental cluster connected to Redis in dev.
pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://webdis:7379";
// pub const DEFAULT_DATA_PROVIDER_URL: &str = "http://161.35.140.182:7379";
pub const DATA_PROVIDER_URL_KEY: &[u8; 32] = b"ddc-validator::data-provider-url";
pub const DATA_PROVIDER_URL_KEY: &[u8; 7] = b"dac-url";
pub const QUORUM_SIZE: usize = 1;

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion zombienet/0001-ddc-validation/ddc-validation.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[relaychain]
default_command = "./target/release/cere"
default_args = ["--enable-ddc-validation"]
default_args = ["--enable-ddc-validation --dac-url {{DAC_URL}}"]
chain = "local"

[[relaychain.nodes]]
Expand Down

0 comments on commit 28fe7af

Please sign in to comment.