-
Notifications
You must be signed in to change notification settings - Fork 14
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: persistent storage #462
Conversation
2b0f792
to
378368e
Compare
Codecov Report
@@ Coverage Diff @@
## feat/new-storage-scheme #462 +/- ##
===========================================================
+ Coverage 52.04% 52.90% +0.86%
===========================================================
Files 57 64 +7
Lines 4206 4682 +476
Branches 868 934 +66
===========================================================
+ Hits 2189 2477 +288
- Misses 1923 2111 +188
Partials 94 94
... and 2 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -4,6 +4,7 @@ on: | |||
branches: | |||
- dev | |||
- master | |||
- feat/new-storage-scheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make the CI run on the PR, it will be removed before being merged.
.github/workflows/main.yml
Outdated
@@ -10,13 +10,14 @@ on: | |||
branches: | |||
- dev | |||
- master | |||
- feat/new-storage-scheme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to make the CI run on the PR, it will be removed before being merged.
} | ||
} | ||
|
||
describe("LevelDB persistent store", () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} | ||
// The order should follow the index ordering | ||
expect(values).toStrictEqual(['b', 'a', 'c']); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra blankline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
index.js
Outdated
@@ -9,7 +9,9 @@ const txMiningApi = require('./lib/api/txMining'); | |||
const versionApi = require('./lib/api/version'); | |||
const axios = require('./lib/api/axiosInstance'); | |||
const metadataApi = require('./lib/api/metadataApi'); | |||
const storage = require('./lib/storage'); | |||
const storage = require('./lib/storage/storage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const storage = require('./lib/storage/storage'); | |
const { Storage } = require('./lib/storage/storage'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
index.js
Outdated
@@ -57,7 +59,9 @@ module.exports = { | |||
ErrorMessages: ErrorMessages, | |||
constants, | |||
axios, | |||
storage: storage.default, | |||
Storage: storage.Storage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storage: storage.Storage, | |
Storage, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
setupTests.js
Outdated
@@ -72,4 +72,9 @@ expect.extend({ | |||
}); | |||
|
|||
|
|||
global.window = {}; | |||
// global.window = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
src/storage/leveldb/history_index.ts
Outdated
|
||
try { | ||
await this.tsHistoryDB.get(`${value.timestamp}:${value.tx_id}`); | ||
} catch(err: unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} catch(err: unknown) { | |
} catch (err: unknown) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/storage/leveldb/store.ts
Outdated
if (process.version < 'v14.14.0') { | ||
// rmSync was introduced in v14.14.0, earlier versions should use rmdirSync | ||
// https://nodejs.org/docs/latest-v14.x/api/fs.html#fs_fs_rmdirsync_path_options | ||
fs.rmdirSync(this.dbpath, { recursive: true }); | ||
} else { | ||
fs.rmSync(this.dbpath, { recursive: true, force: true }); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method already returns a promise, why do we need to use the sync methods?
This will only cause clients using our lib and calling destroy() to be slower as it will block the event loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Started using async version or rm
|
||
async saveAddress(info: IAddressInfo): Promise<void> { | ||
if (!info.base58) { | ||
throw new Error('Invalid address'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have standard errors like the ones in errors.ts so they can be better handled?
e.g.
class InvalidAddressError extends Error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also believe we should create a standard error, but since it would affect both the persistent storage files and the base storage scheme implementation I think we should make this on its own PR, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, can you create an issue so we don't forget to refactor this?
00a8d5d
to
4fcf868
Compare
920957d
to
66121af
Compare
src/storage/leveldb/history_index.ts
Outdated
} | ||
|
||
/** | ||
* Run a full count of the txs in the database. | ||
* Since we have made a full count we can update the tx count in the database. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also remove this line in the address index file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed from the other file
* feat/new-storage-scheme: chore: rename methods
Acceptance Criteria
IStore
interfaceSecurity Checklist