Reconciling timestamps in Quorum Raft

One tricky aspect to timestamps using the now variable in Ethereum is the use of different units, depending on environment type. Unlike vanilla Ethereum implementations, timestamps in an environment with a Quorum client and Raft consensus (Quorum-Raft) are represented in nanoseconds because the Raft consensus can produce more than one block per second. Contrastingly, Quorum-IBFTand Geth-PoA (Proof-of-Authority) environments use timestamps whose units are denoted in seconds. In all three environment types, the now keyword provides the timestamp of the most recent block in UNIX Epoch time format (time since 00:00:00 Coordinated Universal Time (UTC), Thursday, 1 January 1970).

NOTE: The difference in timestamp units can be the root-cause of out-of-gas errors if you transport the same timestamp-dependent require statements from smart contract code in one environment type to another.

Smart Contract Example

Here is a simple smart contract that returns the timestamp of the latest block via the keyword now.

pragma solidity ^0.4.0;
contract timestamp{
    function getTime() public returns (uint) {
        return now;
    }
}

Return Values

The return values for calls to the timestamp contract from three different environments are shown below. Notice that the Quorum-Raft value must be converted from nanoseconds to seconds.

Quorum with Raft consensus

  • Call result: 0x000000000000000000000000000000000000000000000000154bbc9ffadd5f8d
  • Nanoseconds (decimal): 1534527493344419725
  • Seconds (decimal): 1534527493

Quorum with IBFT consensus

  • Call result: 0x000000000000000000000000000000000000000000000000000000005b7710f1
  • Seconds (decimal): 1534529777

Geth with PoA consensus

  • Call result: 0x000000000000000000000000000000000000000000000000000000005b7710fd
  • Seconds (decimal): 1534529789