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: leveldb #44

Merged
merged 2 commits into from
Sep 26, 2023
Merged

feat: leveldb #44

merged 2 commits into from
Sep 26, 2023

Conversation

mfw78
Copy link
Contributor

@mfw78 mfw78 commented Sep 21, 2023

Description

Given that we are already using a NoSQL database and we need some storage, I dropped in leveldb as the NoSQL solution. This allows us to eliminate all external dependencies, making it friendlier for spinning up in bandwidth constrained environments (ie. hackathons), and reduces complexity with deployment (no requirement for external SQL servers).

Changes

  • Removed all references to Tenderly context / storage.
  • Added level packages and `ts.
  • Created db singleton for holding the database.
  • Removed all secrets as these are now defined by commander.
  • Refactored init to remove await that were dependent on secret lookups previously.

How to test

No testing for this PR, besides eslint and prettier passing, excluding to-be-deprecated actions. This PR is mostly for "readability".

Related Issues

Closes #40

@mfw78 mfw78 added the enhancement New feature or request label Sep 21, 2023
@mfw78 mfw78 requested review from anxolin and a team September 21, 2023 17:06
@mfw78 mfw78 self-assigned this Sep 21, 2023
@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
level-ts 2.1.0 filesystem, environment +43 8.58 MB notryan
level 8.0.0 environment +14 6.53 MB vweevers

src/types/model.ts Outdated Show resolved Hide resolved
Comment on lines +12 to +15
throw new Error(
"Error: Instantiation failed: Use DBService.getInstance() instead of new."
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What about making it a singleton?
If the instance already exists just return it rather than throwing

src/utils/db.ts Outdated Show resolved Hide resolved
@mfw78 mfw78 linked an issue Sep 24, 2023 that may be closed by this pull request
@@ -11,8 +10,18 @@ export interface RunOptions extends WatchtowerOptions {
rpc: string[];
deploymentBlock: string[];
Copy link
Contributor

Choose a reason for hiding this comment

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

why was the deploymentBlock an array?
is this how you plan to run it in multiple networks? If so, in principle, it feels a better idea to use separated instances


export type DBLevel = Level<string, string>;

export default class DBService {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This name is a bit generic (but it depeds on Level db).

It would be great if you can use the Repository or DAO pattern to abstract the persistance. This way, this implementation will use Level DB, but others could use anything else.

This could have a repository or DAO layer, and then you create a ContextRepository interface, with a ContextRepositoryLevel or ContextRepositoryImpl (since we don't have more)

src/utils/db.ts Outdated Show resolved Hide resolved
}

public getDB() {
return this.db;
Copy link
Contributor

Choose a reason for hiding this comment

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

If you use the repository pattern, you would not expose this, but would provide for the service layer the basic CRUD operations you need

}

export type SingularRunOptions = Omit<RunOptions, "rpc" | "deploymentBlock"> & {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we should have "plural" TBH, this should be the default run

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Great PR!

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Great PR!

Adding some comments, no need to address for this PR, but it would be great to consider for the top of the waterfall

Copy link
Contributor

@anxolin anxolin left a comment

Choose a reason for hiding this comment

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

Great PR!

Could you ignore the db in git?
image

src/utils/db.ts Outdated Show resolved Hide resolved
@mfw78 mfw78 changed the base branch from feat-commander to standalone September 26, 2023 05:05
@mfw78 mfw78 mentioned this pull request Sep 26, 2023
9 tasks
@mfw78 mfw78 merged commit faf4637 into standalone Sep 26, 2023
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2023
@alfetopito alfetopito deleted the feat-leveldb branch September 26, 2023 08:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: use leveldb for persistence
3 participants