About @chainlink oracle: roundId, phaseId and aggregatorRoundID

If you invoke the latestRoundData function on a Chainlink oracle, you will get the following output values:

As we all know, answer is the current price, in that example it is the current ETH price in USD

But this post is about the roundId, which is currently 110680464442257326664. This could make one think that the oracle was updated exactly 110680464442257326664 times. However, this seems quite high, right?

Well, actually this value is not how many times the oracle was updated but it stores two values. Now we need to understand that each Chainlink Oracle is inherently connected to an aggregator, which is responsible to bring the off-chain reports on-chain.

Now we need to understand that the possibility exists that this aggregator can be changed over time:

Whenever now a new aggregator is now set, this will increase the phaseId value.

As previously managed, the roundId contains two values: phaseId and aggregatorRoundId. These values are simply stored via bit manipulation in the roundId:

a) phaseId: Shifting roundId 64 to the right will yield the phaseId: 110680464442257326664 >> 64 = 6

b) aggregatorRoundId: cast roundId to uint64: uint64(110680464442257326664) = 16968

Summarized this means that the roundId is the following mathematical product

16968 OR (6<<64)

which means nothing else that the aggregatorRoundId is stored in the first 64 bits and the roundId in the subsequent ones.