From 58e4313517f94a6eec828a050f1809f3bb4d1108 Mon Sep 17 00:00:00 2001 From: sat-3 <144347307+j34g@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:11:29 +0000 Subject: [PATCH 1/2] Add additional properties to make knots s9pk better than core Options added: - Max Mempool Size in MB - Current Mempool Usage in MB and as a percentage - Mempool Transaction Count - progress to next halving - 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 have also made and tested this to ensure it works flawlessly. s9pk added in comments --- manager/src/main.rs | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/manager/src/main.rs b/manager/src/main.rs index dc1323af..5404830c 100644 --- a/manager/src/main.rs +++ b/manager/src/main.rs @@ -168,6 +168,121 @@ fn sidecar(config: &Mapping, addr: &str) -> Result<(), Box> { }, ); } + + // Calculate total supply and progress to the next halving + let blockchain_info = std::process::Command::new("bitcoin-cli") + .arg("-conf=/root/.bitcoin/bitcoin.conf") + .arg("getblockchaininfo") + .output()?; + + 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; + } + + stats.insert( + Cow::from("Total Bitcoin Supply"), + Stat { + value_type: "string", + value: format!("{:.8} BTC", total_supply), + description: Some(Cow::from("Current total supply of Bitcoin based on issuance schedule")), + copyable: false, + qr: false, + masked: false, + }, + ); + + // Progress to Next Halving calculation + let last_halving_block = (current_height / halving_interval) * halving_interval; + let blocks_since_last_halving = current_height - last_halving_block; + let progress_to_next_halving = (blocks_since_last_halving as f64 / halving_interval as f64) * 100.0; + + stats.insert( + Cow::from("Progress to Next Halving"), + Stat { + value_type: "string", + value: format!("{:.2}%", progress_to_next_halving), + description: Some(Cow::from("Percentage of blocks completed until the next Bitcoin halving")), + copyable: false, + qr: false, + masked: false, + }, + ); + } + + // New section to fetch mempool statistics + 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 bytes to MB + let mempool_usage = mempool_data["usage"].as_u64().unwrap_or(0) as f64 / 1024_f64.powf(2.0); // Convert bytes 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 + + stats.insert( + Cow::from("Max Mempool Size"), + Stat { + value_type: "string", + value: format!("{:.2} MB", max_mempool), + description: Some(Cow::from("Maximum memory pool size")), + copyable: false, + qr: false, + masked: false, + }, + ); + + stats.insert( + Cow::from("Current Mempool Usage"), + Stat { + value_type: "string", + value: format!("{:.2} MB ({:.2}%)", mempool_usage, mempool_percent), + description: Some(Cow::from("Current memory pool usage as a percentage of max size")), + copyable: false, + qr: false, + masked: false, + }, + ); + + stats.insert( + Cow::from("Mempool Transaction Count"), + Stat { + value_type: "string", + value: format!("{}", tx_count), + description: Some(Cow::from("Current number of transactions in the mempool")), + copyable: false, + qr: false, + masked: false, + }, + ); + } else { + eprintln!( + "Error retrieving mempool info: {}", + std::str::from_utf8(&mempool_info.stderr).unwrap_or("UNKNOWN ERROR") + ); + } + + // Existing code for blockchain and network info retrieval continues here... let info_res = std::process::Command::new("bitcoin-cli") .arg("-conf=/root/.bitcoin/bitcoin.conf") .arg("getblockchaininfo") From 98bda455792ba26574f83494628bdf9478a8f806 Mon Sep 17 00:00:00 2001 From: sat-3 <144347307+j34g@users.noreply.github.com> Date: Thu, 7 Nov 2024 20:04:35 +0000 Subject: [PATCH 2/2] Update README.md to be knots specific Made stuff knots specific and Linked to the new https://config.mempool.guide/ instead of Lopp's core config generator --- README.md | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6ac17e01..55dbc909 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,15 @@ Project Logo

-# Bitcoin Core for StartOS +# Bitcoin Knots for StartOS -This project packages [Bitcoin](https://bitcoin.org) for StartOS. Bitcoin uses peer-to-peer technology to operate with no central authority or banks - managing transactions and the issuing of bitcoins is carried out collectively by the network. +This project packages [Bitcoin Knots](https://bitcoinknots.org/) for StartOS. + +By using Knots, you’re supporting a version of Bitcoin that prioritizes efficiency, security, and flexibility. With Bitcoin Knots’ enhanced configuration options, you can fine-tune your node to help keep the network clean and resilient, actively reducing unnecessary load from spam or parasitic transactions. + +Every node strengthens the Bitcoin network, and your decision to use Bitcoin Knots contributes directly to a more decentralized and spam-resistant ecosystem. Your node not only validates and secures transactions but also sets an example for a more sustainable, user-focused Bitcoin network. + +Welcome to the community of Bitcoin Knots users, and thank you for helping Bitcoin grow stronger! ## Contributing @@ -16,7 +22,7 @@ For technical contributors, please fork this repository, make your changes accor ### Adding Config Options -To add config options, include the new config options in *both* `scripts/services/getConfig.ts` and `assets/compat/bitcoin.conf.template`, adhering to the syntax and conventions of those files. To view the full list of config options, complete with descriptions and specifications, check out this [site](https://jlopp.github.io/bitcoin-core-config-generator) from Jameson Lopp. +To add config options, include the new config options in *both* `scripts/services/getConfig.ts` and `assets/compat/bitcoin.conf.template`, adhering to the syntax and conventions of those files. To view the full list of config options, complete with descriptions and specifications, check out this [site](https://config.mempool.guide). ## Dependencies @@ -35,8 +41,8 @@ Install the following system dependencies to build this project by following the Clone the project locally. Note the submodule link to the original project(s). ``` -git clone git@github.com:Start9Labs/bitcoind-wrapper.git -cd bitcoind-wrapper +git clone https://github.com/Retropex/knots-startos.git +cd knots-startos git submodule update --init ```