Commit Graph

55 Commits (29f697560169db6c1c9b48f2794c98480cc9c5ca)
 

Author SHA1 Message Date
alex 29f6975601
nd,ngui: remove memleaks and deadlocks mostly from v0.4.0
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
the offending memleak printed out at program exit was introduced in
116fb3b5, specifically line 140 in src/bitcoindrpc.zig using incorrect
allocator.

while there, improved a bit overall memory handling by making sure
heap-alloc'ed messages are always deinit'ed.

another source of trouble was logging from within a sighandler: the
logger uses a thread mutex which may deadlock when the handler is
invoked by the OS.
1 year ago
alex 280bea40df
nd/conf: link to sysupdates repo in doc comments
it is important the constants in Config.zig match those in sysupdates.
somehow should've made it into 664c75a9 but never did.
1 year ago
alex c82848d186
nd,ngui: let users switch sysupdates channel from the UI
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
at the moment, there are two channels: edge and stable.

this builds up on few previous commits, most notably the persistent
configuration storage.
1 year ago
alex 1d8d67a987
ui/lvgl: add a dropdown widget 1 year ago
alex e8838b3eaf
ui/lvgl: add an optional spinner to card widget
some cards will need to show a nondeterministic progress.
the spinner in the top right corner does exactly that, controlled
via the new spin function.

the default is no spinner.
1 year ago
alex 094f6406e3
ui/lvgl: add a couple convenience methods for next commits
small things like show/hide and enable/disable. also, the text of the
button can now be set directly using its label field.
1 year ago
alex 664c75a9c9
nd: add a persistent configuration support
the config will be used by the daemon to store user choices across
reboots.

closes #6
1 year ago
alex aca7eb1165
comm: introduce a simpler way to read/write
this builds on top of the main read and write fn, setting up a global
structure to allow module users imply comm.pipeWrite(msg)
and comm.pipeRead() without providing an allocator or reader/writer
on each call.

the advantage is simplification in the gui functions because they don't
have access to an allocator or the nd process read/write pipe.

disadvantage is in testing because it requires a global,
"before all tests" setup.

at the moment, only ngui is modified to use the new pipeRead/Write. the
daemon would suffer too many changes, especially in tests, due to the
global state.
1 year ago
alex a18a2a5435
lndhttp: remove nonexistent field from pending chan list
funding_expiry_blocks is present in lightning.proto but a REST API call
shows no such field, at least in lnd v0.16.4, leading to json parsing error.

the field is unused at the moment anyway.
1 year ago
alex 116fb3b59c
nd,ngui: display on-chain balance in bitcoin tab
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
a previous commit added some lightning tab implementation which
including balance details but only for lightning channels.

this commit queries lnd for a wallet balance and displays it on the
bitcoin tab since "wallet" funds are on-chain and it doesn't feel like
it belongs to the lightning tab in the UI.

while there, also improved some daemon backend code style, alightning
with the lightning implementation structures.
1 year ago
alex 05c89bbd1c
ui: visualize lnd lightning report on the tab panel
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
similarly to 0260d477, the lightning tab has now some basic info
including channels list.

the gui playground is updated to send some stub data via comms
periodically.
1 year ago
alex 52a8c1fb1a
nd: add lnd lightning report sent to UI every min
similarly to 2642a554, this adds an lnd HTTP client able to make some
queries like getinfo. the daemon then uses the client to compose a
lightning status report and sends it over to ngui through comms,
periodically.

there's also a client playground built on demand with
"zig build lndhc".
1 year ago
alex 328df67c5d
zig: upgrade from 0.10.x to 0.11.0
ci/woodpecker/push/woodpecker Pipeline was successful Details
while there's lots of changes and new features in zig v0.11.0, the most
important for this project at the moment is the HTTP client.
the client is most likely what will connect to lnd lightning node to
fetch stats and info for the UI to then visualize it on "lightning" tab,
similar to the bitcoind RPC client.

