Skip to content

Fix for the chance of failure in the leader election algorithm #52

@remcosurtel

Description

@remcosurtel

Description
The leader election algorithm algorithm currently has a chance to fail, as explained in a comment at the top of the leaderelection.h file. There is a possible order of activations when there are only two candidates in the segment comparison phase, where both candidates will demote themselves.

The fix
This issue can be fixed as shown in this commit on my fork of AmoebotSim:
remcosurtel@b96d525

Firstly, in line 479 the hasCoveredCandidate variable on the FinalSegmentCleanToken should be set appropriately, and the isCoveredCandidate variable should be set to false afterwards.

Secondly, on line 354, when a candidate demotes itself because it is shorter than its predecessor, it should set its isCoveredCandidate variable to true to avoid its successor from also revoking its candidacy erroneously.

From my testing these two changes appear to completely eliminate the chance of failure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions