Skip to content

Commit

Permalink
Merge pull request #32 from ryo-currency/topic-1.3.2
Browse files Browse the repository at this point in the history
Topic 1.3.2
  • Loading branch information
mosu-forge authored May 31, 2019
2 parents 9ba1d82 + 4b8b208 commit d1793b2
Show file tree
Hide file tree
Showing 23 changed files with 309 additions and 4,306 deletions.
48 changes: 0 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,51 +69,3 @@ cp /path/to/ryo/binaries/ryo-wallet-rpc bin/
npm install
quasar build -m electron -t mat
```

---

### LICENSE

Copyright (c) 2018, Ryo Currency Project

Portions of this software are available under BSD-3 license. Please see ORIGINAL-LICENSE for details

All rights reserved.

Authors and copyright holders give permission for following:

1. Redistribution and use in source and binary forms WITHOUT modification.

2. Modification of the source form for your own personal use.

As long as the following conditions are met:

3. You must not distribute modified copies of the work to third parties. This includes
posting the work online, or hosting copies of the modified work for download.

4. Any derivative version of this work is also covered by this license, including point 8.

5. Neither the name of the copyright holders nor the names of the authors may be
used to endorse or promote products derived from this software without specific
prior written permission.

6. You agree that this licence is governed by and shall be construed in accordance
with the laws of England and Wales.

7. You agree to submit all disputes arising out of or in connection with this licence
to the exclusive jurisdiction of the Courts of England and Wales.

Authors and copyright holders agree that:

8. This licence expires and the work covered by it is released into the
public domain on 1st of February 2019

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ryo-wallet-atom",
"version": "1.3.1",
"version": "1.3.2",
"daemonVersion": "0.4.0.1",
"description": "Modern GUI interface for Ryo Currency",
"productName": "Ryo Wallet Atom",
Expand Down
6 changes: 6 additions & 0 deletions src-electron/main-process/electron-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ function createWindow() {
}
})

ipcMain.on("autostartSettings", (e, openAtLogin) => {
app.setLoginItemSettings({
openAtLogin
})
})

ipcMain.on("confirmMinimizeTray", (e, minimize_to_tray) => {
mainWindow.setMinimizable(true)
backend.config_data.preference.minimize_to_tray = minimize_to_tray
Expand Down
11 changes: 11 additions & 0 deletions src-electron/main-process/modules/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class Backend {
notify_no_payment_id: true,
notify_empty_password: true,
minimize_to_tray: false,
autostart: false,
timeout: 600000 // 10 minutes
},

Expand Down Expand Up @@ -86,6 +87,7 @@ export class Backend {
},
mining: {
address: "",
enableBlockRefreshInterval: false,
blockRefreshInterval: 5,
minerTimeout: 900,
uniform: true,
Expand Down Expand Up @@ -280,6 +282,15 @@ export class Backend {
// here we may want to check if config data is valid, if not also send code -1
// i.e. check ports are integers and > 1024, check that data dir path exists, etc

// Filter out http:// from remote_host (remote daemon address)
if(this.config_data.daemon.remote_host.indexOf("//") !== -1) {
let remote_host = this.config_data.daemon.remote_host
remote_host = this.config_data.daemon.remote_host.split("//")
remote_host.shift()
remote_host = remote_host.join("//")
this.config_data.daemon.remote_host = remote_host
}

// save config file back to file, so updated options are stored on disk
fs.writeFileSync(this.config_file, JSON.stringify(this.config_data, null, 4), "utf8");

Expand Down
2 changes: 1 addition & 1 deletion src-electron/main-process/modules/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,9 @@ export class Daemon {
continue
if(n.method == "get_info") {
daemon_info.info = n.result
this.daemon_info = n.result
}
}
this.daemon_info = daemon_info.info
this.sendGateway("set_daemon_data", daemon_info)
})
}
Expand Down
87 changes: 58 additions & 29 deletions src-electron/main-process/modules/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,20 +202,13 @@ export class Pool {
}

startHeartbeat() {
if(this.intervals.job) {
clearInterval(this.intervals.job)
}
if(this.intervals.timeout) {
clearInterval(this.intervals.timeout)
}
if(this.intervals.watchdog) {
clearInterval(this.intervals.watchdog)
}

this.intervals.job = setInterval(() => {
this.getBlock().catch(() => {})
}, this.config.mining.blockRefreshInterval * 1000)

this.intervals.timeout = setInterval(() => {
for(let connection_id in this.connections) {
const miner = this.connections[connection_id]
Expand All @@ -228,32 +221,68 @@ export class Pool {
}, 30000)

this.intervals.watchdog = setInterval(() => {
// check for desynced daemon
if(this.blocks.current == null) {
return
}
this.checkHeight().then(response => {
try {
const json = JSON.parse(response)
if(json !== null && typeof json === "object" && json.hasOwnProperty("data") && json.data.hasOwnProperty("height")) {
const remote_height = json.data.height
const desynced = this.blocks.current.height < remote_height - 5
if(desynced) {
logger.log("error", "Pool height is desynced { remote: %d, local: %d }", [remote_height, this.blocks.current.height])
} else {
logger.log("info", "Pool height is okay { remote: %d, local: %d }", [remote_height, this.blocks.current.height])
}
this.sendGateway("set_pool_data", { desynced })
}
} catch(err) {
}
}).catch(() => {
})
this.watchdog()
}, 240000)
this.watchdog()

this.startJobRefreshInterval()

this.startRetargetInterval()
}

watchdog() {
// check for desynced daemon and incorrect local clock
this.checkHeight().then(response => {
try {
const json = JSON.parse(response)
if(json === null || typeof json !== "object" || !json.hasOwnProperty("data")) {
return
}
let desynced = false, system_clock_error = false
if(json.data.hasOwnProperty("height") && this.blocks.current != null) {
const remote_height = json.data.height
desynced = this.blocks.current.height < remote_height - 5
if(desynced) {
logger.log("error", "Pool height is desynced { remote: %d, local: %d }", [remote_height, this.blocks.current.height])
} else {
logger.log("info", "Pool height is okay { remote: %d, local: %d }", [remote_height, this.blocks.current.height])
}
}
if(json.data.hasOwnProperty("server_time")) {
const allowed_time_variance = 15 * 60 // 15 minutes
const server_time = json.data.server_time
const system_time = Math.floor(Date.now() / 1000)
system_clock_error = Math.abs(server_time - system_time) > allowed_time_variance
if(system_clock_error) {
logger.log("error", "System clock is not correct { server: %d, local: %d }", [server_time, system_time])
} else {
logger.log("info", "System clock is okay { server: %d, local: %d }", [server_time, system_time])
}
}
this.sendGateway("set_pool_data", { desynced, system_clock_error })
} catch(err) {
}
}).catch(() => {
})
}

startJobRefreshInterval() {

let blockRefreshInterval = 1 * 1000 // 1 second
if(this.config.mining.enableBlockRefreshInterval) {
if(!Number.isNaN(this.config.mining.blockRefreshInterval * 1000)) {
blockRefreshInterval = this.config.mining.blockRefreshInterval * 1000
}
}

if(this.intervals.job) {
clearInterval(this.intervals.job)
}
this.intervals.job = setInterval(() => {
this.getBlock().catch(() => {})
}, blockRefreshInterval)
}

startRetargetInterval() {
if(this.intervals.retarget) {
clearInterval(this.intervals.retarget)
Expand Down Expand Up @@ -456,6 +485,7 @@ export class Pool {

this.processShare(job, block, nonce, hash).then(result => {
logger.log("info", "Accepted share { difficulty: %d, actual: %d } from %s@%s", [job.difficulty, result.diff, miner.workerName, miner.ip])
reply(null, { status: "OK" })
if(result.hash) {
logger.log("success", "Block found { hash: %s, height: %d } by %s@%s", [result.hash, job.height, miner.workerName, miner.ip])
this.database.recordShare(miner, job, true, result.hash, block)
Expand All @@ -464,7 +494,6 @@ export class Pool {
}
miner.heartbeat()
miner.recordShare()
reply(null, { status: "OK" })
}).catch(error => {
logger.log("info", "Rejected share { difficulty: %d, actual: %d } from %s@%s", [job.difficulty, error.diff, miner.workerName, miner.ip])
logger.log("error", "%s { height: %d } from worker %s@%s", [error.message, job.height, miner.workerName, miner.ip])
Expand Down
25 changes: 21 additions & 4 deletions src-electron/main-process/modules/pool/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class Database {
} else {
this.sqlitePath = join(options.data_dir, "gui", "pool_stats.sqlite")
}
this.vacuum_interval = 1000 * 60 * 60 * 24 // 24 hours
}

start() {
Expand Down Expand Up @@ -53,6 +54,13 @@ export class Database {
hashrate_avg_clean: this.db.prepare("DELETE FROM hashrate WHERE time < :time"),
}


this.vacuum()

setInterval(() => {
this.vacuum()
}, this.vacuum_interval)

}

stop() {
Expand All @@ -65,6 +73,18 @@ export class Database {
return this.db.prepare("SELECT name FROM sqlite_master WHERE type='table'").all()
}

vacuum() {
if(!this.db) {
return
}
try {
this.db.exec("VACUUM")
logger.log("info", "Success vacuuming database")
} catch(error) {
logger.log("error", "Error vacuuming database")
}
}

init() {
this.db.prepare("CREATE TABLE IF NOT EXISTS round(miner TEXT PRIMARY KEY, hashes INTEGER) WITHOUT ROWID;").run()
this.db.prepare("CREATE TABLE IF NOT EXISTS hashrate(miner TEXT, time DATETIME, hashes INTEGER);").run()
Expand Down Expand Up @@ -257,10 +277,7 @@ export class Database {

let hashrates = {}
for(const h of this.stmt.hashrate_calc.all({ start_time, end_time })) {
if(n_time > 300) {
n_time = Math.max(300, (end_time - h.start_time) / 1000)
}
hashrates[h.miner] = Math.round(100 * h.hashes / n_time) / 100
hashrates[h.miner] = Math.round(100 * h.hashes / Math.max(300, (end_time - h.start_time) / 1000) ) / 100
}
return hashrates
}
Expand Down
3 changes: 0 additions & 3 deletions src-electron/main-process/modules/status-codes.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/components/footer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ export default {
if(pct == 100.0 && this.daemon.info.height_without_bootstrap < this.target_height)
return 99.9
else
return pct
return Math.min(pct, 100)
},
wallet_pct (state) {
let pct = (100 * this.wallet.info.height / this.target_height).toFixed(1)
if(pct == 100.0 && this.wallet.info.height < this.target_height)
return 99.9
else
return pct
return Math.min(pct, 100)
},
status(state) {
if(this.config.daemon.type === "local") {
Expand Down
Loading

0 comments on commit d1793b2

Please sign in to comment.