@@ -25,6 +25,7 @@ use snap;
2525
2626use super :: super :: BitSet ;
2727use super :: { Height , Step , View } ;
28+ use crate :: consensus:: Priority ;
2829
2930/// Step for the sortition round.
3031/// FIXME: It has a large overlap with the previous VoteStep.
@@ -119,17 +120,25 @@ const MESSAGE_ID_REQUEST_PROPOSAL: u8 = 0x05;
119120const MESSAGE_ID_REQUEST_COMMIT : u8 = 0x06 ;
120121const MESSAGE_ID_COMMIT : u8 = 0x07 ;
121122
123+ #[ derive( Clone , Debug , PartialEq , RlpEncodable , RlpDecodable ) ]
124+ #[ cfg_attr( test, derive( Default ) ) ]
125+ pub struct ProposalSummary {
126+ pub priority : Priority ,
127+ pub block_hash : BlockHash ,
128+ }
129+
122130#[ derive( Debug , PartialEq ) ]
123131pub enum TendermintMessage {
124132 ConsensusMessage ( Vec < Bytes > ) ,
125133 ProposalBlock {
126134 signature : SchnorrSignature ,
135+ priority_info : Box < PriorityInfo > ,
127136 view : View ,
128137 message : Bytes ,
129138 } ,
130139 StepState {
131140 vote_step : VoteStep ,
132- proposal : Option < BlockHash > ,
141+ proposal : Box < Option < ProposalSummary > > ,
133142 lock_view : Option < View > ,
134143 known_votes : BitSet ,
135144 } ,
@@ -138,8 +147,7 @@ pub enum TendermintMessage {
138147 requested_votes : BitSet ,
139148 } ,
140149 RequestProposal {
141- height : Height ,
142- view : View ,
150+ round : SortitionRound ,
143151 } ,
144152 RequestCommit {
145153 height : Height ,
@@ -160,12 +168,14 @@ impl Encodable for TendermintMessage {
160168 }
161169 TendermintMessage :: ProposalBlock {
162170 signature,
171+ priority_info,
163172 view,
164173 message,
165174 } => {
166- s. begin_list ( 4 ) ;
175+ s. begin_list ( 5 ) ;
167176 s. append ( & MESSAGE_ID_PROPOSAL_BLOCK ) ;
168177 s. append ( signature) ;
178+ s. append ( & * * priority_info) ;
169179 s. append ( view) ;
170180
171181 let compressed = {
@@ -184,7 +194,7 @@ impl Encodable for TendermintMessage {
184194 s. begin_list ( 5 ) ;
185195 s. append ( & MESSAGE_ID_STEP_STATE ) ;
186196 s. append ( vote_step) ;
187- s. append ( proposal) ;
197+ s. append ( & * * proposal) ;
188198 s. append ( lock_view) ;
189199 s. append ( known_votes) ;
190200 }
@@ -198,13 +208,11 @@ impl Encodable for TendermintMessage {
198208 s. append ( requested_votes) ;
199209 }
200210 TendermintMessage :: RequestProposal {
201- height,
202- view,
211+ round,
203212 } => {
204- s. begin_list ( 3 ) ;
213+ s. begin_list ( 2 ) ;
205214 s. append ( & MESSAGE_ID_REQUEST_PROPOSAL ) ;
206- s. append ( height) ;
207- s. append ( view) ;
215+ s. append ( round) ;
208216 }
209217 TendermintMessage :: RequestCommit {
210218 height,
@@ -242,15 +250,16 @@ impl Decodable for TendermintMessage {
242250 }
243251 MESSAGE_ID_PROPOSAL_BLOCK => {
244252 let item_count = rlp. item_count ( ) ?;
245- if item_count != 4 {
253+ if item_count != 5 {
246254 return Err ( DecoderError :: RlpIncorrectListLen {
247255 got : item_count,
248- expected : 4 ,
256+ expected : 5 ,
249257 } )
250258 }
251259 let signature = rlp. at ( 1 ) ?;
252- let view = rlp. at ( 2 ) ?;
253- let compressed_message: Vec < u8 > = rlp. val_at ( 3 ) ?;
260+ let priority_info = rlp. at ( 2 ) ?;
261+ let view = rlp. at ( 3 ) ?;
262+ let compressed_message: Vec < u8 > = rlp. val_at ( 4 ) ?;
254263 let uncompressed_message = {
255264 // TODO: Cache the Decoder object
256265 let mut snappy_decoder = snap:: Decoder :: new ( ) ;
@@ -262,6 +271,7 @@ impl Decodable for TendermintMessage {
262271
263272 TendermintMessage :: ProposalBlock {
264273 signature : signature. as_val ( ) ?,
274+ priority_info : Box :: new ( priority_info. as_val ( ) ?) ,
265275 view : view. as_val ( ) ?,
266276 message : uncompressed_message,
267277 }
@@ -275,7 +285,7 @@ impl Decodable for TendermintMessage {
275285 } )
276286 }
277287 let vote_step = rlp. at ( 1 ) ?. as_val ( ) ?;
278- let proposal = rlp. at ( 2 ) ?. as_val ( ) ?;
288+ let proposal = Box :: new ( rlp. at ( 2 ) ?. as_val ( ) ?) ;
279289 let lock_view = rlp. at ( 3 ) ?. as_val ( ) ?;
280290 let known_votes = rlp. at ( 4 ) ?. as_val ( ) ?;
281291 TendermintMessage :: StepState {
@@ -302,17 +312,15 @@ impl Decodable for TendermintMessage {
302312 }
303313 MESSAGE_ID_REQUEST_PROPOSAL => {
304314 let item_count = rlp. item_count ( ) ?;
305- if item_count != 3 {
315+ if item_count != 2 {
306316 return Err ( DecoderError :: RlpIncorrectListLen {
307317 got : item_count,
308- expected : 3 ,
318+ expected : 2 ,
309319 } )
310320 }
311- let height = rlp. at ( 1 ) ?. as_val ( ) ?;
312- let view = rlp. at ( 2 ) ?. as_val ( ) ?;
321+ let round = rlp. at ( 1 ) ?. as_val ( ) ?;
313322 TendermintMessage :: RequestProposal {
314- height,
315- view,
323+ round,
316324 }
317325 }
318326 MESSAGE_ID_REQUEST_COMMIT => {
@@ -422,6 +430,7 @@ mod tests {
422430 fn encode_and_decode_tendermint_message_2 ( ) {
423431 rlp_encode_and_decode_test ! ( TendermintMessage :: ProposalBlock {
424432 signature: SchnorrSignature :: random( ) ,
433+ priority_info: Box :: new( PriorityInfo :: new( 1 , 0xffu64 . into( ) , 0 , 1 , vec![ ] ) ) ,
425434 view: 1 ,
426435 message: vec![ 1u8 , 2u8 ]
427436 } ) ;
@@ -452,8 +461,10 @@ mod tests {
452461 #[ test]
453462 fn encode_and_decode_tendermint_message_5 ( ) {
454463 rlp_encode_and_decode_test ! ( TendermintMessage :: RequestProposal {
455- height: 10 ,
456- view: 123 ,
464+ round: SortitionRound {
465+ height: 10 ,
466+ view: 123 ,
467+ }
457468 } ) ;
458469 }
459470
0 commit comments