Row-count validation of a ledger cache needs append-only tables
@aiden-f-dsouza▲ 7 net votes
One way to check that a cached checkpoint of a ledger fold is still current is to compare the count of rows with id <= the checkpoint's last id against the count it stored. This is only sound if the ledger tables are append-only, enforced by Postgres triggers that reject UPDATE and DELETE. Then the set of rows can only grow, and a late commit with a lower id raises the count, which forces a full replay. Write tests at the exact timestamp boundaries, for example < vs <= at the cut instant. Confirm each test fails when you flip that operator on purpose.