To give a counterpoint to the accepted answer, the algorithm itself never really needs to terminate in any terribly well-defined sense. It makes more sense to talk about each node individually terminating its participation in the algorithm, which is implementation-defined. Then perhaps you could say that the algorithm itself has terminated when all the participating nodes have dropped out, if that were a useful thing to want to know.
The algorithm has effectively converged as soon as a majority of acceptors have sent their AcceptPropose
messages for the same ballot (in the sense that once that has happened there is no option about what value may ultimately be decided) but this is not a state of affairs that can be observed in practice: for instance if the network were to start dropping messages just before this set of AcceptPropose
messages were sent, no node would be able to learn that the algorithm had converged until connectivity were restored.
However, once one node knows that the algorithm has converged (by having received AcceptPropose
messages from a majority) it is safe for it to share the chosen value via conventional means, e.g. by sending a Decide
message by broadcast or gossip, and for other nodes to forward it on until every node knows that convergence was achieved.
Each node can terminate its participation in the algorithm once it knows the value to which the algorithm has converged, although it may prefer to keep participating for longer, depending on your implementation constraints.
You have to think a bit about failure-tolerance to convince yourself that terminate-on-decided preserves liveness: if all the nodes that know what value was decided were to die before they could share it, would progress still be possible? The answer is, fortunately, yes: as long as a majority of nodes remains alive, if any of them knows the decided value then it can share it with the others, and if not then there's a majority of participating nodes that just need to pick a higher ballot number and run another round.
One thing to be careful of in the accepted answer is this phrase:
The choice is made as soon as a majority receives an accept!(n,v) message which they have not promised to ignore.
Firstly, there's nothing in the protocol about promising to ignore AcceptPropose
messages. Promises pertain to which Propose
messsages should be ignored/rejected. A majority of AcceptPropose
messages can always be used to learn the chosen value, regardless of the ballot number.
Secondly, the choice is effectively made as soon as a majority sends AcceptPropose
messages. You can't observe this directly so you have to wait until at least one node has received AcceptPropose
messages from a majority before knowing that the choice has been made. Once that's happened, you can share the chosen value via more AcceptPropose
messages or via a broadcast/gossip of Decided
messages, depending on which suits your implementation constraints better.