let time_for_elections constants n' maybe_previous =

if constants.store # quiesced ()

ns' origine am (Sn.string_of al) (Sn.string_of now) >>= fun () ->

let diff = abs (Int64.to_int (Int64.sub now al)) in

- diff >= constants.lease_expiration

+ diff >= constants.lease_expiration, Printf.sprintf "diff=%i" diff

let slave_steady_state constants state event =

let (n,i,previous) = state in

- let me = constants.me in

let store = constants.store in

| FromNode (msg,source) ->

let accept_e = EAccept (v,n,i) in

- let start_e = EStartLeaseExpiration(v,n) in

+ let start_e = EStartLeaseExpiration(v,n, true) in

let send_e = ESend(reply, source) in

let log_e = ELog (fun () ->

Printf.sprintf "steady_state :: replying with %S" (string_of reply)

Fsm.return ~sides:[log_e] (Slave_steady_state state)

- let ns = (Sn.string_of n)

- and ns' = (Sn.string_of n') in

- if (not (is_election constants || constants.is_learner)) || n' < n

- let log_e = ELog (fun () ->

- Printf.sprintf "steady state: ignoring old lease expiration (n'=%s,n=%s)" ns' ns )

- Fsm.return ~sides:[log_e] (Slave_steady_state (n,i,previous))

- let elections_needed = time_for_elections constants n' (Some (previous,Sn.pred i)) in

- if elections_needed then

- let new_n = update_n constants n in

- let el_i = Store.get_succ_store_i constants.store in

- let log_e = ELog (fun () -> "ELECTIONS NEEDED") in

- Fsm.return ~sides:[log_e] (Election_suggest (new_n, el_i, el_up ))

- Fsm.return (Slave_steady_state(n,i,previous))

+ let ns = (Sn.string_of n)

+ and ns' = (Sn.string_of n') in

+ if (not (is_election constants || constants.is_learner)) || n' < n

+ let log_e = ELog (fun () ->

+ Printf.sprintf "steady state: ignoring old lease expiration (n'=%s,n=%s)" ns' ns )

+ Fsm.return ~sides:[log_e] (Slave_steady_state (n,i,previous))

+ let elections_needed, msg = time_for_elections constants n' (Some (previous,Sn.pred i)) in

+ if elections_needed then

+ let new_n = update_n constants n in

+ let el_i = Store.get_succ_store_i constants.store in

+ let log_e = ELog (fun () -> "ELECTIONS NEEDED") in

+ Fsm.return ~sides:[log_e] (Election_suggest (new_n, el_i, el_up ))

+ let log_e = ELog(fun () ->

+ "slave_steady_state ignoring lease expiration (n'=%s,n=%s) %s" ns' ns msg)

+ Fsm.return ~sides:[log_e] (Slave_steady_state(n,i,previous))

(* a pending slave that has promised a value to a pending master waits

for an Accept from the master about this *)

let slave_wait_for_accept constants (n,i, vo, maybe_previous) event =

- let me = constants.me in

| FromNode(msg,source) ->

Fsm.return ~sides:[log_e] (Slave_wait_for_accept (n,i,vo, maybe_previous))

- let elections_needed = time_for_elections constants n' maybe_previous in

+ let elections_needed,_ = time_for_elections constants n' maybe_previous in

let log_e = ELog (fun () -> "slave_wait_for_accept: Elections needed") in