18
18
19
19
mod binom_cdf;
20
20
mod draw;
21
+ pub mod seed;
21
22
pub mod vrf_sortition;
22
23
23
24
use std:: sync:: Arc ;
24
25
25
26
use ckey:: Public ;
26
- use primitives:: H256 ;
27
- use vrf:: openssl:: Error as VrfError ;
27
+ use vrf:: openssl:: { Error as VRFError , ECVRF } ;
28
28
29
- use self :: vrf_sortition:: { PriorityInfo , VRFSortition } ;
29
+ use self :: seed:: { SeedInfo , VRFSeed } ;
30
+ use self :: vrf_sortition:: { Priority , PriorityInfo , VRFSortition } ;
31
+ use crate :: consensus:: { Height , View } ;
30
32
31
- pub type VRFSeed = H256 ;
32
-
33
- #[ derive( Debug , PartialEq , RlpEncodable , RlpDecodable ) ]
33
+ #[ derive( Debug , Eq , PartialEq , Clone , RlpEncodable , RlpDecodable ) ]
34
34
pub struct PriorityMessage {
35
- pub seed : VRFSeed ,
36
- pub info : PriorityInfo ,
35
+ pub seed : SeedInfo ,
36
+ pub priority : PriorityInfo ,
37
37
}
38
38
39
39
impl PriorityMessage {
40
- pub fn verify (
40
+ pub fn seed ( & self ) -> & VRFSeed {
41
+ self . seed . seed ( )
42
+ }
43
+
44
+ pub fn verify_seed (
45
+ & self ,
46
+ height : Height ,
47
+ view : View ,
48
+ prev_seed : & VRFSeed ,
49
+ signer_public : & Public ,
50
+ vrf_inst : & mut ECVRF ,
51
+ ) -> Result < bool , VRFError > {
52
+ self . seed . verify ( height, view, prev_seed, signer_public, vrf_inst)
53
+ }
54
+
55
+ pub fn verify_priority (
41
56
& self ,
42
57
signer_public : & Public ,
43
58
voting_power : u64 ,
44
59
sortition_scheme : & VRFSortition ,
45
- ) -> Result < bool , VrfError > {
60
+ ) -> Result < bool , VRFError > {
46
61
// 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 ) ) ?)
62
+ Ok ( self . priority . verify_sub_user_idx ( voting_power, sortition_scheme. total_power , sortition_scheme. expectation )
63
+ && self . priority . verify_priority ( )
64
+ && self . priority . verify_vrf_hash ( signer_public, self . seed ( ) , Arc :: clone ( & sortition_scheme. vrf_inst ) ) ?)
65
+ }
66
+
67
+ pub fn priority ( & self ) -> Priority {
68
+ self . priority . priority ( )
50
69
}
51
70
}
52
71
@@ -80,7 +99,7 @@ mod priority_message_tests {
80
99
sortition_scheme. create_highest_priority_info ( seed, priv_key, voting_power) . unwrap ( ) . unwrap ( ) ;
81
100
82
101
let priority_message = PriorityMessage {
83
- seed,
102
+ seed : seed . into ( ) ,
84
103
info : priority_info,
85
104
} ;
86
105
assert ! ( priority_message. verify( & pub_key, voting_power, & sortition_scheme) . unwrap( ) ) ;
@@ -104,7 +123,7 @@ mod priority_message_tests {
104
123
sortition_scheme. create_highest_priority_info ( seed, priv_key, voting_power) . unwrap ( ) . unwrap ( ) ;
105
124
106
125
let priority_message = PriorityMessage {
107
- seed,
126
+ seed : seed . into ( ) ,
108
127
info : priority_info,
109
128
} ;
110
129
rlp_encode_and_decode_test ! ( priority_message) ;
0 commit comments