Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spending order won't necessarily survive a "vacuum" operation #238

Open
exarkun opened this issue Oct 13, 2021 · 1 comment
Open

Spending order won't necessarily survive a "vacuum" operation #238

exarkun opened this issue Oct 13, 2021 · 1 comment

Comments

@exarkun
Copy link
Collaborator

exarkun commented Oct 13, 2021

According to https://www.sqlite.org/rowidtable.html:

If the rowid is not aliased by INTEGER PRIMARY KEY then it is not persistent and might change. In particular the VACUUM command will change rowids for tables that do not declare an INTEGER PRIMARY KEY. Therefore, applications should not normally access the rowid directly, but instead use an INTEGER PRIMARY KEY.

The unblinded-tokens table has the schema:

CREATE TABLE [unblinded-tokens] (
        [token] text, -- The base64 encoded unblinded token.
        PRIMARY KEY([token])
)

Then tokens are spent in an order defined by:

SELECT [token]
FROM [unblinded-tokens]

Additionally, tokens are discarded by the checkpoint restore mechanism like this:

DELETE FROM [unblinded-tokens]
WHERE [rowid] < ?

If the unblinded-tokens table has its rows renumbered between the time when backup is made and the checkpoint restore mechanism is used then the order of unblinded-tokens will not allow a correct checkpoint restore based on this rowid value.

As https://www.sqlite.org/rowidtable.html suggests, "instead use an INTEGER PRIMARY KEY."

@exarkun
Copy link
Collaborator Author

exarkun commented Oct 13, 2021

Conveniently, we never vacuum the database so I don't think this can hurt us yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant