@@ -54,7 +54,7 @@ module tendermint {
5454
5555 type CustomEffects = ()
5656 type Event = TimeoutEvent
57- type Extensions = Bookkeeping
57+ type Extensions = ()
5858
5959 /* Boilerplate */
6060 type LocalState = choreo:: LocalState[ Node, StateFields]
@@ -106,8 +106,8 @@ module tendermint {
106106
107107 pure def id( v: Value) : ValueId = { hashed : v }
108108
109- pure def start_round( input : LocalContext, round : Round) : Transition = {
110- val s = input .state
109+ pure def start_round( ctx : LocalContext, round : Round) : Transition = {
110+ val s = ctx .state
111111
112112 pure val effect =
113113 if ( s.process_id == PROPOSER.get( round)) {
@@ -134,9 +134,9 @@ module tendermint {
134134 }
135135 }
136136
137- pure def upon_proposal_in_propose ( input : LocalContext) : Set[ Transition] = {
138- val s = input .state
139- val messages = input .messages
137+ pure def listen_proposal_in_propose ( ctx : LocalContext) : Set[ Transition] = {
138+ val s = ctx .state
139+ val messages = ctx .messages
140140
141141 val state_guard = and {
142142 s.stage == ProposeStage
@@ -155,26 +155,30 @@ module tendermint {
155155 state_guard
156156 } )
157157
158- def effect_builder = ( p) = > {
159- // Broadcast the PreVote message for the proposal
160- if ( valid( p.proposal) and ( s.locked_round == - 1 or s.locked_value == Some( p.proposal))) {
161- Set( choreo:: Broadcast( PreVote( { src : s.process_id, round : s.round, id : Some( id( p.proposal)) } )))
162- } else {
163- Set( choreo:: Broadcast( PreVote( { src : s.process_id, round : s.round, id : None } )))
164- }
158+ // Map the enabled proposals to effects and the corresponding state updates
159+ enabled_proposals.map( p = > upon_proposal_in_propose( ctx, p))
160+ }
161+
162+ pure def upon_proposal_in_propose( ctx: LocalContext, p : ProposeMsg) : Set[ Transition] = {
163+ val s = ctx.state
164+
165+ // Broadcast the PreVote message for the proposal
166+ pure val effects = if ( valid( p.proposal) and ( s.locked_round == - 1 or s.locked_value == Some( p.proposal))) {
167+ Set( choreo:: Broadcast( PreVote( { src : s.process_id, round : s.round, id : Some( id( p.proposal)) } )))
168+ } else {
169+ Set( choreo:: Broadcast( PreVote( { src : s.process_id, round : s.round, id : None } )))
165170 }
166171
167- // Map the enabled proposals to effects and the corresponding state updates
168- enabled_proposals.map( p = > {
169- post_state : { ...s, stage : PreVoteStage} ,
170- effects : effect_builder( p)
171- // TODO -> add timeout and logging effects
172- } )
172+ // TODO -> add timeout and logging effects
173+ {
174+ post_state : { ...s, stage : PreVoteStage } ,
175+ effetcs : effects
176+ }
173177 }
174178
175- pure def upon_proposal_in_propose_prevote( input : LocalContext) : Set[ Transition] = {
176- val s = input .state
177- val messages = input .messages
179+ pure def upon_proposal_in_propose_prevote( ctx : LocalContext) : Set[ Transition] = {
180+ val s = ctx .state
181+ val messages = ctx .messages
178182
179183 val state_guard = and {
180184 s.stage == ProposeStage,
@@ -212,9 +216,9 @@ module tendermint {
212216 }
213217
214218
215- pure def upon_quorum_prevotes_any( input : LocalContext) : Set[ Transition] = {
216- val s = input .state
217- val messages = input .messages
219+ pure def upon_quorum_prevotes_any( ctx : LocalContext) : Set[ Transition] = {
220+ val s = ctx .state
221+ val messages = ctx .messages
218222
219223 // Do we have a quorum of PreVotes in the current round
220224 def message_guard = ( pv) = > ( pv.round == s.round)
@@ -233,9 +237,9 @@ module tendermint {
233237 }
234238 }
235239
236- pure def upon_quorum_nil_prevotes( input : LocalContext) : Set[ Transition] = {
237- val s = input .state
238- val messages = input .messages
240+ pure def upon_quorum_nil_prevotes( ctx : LocalContext) : Set[ Transition] = {
241+ val s = ctx .state
242+ val messages = ctx .messages
239243
240244 val state_guard = and {
241245 s.stage == PreVoteStage,
@@ -258,9 +262,9 @@ module tendermint {
258262 }
259263 }
260264
261- pure def upon_quorum_precommits_any( input : LocalContext) : Set[ Transition] = {
262- val s = input .state
263- val messages = input .messages
265+ pure def upon_quorum_precommits_any( ctx : LocalContext) : Set[ Transition] = {
266+ val s = ctx .state
267+ val messages = ctx .messages
264268
265269 // Do we have a quorum of PreCommits in the current round
266270 def message_guard = ( pc) = > ( pc.round == s.round)
@@ -279,9 +283,9 @@ module tendermint {
279283 }
280284 }
281285
282- pure def upon_proposal_in_prevote_commit( input : LocalContext) : Set[ Transition] = {
283- val s = input .state
284- val messages = input .messages
286+ pure def upon_proposal_in_prevote_commit( ctx : LocalContext) : Set[ Transition] = {
287+ val s = ctx .state
288+ val messages = ctx .messages
285289
286290 val state_guard = and {
287291 s.stage.in( Set( PreVoteStage, PreCommitStage))
@@ -342,9 +346,9 @@ module tendermint {
342346 } )
343347 }
344348
345- pure def upon_proposal_in_precommit_no_decision( input : LocalContext) : Set[ Transition] = {
346- val s = input .state
347- val messages = input .messages
349+ pure def upon_proposal_in_precommit_no_decision( ctx : LocalContext) : Set[ Transition] = {
350+ val s = ctx .state
351+ val messages = ctx .messages
348352
349353 val state_guard = and {
350354 s.decision == None
@@ -383,10 +387,10 @@ module tendermint {
383387 } )
384388 }
385389
386- pure def on_propose_timeout( input : LocalContext) : Set[ Transition] = {
387- val s = input .state
390+ pure def on_propose_timeout( ctx : LocalContext) : Set[ Transition] = {
391+ val s = ctx .state
388392
389- val candidates = input .events.filter( t = > t.round >= s.round and t.kind == ProposeTimeout)
393+ val candidates = ctx .events.filter( t = > t.round >= s.round and t.kind == ProposeTimeout)
390394 val guard = and {
391395 candidates.size() > 0 ,
392396 s.stage == ProposeStage,
@@ -404,10 +408,10 @@ module tendermint {
404408 Set()
405409 }
406410
407- pure def on_prevote_timeout( input : LocalContext) : Set[ Transition] = {
408- val s = input .state
411+ pure def on_prevote_timeout( ctx : LocalContext) : Set[ Transition] = {
412+ val s = ctx .state
409413
410- val candidates = input .events.filter( t = > t.round >= s.round and t.kind == PreVoteTimeout)
414+ val candidates = ctx .events.filter( t = > t.round >= s.round and t.kind == PreVoteTimeout)
411415 val guard = and {
412416 candidates.size() > 0 ,
413417 s.stage == PreVoteStage,
@@ -425,33 +429,33 @@ module tendermint {
425429 Set()
426430 }
427431
428- pure def on_precommit_timeout( input : LocalContext) : Set[ Transition] = {
429- val s = input .state
432+ pure def on_precommit_timeout( ctx : LocalContext) : Set[ Transition] = {
433+ val s = ctx .state
430434
431- val candidates = input .events.filter( t = > t.round >= s.round and t.kind == PreCommitTimeout)
435+ val candidates = ctx .events.filter( t = > t.round >= s.round and t.kind == PreCommitTimeout)
432436 val guard = and {
433437 candidates.size() > 0 ,
434438 s.stage == PreCommitStage,
435439 }
436440
437441 if ( guard)
438- Set( start_round( input , s.round + 1 ))
442+ Set( start_round( ctx , s.round + 1 ))
439443 else
440444 Set()
441445 }
442446
443- pure def main_listener( input : LocalContext) : Set[ Transition] =
447+ pure def main_listener( ctx : LocalContext) : Set[ Transition] =
444448 Set(
445- upon_proposal_in_propose ( input ) ,
446- upon_proposal_in_propose_prevote( input ) ,
447- upon_proposal_in_precommit_no_decision( input ) ,
448- upon_proposal_in_prevote_commit( input ) ,
449- upon_quorum_prevotes_any( input ) ,
450- upon_quorum_nil_prevotes( input ) ,
451- upon_quorum_precommits_any( input ) ,
452- on_propose_timeout( input ) ,
453- on_prevote_timeout( input ) ,
454- on_precommit_timeout( input )
449+ listen_proposal_in_propose ( ctx ) ,
450+ upon_proposal_in_propose_prevote( ctx ) ,
451+ upon_proposal_in_precommit_no_decision( ctx ) ,
452+ upon_proposal_in_prevote_commit( ctx ) ,
453+ upon_quorum_prevotes_any( ctx ) ,
454+ upon_quorum_nil_prevotes( ctx ) ,
455+ upon_quorum_precommits_any( ctx ) ,
456+ on_propose_timeout( ctx ) ,
457+ on_prevote_timeout( ctx ) ,
458+ on_precommit_timeout( ctx )
455459 ) .flatten()
456460
457461 pure val initial_message =
0 commit comments