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

Wiring for Custom Datadir #408

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

D33r-Gee
Copy link
Contributor

@D33r-Gee D33r-Gee commented Jun 15, 2024

This pull request builds upon previous issues (#390, #392, and #397) by re-introducing the functionality for users to specify a custom data directory (datadir) during the onboarding process.

The majority of changes in qml/bitcoin.cpp are mainly splitting the onboarding and node creation so that the user can set their preferred datatdir it's inspired by the qt/bitcoin.cpp however it uses the anonymous namespace instead of using a class. The intention came from feedback on #390

In the QML pages, the node_model context property is no longer been initialized during onboarding. We're now using options_model instead. This means the code has been updated to use the options_model for settings that were previously set with the node_model context property.

Support for the Android version is being added to this PR.

Copy link
Contributor

@johnny9 johnny9 left a comment

Choose a reason for hiding this comment

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

https://github.com/bitcoin-core/gui-qml/actions/runs/9523738145/job/26255610402?pr=408

qml/models/options_model.cpp:232:9: error: use of undeclared identifier 'settings'
        settings.setValue("strDataDir", path);
        ^

Android builds are failing. Will need that fixed.

My testing on desktop seemed to work well. I had one odd thing happening. After onboarding, I tried again with using -resetguisettings and the onboarding page had a strange Custom path as the initial selection. I imagine this is maybe just resetguisettings not clearing out the datadir in QSettings but haven't dug in yet.

Screenshot from 2024-06-14 23-26-36

@D33r-Gee
Copy link
Contributor Author

Thanks @johnny9 for testing

Android builds are failing. Will need that fixed.

addressed it for now with the latest push 679818a

My testing on desktop seemed to work well. I had one odd thing happening. After onboarding, I tried again with using -> > resetguisettings and the onboarding page had a strange Custom path as the initial selection. I imagine this is maybe just resetguisettings not clearing out the datadir in QSettings but haven't dug in yet.

Addressed the above for now... although there are a few issues when using the -resetguisettings flag, so a question I have is is it crucial to address them here or can they be addressed in later PRs that specifically tackle them?

Copy link
Contributor

@MarnixCroes MarnixCroes left a comment

Choose a reason for hiding this comment

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

679818a

  • during onboarding, when clicking Custom datadir it gives this output in terminal
Model size of -106 is less than 0
Model size of -6 is less than 0
  • startNode and startOnboarding have a lot of duplicate code. maybe consider extracting common functionality to avoid duplication?

src/qml/components/StorageLocations.qml Show resolved Hide resolved
src/qml/bitcoin.cpp Outdated Show resolved Hide resolved
@D33r-Gee
Copy link
Contributor Author

679818a

Thanks testing and reviewing @MarnixCroes

  • during onboarding, when clicking Custom datadir it gives this output in terminal
Model size of -106 is less than 0
Model size of -6 is less than 0

Hmmm... not sure what that is... will look into it

  • startNode and startOnboarding have a lot of duplicate code. maybe consider extracting common functionality to avoid duplication?

Yes some refinement can be done there... will look into how best approach it

@D33r-Gee
Copy link
Contributor Author

Currently tackling a strange beahvior involving the custom datadir and reading the settings files:

when going through first setup it up it works great and the settings.json file is created in the the proper place...

However on restart it seems like it doesn't read the settings.json file from the new datadir and only looks in the default directory.

Right now trying to see how that can be addressed... will update soon with what I find

@D33r-Gee
Copy link
Contributor Author

with aebfc89 addressed the settings.json file not being read on restart by moving the gArgs.ReadSettingsFile right before node creation in qml/bitcoin.cpp

Now will tackle the -resetguisettings not updating the datadir location right away

@D33r-Gee
Copy link
Contributor Author

with the latest update 5ef5d19 addressed the -resetguisettings discrepencies.

It now resets to defaults and allows for changing the datadir

Next will tackle code optimization...

@D33r-Gee
Copy link
Contributor Author

This update 6d4c111 is the first pass at optimizing the qml/bitcoin.cpp code.

There are no major functionality updates, mainly code consolidation.

@D33r-Gee
Copy link
Contributor Author

  • during onboarding, when clicking Custom datadir it gives this output in terminal
Model size of -106 is less than 0
Model size of -6 is less than 0

@MarnixCroes are you still seeing the above pop-up with 6d4c111?

Copy link
Contributor

@pablomartin4btc pablomartin4btc left a comment

Choose a reason for hiding this comment

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

tACK 6d4c111

Normal use case, running bitcoin-qt and setting the custom data dir in one go, works as expected.

A use case that has an issue I think, which is selecting a custom datadir, going back to the default, I can't manage to set a custom datadir back, the default remains selected and this is working in main.

I got this crash (not always but quite common) when I click on the "Custom" component:

./src/qt/bitcoin-qt -signet
Warning: Ignoring XDG_SESSION_TYPE=wayland on Gnome. Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.
**
Gtk:ERROR:../../../../gtk/gtkpathbar.c:1342:set_button_image_get_info_cb: assertion failed: (cancellable == data->button_data->cancellable)
Bail out! Gtk:ERROR:../../../../gtk/gtkpathbar.c:1342:set_button_image_get_info_cb: assertion failed: (cancellable == data->button_data->cancellable)
Aborted (core dumped)

To reproduce it delete any settings.json and any "BitcoinCore-App*.conf" in home/.config/BitcoinCore.

Code-wise I need more time to check the changes, especially the last commit, cannot be split? It would be useful to add a brief description of the intention, what's the intention of the changes in the protocol of bitcoin.cpp (re-structuring it for clarity? something was missing/ needed?).

On the first commit, the commit name doesn't explain much either (eg , it seems there's a refactoring within, what's the motivation behind making node a pointer instead of a reference? If you check the code in core/ qt it's always defined as &. Is there an issue you are trying to solve or just syntax or semantic?).

