Skip to content

Commit

Permalink
doc: Enhanced and updated all documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkingLee committed Jan 27, 2024
1 parent ef38bc9 commit a3beebb
Show file tree
Hide file tree
Showing 22 changed files with 763 additions and 427 deletions.
88 changes: 72 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,78 @@
# Substrate Cumulus Parachain Template
# Redot

A new [Cumulus](https://github.com/paritytech/cumulus/)-based Substrate node, ready for hacking ☁️..
Redot serves as Polkadot's re-staking layer. It includes a specialized parachain, essentially an adapter for Polkadot's consensus layer, designed to extend the capabilities of the consensus layer. Redot comprises a parachain and redlight. The parachain facilitates on-chain management of various tasks and validators. redlight is a lightweight client for validators, used for completing different validation tasks.

This project is originally a fork of the
[Substrate Node Template](https://github.com/substrate-developer-hub/substrate-node-template)
modified to include dependencies required for registering this node as a **parathread** or
**parachain** to a **relay chain**.
## Philosophy

The stand-alone version of this template is hosted on the
[Substrate Devhub Parachain Template](https://github.com/substrate-developer-hub/substrate-parachain-template/)
for each release of Polkadot. It is generated directly to the upstream
[Parachain Template in Cumulus](https://github.com/paritytech/cumulus/tree/master/parachain-template)
at each release branch using the
[Substrate Template Generator](https://github.com/paritytech/substrate-template-generator/).
- Zero Knowledge Leakage: As a consensus layer, Polkadot should not be privy to information about layers like data availability. This focus on consensus allows Polkadot to be more efficient. Redot, as an adapter to the consensus layer, extends its capabilities to the data availability layer through re-staking.
- Neutrality: Redot imposes no restrictions on the nature of tasks. It supports tasks beyond data availability and accommodates various data availability layers.
- Lightweight: Validator tasks should be sufficiently lightweight. Only information pertinent to the consensus layer should be incorporated into these tasks.

👉 Learn more about parachains [here](https://wiki.polkadot.network/docs/learn-parachains), and
parathreads [here](https://wiki.polkadot.network/docs/learn-parathreads).
## 模块

Redot 包含了以下模块:

🧙 Learn about how to use this template and run your own parachain testnet for it in the
[Devhub Cumulus Tutorial](https://docs.substrate.io/tutorials/v3/cumulus/start-relay/).
* [core-primitives](./crates/core-primitives/): Implements specific primitives for DKG, threshold signature encryption.
* [rc-validator](./crates/rc-validator/): Depends on the validator network to execute different methods.
* [rc-validator-fetch](./crates/rc-validator-fetch/): A module that supports storing and fetching validator information in different environments.
* [rc-validator-network](./crates/rc-validator-network/): Implementation of the validator network for communication among validators.
* [task](./pallets/task/): Task module for managing different tasks and key rotation, etc.
* [validator-registry](./pallets/validator-registry/): Validator registration and deletion module, using OCW for verification.
* [redlight](./redlight/): A lightweight client for validators to complete various validation tasks.
* [redoxt](./redoxt/): A module for communication with the parachain.

## Building

### Setup rust

Install Rust:

```bash
curl https://sh.rustup.rs -sSf | sh
```

You will also need to install the following packages:

mac

```bash
brew install cmake pkg-config openssl git llvm
```

Linux

```bash
sudo apt install cmake pkg-config libssl-dev git clang libclang-dev protobuf-compiler
```

More: Redot is based on Substrate, for more information please go to [Substrate](https://docs.substrate.io/install/).

### Build

1. Compile the parachain:

```bash
make build-default
```

2. Compile the redlight node:

```bash
make build-light
```

## 3. Run

You can start a development chain with:

```bash
make run-dev
```

However, this does not produce actual blocks. Since Redot is a parachain, it is recommended to use [Zombienet](https://github.com/paritytech/zombienet) for actual operation.

To launch a light node:

```bash
make run-light
```
18 changes: 9 additions & 9 deletions crates/core-primitives/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

///! Frost DKG and signing implementation
///
/// This is a specific implementation of threshold signature, which can be verified in a `no-std` environment,
/// thus enabling on-chain verification in Substrate. Currently, it does not support generation and signing
/// in `no-std`. FROST is used as the underlying cryptographic library. FROST is a threshold signature scheme. It allows splitting a Schnorr signing key
/// into n shares for a threshold t, such that t (or more) participants can together generate a signature
/// that can be validated by the corresponding verifying key. An important aspect is that the resulting
/// signature is indistinguishable from a non-threshold signature from the viewpoint of signature
/// verifiers. You can learn more at [https://frost.zfnd.org/frost.html](https://frost.zfnd.org/frost.html).
//! Frost DKG and signing implementation
//!
//! This is a specific implementation of threshold signature, which can be verified in a `no-std` environment,
//! thus enabling on-chain verification in Substrate. Currently, it does not support generation and signing
//! in `no-std`. FROST is used as the underlying cryptographic library. FROST is a threshold signature scheme. It allows splitting a Schnorr signing key
//! into n shares for a threshold t, such that t (or more) participants can together generate a signature
//! that can be validated by the corresponding verifying key. An important aspect is that the resulting
//! signature is indistinguishable from a non-threshold signature from the viewpoint of signature
//! verifiers. You can learn more at [https://frost.zfnd.org/frost.html](https://frost.zfnd.org/frost.html).
use crate::DkgVerifyingKey;
use anyhow::{anyhow, Context, Ok, Result};
use codec::{Decode, Encode, EncodeLike, MaxEncodedLen};
Expand Down
27 changes: 25 additions & 2 deletions crates/rc-validator-fetch/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use cumulus_primitives_core::BlockT;
#[cfg(feature = "std")]
use cumulus_relay_chain_interface::RelayChainInterface;
use melo_das_db::traits::DasKv;
use melo_das_db::Vec;
#[cfg(feature = "std")]
use redot_core_primitives::GetValidatorsFromRuntime;
#[cfg(feature = "std")]
use std::sync::Arc;
use melo_das_db::Vec;

const STORE_KEY: &[u8] = b"redot_relay_validators";

Expand Down Expand Up @@ -138,17 +138,40 @@ impl ValidatorsInfo {
}
}

/// Gets a list of validators that have been removed compared to a previous set.
///
/// This method compares the current set of validators with a provided set,
/// and identifies which validators are present in the provided set but not in the current set.
///
/// # Arguments
/// * `old` - A slice of `ValidatorId` representing the previous set of validators.
///
/// # Returns
/// A vector of `ValidatorId` representing the validators that have been removed.
/// This vector will be empty if no validators have been removed.
pub fn get_removed_validators(&self, old: &[ValidatorId]) -> Vec<ValidatorId> {
old.iter()
.filter(|old_validator| !self.set.contains(old_validator))
.cloned()
.collect::<Vec<_>>()
}

/// Gets a list of new validators that are present in the current set but not in a provided pending set.
///
/// This method is useful for identifying validators that have been recently added
/// to the current set, compared to a pending set of validators.
///
/// # Arguments
/// * `pending` - A slice of `ValidatorId` representing a pending set of validators,
/// typically validators that are about to be added or are under consideration.
///
/// # Returns
/// A vector of `ValidatorId` representing the new validators that are not present in the pending set.
/// This vector will be empty if there are no new validators compared to the pending set.
pub fn get_new_validators(&self, pending: &[ValidatorId]) -> Vec<ValidatorId> {
self.set
.iter()
.filter(|new_validator| pending.contains(new_validator))
.filter(|new_validator| !pending.contains(new_validator))
.cloned()
.collect::<Vec<_>>()
}
Expand Down
40 changes: 38 additions & 2 deletions crates/rc-validator-fetch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,45 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! # Validators Information Module
//!
//! This Rust library provides a set of tools and abstractions for managing and updating validator information,
//! primarily designed for blockchain and distributed ledger technologies. It allows for efficient tracking and
//! updating of validators based on changes in the blockchain state or external inputs.
//!
//! ## Features
//! - Manage a dynamic set of validators, crucial for blockchain consensus mechanisms.
//! - Store and retrieve validator information from a database, supporting a variety of database implementations through the `DasKv` trait.
//! - Update validators set based on real-time data from a relay chain or blockchain runtime.
//! - Identify new and removed validators, aiding in consensus and governance processes.
//!
//! ## Usage
//! The primary entry point for using this library is the `ValidatorsInfo` struct, which encapsulates the
//! functionality for handling validators' information. It supports operations such as creating a new
//! validator set, fetching the current set from the database, updating the set based on external data,
//! and more.
//!
//! ### Example
//! ```rust,ignore
//! use validators_info_module::ValidatorsInfo;
//! // Assuming `db` is a database instance implementing `DasKv`
//! let mut db = ...;
//!
//! // Creating a new instance of ValidatorsInfo
//! let mut validators_info = ValidatorsInfo::new(&[/* initial validators list */]);
//!
//! // Updating validators information
//! validators_info.update_from_relay(&mut db, /* RelayChainInterface instance */);
//! validators_info.update_from_runtime(&mut db, /* BlockHash */, /* GetValidatorsFromRuntime instance */);
//!
//! // Fetching and storing validators information
//! let validators = validators_info.get(&mut db).unwrap();
//! validators_info.save(&mut db);
//! ```

#![cfg_attr(not(feature = "std"), no_std)]

mod info;

pub use info::ValidatorsInfo;
// mod listener;
pub use info::ValidatorsInfo;
4 changes: 1 addition & 3 deletions crates/rc-validator-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ prometheus-client = "0.18.1"
codec = { package = "parity-scale-codec", version = "3.0.0", features = ["derive"], default-features = false }
ip_network = "0.4.1"
nohash-hasher = "0.2.0"

# Substrate
# sc-network = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
# cumulus-relay-chain-interface = { git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" }
# cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" }
prometheus-endpoint = { package = "substrate-prometheus-endpoint", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
cumulus-primitives-core = { default-features = false, git = "https://github.com/paritytech/cumulus.git", branch = "polkadot-v1.0.0" }
sp-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
Expand Down
Loading

0 comments on commit a3beebb

Please sign in to comment.