Skip to content

Commit 52d4102

Browse files
committed
Implement priority message
1 parent e1d46f4 commit 52d4102

File tree

1 file changed

+32
-0
lines changed
  • core/src/consensus/sortition

1 file changed

+32
-0
lines changed

core/src/consensus/sortition/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,35 @@
1717
mod binom_cdf;
1818
mod lot;
1919
mod vrf_sortition;
20+
21+
use std::sync::Arc;
22+
23+
use ckey::Public;
24+
use primitives::H256;
25+
use vrf::openssl::Error as VrfError;
26+
27+
use self::vrf_sortition::{PriorityInfo, VRFSortition};
28+
29+
pub struct PriorityMessage {
30+
pub seed: H256,
31+
pub info: PriorityInfo,
32+
pub signer_index: usize,
33+
}
34+
35+
impl PriorityMessage {
36+
pub fn signer_index(&self) -> usize {
37+
self.signer_index
38+
}
39+
40+
pub fn verify(
41+
&self,
42+
signer_public: &Public,
43+
voting_power: u64,
44+
sortition_scheme: &VRFSortition,
45+
) -> Result<bool, VrfError> {
46+
// fast verification first
47+
Ok(self.info.verify_sub_user_idx(voting_power, sortition_scheme.total_power, sortition_scheme.expectation)
48+
&& self.info.verify_priority()
49+
&& self.info.verify_vrf_hash(signer_public, &self.seed, Arc::clone(&sortition_scheme.vrf_inst))?)
50+
}
51+
}

0 commit comments

Comments
 (0)