5
5
use super :: * ;
6
6
use qbft_types:: DefaultLeaderFunction ;
7
7
use sha2:: { Digest , Sha256 } ;
8
- use ssv_types:: consensus:: UnsignedSSVMessage ;
9
8
use ssv_types:: message:: { SignedSSVMessage , RSA_SIGNATURE_SIZE } ;
10
9
use ssv_types:: OperatorId ;
11
10
use ssz_derive:: { Decode , Encode } ;
@@ -40,26 +39,22 @@ impl QbftData for TestData {
40
39
}
41
40
}
42
41
43
- fn convert_unsigned_to_wrapped (
44
- msg : UnsignedSSVMessage ,
42
+ fn convert_unsigned_to_signed (
43
+ msg : UnsignedWrappedQbftMessage ,
45
44
operator_id : OperatorId ,
46
45
) -> WrappedQbftMessage {
47
46
// Create a signed message containing just this operator
48
47
let signed_message = SignedSSVMessage :: new (
49
48
vec ! [ vec![ 0 ; RSA_SIGNATURE_SIZE ] ] ,
50
49
vec ! [ OperatorId ( * operator_id) ] ,
51
- msg. ssv_message . clone ( ) ,
52
- msg. full_data ,
50
+ msg. unsigned_message . ssv_message ,
51
+ msg. unsigned_message . full_data ,
53
52
)
54
53
. expect ( "Should create signed message" ) ;
55
54
56
- // Parse the QBFT message from the SSV message data
57
- let qbft_message =
58
- QbftMessage :: from_ssz_bytes ( msg. ssv_message . data ( ) ) . expect ( "Should decode QBFT message" ) ;
59
-
60
55
WrappedQbftMessage {
61
56
signed_message,
62
- qbft_message,
57
+ qbft_message : msg . qbft_message ,
63
58
}
64
59
}
65
60
@@ -85,7 +80,7 @@ impl Default for TestQBFTCommitteeBuilder {
85
80
impl TestQBFTCommitteeBuilder {
86
81
/// Consumes self and runs a test scenario. This returns a [`TestQBFTCommittee`] which
87
82
/// represents a running quorum.
88
- pub fn run < D > ( self , data : D ) -> TestQBFTCommittee < D , impl FnMut ( Message ) >
83
+ pub fn run < D > ( self , data : D ) -> TestQBFTCommittee < D , impl FnMut ( UnsignedWrappedQbftMessage ) >
89
84
where
90
85
D : Default + QbftData < Hash = Hash256 > ,
91
86
{
@@ -102,8 +97,8 @@ impl TestQBFTCommitteeBuilder {
102
97
103
98
/// A testing structure representing a committee of running instances
104
99
#[ allow( clippy:: type_complexity) ]
105
- struct TestQBFTCommittee < D : QbftData < Hash = Hash256 > , S : FnMut ( Message ) > {
106
- msg_queue : Rc < RefCell < VecDeque < ( OperatorId , Message ) > > > ,
100
+ struct TestQBFTCommittee < D : QbftData < Hash = Hash256 > , S : FnMut ( UnsignedWrappedQbftMessage ) > {
101
+ msg_queue : Rc < RefCell < VecDeque < ( OperatorId , UnsignedWrappedQbftMessage ) > > > ,
107
102
instances : HashMap < OperatorId , Qbft < DefaultLeaderFunction , D , S > > ,
108
103
// All of the instances that are currently active, allows us to stop/restart instances by
109
104
// controlling the messages being sent and received
@@ -117,7 +112,7 @@ struct TestQBFTCommittee<D: QbftData<Hash = Hash256>, S: FnMut(Message)> {
117
112
fn construct_and_run_committee < D : QbftData < Hash = Hash256 > > (
118
113
mut config : ConfigBuilder ,
119
114
validated_data : D ,
120
- ) -> TestQBFTCommittee < D , impl FnMut ( Message ) > {
115
+ ) -> TestQBFTCommittee < D , impl FnMut ( UnsignedWrappedQbftMessage ) > {
121
116
// The ID of a committee is just an integer in [0,committee_size)
122
117
123
118
let msg_queue = Rc :: new ( RefCell :: new ( VecDeque :: new ( ) ) ) ;
@@ -145,7 +140,7 @@ fn construct_and_run_committee<D: QbftData<Hash = Hash256>>(
145
140
}
146
141
}
147
142
148
- impl < D : QbftData < Hash = Hash256 > , S : FnMut ( Message ) > TestQBFTCommittee < D , S > {
143
+ impl < D : QbftData < Hash = Hash256 > , S : FnMut ( UnsignedWrappedQbftMessage ) > TestQBFTCommittee < D , S > {
149
144
fn wait_until_end ( mut self ) -> i32 {
150
145
loop {
151
146
let msg = self . msg_queue . borrow_mut ( ) . pop_front ( ) ;
@@ -167,15 +162,8 @@ impl<D: QbftData<Hash = Hash256>, S: FnMut(Message)> TestQBFTCommittee<D, S> {
167
162
// We do not make sure that id != sender since we want to loop back and receive our
168
163
// own messages
169
164
let instance = self . instances . get_mut ( id) . expect ( "Instance exists" ) ;
170
- // get the unsigned message and the sender
171
- let ( _, unsigned) = match msg {
172
- Message :: Propose ( o, ref u)
173
- | Message :: Prepare ( o, ref u)
174
- | Message :: Commit ( o, ref u)
175
- | Message :: RoundChange ( o, ref u) => ( o, u) ,
176
- } ;
177
-
178
- let wrapped = convert_unsigned_to_wrapped ( unsigned. clone ( ) , sender) ;
165
+
166
+ let wrapped = convert_unsigned_to_signed ( msg. clone ( ) , sender) ;
179
167
instance. receive ( wrapped) ;
180
168
}
181
169
}
0 commit comments