diff --git a/Cargo.lock b/Cargo.lock index cc3de59..5195851 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -113,7 +113,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "notemine" -version = "0.3.0" +version = "0.3.1" dependencies = [ "console_error_panic_hook", "hex", diff --git a/Cargo.toml b/Cargo.toml index 49b603f..4599cec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/demo/main.js b/demo/main.js index 135272a..8f4bcf4 100644 --- a/demo/main.js +++ b/demo/main.js @@ -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); } } @@ -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) { @@ -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; @@ -547,7 +548,7 @@ const generateEvent = (content) => { return { pubkey, kind: 1, - tags: [], + tags: [ ["miner", MINER], ["client", CLIENT] ], content, } } diff --git a/src/lib.rs b/src/lib.rs index b5faae3..6835ee9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,18 +23,10 @@ pub struct MinedResult { pub khs: f64, } -fn serialize_u64_as_number(x: &u64, s: S) -> Result -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>, @@ -46,7 +38,7 @@ fn get_event_hash(event: &NostrEvent) -> Vec { 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, @@ -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::().ok();