@@ -10,6 +10,7 @@
#include <cstddef>
#include <map>
#include <string>
#include <univalue.h>
Copy link
Contributor

Choose a reason for hiding this comment

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

Every commit should pass compilation and all tests so if the failure occurs on the previous commit you should include it there (we are missing the "CI / test each commit (pull_request)" that exists on the other repos and I think @hebasto has it pending with other things he wanted to merge here into this repo).

src/qml/models/nodemodel.h Outdated Show resolved Hide resolved
@MarnixCroes
Copy link
Contributor

  • during onboarding, when clicking Custom datadir it gives this output in terminal
Model size of -106 is less than 0
Model size of -6 is less than 0

@MarnixCroes are you still seeing the above pop-up with 6d4c111?

I do not

@D33r-Gee
Copy link
Contributor Author

Thanks @pablomartin4btc for testing and for your questions.

what's the intention of the changes in the protocol of bitcoin.cpp (re-structuring it for clarity?

The majority of changes in qml/bitcoin.cpp are mainly splitting the onboarding and node creation so that the user can set their preferred datatdir it's inspired by the qt/bitcoin.cpp however it uses the anonymous namespace instead of using a class. The intention came from feedback on #390

what's the motivation behind making node a pointer instead of a reference?

I'm assuming you are referencing:

OptionsQmlModel::OptionsQmlModel(interfaces::Node* node, bool is_onboarded)

if so the logic there came from having to initiate the options_model in qml/bitcoin.cpp with the node as a nullptr. And this was a way for it to work with the least amount of changes.

If you check the code in core/ qt it's always defined as &. Is there an issue you are trying to solve or just syntax or semantic?).

Yes in qt/bitcoin.cpp the OptionsModel is initiated through a reference because node creation doesn't happen until the splashscreen/intro have gone through and no settings are being set with the OptionsModel.

On the other hand in qml/bitcoin.cpp the options_model is needed for onboarding so initiating it with a nullptr is allowing the QML context property to be set without Node initiation.

Copy link
Contributor

@MarnixCroes MarnixCroes left a comment

Choose a reason for hiding this comment

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

7a34b0d
did some manual testing, so far works ok

some commits could be squashed imo, also as Pablo mentioned here #408 (comment)

src/qml/components/AboutOptions.qml Outdated Show resolved Hide resolved
src/qml/models/options_model.cpp Outdated Show resolved Hide resolved
@D33r-Gee
Copy link
Contributor Author

D33r-Gee commented Jul 1, 2024

Thanks @MarnixCroes for testing and @hebasto for the comments.

Will update once more with cleaner and clearer commits...

Also working on the Android version... Found a workaround for QSettings not working with Android, will post Android related commits soon...

@D33r-Gee D33r-Gee force-pushed the qml-datadir-custom-wiring branch 2 times, most recently from 8ae13b8 to 2cf64dd Compare July 2, 2024 19:26
@D33r-Gee
Copy link
Contributor Author

D33r-Gee commented Jul 2, 2024

This update 2cf64dd introduces Android functionality by creating qml/androidcustomdatadir files. This allows the app to retrieve the custom data directory path, if previously set by the user.

}
}

QGuiApplication* m_app;
Copy link
Contributor

Choose a reason for hiding this comment

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

