Logical Clock

Logical Clock or Lamport's Clock is a basic protocol that gives a notion of virutal time to all processes. Lamport's clock can be used to totally order all events in a distributed system. This is done by assigning timestamps to each event in a way that is consistent with the happened-before relation. Therefore, the following property should always hold.

e → f ⇒ C(e) < C(f)

Where C(i) is the timestamp for event i.
Note the implication is one way.

The protocol is defined as follows:
For process Pi * On executing an interval event:     Ci := Ci + 1 * On sending a message m:     Ci := Ci + 1     piggyback Ci on m * On receive a message m:     let tm be the timestamp piggybacked on m     Ci := max{Ci, tm} + 1

Note that logical clocks cannot be used to determine two events are concurrent. 
e || f does not imply C(e) = C(f)