Skip to content

Commit a9fc437

Browse files
committed
doc: Modify multiple documents
1 parent a3beebb commit a9fc437

File tree

3 files changed

+117
-70
lines changed

3 files changed

+117
-70
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ Redot serves as Polkadot's re-staking layer. It includes a specialized parachain
88
- Neutrality: Redot imposes no restrictions on the nature of tasks. It supports tasks beyond data availability and accommodates various data availability layers.
99
- Lightweight: Validator tasks should be sufficiently lightweight. Only information pertinent to the consensus layer should be incorporated into these tasks.
1010

11-
## 模块
11+
## Modules
1212

13-
Redot 包含了以下模块:
13+
Redot includes the following modules:
1414

1515
* [core-primitives](./crates/core-primitives/): Implements specific primitives for DKG, threshold signature encryption.
1616
* [rc-validator](./crates/rc-validator/): Depends on the validator network to execute different methods.

crates/rc-validator/src/service.rs

+115-65
Original file line numberDiff line numberDiff line change
@@ -16,85 +16,135 @@ use crate::{Command, DkgSignature, DkgVerifyingKey};
1616
use anyhow::{Context, Result};
1717
use cumulus_primitives_core::relay_chain::ValidatorId;
1818
use futures::{
19-
channel::{mpsc, oneshot},
20-
SinkExt,
19+
channel::{mpsc, oneshot},
20+
SinkExt,
2121
};
22+
2223
use std::fmt::Debug;
2324

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

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

4045
impl Service {
41-
/// Creates a new `Service` instance.
42-
pub(crate) fn new(to_worker: mpsc::Sender<Command>) -> Self {
43-
Self { to_worker }
44-
}
46+
/// Constructs a new instance of `Service`.
47+
///
48+
/// # Arguments
49+
///
50+
/// * `to_worker` - A sender channel used for sending commands to the worker.
51+
pub(crate) fn new(to_worker: mpsc::Sender<Command>) -> Self {
52+
Self { to_worker }
53+
}
4554

46-
/// 轮换密钥,返回新的验证者公钥
47-
pub async fn rotate_key(&self) -> Result<DkgVerifyingKey> {
48-
let (sender, receiver) = oneshot::channel();
49-
self.to_worker
50-
.clone()
51-
.send(Command::RotateKey { sender })
52-
.await
53-
.context("Failed to send command to worker")?;
54-
receiver.await.context("Failed to receive response from worker")?
55-
}
55+
/// Initiates a key rotation process, resulting in a new verifier public key.
56+
///
57+
/// This method sends a `RotateKey` command to the worker and awaits the response.
58+
///
59+
/// # Returns
60+
///
61+
/// A `Result` which, on success, contains the new `DkgVerifyingKey`.
62+
pub async fn rotate_key(&self) -> Result<DkgVerifyingKey> {
63+
let (sender, receiver) = oneshot::channel();
64+
self.to_worker
65+
.clone()
66+
.send(Command::RotateKey { sender })
67+
.await
68+
.context("Failed to send command to worker")?;
69+
receiver.await.context("Failed to receive response from worker")?
70+
}
5671

57-
/// 启动一个签名服务,返回签名
58-
pub async fn start_signing(&self, message: &[u8]) -> Result<DkgSignature> {
59-
let (sender, receiver) = oneshot::channel();
60-
self.to_worker
61-
.clone()
62-
.send(Command::Sign { message: message.to_vec(), sender })
63-
.await
64-
.context("Failed to send command to worker")?;
65-
receiver.await.context("Failed to receive response from worker")?
66-
}
72+
/// Starts a signing service and returns a signature.
73+
///
74+
/// This method sends a `Sign` command with the provided message to the worker and waits for the signature.
75+
///
76+
/// # Arguments
77+
///
78+
/// * `message` - A byte slice representing the message to be signed.
79+
///
80+
/// # Returns
81+
///
82+
/// A `Result` which, on success, contains the `DkgSignature`.
83+
pub async fn start_signing(&self, message: &[u8]) -> Result<DkgSignature> {
84+
let (sender, receiver) = oneshot::channel();
85+
self.to_worker
86+
.clone()
87+
.send(Command::Sign { message: message.to_vec(), sender })
88+
.await
89+
.context("Failed to send command to worker")?;
90+
receiver.await.context("Failed to receive response from worker")?
91+
}
6792

68-
/// 设置验证者网络的阈值和参与者总数
69-
pub async fn setup(&self, nt: (u16, u16)) -> Result<()> {
70-
let (sender, receiver) = oneshot::channel();
71-
self.to_worker
72-
.clone()
73-
.send(Command::Setup { nt, sender })
74-
.await
75-
.context("Failed to send command to worker")?;
76-
receiver.await.context("Failed to receive response from worker")?
77-
}
93+
/// Sets up the validator network with specified threshold and total number of participants.
94+
///
95+
/// # Arguments
96+
///
97+
/// * `nt` - A tuple (u16, u16) where the first element is the threshold and the second is the total number of participants.
98+
///
99+
/// # Returns
100+
///
101+
/// A `Result` indicating the success or failure of the operation.
102+
pub async fn setup(&self, nt: (u16, u16)) -> Result<()> {
103+
let (sender, receiver) = oneshot::channel();
104+
self.to_worker
105+
.clone()
106+
.send(Command::Setup { nt, sender })
107+
.await
108+
.context("Failed to send command to worker")?;
109+
receiver.await.context("Failed to receive response from worker")?
110+
}
78111

79-
/// 删除一个验证者,它将被排除在验证者网络之外
80-
pub async fn remove_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
81-
let (sender, receiver) = oneshot::channel();
82-
self.to_worker
83-
.clone()
84-
.send(Command::RemoveValidators { validators, sender })
85-
.await
86-
.context("Failed to send command to worker")?;
87-
receiver.await.context("Failed to receive response from worker")?
88-
}
112+
/// Removes validators from the network. These validators will no longer be part of the validator network.
113+
///
114+
/// # Arguments
115+
///
116+
/// * `validators` - A vector of `ValidatorId` representing the validators to be removed.
117+
///
118+
/// # Returns
119+
///
120+
/// A `Result` indicating the success or failure of the operation.
121+
pub async fn remove_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
122+
let (sender, receiver) = oneshot::channel();
123+
self.to_worker
124+
.clone()
125+
.send(Command::RemoveValidators { validators, sender })
126+
.await
127+
.context("Failed to send command to worker")?;
128+
receiver.await.context("Failed to receive response from worker")?
129+
}
89130