statically defining all of these pointers is concerning. Eventhough it is redundant it feels safer to keep a lot of these withing the function scopes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok thanks for looking into it... will refactor further to use arguments instead of pointers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After our online chat, let's keep things as is with the caveat that if any issues arise due to the static pointers we'll have to refactor further. Resolving for now...

Copy link
Member

Choose a reason for hiding this comment

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

After our online chat...

Could the main points from that discussion be posted here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To summarize our convo: We talked about the safety of static pointers in the code. We thought about adding a class like in #390, however decided to leave them for now, since there might be issues raised by @jarold that we need to consider first. That said we both agreed that having a clear owner for pointers is usually a good idea for better code management. Is there anything I missed @johnny9 ?

Copy link
Contributor

@johnny9 johnny9 left a comment

Choose a reason for hiding this comment

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

tACK 2cf64dd

Onboarded with a custom directory, started IBD, then restarted the application to make sure the application continued to use the custom directory. Worked on both Linux Desktop and Android.

@hebasto
Copy link
Member

hebasto commented Jul 12, 2024

The https://github.com/bitcoin-core/gui-qml/pull/408/files#r1658350670 still needs to be addressed.

src/qml/bitcoin.cpp Outdated Show resolved Hide resolved
}
}

QGuiApplication* m_app;
Copy link
Member

Choose a reason for hiding this comment

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

After our online chat...

Could the main points from that discussion be posted here?

src/qml/bitcoin.cpp Outdated Show resolved Hide resolved
src/qml/bitcoin.cpp Outdated Show resolved Hide resolved
@D33r-Gee
Copy link
Contributor Author

b67ae97 the Data Directory in the GUI is also incorrect (displays the default one) when user runs with -datadir start up param

Ah that's a great find... hadn't tested that... ok will update

@D33r-Gee D33r-Gee force-pushed the qml-datadir-custom-wiring branch 2 times, most recently from acadaf8 to 94215e5 Compare July 18, 2024 18:14
@D33r-Gee
Copy link
Contributor Author

updated to 94215e5 it now displays the proper datadir when using the -datadir arg

I can still repro it on b67ae97

ok that's a bummer... will keep investigating although it's difficult to know since I'm not able to repro... will ask around

@D33r-Gee
Copy link
Contributor Author

@MarnixCroes RE: the GTK crash, are you using the depends (static build) or are you using dynamic to compile?

@MarnixCroes
Copy link
Contributor

@MarnixCroes RE: the GTK crash, are you using the depends (static build) or are you using dynamic to compile?

yes using the depends
(Pablo also encountered it earlier #408 (review))

@D33r-Gee
Copy link
Contributor Author

@MarnixCroes RE: the GTK crash, are you using the depends (static build) or are you using dynamic to compile?

yes using the depends (Pablo also encountered it earlier #408 (review))

ok when you run dpkg -l "*gtk*" | grep ii do you get this : ii qt5-gtk-platformtheme:amd64 5.15.3+dfsg-2ubuntu0.2 amd64 Qt 5 GTK+ 3 platform theme ?

@MarnixCroes
Copy link
Contributor

ok when you run dpkg -l "*gtk*" | grep ii do you get this : ii qt5-gtk-platformtheme:amd64 5.15.3+dfsg-2ubuntu0.2 amd64 Qt 5 GTK+ 3 platform theme ?

yes

@hebasto
Copy link
Member

hebasto commented Aug 12, 2024

Please rebase to resolve conflicts.

@D33r-Gee
Copy link
Contributor Author

rebased over main with 8d53c44

tested out on WSL Ubuntu 22.04 however didn't tested out on Android...

src/qml/bitcoin.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@MarnixCroes MarnixCroes left a comment

Choose a reason for hiding this comment

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

8d53c44

apart from the know crash issue (which happens occasionally) the previous issues are fixed and it works as expected.

commit history could still be improved (commits like c1067d1) which was also previously mentioned c1067d1#r1658350670

@D33r-Gee
Copy link
Contributor Author

D33r-Gee commented Sep 9, 2024

rebased over main with 370bc64

Addressed @MarnixCroes comment.

Tested on both Ubuntu 22.04 and Android

@jarolrod jarolrod added the enhancement New feature or request label Sep 12, 2024
@johnny9
Copy link
Contributor

johnny9 commented Sep 20, 2024

ACK 370bc64

tested the flow on Desktop and Android and both worked as expected without any crashing.

Desktop
Screenshot from 2024-09-17 15-23-46
Screenshot from 2024-09-17 15-23-30

Android:
Screenshot from 2024-09-17 00-11-56
Screenshot from 2024-09-17 00-12-12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants