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

feat: implement SQL lite storage #72

Conversation

Stefan-Ethernal
Copy link
Collaborator

@Stefan-Ethernal Stefan-Ethernal commented Sep 27, 2024

What does this PR do?

This PR introduces SQL lite storage to the zkevm-eth-txmanager, in case the PersistenceFilename config param is provided.

Reviewers

Main reviewers:

@Stefan-Ethernal Stefan-Ethernal self-assigned this Sep 28, 2024
@Stefan-Ethernal Stefan-Ethernal marked this pull request as ready for review September 30, 2024 08:32
common/common.go Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
Copy link

@joanestebanr joanestebanr left a comment

Choose a reason for hiding this comment

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

I'm wondering if make sense to support dbTx?

ethtxmanager/sqlstorage/sqlstorage.go Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
ethtxmanager/memory_storage/memstorage.go Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/migrations/0001.sql Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/migrations/0001.sql Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/migrations/0001.sql Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
@Stefan-Ethernal
Copy link
Collaborator Author

Stefan-Ethernal commented Oct 1, 2024

I'm wondering if make sense to support dbTx?

Can you elaborate some more? Do you mean to be able to do multiple changes in the same transaction (basically to ensure transactional mode)?

IMO, probably doesn't make too much sense, because it is only a single table, but I'm not sure (it depends of the usage). There might be some valid use case for it 🤔

@joanestebanr
Copy link

I'm wondering if make sense to support dbTx?

Can you elaborate some more? Do you mean to be able to do multiple changes in the same transaction (basically to ensure transactional mode)?

IMO, probably doesn't make too much sense, because it is only a single table, but I'm not sure (it depends of the usage). There might be some valid use case for it 🤔

I don't known that is done internally but even with just 1 table make sense:

  • You do multiples INSERTS but want to rollback if any of them fails
  • You do some INSERTS and check something over them in another function (that need to be in the same set of data)
    Basically, it depends how works internally. But in the future make sense, that if we modify it, we think in that model because is the common in the rest of Database usage

@Stefan-Ethernal
Copy link
Collaborator Author

I don't known that is done internally but even with just 1 table make sense:

You do multiples INSERTS but want to rollback if any of them fails
You do some INSERTS and check something over them in another function (that need to be in the same set of data)
Basically, it depends how works internally. But in the future make sense, that if we modify it, we think in that model because is the common in the rest of Database usage

I discussed this with @goran-ethernal and @joanestebanr, there is no use case, where we would benefit from introducing transactional model. The transactions are affected one by one.

@Stefan-Ethernal Stefan-Ethernal force-pushed the CDK-501-seq-sender-change-current-json-file-ethtxmanager-json-for-a-database-sqlite branch from 26fc997 to d3db367 Compare October 2, 2024 12:15
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
ethtxmanager/sqlstorage/sqlstorage.go Show resolved Hide resolved
@goran-ethernal goran-ethernal force-pushed the CDK-501-seq-sender-change-current-json-file-ethtxmanager-json-for-a-database-sqlite branch from 4c36837 to db40fc9 Compare October 2, 2024 14:27
ethtxmanager/sqlstorage/sqlstorage.go Outdated Show resolved Hide resolved
@Stefan-Ethernal Stefan-Ethernal force-pushed the CDK-501-seq-sender-change-current-json-file-ethtxmanager-json-for-a-database-sqlite branch from d136818 to c009e71 Compare October 2, 2024 19:54
Copy link

sonarcloud bot commented Oct 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
66.3% Coverage on New Code (required ≥ 80%)

See analysis details on SonarCloud

