comm: rename bitcoin report to onchain
ci/woodpecker/push/woodpecker Pipeline was successful Details

the "bitcoin" name is overloaded: everything's about bitcoin here.
a less confusing name is onchain to emphasize the difference w.r.t.
lightning or any other future L2 networks.
pull/31/head
alex 1 year ago
parent 29f6975601
commit e618fee65c
Signed by: x1ddos
GPG Key ID: FDEFB4A63CBD8460

@ -66,7 +66,7 @@ pub const MessageTag = enum(u16) {
// nd -> ngui: reports poweroff progress // nd -> ngui: reports poweroff progress
poweroff_progress = 0x09, poweroff_progress = 0x09,
// nd -> ngui: bitcoin core daemon status report // nd -> ngui: bitcoin core daemon status report
bitcoind_report = 0x0a, onchain_report = 0x0a,
// nd -> ngui: lnd status and stats report // nd -> ngui: lnd status and stats report
lightning_report = 0x0b, lightning_report = 0x0b,
// ngui -> nd: switch sysupdates channel // ngui -> nd: switch sysupdates channel
@ -87,7 +87,7 @@ pub const Message = union(MessageTag) {
network_report: NetworkReport, network_report: NetworkReport,
get_network_report: GetNetworkReport, get_network_report: GetNetworkReport,
poweroff_progress: PoweroffProgress, poweroff_progress: PoweroffProgress,
bitcoind_report: BitcoinReport, onchain_report: OnchainReport,
lightning_report: LightningReport, lightning_report: LightningReport,
switch_sysupdates: SysupdatesChan, switch_sysupdates: SysupdatesChan,
settings: Settings, settings: Settings,
@ -117,7 +117,7 @@ pub const Message = union(MessageTag) {
}; };
}; };
pub const BitcoinReport = struct { pub const OnchainReport = struct {
blocks: u64, blocks: u64,
headers: u64, headers: u64,
timestamp: u64, // unix epoch timestamp: u64, // unix epoch
@ -269,7 +269,7 @@ pub fn write(allocator: mem.Allocator, writer: anytype, msg: Message) !void {
.network_report => try json.stringify(msg.network_report, .{}, data.writer()), .network_report => try json.stringify(msg.network_report, .{}, data.writer()),
.get_network_report => try json.stringify(msg.get_network_report, .{}, data.writer()), .get_network_report => try json.stringify(msg.get_network_report, .{}, data.writer()),
.poweroff_progress => try json.stringify(msg.poweroff_progress, .{}, data.writer()), .poweroff_progress => try json.stringify(msg.poweroff_progress, .{}, data.writer()),
.bitcoind_report => try json.stringify(msg.bitcoind_report, .{}, data.writer()), .onchain_report => try json.stringify(msg.onchain_report, .{}, data.writer()),
.lightning_report => try json.stringify(msg.lightning_report, .{}, data.writer()), .lightning_report => try json.stringify(msg.lightning_report, .{}, data.writer()),
.switch_sysupdates => try json.stringify(msg.switch_sysupdates, .{}, data.writer()), .switch_sysupdates => try json.stringify(msg.switch_sysupdates, .{}, data.writer()),
.settings => try json.stringify(msg.settings, .{}, data.writer()), .settings => try json.stringify(msg.settings, .{}, data.writer()),

@ -57,9 +57,9 @@ network_report_ready: bool, // indicates whether the network status is ready to
wifi_scan_in_progress: bool = false, wifi_scan_in_progress: bool = false,
wpa_save_config_on_connected: bool = false, wpa_save_config_on_connected: bool = false,
// bitcoin fields // bitcoin fields
want_bitcoind_report: bool, want_onchain_report: bool,
bitcoin_timer: time.Timer, bitcoin_timer: time.Timer,
bitcoin_report_interval: u64 = 1 * time.ns_per_min, onchain_report_interval: u64 = 1 * time.ns_per_min,
// lightning fields // lightning fields
want_lnd_report: bool, want_lnd_report: bool,
lnd_timer: time.Timer, lnd_timer: time.Timer,
@ -111,7 +111,7 @@ pub fn init(opt: InitOpt) !Daemon {
.want_wifi_scan = false, .want_wifi_scan = false,
.network_report_ready = true, .network_report_ready = true,
// report bitcoind status immediately on start // report bitcoind status immediately on start
.want_bitcoind_report = true, .want_onchain_report = true,
.bitcoin_timer = try time.Timer.start(), .bitcoin_timer = try time.Timer.start(),
// report lightning status immediately on start // report lightning status immediately on start
.want_lnd_report = true, .want_lnd_report = true,
@ -327,12 +327,12 @@ fn mainThreadLoopCycle(self: *Daemon) !void {
} }
} }
if (self.want_bitcoind_report or self.bitcoin_timer.read() > self.bitcoin_report_interval) { if (self.want_onchain_report or self.bitcoin_timer.read() > self.onchain_report_interval) {
if (self.sendBitcoindReport()) { if (self.sendOnchainReport()) {
self.bitcoin_timer.reset(); self.bitcoin_timer.reset();
self.want_bitcoind_report = false; self.want_onchain_report = false;
} else |err| { } else |err| {
logger.err("sendBitcoinReport: {any}", .{err}); logger.err("sendOnchainReport: {any}", .{err});
} }
} }
if (self.want_lnd_report or self.lnd_timer.read() > self.lnd_report_interval) { if (self.want_lnd_report or self.lnd_timer.read() > self.lnd_report_interval) {
@ -566,7 +566,7 @@ fn readWPACtrlMsg(self: *Daemon) !void {
} }
} }
fn sendBitcoindReport(self: *Daemon) !void { fn sendOnchainReport(self: *Daemon) !void {
var client = bitcoindrpc.Client{ var client = bitcoindrpc.Client{
.allocator = self.allocator, .allocator = self.allocator,
.cookiepath = "/ssd/bitcoind/mainnet/.cookie", .cookiepath = "/ssd/bitcoind/mainnet/.cookie",
@ -590,7 +590,7 @@ fn sendBitcoindReport(self: *Daemon) !void {
}; };
defer if (balance) |bal| bal.deinit(); defer if (balance) |bal| bal.deinit();
const btcrep: comm.Message.BitcoinReport = .{ const btcrep: comm.Message.OnchainReport = .{
.blocks = bcinfo.value.blocks, .blocks = bcinfo.value.blocks,
.headers = bcinfo.value.headers, .headers = bcinfo.value.headers,
.timestamp = bcinfo.value.time, .timestamp = bcinfo.value.time,
@ -624,7 +624,7 @@ fn sendBitcoindReport(self: *Daemon) !void {
} else null, } else null,
}; };
try comm.write(self.allocator, self.uiwriter, .{ .bitcoind_report = btcrep }); try comm.write(self.allocator, self.uiwriter, .{ .onchain_report = btcrep });
} }
fn sendLightningReport(self: *Daemon) !void { fn sendLightningReport(self: *Daemon) !void {
@ -802,7 +802,7 @@ test "start-stop" {
}); });
daemon.want_settings = false; daemon.want_settings = false;
daemon.want_network_report = false; daemon.want_network_report = false;
daemon.want_bitcoind_report = false; daemon.want_onchain_report = false;
daemon.want_lnd_report = false; daemon.want_lnd_report = false;
try t.expect(daemon.state == .stopped); try t.expect(daemon.state == .stopped);
@ -854,7 +854,7 @@ test "start-poweroff" {
}); });
daemon.want_settings = false; daemon.want_settings = false;
daemon.want_network_report = false; daemon.want_network_report = false;
daemon.want_bitcoind_report = false; daemon.want_onchain_report = false;
daemon.want_lnd_report = false; daemon.want_lnd_report = false;
defer { defer {
daemon.deinit(); daemon.deinit();

@ -39,7 +39,7 @@ var state: enum {
var last_report: struct { var last_report: struct {
mu: std.Thread.Mutex = .{}, mu: std.Thread.Mutex = .{},
network: ?comm.ParsedMessage = null, // NetworkReport network: ?comm.ParsedMessage = null, // NetworkReport
bitcoind: ?comm.ParsedMessage = null, // BitcoinReport onchain: ?comm.ParsedMessage = null, // OnchainReport
lightning: ?comm.ParsedMessage = null, // LightningReport lightning: ?comm.ParsedMessage = null, // LightningReport
fn deinit(self: *@This()) void { fn deinit(self: *@This()) void {
@ -49,9 +49,9 @@ var last_report: struct {
v.deinit(); v.deinit();
self.network = null; self.network = null;
} }
if (self.bitcoind) |v| { if (self.onchain) |v| {
v.deinit(); v.deinit();
self.bitcoind = null; self.onchain = null;
} }
if (self.lightning) |v| { if (self.lightning) |v| {
v.deinit(); v.deinit();
@ -70,11 +70,11 @@ var last_report: struct {
} }
self.network = new; self.network = new;
}, },
.bitcoind_report => { .onchain_report => {
if (self.bitcoind) |old| { if (self.onchain) |old| {
old.deinit(); old.deinit();
} }
self.bitcoind = new; self.onchain = new;
}, },
.lightning_report => { .lightning_report => {
if (self.lightning) |old| { if (self.lightning) |old| {
@ -231,7 +231,7 @@ fn commThreadLoopCycle() !void {
try comm.pipeWrite(comm.Message.pong); try comm.pipeWrite(comm.Message.pong);
}, },
.network_report, .network_report,
.bitcoind_report, .onchain_report,
.lightning_report, .lightning_report,
=> last_report.replace(msg), => last_report.replace(msg),
else => { else => {
@ -252,7 +252,7 @@ fn commThreadLoopCycle() !void {
updateNetworkStatus(rep) catch |err| logger.err("updateNetworkStatus: {any}", .{err}); updateNetworkStatus(rep) catch |err| logger.err("updateNetworkStatus: {any}", .{err});
last_report.replace(msg); last_report.replace(msg);
}, },
.bitcoind_report => |rep| { .onchain_report => |rep| {
ui.bitcoin.updateTabPanel(rep) catch |err| logger.err("bitcoin.updateTabPanel: {any}", .{err}); ui.bitcoin.updateTabPanel(rep) catch |err| logger.err("bitcoin.updateTabPanel: {any}", .{err});
last_report.replace(msg); last_report.replace(msg);
}, },
@ -306,8 +306,8 @@ fn uiThreadLoop() void {
logger.err("updateNetworkStatus: {any}", .{err}); logger.err("updateNetworkStatus: {any}", .{err});
}; };
} }
if (last_report.bitcoind) |msg| { if (last_report.onchain) |msg| {
ui.bitcoin.updateTabPanel(msg.value.bitcoind_report) catch |err| { ui.bitcoin.updateTabPanel(msg.value.onchain_report) catch |err| {
logger.err("bitcoin.updateTabPanel: {any}", .{err}); logger.err("bitcoin.updateTabPanel: {any}", .{err});
}; };
} }

@ -152,7 +152,7 @@ fn commWriteThread(gpa: std.mem.Allocator, w: anytype) !void {
block_count += 1; block_count += 1;
const now = time.timestamp(); const now = time.timestamp();
const btcrep: comm.Message.BitcoinReport = .{ const btcrep: comm.Message.OnchainReport = .{
.blocks = block_count, .blocks = block_count,
.headers = block_count, .headers = block_count,
.timestamp = @intCast(now), .timestamp = @intCast(now),
@ -183,7 +183,7 @@ fn commWriteThread(gpa: std.mem.Allocator, w: anytype) !void {
.reserved = 100000, .reserved = 100000,
}, },
}; };
comm.write(gpa, w, .{ .bitcoind_report = btcrep }) catch |err| logger.err("comm.write: {any}", .{err}); comm.write(gpa, w, .{ .onchain_report = btcrep }) catch |err| logger.err("comm.write: {any}", .{err});
if (block_count % 2 == 0) { if (block_count % 2 == 0) {
const lndrep: comm.Message.LightningReport = .{ const lndrep: comm.Message.LightningReport = .{

@ -113,7 +113,7 @@ pub fn initTabPanel(cont: lvgl.Container) !void {
/// updates the tab with new data from the report. /// updates the tab with new data from the report.
/// the tab must be inited first with initTabPanel. /// the tab must be inited first with initTabPanel.
pub fn updateTabPanel(rep: comm.Message.BitcoinReport) !void { pub fn updateTabPanel(rep: comm.Message.OnchainReport) !void {
var buf: [512]u8 = undefined; var buf: [512]u8 = undefined;
// blockchain section // blockchain section