Skip to content

Conversation

KodeyThomas
Copy link
Contributor

This PR adds in a simple leader election algorithm and an interface we can expand on if we want something more robust.

Open Questions:

  • Do we need a cryptographic hash for leader election? Is having a non-zero chance for a collision ok?

// LeaderElection provides a way to determine if an executor should be currently executing a given message.
// This is used to prevent multiple executors from executing the same message concurrently.
type LeaderElection interface {
IsLeader(msgId [32]byte, destChainSelector uint64, offset uint8) bool
Copy link
Contributor

@asoliman92 asoliman92 Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that the offset of current node's place in the sorted nodes that can participate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets say message comes in at 0s unix, after 5m unix we want to swap over to the next executor. Offset is how many times we've swapped over (should loop back to zero, don't know if we want to handle it inside this code though, good point)

for _, offset := range tt.offsets {
result := le.IsLeader(msgId, tt.destChainSelector, offset)
if result != tt.expectedResult {
t.Errorf("expected %v, got %v", tt.expectedResult, result)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's a nit for all tests, use require.Equal or similar instead of that pattern of adding a condition and then do t.Errorf. I know it's only for illustrations purposes now so it doesn't matter much.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!


// LeaderElection provides a way to determine if an executor should be currently executing a given message.
// This is used to prevent multiple executors from executing the same message concurrently.
type LeaderElection interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I was thinking about this Leader interface is that we'll have something like

GetMessagesSchedules(allMsgs) [][]msgs
Where msgs[0] are the ones that needs executing now by this leader, msgs[1] are next in line once all msgs[0] are executed,...etc. WDYT about that approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just trying to think about how it would be used. If the result of this election is some messages getting enqueue() to the executor. i don't think theres a need to know what messages to execute after this batch

Copy link

Metric kodey/check-my-turn will/verifier-process
Coverage 69.6% 69.5%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants