Skip to content

Commit

Permalink
doc: Modify multiple documents
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkingLee committed Jan 30, 2024
1 parent a3beebb commit a9fc437
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 70 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Redot serves as Polkadot's re-staking layer. It includes a specialized parachain
- 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.

## 模块
## Modules

Redot 包含了以下模块:
Redot includes the following modules:

* [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.
Expand Down
180 changes: 115 additions & 65 deletions crates/rc-validator/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,85 +16,135 @@ use crate::{Command, DkgSignature, DkgVerifyingKey};
use anyhow::{Context, Result};
use cumulus_primitives_core::relay_chain::ValidatorId;
use futures::{
channel::{mpsc, oneshot},
SinkExt,
channel::{mpsc, oneshot},
SinkExt,
};

use std::fmt::Debug;

/// `Service` serves as an intermediary to interact with the Worker, handling requests and
/// facilitating communication. It mainly operates on the message passing mechanism between service
/// and worker.
/// `Service` acts as an intermediary for interacting with a Worker. It handles requests and
/// facilitates communication between the service and the worker through a message-passing mechanism.
///
/// This struct is primarily used for sending various commands to the worker, such as key rotation,
/// starting a signing process, setting up validator network parameters, and managing validators.
#[derive(Clone)]
pub struct Service {
// Channel sender to send messages to the worker.
to_worker: mpsc::Sender<Command>,
// Channel sender used to send commands to the worker.
to_worker: mpsc::Sender<Command>,
}

impl Debug for Service {
/// Provides a human-readable representation of the Service, useful for debugging.
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("ValidatorNetworkService").finish()
}
/// Provides a custom formatter for the `Service` struct, aiding in debugging by giving a
/// human-readable representation of the service. This method outputs the struct's name,
/// "ValidatorNetworkService", for simplicity.
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("ValidatorNetworkService").finish()
}
}

impl Service {
/// Creates a new `Service` instance.
pub(crate) fn new(to_worker: mpsc::Sender<Command>) -> Self {
Self { to_worker }
}
/// Constructs a new instance of `Service`.
///
/// # Arguments
///
/// * `to_worker` - A sender channel used for sending commands to the worker.
pub(crate) fn new(to_worker: mpsc::Sender<Command>) -> Self {
Self { to_worker }
}

/// 轮换密钥,返回新的验证者公钥
pub async fn rotate_key(&self) -> Result<DkgVerifyingKey> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::RotateKey { sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
/// Initiates a key rotation process, resulting in a new verifier public key.
///
/// This method sends a `RotateKey` command to the worker and awaits the response.
///
/// # Returns
///
/// A `Result` which, on success, contains the new `DkgVerifyingKey`.
pub async fn rotate_key(&self) -> Result<DkgVerifyingKey> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::RotateKey { sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}

/// 启动一个签名服务,返回签名
pub async fn start_signing(&self, message: &[u8]) -> Result<DkgSignature> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::Sign { message: message.to_vec(), sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
/// Starts a signing service and returns a signature.
///
/// This method sends a `Sign` command with the provided message to the worker and waits for the signature.
///
/// # Arguments
///
/// * `message` - A byte slice representing the message to be signed.
///
/// # Returns
///
/// A `Result` which, on success, contains the `DkgSignature`.
pub async fn start_signing(&self, message: &[u8]) -> Result<DkgSignature> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::Sign { message: message.to_vec(), sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}

/// 设置验证者网络的阈值和参与者总数
pub async fn setup(&self, nt: (u16, u16)) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::Setup { nt, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
/// Sets up the validator network with specified threshold and total number of participants.
///
/// # Arguments
///
/// * `nt` - A tuple (u16, u16) where the first element is the threshold and the second is the total number of participants.
///
/// # Returns
///
/// A `Result` indicating the success or failure of the operation.
pub async fn setup(&self, nt: (u16, u16)) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::Setup { nt, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}

/// 删除一个验证者,它将被排除在验证者网络之外
pub async fn remove_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::RemoveValidators { validators, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
/// Removes validators from the network. These validators will no longer be part of the validator network.
///
/// # Arguments
///
/// * `validators` - A vector of `ValidatorId` representing the validators to be removed.
///
/// # Returns
///
/// A `Result` indicating the success or failure of the operation.
pub async fn remove_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::RemoveValidators { validators, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}

/// 添加新的验证者,它将被包含在验证者网络中
pub async fn add_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::AddValidators { validators, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
/// Adds new validators to the network. These validators will be included in the validator network.
///
/// # Arguments
///
/// * `validators` - A vector of `ValidatorId` representing the validators to be added.
///
/// # Returns
///
/// A `Result` indicating the success or failure of the operation.
pub async fn add_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
let (sender, receiver) = oneshot::channel();
self.to_worker
.clone()
.send(Command::AddValidators { validators, sender })
.await
.context("Failed to send command to worker")?;
receiver.await.context("Failed to receive response from worker")?
}
}

3 changes: 0 additions & 3 deletions pallets/validator-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,6 @@ pub mod pallet {
pub fn registry(origin: OriginFor<T>, validator_id: ValidatorId) -> DispatchResult {
let who = ensure_signed(origin)?;

// TODO 我们是否允许绑定其他 ID 还是直接使用 validator_id?

// 检查 ValidatorsStatus 中对应的 AuthorityStatus
let status = ValidatorsStatus::<T>::get(&validator_id);
match status {
AuthorityStatus::Block => Err(Error::<T>::InvalidKey)?,
Expand Down

0 comments on commit a9fc437

Please sign in to comment.