According to wikipedia, Lamport clocks need to be incremented when sending a message (time = time + 1
) and when receiving a message (time = max(time_stamp, time) + 1
).
In my implementation, Increment()
is used when sending and Witness()
is used when receiving, each of them following the previous rules.
I can't understand why not only Increment()
actually increment the counter, that is why Witness()
does not simply do time = max(time_stamp, time)
instead of time = max(time_stamp, time) + 1
.
The source of my confusion is the following scenario:
- clock start at 1
- a message is sent, clock is at 2
- this message is seen locally, clock is now at 3
In this scenario, the clock incremented twice for the same message. Ideally it would just be one. Did I break something by witnessing the clock within the same process? Did I get something wrong?