@Stefan-Ethernal Stefan-Ethernal merged commit ec887ce into main Oct 3, 2024
5 of 6 checks passed
@Stefan-Ethernal Stefan-Ethernal deleted the CDK-501-seq-sender-change-current-json-file-ethtxmanager-json-for-a-database-sqlite branch October 3, 2024 06:00
Vui-Chee added a commit to okx/xlayer-ethtx-manager that referenced this pull request Nov 12, 2024
* tag 'v0.2.1':
  fix if a tx is finalized very fast (0xPolygon#84)
  Rename config parameter `DBPath` to `StoragePath` (0xPolygon#77)
  feat: implement SQL lite storage (0xPolygon#72)
  Nonce too low issues fix (0xPolygon#75)
  fix nonce too low (0xPolygon#67)
  change namespace (0xPolygon#65)
  ensure tx order (0xPolygon#64)
  Quality Gate (0xPolygon#61)
  option to avoid gas estimationi
Vui-Chee added a commit to okx/xlayer-ethtx-manager that referenced this pull request Nov 13, 2024
* tag 'v0.2.1':
  fix if a tx is finalized very fast (0xPolygon#84)
  Rename config parameter `DBPath` to `StoragePath` (0xPolygon#77)
  feat: implement SQL lite storage (0xPolygon#72)
  Nonce too low issues fix (0xPolygon#75)
  fix nonce too low (0xPolygon#67)
  change namespace (0xPolygon#65)
  ensure tx order (0xPolygon#64)
  Quality Gate (0xPolygon#61)
  option to avoid gas estimationi
KamiD pushed a commit to okx/xlayer-ethtx-manager that referenced this pull request Nov 14, 2024
* option to avoid gas estimationi

* Quality Gate (0xPolygon#61)

* add linters

* fix: lint fix

* fix: lint make file

* feat: sonar

* fix: remove unused files

* try to include coverage

* fix: change sonar cloud project key

* small fix

* fix: comments

---------

Co-authored-by: Rachit Sonthalia <[email protected]>

* ensure tx order (0xPolygon#64)

* ensure tx order

* fix: linter

* change namespace (0xPolygon#65)

* fix nonce too low (0xPolygon#67)

* Nonce too low issues fix (0xPolygon#75)

* Serial nonce update (0xPolygon#74)

* feat: prepare txns before routines

* fix: remove forcedNonce feature

* feat: uts

* fix: lint

* lint fix

---------

Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>

* feat: implement SQL lite storage (0xPolygon#72)

* feat: initial scaffolding

* feat: insert implementation

* feat: change column types based on the SQL lite supported types

* feat: changed schema, first version of CRUD operations implementation

* refactor: extract common parts to helper functions

* chore: add comments

* fix: linter config warning

* refactor: simplify in-memory storage and fix deadlocks in case of errors

* feat: instantiate either in memory or sql storage

* chore: add comment

* test: fully covered memstorage feat minor renames

* feat: add github.com/mattn/go-sqlite3 as direct dependency

* fix: adapt the DB schema, fix issues and add unit tests for sql storage

* feat: increase coverage

* test: add some more unit tests

* fix: group variables

* refactor: rename PersistenceFilename config parameter

* fix: rename helper function (address comment part 1)

* feat: introduce meddler

* chore: remove useless comments

* fix: revert update logic to manually constructing SQL and address comments from @joanestebanr (part 1)

* fix: change some columns types (address comment from @joanestebanr 2nd part)

* fix: use meddler to construct on fly update statement, address comments from @joanestebanr (part 3)

* feat: remove in memory storage, change block_number to BIGINT (address @joanestebanr part 4)

* fix: remove redundant code

* feat: simplify building of UPDATE clause

* rebase fix

* refactor: build base select and base delete statement dynamically (address comment from @arnaubennassar)

* test: concurrent write to the database unit test

---------

Co-authored-by: Goran Rojovic <[email protected]>

* Rename config parameter `DBPath` to `StoragePath` (0xPolygon#77)

* fix if a tx is finalized very fast (0xPolygon#84)

* fix

* comment

* # This is a combination of 3 commits.
# This is the 1st commit message:

Merge `dev` into upstream v0.2.1

# This is the commit message #2:

Fix lint errs

# This is the commit message #3:

Comment interface method

* parent 4da7722
author Vui-Chee <[email protected]> 1731548943 +0800
committer Vui-Chee <[email protected]> 1731548943 +0800

parent 1b8de9d
author Vui-Chee <[email protected]> 1731476344 +0800
committer Vui-Chee <[email protected]> 1731548582 +0800

Merge `dev` into upstream v0.2.1

Fix lint errs

Comment interface method

Fix configure (#3)

* fix configure

* keep the same with genesis

Silence sonar cloud

go mod tidy

Add back hex ut to keep consistent with `dev`

---------

Co-authored-by: Arnau <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Rachit Sonthalia <[email protected]>
Co-authored-by: Toni Ramírez <[email protected]>
Co-authored-by: Stefan Negovanović <[email protected]>
Co-authored-by: Goran Rojovic <[email protected]>
Co-authored-by: Alonso Rodriguez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants