Purge transactions#232
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
67edffc to
b5ecde9
Compare
a2260d0 to
403f38b
Compare
HAPPY-113 txmanager: We should purge finalized transactions after a delay
We should implement a system for purging transactions after a delay. The delay could be configurable, or perhaps occur after block finalization, considering a future system that handles possible forks |
| @@ -0,0 +1,5 @@ | |||
| export async function up(db) { | |||
| await db.schema.alterTable("transaction").addColumn("createdAt", "integer").execute() | |||
There was a problem hiding this comment.
should this not be some timestamp column?
There was a problem hiding this comment.
SQLite doesn't have a timestamp type, so what I'm doing is saving the timestamp in a numeric format. https://www.sqlite.org/datatype3.html
There was a problem hiding this comment.
the more i use sqlite the more my lovehate relationship with it grows 😄
I guess i would still be inclined to use a date or datetime https://www.sqlite.org/datatype3.html#affinity_name_examples here in the migration, then if we use something other than sqlite it'll still make sense 🤔 maybe this will strictly always be sqlite though 🤷
just sharing thoughts, don't have to change
There was a problem hiding this comment.
If I use the datetime type, I get this error: invalid column data type "DATETIME"
There was a problem hiding this comment.
This is probably the explanation: https://stackoverflow.com/questions/17227110/how-do-datetime-values-work-in-sqlite
SQLite allows anything (including DATETIME) as declared type of a column. Based on that, it gives that column an affinity with a storage class (it even has the example of how this works for DATETIME in the documentation). That affinity is more like a hint, as each entry the column can actually have a different storage class. A storage class is still a step weaker than a type and can be backed by multiple types. So yes, you can use DATETIME. No, it does not actually support it as a type or storage class. Yes, the documentation actually contains the word "DATETIME".
So there's probably something here that validates that the type is one of the "standard" types.
In any case, DATETYPE gives NUMERIC affinity which is probably not what we want to store timestamps.
Let's add a comment here though to explain this. Somethiing like "SQLite does not have native time types. The SQL interface allows arbitrary type names including "DATE" and "DATETIME", but this is invalid in this API, and results in "NUMERIC" affinity instead of "INTEGER" affinity, which is the one we want here."
| unknownToError, | ||
| ) | ||
|
|
||
| this.notFinalizedTransactions = this.notFinalizedTransactions = this.notFinalizedTransactions.filter( |
There was a problem hiding this comment.
| this.notFinalizedTransactions = this.notFinalizedTransactions = this.notFinalizedTransactions.filter( | |
| this.notFinalizedTransactions = this.notFinalizedTransactions.filter( |
🧐 not sure what happened here 😁
| unknownToError, | ||
| ) | ||
|
|
||
| this.notFinalizedTransactions = this.notFinalizedTransactions = this.notFinalizedTransactions.filter( |
There was a problem hiding this comment.
and there 🤔
| this.notFinalizedTransactions = this.notFinalizedTransactions = this.notFinalizedTransactions.filter( | |
| this.notFinalizedTransactions = this.notFinalizedTransactions.filter( |
| @@ -0,0 +1,5 @@ | |||
| export async function up(db) { | |||
| await db.schema.alterTable("transaction").addColumn("createdAt", "integer").execute() | |||
There was a problem hiding this comment.
the more i use sqlite the more my lovehate relationship with it grows 😄
I guess i would still be inclined to use a date or datetime https://www.sqlite.org/datatype3.html#affinity_name_examples here in the migration, then if we use something other than sqlite it'll still make sense 🤔 maybe this will strictly always be sqlite though 🤷
just sharing thoughts, don't have to change
3c88ccd to
553dece
Compare
c5452a4 to
e3016df
Compare
norswap
left a comment
There was a problem hiding this comment.
Has this been tested (even if just manually)? If not, we should probably make sure it works.
| * The time (in milliseconds) after which finalized transactions are purged from the database. | ||
| * Defaults to 2 minutes. | ||
| */ | ||
| finalizedTransactionPurgeTime?: number |
There was a problem hiding this comment.
Should we enable setting this to 0 to disable purging?
There was a problem hiding this comment.
It's a good idea. I just implemented it
| @@ -0,0 +1,5 @@ | |||
| export async function up(db) { | |||
| await db.schema.alterTable("transaction").addColumn("createdAt", "integer").execute() | |||
There was a problem hiding this comment.
This is probably the explanation: https://stackoverflow.com/questions/17227110/how-do-datetime-values-work-in-sqlite
SQLite allows anything (including DATETIME) as declared type of a column. Based on that, it gives that column an affinity with a storage class (it even has the example of how this works for DATETIME in the documentation). That affinity is more like a hint, as each entry the column can actually have a different storage class. A storage class is still a step weaker than a type and can be backed by multiple types. So yes, you can use DATETIME. No, it does not actually support it as a type or storage class. Yes, the documentation actually contains the word "DATETIME".
So there's probably something here that validates that the type is one of the "standard" types.
In any case, DATETYPE gives NUMERIC affinity which is probably not what we want to store timestamps.
Let's add a comment here though to explain this. Somethiing like "SQLite does not have native time types. The SQL interface allows arbitrary type names including "DATE" and "DATETIME", but this is invalid in this API, and results in "NUMERIC" affinity instead of "INTEGER" affinity, which is the one we want here."
Yes, I have tested it |
…lized transaction
3d8200e to
109902a
Compare
a520cec to
4eb5c38
Compare
… DATETIME in sqlite
109902a to
ef383c3
Compare

Linked Issues
Description
This PR implements a mechanism that removes finalized transactions after a period without changes. The time interval for removing the transaction is configurable, with a default of 2 minutes
Toggle Checklist
Checklist
Basics
norswap/build-system-caching).Reminder: PR review guidelines
Correctness
testnet, mainnet, standalone wallet, ...).
This PR has been tested using the randomness service on localhost, interacting with the Anvil blockchain
and have updated the code & comments accordingly.
Architecture & Documentation
(2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
comments.
in a Markdown document.