Skip to content

Instantly share code, notes, and snippets.

Last active December 31, 2015 02:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rystsov/ca9d195b2737039faaf3 to your computer and use it in GitHub Desktop.
class Proposer:
def __init__(self, nodes, q, node_id):
self.q = q
self.nodes = nodes
self.node_id = node_id
# generates a new ballot number which is greater than v
def get_n(self, v):
# ...
def change_query(self, change, query, due):
n = self.get_n(0)
resps = net.send(self.nodes, lambda x: x.prepare(ballot_n=n), due-now())
# Waiting for q (majority) succeeded responses.
ok = resps.where(lambda x: isinstance(x.msg, Accepted)).wait(self.q)
change=change, x: dict(,
last = ok.max(lambda x: x.msg.n).msg
# always true, but explicit check simplyfies proof
# since it guarantees monotonicity of accepted states
assert last.n < n
state = change(last.state)
on_executed = lambda x: return OK(query(state))
except Conflict as e:
state = last.state
on_executed = lambda x: return Conflict(
acks = net.send( x.node), lambda x: x.accept(n, state), due-now())
resps += acks
ok = acks.where(lambda x: isinstance(x.msg, OK)).wait(self.q)
emit_executed(n, state=state, accepted_n=n, x: dict(
return on_executed()
except Conflict as e:
return Conflict(
except CantResolveWait:
return NetworkError()
resps = resps.abort() # abort the connections and
# pick a ballot number greater than any of already known
for x in resps.where(lambda x: isinstance(x.msg, Conflict)):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment