6868/// Valid transitions result in at least a change to the state and/or an output.
6969///
7070/// Commented numbers refer to line numbers in the spec paper.
71- pub fn apply < Ctx > ( mut state : State < Ctx > , info : & Info < Ctx > , input : Input < Ctx > ) -> Transition < Ctx >
71+ pub fn apply < Ctx > (
72+ ctx : & Ctx ,
73+ mut state : State < Ctx > ,
74+ info : & Info < Ctx > ,
75+ input : Input < Ctx > ,
76+ ) -> Transition < Ctx >
7277where
7378 Ctx : Context ,
7479{
8792 debug_trace ! ( state, Line :: L11Proposer ) ;
8893
8994 // We are the proposer
90- propose_valid_or_get_value ( state, info. address )
95+ propose_valid_or_get_value ( ctx , state, info. address )
9196 }
9297
9398 // L11/L20
@@ -109,7 +114,7 @@ where
109114 ( Step :: Propose , Input :: ProposeValue ( value) ) if this_round => {
110115 debug_assert ! ( info. is_proposer( ) ) ;
111116
112- propose ( state, value, info. address )
117+ propose ( ctx , state, value, info. address )
113118 }
114119
115120 // L22 with valid proposal
@@ -118,18 +123,20 @@ where
118123 {
119124 debug_trace ! ( state, Line :: L22 ) ;
120125
121- prevote ( state, info. address , & proposal)
126+ prevote ( ctx , state, info. address , & proposal)
122127 }
123128
124129 // L22 with invalid proposal
125- ( Step :: Propose , Input :: InvalidProposal ) if this_round => prevote_nil ( state, info. address ) ,
130+ ( Step :: Propose , Input :: InvalidProposal ) if this_round => {
131+ prevote_nil ( ctx, state, info. address )
132+ }
126133
127134 // L28 with valid proposal
128135 ( Step :: Propose , Input :: ProposalAndPolkaPrevious ( proposal) )
129136 if this_round && is_valid_pol_round ( & state, proposal. pol_round ( ) ) =>
130137 {
131138 debug_trace ! ( state, Line :: L28ValidProposal ) ;
132- prevote_previous ( state, info. address , & proposal)
139+ prevote_previous ( ctx , state, info. address , & proposal)
133140 }
134141
135142 // L28 with invalid proposal
@@ -139,23 +146,23 @@ where
139146 debug_trace ! ( state, Line :: L28InvalidProposal ) ;
140147 debug_trace ! ( state, Line :: L32InvalidValue ) ;
141148
142- prevote_nil ( state, info. address )
149+ prevote_nil ( ctx , state, info. address )
143150 }
144151
145152 // L57
146153 // We are the proposer.
147154 ( Step :: Propose , Input :: TimeoutPropose ) if this_round && info. is_proposer ( ) => {
148155 debug_trace ! ( state, Line :: L59Proposer ) ;
149156
150- prevote_nil ( state, info. address )
157+ prevote_nil ( ctx , state, info. address )
151158 }
152159
153160 // L57
154161 // We are not the proposer.
155162 ( Step :: Propose , Input :: TimeoutPropose ) if this_round => {
156163 debug_trace ! ( state, Line :: L59NonProposer ) ;
157164
158- prevote_nil ( state, info. address )
165+ prevote_nil ( ctx , state, info. address )
159166 }
160167
161168 //
@@ -174,22 +181,22 @@ where
174181 ( Step :: Prevote , Input :: PolkaNil ) if this_round => {
175182 debug_trace ! ( state, Line :: L45 ) ;
176183
177- precommit_nil ( state, info. address )
184+ precommit_nil ( ctx , state, info. address )
178185 }
179186
180187 // L36/L37
181188 // NOTE: Only executed the first time, as the votekeeper will only emit this threshold once.
182189 ( Step :: Prevote , Input :: ProposalAndPolkaCurrent ( proposal) ) if this_round => {
183190 debug_trace ! ( state, Line :: L36ValidProposal ) ;
184191
185- precommit ( state, info. address , proposal)
192+ precommit ( ctx , state, info. address , proposal)
186193 }
187194
188195 // L61
189196 ( Step :: Prevote , Input :: TimeoutPrevote ) if this_round => {
190197 debug_trace ! ( state, Line :: L61 ) ;
191198
192- precommit_nil ( state, info. address )
199+ precommit_nil ( ctx , state, info. address )
193200 }
194201
195202 //
@@ -251,6 +258,7 @@ where
251258///
252259/// Ref: L13-L16, L19
253260pub fn propose_valid_or_get_value < Ctx > (
261+ ctx : & Ctx ,
254262 mut state : State < Ctx > ,
255263 address : & Ctx :: Address ,
256264) -> Transition < Ctx >
@@ -264,6 +272,7 @@ where
264272 // L16
265273 let pol_round = round_value. round ;
266274 let proposal = Output :: proposal (
275+ ctx,
267276 state. height ,
268277 state. round ,
269278 round_value. value . clone ( ) ,
@@ -294,6 +303,7 @@ where
294303///
295304/// Ref: L13, L17-18
296305pub fn propose < Ctx > (
306+ ctx : & Ctx ,
297307 mut state : State < Ctx > ,
298308 value : Ctx :: Value ,
299309 address : & Ctx :: Address ,
@@ -302,6 +312,7 @@ where
302312 Ctx : Context ,
303313{
304314 let proposal = Output :: proposal (
315+ ctx,
305316 state. height ,
306317 state. round ,
307318 value,
@@ -322,6 +333,7 @@ where
322333///
323334/// Ref: L22 with valid proposal
324335pub fn prevote < Ctx > (
336+ ctx : & Ctx ,
325337 mut state : State < Ctx > ,
326338 address : & Ctx :: Address ,
327339 proposal : & Ctx :: Proposal ,
@@ -350,7 +362,7 @@ where
350362 }
351363 } ;
352364
353- let output = Output :: prevote ( state. height , state. round , value, address. clone ( ) ) ;
365+ let output = Output :: prevote ( ctx , state. height , state. round , value, address. clone ( ) ) ;
354366 Transition :: to ( state. with_step ( Step :: Prevote ) ) . with_output ( output)
355367}
356368
@@ -359,6 +371,7 @@ where
359371///
360372/// Ref: L28
361373pub fn prevote_previous < Ctx > (
374+ ctx : & Ctx ,
362375 mut state : State < Ctx > ,
363376 address : & Ctx :: Address ,
364377 proposal : & Ctx :: Proposal ,
@@ -394,18 +407,19 @@ where
394407 }
395408 } ;
396409
397- let output = Output :: prevote ( state. height , state. round , value, address. clone ( ) ) ;
410+ let output = Output :: Vote ( ctx . new_prevote ( state. height , state. round , value, address. clone ( ) ) ) ;
398411 Transition :: to ( state. with_step ( Step :: Prevote ) ) . with_output ( output)
399412}
400413
401414/// Received a complete proposal for an empty or invalid value, or timed out; prevote nil.
402415///
403416/// Ref: L22/L25, L28/L31, L57
404- pub fn prevote_nil < Ctx > ( state : State < Ctx > , address : & Ctx :: Address ) -> Transition < Ctx >
417+ pub fn prevote_nil < Ctx > ( ctx : & Ctx , state : State < Ctx > , address : & Ctx :: Address ) -> Transition < Ctx >
405418where
406419 Ctx : Context ,
407420{
408- let output = Output :: prevote ( state. height , state. round , NilOrVal :: Nil , address. clone ( ) ) ;
421+ let output =
422+ Output :: Vote ( ctx. new_prevote ( state. height , state. round , NilOrVal :: Nil , address. clone ( ) ) ) ;
409423
410424 Transition :: to ( state. with_step ( Step :: Prevote ) ) . with_output ( output)
411425}
@@ -421,6 +435,7 @@ where
421435/// NOTE: Only one of this and set_valid_value should be called once in a round
422436/// How do we enforce this?
423437pub fn precommit < Ctx > (
438+ ctx : & Ctx ,
424439 state : State < Ctx > ,
425440 address : & Ctx :: Address ,
426441 proposal : Ctx :: Proposal ,
@@ -434,6 +449,7 @@ where
434449
435450 let value = proposal. value ( ) ;
436451 let output = Output :: precommit (
452+ ctx,
437453 state. height ,
438454 state. round ,
439455 NilOrVal :: Val ( value. id ( ) ) ,
@@ -451,11 +467,13 @@ where
451467/// Received a polka for nil or timed out of prevote; precommit nil.
452468///
453469/// Ref: L44, L61
454- pub fn precommit_nil < Ctx > ( state : State < Ctx > , address : & Ctx :: Address ) -> Transition < Ctx >
470+ pub fn precommit_nil < Ctx > ( ctx : & Ctx , state : State < Ctx > , address : & Ctx :: Address ) -> Transition < Ctx >
455471where
456472 Ctx : Context ,
457473{
458- let output = Output :: precommit ( state. height , state. round , NilOrVal :: Nil , address. clone ( ) ) ;
474+ let output =
475+ Output :: Vote ( ctx. new_precommit ( state. height , state. round , NilOrVal :: Nil , address. clone ( ) ) ) ;
476+
459477 Transition :: to ( state. with_step ( Step :: Precommit ) ) . with_output ( output)
460478}
461479
0 commit comments