Skip to content

Commit 9fedc00

Browse files
committed
fix: only use active_slots_coeff in block_vrf_validator
1 parent f897a27 commit 9fedc00

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

modules/block_vrf_validator/src/ouroboros/praos.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::ouroboros::{
66
};
77
use acropolis_common::{
88
crypto::keyhash_224,
9-
protocol_params::{Nonce, PraosParams},
9+
protocol_params::Nonce,
1010
rational_number::RationalNumber,
1111
validation::{VrfValidation, VrfValidationError},
1212
BlockInfo, PoolId, VrfKeyHash,
@@ -19,13 +19,11 @@ pub fn validate_vrf_praos<'a>(
1919
block_info: &'a BlockInfo,
2020
header: &'a MultiEraHeader,
2121
epoch_nonce: &'a Nonce,
22-
praos_params: &'a PraosParams,
22+
active_slots_coeff: RationalNumber,
2323
active_spos: &'a HashMap<PoolId, VrfKeyHash>,
2424
active_spdd: &'a HashMap<PoolId, u64>,
2525
total_active_stake: u64,
2626
) -> Result<Vec<VrfValidation<'a>>, Box<VrfValidationError>> {
27-
let active_slots_coeff = praos_params.active_slots_coeff;
28-
2927
let Some(issuer_vkey) = header.issuer_vkey() else {
3028
return Ok(vec![Box::new(|| {
3129
Err(VrfValidationError::Other(
@@ -101,7 +99,6 @@ mod tests {
10199

102100
#[test]
103101
fn test_7854823_block() {
104-
let praos_params = PraosParams::mainnet();
105102
let epoch_nonce = Nonce::from(
106103
NonceHash::try_from(
107104
hex::decode("8dad163edf4607452fec9c5955d593fb598ca728bae162138f88da6667bba79b")
@@ -110,6 +107,7 @@ mod tests {
110107
)
111108
.unwrap(),
112109
);
110+
let active_slots_coeff = RationalNumber::new(1, 20);
113111

114112
let block_header_7854823: Vec<u8> =
115113
hex::decode(include_str!("./data/7854823.cbor")).unwrap();
@@ -142,7 +140,7 @@ mod tests {
142140
&block_info,
143141
&block_header,
144142
&epoch_nonce,
145-
&praos_params,
143+
active_slots_coeff,
146144
&active_spos,
147145
&active_spdd,
148146
25069171797357766,

modules/block_vrf_validator/src/ouroboros/tpraos.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::ouroboros::{
88
};
99
use acropolis_common::{
1010
crypto::keyhash_224,
11-
protocol_params::{Nonce, PraosParams},
11+
protocol_params::Nonce,
1212
rational_number::RationalNumber,
1313
validation::{VrfValidation, VrfValidationError},
1414
BlockInfo, GenesisDelegates, PoolId, VrfKeyHash,
@@ -23,14 +23,12 @@ pub fn validate_vrf_tpraos<'a>(
2323
header: &'a MultiEraHeader,
2424
epoch_nonce: &'a Nonce,
2525
genesis_delegs: &'a GenesisDelegates,
26-
praos_params: &'a PraosParams,
26+
active_slots_coeff: RationalNumber,
27+
decentralisation_param: RationalNumber,
2728
active_spos: &'a HashMap<PoolId, VrfKeyHash>,
2829
active_spdd: &'a HashMap<PoolId, u64>,
2930
total_active_stake: u64,
30-
decentralisation_param: RationalNumber,
3131
) -> Result<Vec<VrfValidation<'a>>, Box<VrfValidationError>> {
32-
let active_slots_coeff = praos_params.active_slots_coeff;
33-
3432
// first look up for overlay slot
3533
let obft_slot = overlay_schedule::lookup_in_overlay_schedule(
3634
block_info.epoch_slot,
@@ -189,7 +187,6 @@ mod tests {
189187
#[test]
190188
fn test_4490511_block_produced_by_genesis_key() {
191189
let genesis_value = GenesisValues::mainnet();
192-
let praos_params = PraosParams::mainnet();
193190
let epoch_nonce = Nonce::from(
194191
NonceHash::try_from(
195192
hex::decode("1a3be38bcbb7911969283716ad7aa550250226b76a61fc51cc9a9a35d9276d81")
@@ -198,6 +195,7 @@ mod tests {
198195
)
199196
.unwrap(),
200197
);
198+
let active_slots_coeff = RationalNumber::new(1, 20);
201199
let decentralisation_param = RationalNumber::from(1);
202200

203201
let block_header_4490511: Vec<u8> =
@@ -226,11 +224,11 @@ mod tests {
226224
&block_header,
227225
&epoch_nonce,
228226
&genesis_value.genesis_delegs,
229-
&praos_params,
227+
active_slots_coeff,
228+
decentralisation_param,
230229
&active_spos,
231230
&active_spdd,
232231
1,
233-
decentralisation_param,
234232
)
235233
.and_then(|vrf_validations| {
236234
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -241,7 +239,6 @@ mod tests {
241239
#[test]
242240
fn test_4556956_block() {
243241
let genesis_value = GenesisValues::mainnet();
244-
let praos_params = PraosParams::mainnet();
245242
let epoch_nonce = Nonce::from(
246243
NonceHash::try_from(
247244
hex::decode("3fac34ac3d7d1ac6c976ba68b1509b1ee3aafdbf6de96e10789e488e13e16bd7")
@@ -250,6 +247,7 @@ mod tests {
250247
)
251248
.unwrap(),
252249
);
250+
let active_slots_coeff = RationalNumber::new(1, 20);
253251
let decentralisation_param = RationalNumber::new(9, 10);
254252

255253
let block_header_4556956: Vec<u8> =
@@ -284,11 +282,11 @@ mod tests {
284282
&block_header,
285283
&epoch_nonce,
286284
&genesis_value.genesis_delegs,
287-
&praos_params,
285+
active_slots_coeff,
286+
decentralisation_param,
288287
&active_spos,
289288
&active_spdd,
290289
10177811974823000,
291-
decentralisation_param,
292290
)
293291
.and_then(|vrf_validations| {
294292
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -299,7 +297,6 @@ mod tests {
299297
#[test]
300298
fn test_4576496_block() {
301299
let genesis_value = GenesisValues::mainnet();
302-
let praos_params = PraosParams::mainnet();
303300
let epoch_nonce = Nonce::from(
304301
NonceHash::try_from(
305302
hex::decode("3fac34ac3d7d1ac6c976ba68b1509b1ee3aafdbf6de96e10789e488e13e16bd7")
@@ -308,6 +305,7 @@ mod tests {
308305
)
309306
.unwrap(),
310307
);
308+
let active_slots_coeff = RationalNumber::new(1, 20);
311309
let decentralisation_param = RationalNumber::new(9, 10);
312310

313311
let block_header_4576496: Vec<u8> =
@@ -342,11 +340,11 @@ mod tests {
342340
&block_header,
343341
&epoch_nonce,
344342
&genesis_value.genesis_delegs,
345-
&praos_params,
343+
active_slots_coeff,
344+
decentralisation_param,
346345
&active_spos,
347346
&active_spdd,
348347
10177811974823000,
349-
decentralisation_param,
350348
)
351349
.and_then(|vrf_validations| {
352350
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -357,7 +355,6 @@ mod tests {
357355
#[test]
358356
fn test_4576496_block_as_unknown_pool() {
359357
let genesis_value = GenesisValues::mainnet();
360-
let praos_params = PraosParams::mainnet();
361358
let epoch_nonce = Nonce::from(
362359
NonceHash::try_from(
363360
hex::decode("3fac34ac3d7d1ac6c976ba68b1509b1ee3aafdbf6de96e10789e488e13e16bd7")
@@ -366,6 +363,7 @@ mod tests {
366363
)
367364
.unwrap(),
368365
);
366+
let active_slots_coeff = RationalNumber::new(1, 20);
369367
let decentralisation_param = RationalNumber::new(9, 10);
370368

371369
let block_header_4576496: Vec<u8> =
@@ -397,11 +395,11 @@ mod tests {
397395
&block_header,
398396
&epoch_nonce,
399397
&genesis_value.genesis_delegs,
400-
&praos_params,
398+
active_slots_coeff,
399+
decentralisation_param,
401400
&active_spos,
402401
&active_spdd,
403402
10177811974823000,
404-
decentralisation_param,
405403
)
406404
.and_then(|vrf_validations| {
407405
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -416,7 +414,6 @@ mod tests {
416414
#[test]
417415
fn test_4576496_block_as_wrong_leader_vrf_key() {
418416
let genesis_value = GenesisValues::mainnet();
419-
let praos_params = PraosParams::mainnet();
420417
let epoch_nonce = Nonce::from(
421418
NonceHash::try_from(
422419
hex::decode("3fac34ac3d7d1ac6c976ba68b1509b1ee3aafdbf6de96e10789e488e13e16bd7")
@@ -425,6 +422,7 @@ mod tests {
425422
)
426423
.unwrap(),
427424
);
425+
let active_slots_coeff = RationalNumber::new(1, 20);
428426
let decentralisation_param = RationalNumber::new(9, 10);
429427

430428
let block_header_4576496: Vec<u8> =
@@ -457,11 +455,11 @@ mod tests {
457455
&block_header,
458456
&epoch_nonce,
459457
&genesis_value.genesis_delegs,
460-
&praos_params,
458+
active_slots_coeff,
459+
decentralisation_param,
461460
&active_spos,
462461
&active_spdd,
463462
10177811974823000,
464-
decentralisation_param,
465463
)
466464
.and_then(|vrf_validations| {
467465
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -484,7 +482,6 @@ mod tests {
484482
#[test]
485483
fn test_4576496_block_with_small_active_stake() {
486484
let genesis_value = GenesisValues::mainnet();
487-
let praos_params = PraosParams::mainnet();
488485
let epoch_nonce = Nonce::from(
489486
NonceHash::try_from(
490487
hex::decode("3fac34ac3d7d1ac6c976ba68b1509b1ee3aafdbf6de96e10789e488e13e16bd7")
@@ -493,6 +490,7 @@ mod tests {
493490
)
494491
.unwrap(),
495492
);
493+
let active_slots_coeff = RationalNumber::new(1, 20);
496494
let decentralisation_param = RationalNumber::new(9, 10);
497495

498496
let block_header_4576496: Vec<u8> =
@@ -528,11 +526,11 @@ mod tests {
528526
&block_header,
529527
&epoch_nonce,
530528
&genesis_value.genesis_delegs,
531-
&praos_params,
529+
active_slots_coeff,
530+
decentralisation_param,
532531
&active_spos,
533532
&active_spdd,
534533
10177811974823000,
535-
decentralisation_param,
536534
)
537535
.and_then(|vrf_validations| {
538536
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))

modules/block_vrf_validator/src/state.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use acropolis_common::{
88
messages::{
99
EpochActivityMessage, ProtocolParamsMessage, SPOStakeDistributionMessage, SPOStateMessage,
1010
},
11-
protocol_params::{Nonce, PraosParams},
11+
protocol_params::Nonce,
1212
rational_number::RationalNumber,
1313
validation::VrfValidationError,
1414
BlockInfo, Era,
@@ -33,11 +33,9 @@ impl EpochSnapshots {
3333

3434
#[derive(Default, Debug, Clone)]
3535
pub struct State {
36-
/// shelley params
3736
pub decentralisation_param: Option<RationalNumber>,
3837

39-
/// protocol parameter for Praos and TPraos
40-
pub praos_params: Option<PraosParams>,
38+
pub active_slots_coeff: Option<RationalNumber>,
4139

4240
/// epoch nonce
4341
pub epoch_nonce: Option<Nonce>,
@@ -49,7 +47,7 @@ pub struct State {
4947
impl State {
5048
pub fn new() -> Self {
5149
Self {
52-
praos_params: None,
50+
active_slots_coeff: None,
5351
decentralisation_param: None,
5452
epoch_nonce: None,
5553
epoch_snapshots: EpochSnapshots::default(),
@@ -60,7 +58,7 @@ impl State {
6058
if let Some(shelley_params) = msg.params.shelley.as_ref() {
6159
self.decentralisation_param =
6260
Some(shelley_params.protocol_params.decentralisation_param);
63-
self.praos_params = Some(shelley_params.into());
61+
self.active_slots_coeff = Some(shelley_params.active_slots_coeff);
6462
}
6563
}
6664

@@ -104,9 +102,9 @@ impl State {
104102
"Decentralisation Param is not set".to_string(),
105103
)));
106104
};
107-
let Some(praos_params) = self.praos_params.as_ref() else {
105+
let Some(active_slots_coeff) = self.active_slots_coeff else {
108106
return Err(Box::new(VrfValidationError::Other(
109-
"Praos Params are not set".to_string(),
107+
"Active Slots Coeff is not set".to_string(),
110108
)));
111109
};
112110
let Some(epoch_nonce) = self.epoch_nonce.as_ref() else {
@@ -126,11 +124,11 @@ impl State {
126124
&header,
127125
epoch_nonce,
128126
&genesis.genesis_delegs,
129-
praos_params,
127+
active_slots_coeff,
128+
decentralisation_param,
130129
&self.epoch_snapshots.set.active_spos,
131130
&self.epoch_snapshots.set.active_stakes,
132131
self.epoch_snapshots.set.total_active_stakes,
133-
decentralisation_param,
134132
)
135133
.and_then(|vrf_validations| {
136134
vrf_validations.iter().try_for_each(|assert| assert().map_err(Box::new))
@@ -141,7 +139,7 @@ impl State {
141139
block_info,
142140
&header,
143141
epoch_nonce,
144-
praos_params,
142+
active_slots_coeff,
145143
&self.epoch_snapshots.set.active_spos,
146144
&self.epoch_snapshots.set.active_stakes,
147145
self.epoch_snapshots.set.total_active_stakes,

0 commit comments

Comments
 (0)