Skip to content

Getting the same rows twice ​

The same query at the same blocks returns the same rows, and what changes between runs is the block that latest points at.

That one sentence is the whole promise. This page covers its edges:

  • what a re-run does
  • what a chain reorganisation does
  • when the rows can legitimately change
  • how to insist on a fresh read

What is fixed at run time ​

When you press Run, CQL pins the head of every chain in the query: the block number and its hash. It then answers the entire run against those pins. Every call, every storage read and every log fetch is at a block whose hash CQL recorded, so the rows describe one consistent state.

Two consequences follow. First, a query written against numbered blocks asks for exactly the same blocks every time and returns exactly the same rows. Examples are at 26_000_000, or the month of stETH share rates at at 25_800_000..26_000_000 every 7200 in Sample a long range.

Second, a query written against latest asks a different question each run, because the head moves between runs. The quick start's at latest-21600..latest every 7200 is an example. Its last row is the head itself. Every 7 200 blocks, the oldest sample leaves the window as a new one enters. The rows differ for that reason and no other.

Running it again ​

If you press Run on a query that you already ran, CQL returns the result that it already has for those pins. It does not go to the chain. That is why switching between two saved queries is instant.

Force re-run (⌘⇧⏎) discards that result and reads everything again at a fresh pin. Use it when you suspect that the chain advanced since the last run. Also use it when an ABI that you uploaded to your library changed, and you want CQL to decode the calls with the new ABI.

Reorganisations ​

Above the finalized block a chain can reorganise, and replace the block that a run read with another block. CQL notices, because it reads every block above finalized by hash. The run then fails with CQL4001, and the message names the chain and the block.

Wait 20 seconds before you run the query again. All runs in one period of 20 seconds use the same pin, so a run that starts sooner can fail again. After the wait, the new run pins the new head. A query at finalized does not fail this way, because that block cannot move. at finalized-21600..finalized every 7200 is the way to write the three-day series so that its rows will never change.

When the same blocks give different rows ​

Three things can change the rows without the blocks changing, and each is visible in the run:

  • A proxy was upgraded. CQL asks about a proxy again after seven days. After that, it decodes every row with the new implementation's ABI. stETH is a proxy, so this can happen to it. The borrowed from line of the Contract tab names the implementation.
  • Your library changed. A query that says with { abi: 'lido' } reads whatever lido is now.
  • A contract was verified after you saw CQL3008 and pressed Check again.

Until CQL asks about the proxy again, it keeps the ABI that it found when it last asked. The Contract tab names the implementation that this ABI came from. A function that only a newer implementation has ends in CQL3013. To call such a function sooner, give an ABI that has it with with { abi: … }.

See also ​