1+ //! Chain logic implementation.
2+ //! Price for some abstraction boundaries is traded for speed.
13use super :: {
24 cache,
35 epoch:: { EpochConfig , EpochNode } ,
@@ -39,6 +41,7 @@ use tokio::{
3941use tokio_util:: task:: TaskTracker ;
4042use tonic:: Status ;
4143
44+ /// Truncated signature bytes for compact log output.
4245const SHORT_SIG_BYTES : usize = 3 ;
4346
4447#[ derive( thiserror:: Error , Debug ) ]
@@ -53,8 +56,8 @@ pub enum ChainError {
5356 TickerClosedTx ,
5457 #[ error( "pool receiver has been closed unexpectedly" ) ]
5558 PoolClosedRx ,
56- #[ error( "invalid lengh of partial: expected {expected} received {received}" ) ]
57- InvalidShareLenght { expected : usize , received : usize } ,
59+ #[ error( "invalid length of partial: expected {expected} received {received}" ) ]
60+ InvalidShareLength { expected : usize , received : usize } ,
5861 #[ error( "attempt to process beacon from node of index {0}, but it was not in the group file" ) ]
5962 UnknownIndex ( u32 ) ,
6063 #[ error( "received partial with invalid signature" ) ]
@@ -68,11 +71,11 @@ pub enum ChainError {
6871 #[ error( "recovered signature is invalid" ) ]
6972 InvalidRecovered ,
7073 #[ error( "chain store: {0}" ) ]
71- ChainStoreError ( #[ from] StoreError ) ,
74+ ChainStore ( #[ from] StoreError ) ,
7275 #[ error( "t_bls: {0}" ) ]
7376 TBlsError ( #[ from] tbls:: TBlsError ) ,
7477 #[ error( "fs: {0}" ) ]
75- FileStoreError ( #[ from] FileStoreError ) ,
78+ FileStore ( #[ from] FileStoreError ) ,
7679 #[ error( "recover_unchecked: scalar is non-invertable" ) ]
7780 NonInvertableScalar ,
7881 #[ error( "internal error" ) ]
@@ -85,7 +88,7 @@ pub enum ChainError {
8588struct ChainHandler < S : Scheme , B : BeaconRepr > {
8689 /// Public information of chain.
8790 chain_info : ChainInfo < S > ,
88- /// Minimum period allowed between and subsequent partial generation.
91+ /// Minimum period allowed between subsequent partial generation.
8992 catchup_period : Duration ,
9093 /// Actor handle for beacon persistent database.
9194 store : ChainStore < B > ,
@@ -97,19 +100,20 @@ struct ChainHandler<S: Scheme, B: BeaconRepr> {
97100 ec : EpochConfig < S > ,
98101 /// Private binding address.
99102 private_listen : String ,
100- /// Public URI Authority .
101- our_addres : Address ,
103+ /// Public URI authority .
104+ our_address : Address ,
102105 log : Logger ,
103106}
104107
105108pub enum ChainCmd {
106109 Shutdown ( Callback < ( ) , ChainError > ) ,
107- /// Chain is notified once DKG output is received, triggering preparation
110+ /// Notification once DKG output is received, triggers preparation
108111 /// for transition into the next epoch (see: [`wait_last_round`]).
109112 NewEpoch {
110113 first_round : u64 ,
111114 } ,
112- /// Partial reload of the chain module during transition to update [`EpochConfig`] and logger.
115+ /// Partially reloads the chain module during transitions to update
116+ /// the [`EpochConfig`] and metadata for logger.
113117 Reload ,
114118 /// Request for chain public information.
115119 ChainInfo ( Callback < ChainInfoPacket , BeaconProcessError > ) ,
@@ -151,8 +155,8 @@ pub struct ChainConfig<B: BeaconRepr> {
151155}
152156
153157impl < S : Scheme , B : BeaconRepr > ChainHandler < S , B > {
154- /// This function updates the epoch configuration and logger for chain handler
155- /// after each DKG.
158+ /// This function updates the epoch configuration and logger metadata
159+ /// for chain handler after each DKG.
156160 ///
157161 /// Returns top-level components of chain module with their channels:
158162 /// - Chain configuration: [`ChainHandler`].
@@ -211,8 +215,8 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
211215 genesis_time,
212216 genesis_seed,
213217 } ;
214- let catchup_period = Duration :: from_secs ( catchup_period. get_value ( ) . into ( ) ) ;
215218
219+ let catchup_period = Duration :: from_secs ( catchup_period. get_value ( ) . into ( ) ) ;
216220 let chain_handler = Self {
217221 chain_info,
218222 catchup_period,
@@ -221,12 +225,11 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
221225 fs,
222226 ec,
223227 private_listen,
224- our_addres,
228+ our_address : our_addres,
225229 log,
226230 } ;
227231
228232 let latest_stored = chain_handler. store . last ( ) . await ?;
229-
230233 let registry = Registry :: new (
231234 & chain_handler. chain_info ,
232235 latest_stored,
@@ -239,9 +242,6 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
239242 }
240243
241244 /// Adds remote nodes to connection pool for given beacon ID.
242- ///
243- /// If some nodes are already in pool (registered for other ID),
244- /// their connections will be reused.
245245 async fn register_in_pool ( & self ) -> Result < ( ) , ChainError > {
246246 let peers = self
247247 . ec
@@ -315,7 +315,7 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
315315 {
316316 if let Some ( thr_sigs) =
317317 reg. cache_mut ( )
318- . add_prechecked ( sigshare, & self . our_addres , & self . log )
318+ . add_prechecked ( sigshare, & self . our_address , & self . log )
319319 {
320320 let Ok ( recovered) = tbls:: recover_unchecked ( thr_sigs) else {
321321 return Err ( ChainError :: NonInvertableScalar ) ;
@@ -403,7 +403,7 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
403403 // Add packet to cache if p_round hits the allowed range and signature is not duplicated.
404404 if p_round > ls_round + 1 && p_round <= ls_round + 1 + cache:: CACHE_LIMIT_ROUNDS {
405405 let Some ( is_added) = reg. cache_mut ( ) . add_packet ( partial. packet ) else {
406- error ! ( & self . log, "cache_height {}: attempt to add non-allowed round {p_round}, current {c_round}, please report this. " , reg. cache( ) . height( ) ) ;
406+ error ! ( & self . log, "cache_height {}: attempt to add non-allowed round {p_round}, current {c_round}, please report this" , reg. cache( ) . height( ) ) ;
407407 return Err ( ChainError :: InvalidRound {
408408 invalid : p_round,
409409 current : c_round,
@@ -423,7 +423,7 @@ impl<S: Scheme, B: BeaconRepr> ChainHandler<S, B> {
423423 // Process packet as sigshare.
424424 } else if p_round == ls_round + 1 {
425425 let Some ( idx) = cache:: get_partial_index :: < S > ( & partial. packet . partial_sig ) else {
426- return Err ( ChainError :: InvalidShareLenght {
426+ return Err ( ChainError :: InvalidShareLength {
427427 expected : <S :: Sig as energon:: traits:: Group >:: POINT_SIZE + 2 ,
428428 received : partial. packet . partial_sig . len ( ) ,
429429 } ) ;
@@ -855,7 +855,7 @@ async fn run_chain<S: Scheme, B: BeaconRepr>(
855855 private_listen : h. private_listen ,
856856 id : h. chain_info . beacon_id ,
857857 fs : h. fs ,
858- our_addres : h. our_addres ,
858+ our_addres : h. our_address ,
859859 } ;
860860
861861 Ok ( Some ( config_for_next_epoch) )
0 commit comments