Skip to content

Commit

Permalink
Fix algorithm compliance bug in Proposer
Browse files Browse the repository at this point in the history
We can't just send any value we want in an `Accept' message: it must be
the value found in the highest previously accepted proposal (which is
received as part of `Promise's from Acceptors), or a chosen value if not
a single value was accepted before.
  • Loading branch information
NicolasT committed Dec 13, 2012
1 parent 18ad670 commit 4b144a1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Network/Paxos/Synod/Proposer.hs
Expand Up @@ -114,7 +114,12 @@ handlePromise state acceptor (Promise proposalId' highestAccepted')
Just v' -> Just $ max v v'
msgs = if length (acceptors state') /= fromIntegral (unQuorum $ quorum state')
then []
else [Broadcast Acceptors $ MsgAccept $ Accept (proposalId state') (value state')]
else [Broadcast Acceptors $ MsgAccept $ Accept (proposalId state') value']
-- Retrieve the value to be distributed in an `Accept' message. This is
-- the value of the highest `AcceptedValue' we received as part of
-- `Promise' message, or the value passed by our user initially if
-- none.
value' = maybe (value state') (\(AcceptedValue _ v) -> v) (highestAccepted state')

prop_handlePromise :: ProposerState Int ()
-> Int
Expand All @@ -130,10 +135,11 @@ prop_handlePromise state acceptor p@(Promise proposalId' highestAccepted')
, highestAccepted state' == max (highestAccepted state) highestAccepted'
, proposalId state' == proposalId state
, (length (acceptors state') /= fromIntegral (unQuorum $ quorum state')) ||
(actions == [Broadcast Acceptors $ MsgAccept $ Accept (proposalId state') (value state')])
(actions == [Broadcast Acceptors $ MsgAccept $ Accept (proposalId state') value'])
]
where
result@(state', actions) = handlePromise state acceptor p
value' = maybe (value state') (\(AcceptedValue _ v) -> v) (highestAccepted state')


-- | Tests
Expand Down

0 comments on commit 4b144a1

Please sign in to comment.