-
Notifications
You must be signed in to change notification settings - Fork 81
Wallet: move database to sqlite, remove kv and memmory db #804
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
base: master
Are you sure you want to change the base?
Conversation
| fn init_tables(&self) -> Result<()> { | ||
| self.conn.lock()?.execute_batch( | ||
| " | ||
| CREATE TABLE IF NOT EXISTS addresses ( | ||
| script_hash TEXT PRIMARY KEY, | ||
| data BLOB NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS transactions ( | ||
| txid BLOB PRIMARY KEY, | ||
| data BLOB NOT NULL | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS descriptors ( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| descriptor TEXT NOT NULL UNIQUE | ||
| ); | ||
|
|
||
| CREATE TABLE IF NOT EXISTS metadata ( | ||
| key TEXT PRIMARY KEY, | ||
| value BLOB NOT NULL | ||
| ); | ||
| ", | ||
| )?; | ||
| Ok(()) | ||
| } |
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 still looks like a KVDB, but in SQLite, what's the benefit?
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 wanted for this PR to be simple to review and merged.
For sure further optimizations taking more advantage of the greatness of SQL can be proposed, but I want for this to be the first step.
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.
@GustavoStingelin we want to get rid of the kv dependency.
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.
tks
90f9da2 to
a5e86c3
Compare
|
a5e86c3: Im seeing some build related problems, it appears that |
ba07354 to
14231f8
Compare
|
37e383c: Okay, this commit fixed the build problem i was having. Basically what happened is that they were bundling pre-generated bindings and that was triggering a version compatibility problem basicaly because rust doesnt want to have a stable ABI, it can change trough versions affecting bindings and yada yada. They took that decision to avoid bigger compile times but that doesnt appear to be a big problem, well... To solve that i activated the feature that should generate the bindings on the go and it worked, otherwise i would need to find a rusqlite version that was bundling the correct bindings for our MSRV and pin it, and im not sure if that would support our case. If anyone want to further investigate to help me being sure that was the correct decision: |
Davidson-Souza
left a comment
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.
| let value = serde_json::to_vec(&address).expect("Invalid object serialization"); | ||
|
|
||
| self.conn | ||
| .execute( | ||
| "INSERT OR REPLACE INTO addresses (script_hash, data) VALUES (?1, ?2)", | ||
| params![key, value], | ||
| ) | ||
| .expect("Fatal: Database isn't working"); |
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.
9cbc9f1
So, you plan to make this more sql-like in a follow-up (#804 (comment))? Because we definitely should stop using json here. But I understand if the goal is to do this in a follow-up
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 was not planning to be the one to optimize the tables, because this was the very first time that I actually did something with SQL besides hating it in exams lol.
But I can totally do that, ill just need some more time studying the use of SQL, im also writing the PR for our wallet to be descriptor based with SQL in mind.
Regarding the use of json, I really thought of that being a problem because of jsons bloat but it was simple enough for a first implementation.
After searching solutions besides using json, ill prefer to follow an approach using BLOBS for rust-bitcoin types and mapping primitives for other data.
I can already get rid of serde_json for watch-only in this PR without much overhead, but theres room to upgrade, we can optimize types and tables so they can talk better, and I plan to do that in the Descriptor Based PR.
I know that schwab proposed for us to migrate to BDK but i see that change being more radical and having more concerns than what I want to do with the descriptor based PR. I feel that this will be something more for the future, what im trying to do now is just making easier to handle descriptors around in floresta.
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 know that schwab proposed for us to migrate to BDK but i see that change being more radical and having more concerns than what I want to do with the descriptor based PR.
Yes, migrating to BDK is something for the future as it still needs some work upstream such that it plays nicely with Electrum's transaction Merkle proofs.
| let value = serde_json::to_vec(&address).expect("Invalid object serialization"); | ||
|
|
||
| self.conn | ||
| .execute( | ||
| "INSERT OR REPLACE INTO addresses (script_hash, data) VALUES (?1, ?2)", | ||
| params![key, value], | ||
| ) | ||
| .expect("Fatal: Database isn't working"); |
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.
Propagate error here
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.
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.
It can return a Result<(), SqliteError>, so it can return an error and therefore panic. You should propagate the error upwards.
6f0f109 to
05134fe
Compare
|
Notable changes on 57695dc
|
4252dbd to
090fe9d
Compare
090fe9d to
c8199b4
Compare
c8199b4 to
47bd5c7
Compare
Davidson-Souza
left a comment
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.
Your commits are in reverse chronological order. What happened?
| self.database.save(&new_address); | ||
| self.database | ||
| .save(&new_address) | ||
| .expect("Database not working"); |
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.
Errors that can happens should either be handled or propagated
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.
again, that refers to another method that does not return a result and IMHO changing this method would be out-of-scope for this pr.
Yeah, i reversed the commits because its easier to apply suggestions on the latest commit instead of the first... The old order was erroring while editing the first commit because of feature flags and deprecation changes |
47bd5c7 to
cfaa2ab
Compare
|
Applied @Davidson-Souza suggestions |
cfaa2ab to
e358b7f
Compare
|
Blank push -f, for some reason the CI just DIED |
Description and Notes
Addressing #665, I implemented the existing
AddressCacheDatabasetrait on top ofrusqlite, the only feature that the changes present is "bundled" which they declared to be better when regarding windows support.Regarding the implementation, it is pretty straightforward, I had the other two databases,
memmory_database.rsandkv_database.rsto be inspired. I think the tests are extensive and ensure the implementation runs fine, for every commit I made sure forjust lint-featuresandjust test-featureto also run fine.How to verify the changes you have done?
Review tests under
sqlite_database.rsand run them.Since this present a lot of features changes, running
just lint-featuresandjust test-featureis good.Contributor Checklist
just pcc(recommended but slower)just lint-features '-- -D warnings' && cargo test --releaseFinally, you are encouraged to sign all your commits (it proves authorship and guards against tampering—see How (and why) to sign Git commits and GitHub's guide to signing commits).