see all zig 0.11 release notes here:
https://ziglang.org/download/0.11.0/release-notes.html
1 year ago
alex e84489c345
ui: keep last comm reports to update on wakeup
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
a previous commit a06a4757 stopped updating the UI while in standby
mode. unfortunately, this makes the UI data become stale on wakeup.
for example, bitcoin chain height and its timestamp.

this commit keeps the last report received from daemon comm during
standby and uses it to update the UI immediately on wakeup.
1 year ago
alex a06a4757b2
ngui: clarify and handle concurrency during screen sleep/standby
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
the screen.sleep fn was actually called in concurrent-unsafe mode,
i.e without acquiring UI mutex. in conjuction with commThreadLoopCycle
this would have eventually led to LVGL primitives concurrent access.

so, screen.sleep now takes UI mutex to hold during LVGL calls.
a bit ugly but certainly better than relying on luck.
1 year ago
alex 0260d47747
ui: visualize bitcoind status report on the tab panel
the bitcoin tab has now some basic status and stats: parts of blockchain
info, network info and mempool. this is far from complete but makes a
good start for an initial version.

the gui playground is also updated to sent some stub info via comms
periodically.
1 year ago
alex 2642a55477
nd: add bitcoin core report sent to UI every min
this adds a very simple bitcoind RPC client able to make a few queries
like the blockchain and network status. the daemon uses the client
to get the bitcoind status and sends a report through comms periodically.

there's also a little playground program which simply dumps a query
result to stderr. built on demand with "zig build btcrpc".
1 year ago
alex c1a809c567
ui/lvgl: fix a bug where a top container didn't have its object created
ci/woodpecker/push/woodpecker Pipeline was successful Details
a previous commit 7d1ab5cb rewrote toplayer objects creation as
Container.newTop except the new code was using the top layer object
obtained from lv_disp_get_layer_top as is. this obviously led to all
sorts of UB and illegal memory access when screen.sleep'ing.
1 year ago
alex 7d1ab5cb78
ui/lvgl: improve UI element types in zig
ci/woodpecker/push/woodpecker Pipeline was successful Details
this commit improves on the LVGL API wrapping interface in zig by
defining different types where each is associated with either a
particular lv_xxx_t object in C or a logically different UI element.

this makes programming much more pleasant, allows compartmentalizing
different UI concepts and elements, and reduces chances of making a
thanks to stricter type enforcement.

no visual changes in the UI.
1 year ago
alex 746b179478
ui: force alignment of modal callback function
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
fullscreen modal dialog was added in 4297c139. the callback function to
that modal *must* be aligned according to the target architecture.
failing to do so may result in "incorrect alignment" panic.

this somehow worked in 4297c139 but sometimes panic. i suspect this may
be due to PIE-enabled build, possibly in conjuction with some zig v0.10
compiler bugs.

ref #20
ref #5
1 year ago
alex 63eb27bf18
nd,ngui: make program termination reliable on SIGTERM
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
most troubles were due to blocking nature of child process pipe
descriptions which made comm.read loops hang in various places
under certain conditions.

this commit moves all read/writes in separate threads to be able to
always watch for sig TERM and INT, and ensures child process pipes
are closed early allowing comm.read loops to terminate.
1 year ago
alex 532581a246
ngui: display poweroff progress during system shutdown
ci/woodpecker/pr/woodpecker Pipeline was successful Details
ci/woodpecker/push/woodpecker Pipeline was successful Details
this greatly improves UX during shutdown: no need to guess at which
point it's ok to unplug the power cord.

the commit also includes a GUI playground. a sort of a fake daemon which
sends hardcoded messages to ngui. useful for manual debugging and trying
different UX scenarious.
1 year ago
alex 78df4ad7ee
nd: poweroff with progress report to ngui
the daemon now sends info about the system shutdown progress: a list of
important services which may require up to several minutes to stop such
as lnd lightning daemon and bitcoin core.

