@@ -39,6 +39,10 @@ use crate::{
3939 utils:: WithDir ,
4040} ;
4141
42+ // We use one trillion as a block reward unit because it's large enough to allow precise
43+ // fractions, and small enough for many block rewards to fit into a u64.
44+ const BLOCK_REWARD : u64 = 1_000_000_000_000 ;
45+
4246#[ derive( Debug , Clone , Copy , Hash , PartialEq , Eq , PartialOrd , Ord , Serialize , Deserialize ) ]
4347pub struct EraId ( pub ( crate ) u64 ) ;
4448
@@ -58,8 +62,6 @@ impl EraId {
5862pub ( crate ) struct Era < I > {
5963 /// The consensus protocol instance.
6064 consensus : Box < dyn ConsensusProtocol < I , ProtoBlock , PublicKey > > ,
61- /// The timestamp of the last block of the previous era.
62- start_time : Timestamp ,
6365 /// The height of this era's first block.
6466 start_height : u64 ,
6567}
@@ -163,16 +165,13 @@ where
163165 let ftt = validators. total_weight ( )
164166 * u64:: from ( self . highway_config . finality_threshold_percent )
165167 / 100 ;
166- // We use one trillion as a block reward unit because it's large enough to allow precise
167- // fractions, and small enough for many block rewards to fit into a u64.
168- let block_reward = 1_000_000_000_000 ;
169168 // The number of rounds after which a block reward is paid out.
170169 // TODO: Make this configurable?
171170 let reward_delay = 8 ;
172171 let params = Params :: new (
173172 0 , // TODO: get a proper seed.
174- block_reward ,
175- block_reward / 5 , // TODO: Make reduced block reward configurable?
173+ BLOCK_REWARD ,
174+ BLOCK_REWARD / 5 , // TODO: Make reduced block reward configurable?
176175 reward_delay,
177176 self . highway_config . minimum_round_exponent ,
178177 self . highway_config . minimum_era_height ,
@@ -190,22 +189,23 @@ where
190189
191190 let era = Era {
192191 consensus : Box :: new ( highway) ,
193- start_time,
194192 start_height,
195193 } ;
196194 let _ = self . active_eras . insert ( era_id, era) ;
197195
198196 results
199197 }
200198
199+ #[ allow( clippy:: too_many_arguments) ]
201200 fn handle_finalized_block (
202201 & mut self ,
203202 era_id : EraId ,
204203 proto_block : ProtoBlock ,
205204 new_equivocators : Vec < PublicKey > ,
206205 rewards : BTreeMap < PublicKey , u64 > ,
207206 timestamp : Timestamp ,
208- relative_height : u64 ,
207+ height : u64 ,
208+ switch_block : bool ,
209209 ) -> (
210210 Vec < ConsensusProtocolResult < I , ProtoBlock , PublicKey > > ,
211211 FinalizedBlock ,
@@ -221,18 +221,14 @@ where
221221 if !rewards. is_empty ( ) {
222222 system_transactions. push ( SystemTransaction :: Rewards ( rewards) ) ;
223223 } ;
224- let start_height = self . active_eras [ & era_id] . start_height ;
225- let start_time = self . active_eras [ & era_id] . start_time ;
226- let switch_block = relative_height + 1 >= self . highway_config . minimum_era_height
227- && timestamp >= start_time + self . highway_config . era_duration ;
228224 // Request execution of the finalized block.
229225 let fb = FinalizedBlock :: new (
230226 proto_block,
231227 timestamp,
232228 system_transactions,
233229 switch_block,
234230 era_id,
235- start_height + relative_height ,
231+ self . active_eras [ & era_id ] . start_height + height ,
236232 ) ;
237233 let results = if fb. switch_block ( ) {
238234 self . current_era_mut ( ) . consensus . deactivate_validator ( ) ;
@@ -457,7 +453,8 @@ where
457453 new_equivocators,
458454 rewards,
459455 timestamp,
460- relative_height,
456+ height,
457+ switch_block,
461458 } => {
462459 // Announce the finalized proto block.
463460 let mut effects = self
@@ -470,7 +467,8 @@ where
470467 new_equivocators,
471468 rewards,
472469 timestamp,
473- relative_height,
470+ height,
471+ switch_block,
474472 ) ;
475473 effects. extend (
476474 results
0 commit comments