90-
/// 添加新的验证者,它将被包含在验证者网络中
91-
pub async fn add_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
92-
let (sender, receiver) = oneshot::channel();
93-
self.to_worker
94-
.clone()
95-
.send(Command::AddValidators { validators, sender })
96-
.await
97-
.context("Failed to send command to worker")?;
98-
receiver.await.context("Failed to receive response from worker")?
99-
}
131+
/// Adds new validators to the network. These validators will be included in the validator network.
132+
///
133+
/// # Arguments
134+
///
135+
/// * `validators` - A vector of `ValidatorId` representing the validators to be added.
136+
///
137+
/// # Returns
138+
///
139+
/// A `Result` indicating the success or failure of the operation.
140+
pub async fn add_validators(&self, validators: Vec<ValidatorId>) -> Result<()> {
141+
let (sender, receiver) = oneshot::channel();
142+
self.to_worker
143+
.clone()
144+
.send(Command::AddValidators { validators, sender })
145+
.await
146+
.context("Failed to send command to worker")?;
147+
receiver.await.context("Failed to receive response from worker")?
148+
}
100149
}
150+

pallets/validator-registry/src/lib.rs

-3
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ pub mod pallet {
255255
pub fn registry(origin: OriginFor<T>, validator_id: ValidatorId) -> DispatchResult {
256256
let who = ensure_signed(origin)?;
257257

258-
// TODO 我们是否允许绑定其他 ID 还是直接使用 validator_id?
259-
260-
// 检查 ValidatorsStatus 中对应的 AuthorityStatus
261258
let status = ValidatorsStatus::<T>::get(&validator_id);
262259
match status {
263260
AuthorityStatus::Block => Err(Error::<T>::InvalidKey)?,

0 commit comments

Comments
 (0)