see next commit for how this info is displayed and used by the GUI.
1 year ago
alex a7c560e92a
build: switch LVGL default logging from info to warn
ci/woodpecker/push/woodpecker Pipeline was successful Details
this hides all LVGL info messages about UI interactions like events,
making the log output more useful during development.

it is still possible to increase verbosity to the original level using
the lvgl_loglevel build flag.
1 year ago
alex ec5e15e8e9
build-time semantic versioning support
ci/woodpecker/push/woodpecker Pipeline was successful Details
1 year ago
alex 517f9d4056
ui: display ngui semver on a new info panel tab
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline was successful Details
this adds the 4th tab, an info-icon button, and shows the value of
the release version recorded at build time - a feature added in a
previous commit.
1 year ago
alex 7dc1f6329e
build: add semantic versioning support
both nd and ngui now acquire semantic versioning recorded at the build
time. they also report the version at startup and -v flag.
this is useful for a release process and to avoid potential
compatibility issues in the future.

in a regular build flow, the version is taken from a git tag using the
following command:

    git -C . describe --match 'v*.*.*' --tags --abbrev=8

in a non-standard scenario where git isn't available, the version can
be provided on the command line during build like so:

    zig build -Dversion=1.2.3

if both git and command line supplied versions are available, they must
match.
1 year ago
alex 53812cbd37
build: make release builds for aarch64 reproducible
ci/woodpecker/push/woodpecker Pipeline was successful Details
part of #2
1 year ago
alex 706a62a08e
build: strip C source file paths from resulting binary
ci/woodpecker/push/woodpecker Pipeline was successful Details
helps with reproducible builds, especially for releases.
1 year ago
alex 81db4aaa71
ci: add sha256sum output for aarch64 build
ci/woodpecker/push/woodpecker Pipeline was successful Details
the goal is reproducible builds.
1 year ago
alex f1784cb39d
ngui: add a way to limit LVGL logging verbosity
ci/woodpecker/push/woodpecker Pipeline was successful Details
the commit adds a build option lvgl_loglevel and sets a default similar
to that of std.log.default_level so the two are aligned more or less.
1 year ago
alex 4297c139a1
ngui: port some LVGL-based UI code from C to zig
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/pr/woodpecker Pipeline was successful Details
this commit includes lots of new code in ui/lvgl.zig and ui/widget.zig
to work with LVGL directly from zig. in fact, some C code is moved from
ui/c/ui.c to ui/xxx.zig.

in addition, a new module ui/widget.zig is where all custom UI elements
will reside. at the moment it comprises of the ported topdrop and a new
modal func. the latter is an alternative to LVGL's lv_msgbox popup.

as a practical example, the commit replaces the power off confirmation
popup with the new modal window.
1 year ago
alex c73867ea4d
ngui: get rid of the ambiguous ui header file
functions declared in ui.h were actually used by ui.c, the opposite of
what such a header is expected to contain. these functions are defined
in zig code and declarations are better off in the same ui.c file.

this is just a quick clean up before porting some C code to zig.
2 years ago
alex cb229d5a26
nd: ping ngui at start as an in-process pipe test
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
this is an attempt at identifying the underlying problem.
unclear whether this normal behaviour on a linux kernel or something to
do with zig implementation.

either way, pinging the UI makes CommReadInvalidTag error disappear on startup.

updates #16
2 years ago
alex ad8cdf727b
ngui: yield CPU during standby mode
ci/woodpecker/push/woodpecker Pipeline was successful Details
when the screen turns off, the idle loop never gave a chance CPU to
do other work and pegged at 100%. adding a short sleep each cycle
yields CPU to the OS.

closes #15
2 years ago
alex fd49235f9e
ui: implement a screen timeout after a period of user inactivity
ci/woodpecker/push/woodpecker Pipeline was successful Details
ci/woodpecker/tag/woodpecker Pipeline was successful Details
passed 60 sec of no touch screen activity, daemon turns off backlight
and gui places a black "topdrop", opposite of backdrop. simply touching
the screen reactivates it immediately.

there seem to be no way to turn screen power off, so backlight plus
black topdrop is the next best.

