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

Update main.rs to improve Properties tab #154

Closed
wants to merge 1 commit into from

Conversation

copy2018
Copy link

@copy2018 copy2018 commented Nov 18, 2024

Properties added:

  • REAL Max Mempool Size in MB given core's overhead and safety buffer
  • Current Mempool Usage in MB and as a percentage
  • Mempool Transaction Count
  • Progress to next halving added (counts in years, days, hours, mins)
  • Node uptime since service was started
  • Current total supply of Bitcoin based on issuance schedule (may be very slightly inaccuate compared to gettxoutsetinfo but is great for monitoring at a glance without needing to wait)

I also consolidated the blockchain sync summary to one line to save screen real estate.

Here is an image of what it looks like:
image

Reasons 'total bitcoin supply' may not be exactly the same as gettxoutinfo:

  1. Varied Inputs and Outputs: The total amount shown represents all unspent coins across all outputs, which includes not only block rewards but also many user transactions, each with its unique input and output values. These transactions may not align with exact multiples of the block reward.
  2. Fee Distribution: Transaction fees also contribute to the total amount but are not typically set to neat multiples. They are instead dynamic values determined by users and miners, so they add irregular values to the total supply.
  3. Decay in Reward Structure: If you're working within a system where block rewards decrease over time, previous block rewards might have been higher or lower than 3.125, meaning historical outputs would still affect the total.
  4. Fractional Accumulation: With every transaction and UTXO creation, there could be small rounding effects or dust amounts, which, over thousands of transactions, contribute to a value that doesn't perfectly align with any specific multiple.

However overall this is a great at a glance metric imo to keep a check on things (with a fraction of a percent difference), especially since gettxoutsetinfo is resource and time intensive.

Comment on lines +601 to +607
if reindex {
match fs::remove_file("/root/.bitcoin/requires.reindex") {
Ok(()) => (),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => (),
a => a?,
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why create a new conditional block here to delete the requires.reindex file when there is already a conditional block above used to add the "-reindex" arg?

@@ -431,7 +560,6 @@ fn inner_main(reindex: bool, reindex_chainstate: bool) -> Result<(), Box<dyn Err
format!("-onion={}:9050", var("EMBASSY_IP")?),
format!("-externalip={}", peer_addr),
"-datadir=/root/.bitcoin".to_owned(),
"-deprecatedrpc=warnings".to_owned(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is the "deprecatedrpc=warnings" arg being removed here?

While Bitcoin 28 has not yet shipped for bitcoind-startos, this arg is currently required for some dependencies like LND until LND 18.4 is released (currently on rc1).

Comment on lines +273 to +310
let mempool_info = std::process::Command::new("bitcoin-cli")
.arg("-conf=/root/.bitcoin/bitcoin.conf")
.arg("getmempoolinfo")
.output()?;

if mempool_info.status.success() {
let mempool_data: serde_json::Value = serde_json::from_slice(&mempool_info.stdout)?;

let max_mempool = mempool_data["maxmempool"].as_u64().unwrap_or(0) as f64 / 1024_f64.powf(2.0); // Convert to MB
let mempool_usage = mempool_data["usage"].as_u64().unwrap_or(0) as f64 / 1024_f64.powf(2.0); // Convert to MB
let mempool_percent = if max_mempool > 0.0 {
(mempool_usage / max_mempool) * 100.0
} else {
0.0
};
let tx_count = mempool_data["size"].as_u64().unwrap_or(0); // Number of transactions

// Insert the simplified mempool summary
stats.insert(
Cow::from("Mempool Summary"),
Stat {
value_type: "string",
value: format!(
"{:.2}/{:.2} MB ({:.2}%), {} Transactions",
mempool_usage, max_mempool, mempool_percent, tx_count
),
description: Some(Cow::from("Summary of current mempool usage and transaction count")),
copyable: false,
qr: false,
masked: false,
},
);
} else {
eprintln!(
"Error retrieving mempool info: {}",
std::str::from_utf8(&mempool_info.stderr).unwrap_or("UNKNOWN ERROR")
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if it makes sense to include this information in Properties when users can get this and more detailed information about their mempool in a better format by using mempool-startos.

mempool


fn inner_main(reindex: bool, reindex_chainstate: bool) -> Result<(), Box<dyn Error>> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This parameter is needed for the Reindex Chainstate action. Is there a reason this parameter and all its subsequent uses are being removed?

Stat {
value_type: "string",
value: uptime_formatted,
description: Some(Cow::from("Total time the Bitcoin node has been running")),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This description is a bit misleading as it might leave a user thinking their node has only been running for a short time in total.

Maybe a description like "Total time Bitcoin has been running since it was last started"?

Comment on lines +225 to +241
if blockchain_info.status.success() {
let blockchain_data: serde_json::Value = serde_json::from_slice(&blockchain_info.stdout)?;
let current_height = blockchain_data["blocks"].as_u64().unwrap_or(0);

// Calculate total supply based on height and halving intervals
let halving_interval = 210_000;
let mut subsidy = 50.0; // Initial subsidy in BTC
let mut total_supply = 0.0;
let mut remaining_height = current_height;

while remaining_height > 0 {
let blocks_in_this_epoch = remaining_height.min(halving_interval);
total_supply += blocks_in_this_epoch as f64 * subsidy;
remaining_height = remaining_height.saturating_sub(halving_interval);
subsidy /= 2.0;
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Given the imprecision of this calculation of issuance compared to gettxoutsetinfo (even if it is small as a percentage) I don't think it makes sense to include this metric in Properties.

Comment on lines +334 to +337
value: format!(
"{}/{} ({:.2}%)",
current_blocks, total_headers, sync_progress
),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is a great improvement to make the Properties more concise. Nicely done. However I would add some spacing here for better readability.

Suggested change
value: format!(
"{}/{} ({:.2}%)",
current_blocks, total_headers, sync_progress
),
value: format!(
"{} / {} ({:.2}%)",
current_blocks, total_headers, sync_progress
),

@copy2018 copy2018 closed this Dec 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants