Skip to content

Purge transactions#232

Merged
GabrielMartinezRodriguez merged 6 commits into
masterfrom
gabriel-txm-purge
Dec 6, 2024
Merged

Purge transactions#232
GabrielMartinezRodriguez merged 6 commits into
masterfrom
gabriel-txm-purge

Conversation

@GabrielMartinezRodriguez

@GabrielMartinezRodriguez GabrielMartinezRodriguez commented Nov 6, 2024

Copy link
Copy Markdown
Contributor

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

  • B1. I have applied the proper label & proper branch name (e.g. norswap/build-system-caching).
  • B2. This PR is not so big that it should be split & addresses only one concern.
  • B3. The PR targets the lowest branch it can (ideally master).

Reminder: PR review guidelines

Correctness

  • C1. Builds and passes tests.
  • C2. The code is properly parameterized & compatible with different environments (e.g. local,
    testnet, mainnet, standalone wallet, ...).
  • C3. I have manually tested my changes & connected features.

This PR has been tested using the randomness service on localhost, interacting with the Anvil blockchain

  • C4. I have performed a thorough self-review of my code after submitting the PR,
    and have updated the code & comments accordingly.

Architecture & Documentation

  • D1. I made it easy to reason locally about the code, by (1) using proper abstraction boundaries,
    (2) commenting these boundaries correctly, (3) adding inline comments for context when needed.
  • D2. All public-facing APIs & meaningful (non-local) internal APIs are properly documented in code
    comments.
  • D3. If appropriate, the general architecture of the code is documented in a code comment or
    in a Markdown document.

GabrielMartinezRodriguez commented Nov 6, 2024

Copy link
Copy Markdown
Contributor Author

@GabrielMartinezRodriguez GabrielMartinezRodriguez mentioned this pull request Nov 6, 2024
10 tasks
@GabrielMartinezRodriguez GabrielMartinezRodriguez added the draft Not ready for review label Nov 6, 2024
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 6, 2024

Copy link
Copy Markdown

Deploying happychain with  Cloudflare Pages  Cloudflare Pages

Latest commit: ef383c3
Status:⚡️  Build in progress...

View logs

@GabrielMartinezRodriguez GabrielMartinezRodriguez changed the title feat(txm): purge transactions Purge transactions Nov 6, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez force-pushed the gabriel-txm-purge branch 2 times, most recently from a2260d0 to 403f38b Compare November 12, 2024 10:26
@linear

linear Bot commented Nov 12, 2024

Copy link
Copy Markdown
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

@GabrielMartinezRodriguez GabrielMartinezRodriguez added reviewing-1 Ready for, or undergoing first-line review and removed draft Not ready for review labels Nov 12, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez marked this pull request as ready for review November 12, 2024 10:57
@@ -0,0 +1,5 @@
export async function up(db) {
await db.schema.alterTable("transaction").addColumn("createdAt", "integer").execute()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this not be some timestamp column?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I use the datetime type, I get this error: invalid column data type "DATETIME"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and there 🤔

Suggested change
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()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@GabrielMartinezRodriguez GabrielMartinezRodriguez removed the reviewing-1 Ready for, or undergoing first-line review label Nov 20, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez mentioned this pull request Nov 20, 2024
10 tasks
@GabrielMartinezRodriguez GabrielMartinezRodriguez added the reviewing-2 Ready for, or undergoing final review label Nov 20, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez mentioned this pull request Nov 28, 2024
10 tasks

@norswap norswap left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we enable setting this to 0 to disable purging?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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."

@norswap norswap added merge-after-changes Can be merged after requested changes are made and removed reviewing-2 Ready for, or undergoing final review labels Nov 28, 2024
@GabrielMartinezRodriguez

Copy link
Copy Markdown
Contributor Author

Has this been tested (even if just manually)? If not, we should probably make sure it works.

Yes, I have tested it

@GabrielMartinezRodriguez GabrielMartinezRodriguez added merge-blocked Ready to merge, waiting for downstack and removed merge-after-changes Can be merged after requested changes are made labels Dec 3, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez changed the base branch from graphite-base/232 to master December 6, 2024 10:07
@GabrielMartinezRodriguez GabrielMartinezRodriguez merged commit 81718aa into master Dec 6, 2024
@GabrielMartinezRodriguez GabrielMartinezRodriguez deleted the gabriel-txm-purge branch December 6, 2024 10:11
This was referenced Dec 13, 2024
This was referenced Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-blocked Ready to merge, waiting for downstack

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants