@@ -79,6 +79,8 @@ const MESSAGE_ID_PROPOSAL_BLOCK: u8 = 0x02;
79
79
const MESSAGE_ID_STEP_STATE : u8 = 0x03 ;
80
80
const MESSAGE_ID_REQUEST_MESSAGE : u8 = 0x04 ;
81
81
const MESSAGE_ID_REQUEST_PROPOSAL : u8 = 0x05 ;
82
+ const MESSAGE_ID_REQUEST_COMMIT : u8 = 0x06 ;
83
+ const MESSAGE_ID_COMMIT : u8 = 0x07 ;
82
84
83
85
#[ derive( Debug , PartialEq ) ]
84
86
pub enum TendermintMessage {
@@ -102,6 +104,13 @@ pub enum TendermintMessage {
102
104
height : Height ,
103
105
view : View ,
104
106
} ,
107
+ RequestCommit {
108
+ height : Height ,
109
+ } ,
110
+ Commit {
111
+ block : Bytes ,
112
+ votes : Vec < ConsensusMessage > ,
113
+ } ,
105
114
}
106
115
107
116
impl Encodable for TendermintMessage {
@@ -160,6 +169,22 @@ impl Encodable for TendermintMessage {
160
169
s. append ( height) ;
161
170
s. append ( view) ;
162
171
}
172
+ TendermintMessage :: RequestCommit {
173
+ height,
174
+ } => {
175
+ s. begin_list ( 2 ) ;
176
+ s. append ( & MESSAGE_ID_REQUEST_COMMIT ) ;
177
+ s. append ( height) ;
178
+ }
179
+ TendermintMessage :: Commit {
180
+ block,
181
+ votes,
182
+ } => {
183
+ s. begin_list ( 3 ) ;
184
+ s. append ( & MESSAGE_ID_COMMIT ) ;
185
+ s. append ( block) ;
186
+ s. append_list ( votes) ;
187
+ }
163
188
}
164
189
}
165
190
}
@@ -253,6 +278,34 @@ impl Decodable for TendermintMessage {
253
278
view,
254
279
}
255
280
}
281
+ MESSAGE_ID_REQUEST_COMMIT => {
282
+ let item_count = rlp. item_count ( ) ?;
283
+ if item_count != 2 {
284
+ return Err ( DecoderError :: RlpIncorrectListLen {
285
+ got : item_count,
286
+ expected : 2 ,
287
+ } )
288
+ }
289
+ let height = rlp. at ( 1 ) ?. as_val ( ) ?;
290
+ TendermintMessage :: RequestCommit {
291
+ height,
292
+ }
293
+ }
294
+ MESSAGE_ID_COMMIT => {
295
+ let item_count = rlp. item_count ( ) ?;
296
+ if item_count != 3 {
297
+ return Err ( DecoderError :: RlpIncorrectListLen {
298
+ got : item_count,
299
+ expected : 3 ,
300
+ } )
301
+ }
302
+ let block = rlp. at ( 1 ) ?. as_val ( ) ?;
303
+ let votes = rlp. at ( 2 ) ?. as_list ( ) ?;
304
+ TendermintMessage :: Commit {
305
+ block,
306
+ votes,
307
+ }
308
+ }
256
309
_ => return Err ( DecoderError :: Custom ( "Unknown message id detected" ) ) ,
257
310
} )
258
311
}
@@ -408,6 +461,42 @@ mod tests {
408
461
} ) ;
409
462
}
410
463
464
+ #[ test]
465
+ fn encode_and_decode_tendermint_message_6 ( ) {
466
+ rlp_encode_and_decode_test ! ( TendermintMessage :: RequestCommit {
467
+ height: 3 ,
468
+ } ) ;
469
+ }
470
+
471
+ #[ test]
472
+ fn encode_and_decode_tendermint_message_7 ( ) {
473
+ rlp_encode_and_decode_test ! ( TendermintMessage :: Commit {
474
+ block: vec![ 1u8 , 2u8 ] ,
475
+ votes: vec![
476
+ ConsensusMessage {
477
+ signature: SchnorrSignature :: random( ) ,
478
+ signer_index: 0x1234 ,
479
+ on: VoteOn {
480
+ step: VoteStep :: new( 2 , 3 , Step :: Commit ) ,
481
+ block_hash: Some ( H256 :: from(
482
+ "07feab4c39250abf60b77d7589a5b61fdf409bd837e936376381d19db1e1f050"
483
+ ) ) ,
484
+ } ,
485
+ } ,
486
+ ConsensusMessage {
487
+ signature: SchnorrSignature :: random( ) ,
488
+ signer_index: 0x1235 ,
489
+ on: VoteOn {
490
+ step: VoteStep :: new( 2 , 3 , Step :: Commit ) ,
491
+ block_hash: Some ( H256 :: from(
492
+ "07feab4c39250abf60b77d7589a5b61fdf409bd837e936376381d19db1e1f050"
493
+ ) ) ,
494
+ } ,
495
+ }
496
+ ]
497
+ } ) ;
498
+ }
499
+
411
500
#[ test]
412
501
fn encode_and_decode_consensus_message_1 ( ) {
413
502
let message = ConsensusMessage :: default ( ) ;
0 commit comments