Skip to content

Commit

Permalink
Merge pull request #54 from arqma/with-zmq
Browse files Browse the repository at this point in the history
fixed peerlist
  • Loading branch information
ArqTras authored Apr 19, 2020
2 parents 03f439f + 25f96a6 commit a0fe91c
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 85 deletions.
33 changes: 9 additions & 24 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "arqma-electron-wallet",
"version": "3.0.1",
"version": "3.0.2",
"daemonVersion": "6.0.2",
"description": "Modern GUI interface for Arqma Currency",
"productName": "Arqma Electron Wallet",
Expand Down
3 changes: 2 additions & 1 deletion quasar.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ module.exports = function (ctx) {
"QTh",
"QTr",
"QTd",
"QTableColumns"
"QTableColumns",
"QSlider"
],
directives: [
"Ripple",
Expand Down
13 changes: 6 additions & 7 deletions src-electron/main-process/modules/backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ export class Backend {
enabled: true,
startDiff: 5000,
minDiff: 1000,
maxDiff: 100000000,
targetTime: 30,
maxDiff: 1000000,
targetTime: 45,
retargetTime: 60,
variancePercent: 30,
maxJump: 100,
variancePercent: 45,
maxJump: 30,
fixedDiffSeparator: ".",
},
},
Expand Down Expand Up @@ -204,7 +204,7 @@ export class Backend {
if (this.config_data.pool.server.enabled) {
if (this.config_data.daemon.type === 'local_zmq') {
if(event === "set_daemon_data") {
if(data.info.isDaemonSyncd) {
if(data.info && data.info.hasOwnProperty("isDaemonSyncd") && data.info.isDaemonSyncd) {
this.pool.startWithZmq()
}
}
Expand Down Expand Up @@ -240,7 +240,6 @@ export class Backend {
handle(data) {

let params = data.data

switch (data.method) {
case "set_language":
this.send("set_language", { lang: params.lang })
Expand Down Expand Up @@ -299,7 +298,7 @@ export class Backend {
this.send("set_app_data", {
config: this.config_data
})

this.pool.init(this.config_data)
if(!originalServerState) {
if (this.config_data.pool.server.enabled && this.config_data.daemon.type === "local_zmq") {
Expand Down
37 changes: 19 additions & 18 deletions src-electron/main-process/modules/daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,14 @@ export class Daemon {
zmqDirector.subscribe(x => {
let daemon_info = {
}
let results = JSON.parse(x.toString());
results.result.info.isDaemonSyncd = false
if (results.result.info.height === results.result.info.target_height && results.result.info.height >= this.remote_height) {
results.result.info.isDaemonSyncd = true
}
daemon_info.info = results.result.info
let json = JSON.parse(x.toString());
json.result.info.isDaemonSyncd = false
daemon_info.info = json.result.info
this.daemon_info = daemon_info
if (json.result.info.height === json.result.info.target_height && json.result.info.height >= this.remote_height) {
json.result.info.isDaemonSyncd = true
}

this.sendGateway("set_daemon_data", daemon_info)
})
}
Expand All @@ -262,7 +263,15 @@ export class Daemon {
case "ban_peer":
this.banPeer(params.host, params.seconds)
break

case "get_peers":
clearInterval(this.heartbeat_slow)
if (params.enabled) {
this.heartbeat_slow = setInterval(() => {
this.heartbeatSlowAction()
}, 10 * 1000) // 30 seconds
this.heartbeatSlowAction()
}
break
default:
}
}
Expand Down Expand Up @@ -377,13 +386,6 @@ export class Daemon {
this.heartbeatAction()
}, this.local ? 5 * 1000 : 30 * 1000) // 5 seconds for local daemon, 30 seconds for remote
this.heartbeatAction()

clearInterval(this.heartbeat_slow)
this.heartbeat_slow = setInterval(() => {
this.heartbeatSlowAction()
}, 30 * 1000) // 30 seconds
this.heartbeatSlowAction()

}

heartbeatAction() {
Expand Down Expand Up @@ -415,12 +417,12 @@ export class Daemon {
})
}

heartbeatSlowAction() {
heartbeatSlowAction(daemon_info = {}) {
let actions = []
if(this.local) {
actions = [
this.getRPC("connections"),
this.getRPC("bans"),
this.getRPC("bans")
//this.getRPC("txpool_backlog"),
]
} else {
Expand All @@ -432,8 +434,7 @@ export class Daemon {
if(actions.length === 0) return

Promise.all(actions).then((data) => {
let daemon_info = {
}

for (let n of data) {
if(n == undefined || !n.hasOwnProperty("result") || n.result == undefined)
continue
Expand Down
32 changes: 18 additions & 14 deletions src-electron/main-process/modules/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Pool {
this.port = options.daemon.rpc_bind_port

try {

this.sendStatus(0)
if(this.database.db == null) {
this.database.start()
logger.log("info", "Database initialized")
Expand All @@ -91,7 +91,8 @@ export class Pool {

let update_work = false
if(!start && this.active) {
if(this.config.mining.address != options.pool.mining.address || this.config.mining.uniform != options.pool.mining.uniform) {

if(this.config.mining.address != options.pool.mining.address) {
update_work = true
}
}
Expand All @@ -112,6 +113,7 @@ export class Pool {
this.connections = {}

this.BlockTemplateParameters = this.calculateBlockTemplateParameters()

const wallet_address = this.config.mining.address;
this.address_abbr = `${wallet_address.substring(0, 5)}...${wallet_address.substring(wallet_address.length - 5)}`

Expand Down Expand Up @@ -140,20 +142,21 @@ export class Pool {
}
}

startWithZmq() {
startWithZmq(isDaemonSyncd = false) {
if(this.daemon_type === "local_zmq") {
if(this.isPoolRunning) return
this.isPoolRunning = true
this.isPoolRunning = true
logger.log("info", "Starting pool with ZMQ")
this.startZMQ(this.backend.config_data.daemon)
let getblocktemplate = {"jsonrpc": "2.0",
"id": "1",
"method": "get_block_template",
"params": this.blocktemplateparameters}
"params": this.BlockTemplateParameters}

this.dealer.send(['', JSON.stringify(getblocktemplate)])
this.startHeartbeat()
this.startServer().then(() => {
this.sendStatus(2)
this.sendStatus(1)
}).catch(error => {
this.sendStatus(-1)
})
Expand Down Expand Up @@ -274,10 +277,10 @@ export class Pool {
this.dealer.identity = this.randomString();
this.dealer.setsockopt(zmq.ZMQ_LINGER, 0)
this.dealer.connect(`tcp://${options.zmq_bind_ip}:${options.zmq_bind_port}`);
console.log(`Pool Dealer connected to port ${options.zmq_bind_ip}:${options.zmq_bind_port}`);
logger.log("info", `Pool Dealer connected to port ${options.zmq_bind_ip}:${options.zmq_bind_port}`);
const zmqDirector = fromEvent(this.dealer, "message");
zmqDirector.subscribe(x => {
let json = JSON.parse(x.toString());
let json = JSON.parse(x.toString());
this.addBlockAndInformMiners(json)
})
}
Expand Down Expand Up @@ -338,14 +341,15 @@ export class Pool {
if(this.intervals.retarget) {
clearInterval(this.intervals.retarget)
}
const retargetTime = this.config ? this.config.varDiff.retargetTime : 60
this.intervals.retarget = setInterval(() => {
for(let connection_id in this.connections) {
const miner = this.connections[connection_id]
if(miner.varDiff.enabled && miner.retarget()) {
logger.log("info", "Difficulty change { old: %d, new: %d } for %s@%s", [miner.difficulty.last, miner.difficulty.now, miner.workerName, miner.ip])
}
}
}, this.config.varDiff.retargetTime * 1000)
}, retargetTime * 1000)
}

startServer() {
Expand Down Expand Up @@ -622,22 +626,22 @@ export class Pool {

calculateBlockTemplateParameters() {
return {wallet_address: this.config.mining.address,
reserve_size: (this.config.mining.uniform || Object.keys(this.connections).length > 128) ? 8 : 1}
reserve_size: (true || Object.keys(this.connections).length > 128) ? 8 : 1}
}

addBlockAndInformMiners(data, force=false) {
try {
const uniform = this.config.mining.uniform || Object.keys(this.connections).length > 128
const uniform = true || Object.keys(this.connections).length > 128
if(data.hasOwnProperty("error")) {
logger.log("error", "Error polling get_block_template %j", [data.error.message])
return data.error.message
}
const block = data.result

if(this.blocks == null || this.blocks.current == null || this.blocks.current.height < block.height || force) {

logger.log("info", "New block to mine { address: %s, height: %d, difficulty: %d, uniform: %s }", [this.address_abbr, block.height, block.difficulty, uniform])

logger.log("info", "New block to mine { address: %s, height: %d, difficulty: %d, uniform: %s }", [this.address_abbr, block.height, block.difficulty, uniform])
this.sendStatus(2)
this.blocks.current = new Block(this, block, uniform)

this.blocks.valid.push(this.blocks.current)
Expand All @@ -652,7 +656,7 @@ export class Pool {
}
}
}
catch(error) {console.log('sheit ', error)}
catch(error) {}
return null
}

Expand Down
Loading

0 comments on commit a0fe91c

Please sign in to comment.