there's no user settings to change 60 sec timeout at the moment because it
is unclear whether it's worth adding UI elements. can always do so later.

the implementation also provides means to reactivate the screen in
an event of an alert from the daemon in the future.

closes #3
2 years ago
alex 021c810dc7
ui: move all C lvgl/zig code into lvgl.zig and drv.zig
the idea is for all zig code to use C LVGL only via this
new module lvgl.zig, all display and input driver/devices is handled
by drv.zig.

this makes C/zig nicely compartmentalized in just a handful places.
2 years ago
alex 5c60b92f85
ci: run lint, tests and build for each commit
ci/woodpecker/push/woodpecker Pipeline was successful Details
the CI uses a custom image produced by tools/ci-containerfile.
see instructions in the readme.

CI logs are at https://woodpecker.qcode.ch/nakamochi/ndg
2 years ago
alex fe68ae96d6
comm: format protocol header manually and eliminate a potential footgun
the nd/ngui protocol is a simple TLV: message tag, length and
a json-encoded payload. the issue is with the (tag, length) header which
was written/read by using raw memory pointers, such as
Writer.writeStruct. in addition, tag ordinal values were auto-generated
by the compiler.

all those deficiencies may potentially lead to bugs hard to find or
serious data leaks.

serializing and deserializing the (tag, length) header manually
makes it more robust and eliminates the footgun.
2 years ago
alex ae7c3b2db8
tools: be silent when checking c code formatting
no news is good news. and either way, clang-format verbose mode is
inconsistent with zig fmt. the latter outputs only malformatted files.
2 years ago
alex 3f6c0aef44
git: add 2ecd44a7 to blame-ignore list 2 years ago
alex 2ecd44a7db
ui/c: workaround clang-format's pointer alignment in a define
it is actually multiplication, not a pointer. reads nicer this way.
2 years ago
alex 6a93ba9a30
zig: switch from stage1 to the new stage2 compiler
stage2 has been merged and set as default around end of aug 2022 in
https://github.com/ziglang/zig/pull/12368. since then the main focus has
been on this new stage2 compiler.

with the release of 0.10.1 the stage2 is fairly useable now and it is
the way forward, towards zig 0.11 or 1.0. read more about difference in
https://github.com/ziglang/zig/wiki/Self-Hosted-Compiler-Upgrade-Guide

another good read on the relevant topic is
https://ziglang.org/news/goodbye-cpp/
2 years ago
alex c08ded524e
docs: a quick local dev setup and contributing sections
while there, made test filter actually work with

    zig build test -Dtest-filter=xxx

a previous invocation with `--test-filter` never worked.
2 years ago
alex 698e5b6f76
src,lib: zig fmt and clang-format all code
C style is now fixed by .clang-format.
a handy script to check all source code formatting is in
tools/fmt-check.sh.
2 years ago
alex 161a2b965b
license: add qeles AG to copyright holders
qeles AG is now a significant contributor, too.
https://qeles.ch
2 years ago
alex 5332d00290 ngui: make it work with zig release v0.10.0
only one tiny change: @maximum -> @max.
nothing to do for nd.
2 years ago
alex 7226c31dfb nd: increase services stop timeout to 10min but in parallel
10min looks quite excessive but based on conversations in
https://github.com/bitcoin/bitcoin/commit/7fb7acfc, better safe than
sorry. same for lnd. in any case, 30sec was indeed far too short to
begin with, especially for bitcoind.

services are now stopped in parallel, though. so, the poweroff sequence
goes faster.
2 years ago
alex 0266125c65 ui: increase default font from 14px to 16px for readability
16px looks easier to read but IPv6 addresses don't fit in the wifi
settings panel anymore. need to find a better way how to display them or
change font.
2 years ago
alex bfc71fec92 start: initial minimal implementation
3 tabs: bitcoin, lightning and settings.
only settings is populated, with wifi info and shutdown.

see build.zig for how everything ties up together.
2 years ago