Skip to content

Commit

Permalink
small speed boosts
Browse files Browse the repository at this point in the history
  • Loading branch information
dskvr committed Sep 23, 2024
1 parent 002b3d0 commit 1f1ded0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "notemine"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
description = "a nostr note miner compiled to wasm"
repository = "https://github.com/sandwichfarm/notemine"
Expand Down
9 changes: 5 additions & 4 deletions demo/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function averageHashRate(hr) {

async function recordMaxRate(workerId, hashRate){
if (workerMaxHashRates[workerId] === undefined || hashRate > workerMaxHashRates[workerId]) {
workerMaxHashRates[workerId] = hashRate;
workerMaxHashRates[workerId] = Math.round(hashRate);
}
}

Expand All @@ -217,14 +217,14 @@ function recordHashRate(workerId, hashRate) {
workerHashRates[workerId] = [];
}
workerHashRates[workerId].push(hashRate);
if (workerHashRates[workerId].length > 22) {
if (workerHashRates[workerId].length > 11) {
workerHashRates[workerId].shift();
}
recordMaxRate(workerId, hashRate)
}

let lastRefresh = 0,
refreshEvery = 200
refreshEvery = 250

function refreshHashRate() {
if (Date.now() - lastRefresh < refreshEvery) {
Expand All @@ -240,6 +240,7 @@ function refreshHashRate() {
function updateWorkerHashrateDisplay() {
let minersHashRate = '';
for (const [workerId, hashRate] of Object.entries(workerHashRates)) {
// minersHashRate += `Miner #${workerId}: ${(averageHashRate(hashRate) / 1000).toFixed(2)} kH/s [Max: ${workerMaxHashRates[workerId] / 1000} kH/s]\n`;
minersHashRate += `Miner #${workerId}: ${(averageHashRate(hashRate) / 1000).toFixed(2)} kH/s\n`;
}
minersHashRateOutput.textContent = minersHashRate;
Expand Down Expand Up @@ -547,7 +548,7 @@ const generateEvent = (content) => {
return {
pubkey,
kind: 1,
tags: [],
tags: [ ["miner", MINER], ["client", CLIENT] ],
content,
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,10 @@ pub struct MinedResult {
pub khs: f64,
}

fn serialize_u64_as_number<S>(x: &u64, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
s.serialize_u64(*x)
}

#[derive(Serialize)]
struct HashableEvent<'a>(
u32,
&'a str,
#[serde(serialize_with = "serialize_u64_as_number")]
u64,
u32,
&'a Vec<Vec<String>>,
Expand All @@ -46,7 +38,7 @@ fn get_event_hash(event: &NostrEvent) -> Vec<u8> {
let hashable_event = HashableEvent(
0u32,
&event.pubkey,
event.created_at.unwrap_or_else(|| (js_sys::Date::now() / 1000.0) as u64),
event.created_at.unwrap(),
event.kind,
&event.tags,
&event.content,
Expand Down Expand Up @@ -139,7 +131,7 @@ pub fn mine_event(
let mut nonce: u64 = start_nonce;
let mut total_hashes: u64 = 0;

let report_interval = 500_000;
let report_interval = 333_000;
let mut last_report_time = start_time;
let should_cancel = should_cancel.dyn_into::<Function>().ok();

Expand Down

0 comments on commit 1f1ded0

Please sign in to comment.