feat: sync process code
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
5cd98ffc49
commit
e693bab5a7
@ -1420,7 +1420,6 @@
|
|||||||
</DIV>
|
</DIV>
|
||||||
<DIV style="float: left;display: none" id="idMiningParams">
|
<DIV style="float: left;display: none" id="idMiningParams">
|
||||||
<DIV style="float: left; color: blue;">CPU use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV>
|
<DIV style="float: left; color: blue;">CPU use:<input type="number" min=0 max=100 id="idPercentMining" onchange="SetPercentMining()"/>%</DIV>
|
||||||
<DIV style="float: left; margin: 2px 0 0 8px;" id="idStatusMining"></DIV>
|
|
||||||
</DIV>
|
</DIV>
|
||||||
</DIV>
|
</DIV>
|
||||||
<DIV id="idDevelopService" style="display: none">
|
<DIV id="idDevelopService" style="display: none">
|
||||||
@ -1460,6 +1459,7 @@
|
|||||||
</DIV>
|
</DIV>
|
||||||
<canvas width='800' height='30' id='idBlockInfo'></canvas>
|
<canvas width='800' height='30' id='idBlockInfo'></canvas>
|
||||||
<BR><BR>
|
<BR><BR>
|
||||||
|
<DIV style="float: left; font-family: monospace" id="idStatusMining"></DIV>
|
||||||
<DIV style="float: left; font-family: monospace">
|
<DIV style="float: left; font-family: monospace">
|
||||||
Block:<B id="idCurBlockNum"></B>
|
Block:<B id="idCurBlockNum"></B>
|
||||||
DB delta:<B id="idDeltaDB" style="min-width: 30px"></B>
|
DB delta:<B id="idDeltaDB" style="min-width: 30px"></B>
|
||||||
|
@ -128,8 +128,7 @@ WebApi2.GetTransaction = function(Params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if (typeof Params === "object" && Params.BlockNum && Params.TrNum !== undefined) {
|
if (typeof Params === "object" && Params.BlockNum && Params.TrNum !== undefined) {
|
||||||
var Block = global.SERVER.ReadBlockDB(Params.BlockNum);
|
var Block = global.SERVER.ReadBlockDB(Params.BlockNum);
|
||||||
if (Block && Block.arrContent) {
|
if (Block && Block.arrContent) {
|
||||||
@ -327,8 +326,7 @@ function SendTransaction(Body, TR, Wait, F) {
|
|||||||
if (text === "Not add" || text === "Bad PoW") {
|
if (text === "Not add" || text === "Bad PoW") {
|
||||||
CreateNonceAndSend(nonce + 1, NumNext + 1);
|
CreateNonceAndSend(nonce + 1, NumNext + 1);
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (text === "Bad time") {
|
if (text === "Bad time") {
|
||||||
if (DELTA_FOR_TIME_TX < 6) {
|
if (DELTA_FOR_TIME_TX < 6) {
|
||||||
DELTA_FOR_TIME_TX++;
|
DELTA_FOR_TIME_TX++;
|
||||||
@ -339,8 +337,7 @@ function SendTransaction(Body, TR, Wait, F) {
|
|||||||
}
|
}
|
||||||
if (Wait && TR._result) {
|
if (Wait && TR._result) {
|
||||||
global.GlobalRunMap[WebID] = F;
|
global.GlobalRunMap[WebID] = F;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
F(TR._result < 1 ? 0 : 1, text);
|
F(TR._result < 1 ? 0 : 1, text);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -8,11 +8,10 @@
|
|||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import '../core/constant'
|
|
||||||
global.PROCESS_NAME = "MAIN";
|
global.PROCESS_NAME = "MAIN";
|
||||||
|
import '../core/constant'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as os from 'os'
|
import * as os from 'os'
|
||||||
// import path = require('path')
|
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1 } from '../core/library'
|
||||||
|
|
||||||
@ -38,8 +37,6 @@ global.glCurNumFindArr = 0;
|
|||||||
global.ArrReconnect = [];
|
global.ArrReconnect = [];
|
||||||
global.ArrConnect = [];
|
global.ArrConnect = [];
|
||||||
var FindList = [
|
var FindList = [
|
||||||
{ "ip": "60.12.241.181", "port": 30000 },
|
|
||||||
{ "ip": "60.12.241.181", "port": 30001 },
|
|
||||||
{ "ip": "60.12.241.181", "port": 30002 },
|
{ "ip": "60.12.241.181", "port": 30002 },
|
||||||
{ "ip": "60.12.241.181", "port": 30003 },
|
{ "ip": "60.12.241.181", "port": 30003 },
|
||||||
{ "ip": "60.12.241.181", "port": 30004 },
|
{ "ip": "60.12.241.181", "port": 30004 },
|
||||||
@ -53,18 +50,15 @@ var FindList = [
|
|||||||
{ "ip": "60.12.241.181", "port": 30012 },
|
{ "ip": "60.12.241.181", "port": 30012 },
|
||||||
{ "ip": "60.12.241.181", "port": 30013 },
|
{ "ip": "60.12.241.181", "port": 30013 },
|
||||||
{ "ip": "60.12.241.181", "port": 30014 },
|
{ "ip": "60.12.241.181", "port": 30014 },
|
||||||
{ "ip": "60.12.241.181", "port": 30015 },
|
|
||||||
{ "ip": "60.12.241.181", "port": 30016 },
|
{ "ip": "60.12.241.181", "port": 30016 },
|
||||||
{ "ip": "60.12.241.181", "port": 30017 },
|
{ "ip": "60.12.241.181", "port": 30017 },
|
||||||
{ "ip": "60.12.241.181", "port": 30018 },
|
{ "ip": "60.12.241.181", "port": 30018 },
|
||||||
];
|
];
|
||||||
if (global.LOCAL_RUN) {
|
if (global.LOCAL_RUN) {
|
||||||
FindList = [{ "ip": "127.0.0.1", "port": 50001 }, { "ip": "127.0.0.1", "port": 50002 }];
|
FindList = [{ "ip": "127.0.0.1", "port": 50001 }, { "ip": "127.0.0.1", "port": 50002 }];
|
||||||
|
} else if (global.TEST_NETWORK) {
|
||||||
|
FindList = [{ "ip": "149.154.70.158", "port": 40000 },];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
if (global.TEST_NETWORK) {
|
|
||||||
FindList = [{ "ip": "149.154.70.158", "port": 40000 },];
|
|
||||||
}
|
|
||||||
global.SERVER = undefined;
|
global.SERVER = undefined;
|
||||||
global.NeedRestart = 0;
|
global.NeedRestart = 0;
|
||||||
process.on('uncaughtException' as any, function(err: TeraError) {
|
process.on('uncaughtException' as any, function(err: TeraError) {
|
||||||
@ -104,8 +98,7 @@ if (global.HTTP_HOSTING_PORT && !global.NWMODE) {
|
|||||||
if (WebProcess.Worker && WebProcess.Worker.connected) {
|
if (WebProcess.Worker && WebProcess.Worker.connected) {
|
||||||
try {
|
try {
|
||||||
WebProcess.Worker.send({ cmd: "Stat", Name: "MAX:ALL_NODES", Value: global.CountAllNode });
|
WebProcess.Worker.send({ cmd: "Stat", Name: "MAX:ALL_NODES", Value: global.CountAllNode });
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
WebProcess.Worker = undefined;
|
WebProcess.Worker = undefined;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -144,7 +137,11 @@ function AddTransactionFromWeb(Params) {
|
|||||||
var body = global.GetArrFromHex(Params.HexValue);
|
var body = global.GetArrFromHex(Params.HexValue);
|
||||||
if (global.TX_PROCESS && global.TX_PROCESS.Worker) {
|
if (global.TX_PROCESS && global.TX_PROCESS.Worker) {
|
||||||
var StrHex = global.GetHexFromArr(global.sha3(body));
|
var StrHex = global.GetHexFromArr(global.sha3(body));
|
||||||
global.TX_PROCESS.Worker.send({ cmd: "FindTX", TX: StrHex, Web: 1, WebID: Params.WebID });
|
global.TX_PROCESS.Worker.send({
|
||||||
|
cmd: "FindTX",
|
||||||
|
TX: StrHex, Web: 1,
|
||||||
|
WebID: Params.WebID
|
||||||
|
});
|
||||||
}
|
}
|
||||||
var Res = global.SERVER.AddTransaction({ body: body }, 1);
|
var Res = global.SERVER.AddTransaction({ body: body }, 1);
|
||||||
var text = global.AddTrMap[Res];
|
var text = global.AddTrMap[Res];
|
||||||
@ -259,15 +256,18 @@ function StartChildProcess(Item) {
|
|||||||
if (typeof msg.Params === "object" && msg.Params.F) {
|
if (typeof msg.Params === "object" && msg.Params.F) {
|
||||||
global[msg.Name](msg.Params, function(Err, Ret) {
|
global[msg.Name](msg.Params, function(Err, Ret) {
|
||||||
if (msg.id && ITEM.Worker)
|
if (msg.id && ITEM.Worker)
|
||||||
ITEM.Worker.send({ cmd: "retcall", id: msg.id, Err: Err, Params: Ret });
|
ITEM.Worker.send({
|
||||||
|
cmd: "retcall",
|
||||||
|
id: msg.id,
|
||||||
|
Err: Err,
|
||||||
|
Params: Ret
|
||||||
|
});
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
Ret = global[msg.Name](msg.Params);
|
Ret = global[msg.Name](msg.Params);
|
||||||
}
|
}
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Err = 1;
|
Err = 1;
|
||||||
Ret = "" + e;
|
Ret = "" + e;
|
||||||
}
|
}
|
||||||
@ -284,7 +284,7 @@ function StartChildProcess(Item) {
|
|||||||
case "log":
|
case "log":
|
||||||
global.ToLog(msg.message);
|
global.ToLog(msg.message);
|
||||||
break;
|
break;
|
||||||
case "global.ToLogClient":
|
case "ToLogClient":
|
||||||
if (WebProcess && WebProcess.Worker) {
|
if (WebProcess && WebProcess.Worker) {
|
||||||
WebProcess.Worker.send(msg);
|
WebProcess.Worker.send(msg);
|
||||||
}
|
}
|
||||||
@ -333,14 +333,22 @@ function StartChildProcess(Item) {
|
|||||||
if (F) {
|
if (F) {
|
||||||
GlobalRunID++;
|
GlobalRunID++;
|
||||||
try {
|
try {
|
||||||
ITEM.Worker.send({ cmd: "call", id: GlobalRunID, Name: Name, Params: Params });
|
ITEM.Worker.send({
|
||||||
|
cmd: "call",
|
||||||
|
id: GlobalRunID,
|
||||||
|
Name: Name,
|
||||||
|
Params: Params
|
||||||
|
});
|
||||||
GlobalRunMap[GlobalRunID] = F;
|
GlobalRunMap[GlobalRunID] = F;
|
||||||
|
} catch (e) {
|
||||||
}
|
}
|
||||||
catch (e) {
|
} else {
|
||||||
}
|
ITEM.Worker.send({
|
||||||
}
|
cmd: "call",
|
||||||
else {
|
id: 0,
|
||||||
ITEM.Worker.send({ cmd: "call", id: 0, Name: Name, Params: Params });
|
Name: Name,
|
||||||
|
Params: Params
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -413,8 +421,7 @@ function RunStopPOWProcess(Mode) {
|
|||||||
global.MiningPaused = 1;
|
global.MiningPaused = 1;
|
||||||
if (TimeCur >= StartTime && TimeCur <= TimeEnd) {
|
if (TimeCur >= StartTime && TimeCur <= TimeEnd) {
|
||||||
global.MiningPaused = 0;
|
global.MiningPaused = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
StartTime -= 24 * 3600;
|
StartTime -= 24 * 3600;
|
||||||
TimeEnd -= 24 * 3600;
|
TimeEnd -= 24 * 3600;
|
||||||
if (TimeCur >= StartTime && TimeCur <= TimeEnd) {
|
if (TimeCur >= StartTime && TimeCur <= TimeEnd) {
|
||||||
@ -425,16 +432,13 @@ function RunStopPOWProcess(Mode) {
|
|||||||
global.ToLog("------------ MINING MUST STOP ON TIME");
|
global.ToLog("------------ MINING MUST STOP ON TIME");
|
||||||
ClearArrMining();
|
ClearArrMining();
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (!global.ArrMiningWrk.length && !global.MiningPaused) {
|
if (!global.ArrMiningWrk.length && !global.MiningPaused) {
|
||||||
global.ToLog("*********** MINING MUST START ON TIME");
|
global.ToLog("*********** MINING MUST START ON TIME");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
global.MiningPaused = 0;
|
global.MiningPaused = 0;
|
||||||
}
|
}
|
||||||
if (!global.USE_MINING || Mode === "STOP") {
|
if (!global.USE_MINING || Mode === "STOP") {
|
||||||
@ -480,12 +484,10 @@ function RunStopPOWProcess(Mode) {
|
|||||||
if (msg.cmd === "online") {
|
if (msg.cmd === "online") {
|
||||||
Worker.bOnline = true;
|
Worker.bOnline = true;
|
||||||
global.ToLog("RUNNING PROCESS:" + Worker.Num + ":" + msg.message);
|
global.ToLog("RUNNING PROCESS:" + Worker.Num + ":" + msg.message);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (msg.cmd === "POW") {
|
if (msg.cmd === "POW") {
|
||||||
global.SERVER.MiningProcess(msg);
|
global.SERVER.MiningProcess(msg);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (msg.cmd === "HASHRATE") {
|
if (msg.cmd === "HASHRATE") {
|
||||||
global.ADD_HASH_RATE(msg.CountNonce);
|
global.ADD_HASH_RATE(msg.CountNonce);
|
||||||
}
|
}
|
||||||
@ -518,9 +520,20 @@ function SetCalcPOW(Block, cmd) {
|
|||||||
if (!CurWorker.bOnline)
|
if (!CurWorker.bOnline)
|
||||||
continue;
|
continue;
|
||||||
CurWorker.send({
|
CurWorker.send({
|
||||||
cmd: cmd, BlockNum: Block.BlockNum, Account: global.GENERATE_BLOCK_ACCOUNT, MinerID: global.GENERATE_BLOCK_ACCOUNT, SeqHash: Block.SeqHash,
|
cmd: cmd,
|
||||||
Hash: Block.Hash, PrevHash: Block.PrevHash, Time: Date.now(), Num: CurWorker.Num, RunPeriod: global.POWRunPeriod, RunCount: global.POW_RUN_COUNT,
|
BlockNum: Block.BlockNum,
|
||||||
Percent: global.POW_MAX_PERCENT, CountMiningCPU: global.GetCountMiningCPU(), ProcessMemorySize: ProcessMemorySize,
|
Account: global.GENERATE_BLOCK_ACCOUNT,
|
||||||
|
MinerID: global.GENERATE_BLOCK_ACCOUNT,
|
||||||
|
SeqHash: Block.SeqHash,
|
||||||
|
Hash: Block.Hash,
|
||||||
|
PrevHash: Block.PrevHash,
|
||||||
|
Time: Date.now(),
|
||||||
|
Num: CurWorker.Num,
|
||||||
|
RunPeriod: global.POWRunPeriod,
|
||||||
|
RunCount: global.POW_RUN_COUNT,
|
||||||
|
Percent: global.POW_MAX_PERCENT,
|
||||||
|
CountMiningCPU: global.GetCountMiningCPU(),
|
||||||
|
ProcessMemorySize: ProcessMemorySize,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -567,8 +580,7 @@ function DoConnectToNodes(Arr, Mode) {
|
|||||||
if (Mode === "CONNECT") {
|
if (Mode === "CONNECT") {
|
||||||
Node.WasAddToConnect = undefined;
|
Node.WasAddToConnect = undefined;
|
||||||
global.SERVER.StartConnectTry(Node);
|
global.SERVER.StartConnectTry(Node);
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (Mode === "RECONNECT") {
|
if (Mode === "RECONNECT") {
|
||||||
Node.WasAddToReconnect = undefined;
|
Node.WasAddToReconnect = undefined;
|
||||||
Node.CreateConnect();
|
Node.CreateConnect();
|
||||||
|
@ -8,82 +8,132 @@
|
|||||||
* Telegram: https://t.me/terafoundation
|
* Telegram: https://t.me/terafoundation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
global.PROCESS_NAME = "POW"
|
global.PROCESS_NAME = "POW";
|
||||||
global.POWPROCESS = 1
|
global.POWPROCESS = 1;
|
||||||
require("../core/library")
|
import "../core/library"
|
||||||
require("../core/crypto-library")
|
import "../core/crypto-library"
|
||||||
require("../core/terahashmining");
|
import "../core/terahashmining"
|
||||||
var PROCESS = process;
|
var PROCESS = process;
|
||||||
process.send && !global.DEBUGPROCESS ? process.send({ cmd: "online", message: "OK" }) : PROCESS = global.DEBUGPROCESS;
|
if (process.send && !global.DEBUGPROCESS) {
|
||||||
|
process.send({ cmd: "online", message: "OK" });
|
||||||
|
} else {
|
||||||
|
PROCESS = global.DEBUGPROCESS;
|
||||||
|
}
|
||||||
var LastAlive = Date.now();
|
var LastAlive = Date.now();
|
||||||
setInterval(CheckAlive, 1e3);
|
setInterval(CheckAlive, 1000);
|
||||||
var idInterval = void 0, Block: any = {};
|
var idInterval = undefined;
|
||||||
|
var Block: any = {};
|
||||||
|
PROCESS.on('message', function(msg) {
|
||||||
|
LastAlive = Date.now();
|
||||||
|
if (msg.cmd === "FastCalcBlock") {
|
||||||
|
var FastBlock = msg;
|
||||||
|
StartHashPump(FastBlock);
|
||||||
|
FastBlock.RunCount = 0;
|
||||||
|
try {
|
||||||
|
if (global.CreatePOWVersionX(FastBlock))
|
||||||
|
process.send({
|
||||||
|
cmd: "POW",
|
||||||
|
BlockNum: FastBlock.BlockNum,
|
||||||
|
SeqHash: FastBlock.SeqHash,
|
||||||
|
Hash: FastBlock.Hash,
|
||||||
|
PowHash: FastBlock.PowHash,
|
||||||
|
AddrHash: FastBlock.AddrHash,
|
||||||
|
Num: FastBlock.Num
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
global.ToError(e);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (msg.cmd === "SetBlock") {
|
||||||
|
var StartNonce = 1000000 * (1 + msg.Num);
|
||||||
|
if (Block.HashCount) {
|
||||||
|
process.send({ cmd: "HASHRATE", CountNonce: Block.HashCount, Hash: Block.Hash });
|
||||||
|
}
|
||||||
|
Block.HashCount = 0;
|
||||||
|
Block = msg;
|
||||||
|
Block.Time = Date.now();
|
||||||
|
Block.LastNonce = StartNonce;
|
||||||
|
Block.Period = global.CONSENSUS_PERIOD_TIME * Block.Percent / 100;
|
||||||
|
if (Block.Period > 0 && Block.RunPeriod > 0) {
|
||||||
|
CalcPOWHash();
|
||||||
|
if (idInterval !== undefined) {
|
||||||
|
clearInterval(idInterval);
|
||||||
|
}
|
||||||
|
idInterval = setInterval(CalcPOWHash, Block.RunPeriod);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if (msg.cmd === "Alive") {
|
||||||
|
} else
|
||||||
|
if (msg.cmd === "Exit") {
|
||||||
|
PROCESS.exit(0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function CheckAlive() {
|
function CheckAlive() {
|
||||||
if (!global.NOALIVE) {
|
if (global.NOALIVE)
|
||||||
var e = Date.now() - LastAlive;
|
return;
|
||||||
Math.abs(e) > global.CHECK_STOP_CHILD_PROCESS && PROCESS.exit(0);
|
var Delta = Date.now() - LastAlive;
|
||||||
|
if (Math.abs(Delta) > global.CHECK_STOP_CHILD_PROCESS) {
|
||||||
|
PROCESS.exit(0);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function CalcPOWHash() {
|
function CalcPOWHash() {
|
||||||
if (Block.SeqHash) {
|
if (!Block.SeqHash)
|
||||||
if ((new Date as any) - Block.Time > Block.Period)
|
return;
|
||||||
return clearInterval(idInterval), void (idInterval = void 0);
|
if ((new Date() as any) - Block.Time > Block.Period) {
|
||||||
try {
|
clearInterval(idInterval);
|
||||||
global.CreatePOWVersionX(Block) && process.send({
|
idInterval = undefined;
|
||||||
cmd: "POW", BlockNum: Block.BlockNum, SeqHash: Block.SeqHash, Hash: Block.Hash, PowHash: Block.PowHash,
|
return;
|
||||||
AddrHash: Block.AddrHash, Num: Block.Num
|
}
|
||||||
|
try {
|
||||||
|
if (global.CreatePOWVersionX(Block))
|
||||||
|
process.send({
|
||||||
|
cmd: "POW", BlockNum: Block.BlockNum, SeqHash: Block.SeqHash, Hash: Block.Hash, PowHash: Block.PowHash, AddrHash: Block.AddrHash,
|
||||||
|
Num: Block.Num
|
||||||
});
|
});
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
global.ToError(e);
|
||||||
global.ToError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
PROCESS.on("message", function(e) {
|
global.BlockPump = undefined;
|
||||||
if (LastAlive = Date.now(), "FastCalcBlock" === e.cmd) {
|
var idIntervalPump = undefined;
|
||||||
var o = e;
|
|
||||||
StartHashPump(o), o.RunCount = 0;
|
function StartHashPump(SetBlock) {
|
||||||
try {
|
if (!global.BlockPump || global.BlockPump.BlockNum < SetBlock.BlockNum || global.BlockPump.MinerID !== SetBlock.MinerID || global.BlockPump.Percent !== SetBlock.Percent) {
|
||||||
global.CreatePOWVersionX(o) && process.send({
|
global.BlockPump = {
|
||||||
cmd: "POW", BlockNum: o.BlockNum, SeqHash: o.SeqHash, Hash: o.Hash, PowHash: o.PowHash, AddrHash: o.AddrHash,
|
BlockNum: SetBlock.BlockNum,
|
||||||
Num: o.Num
|
RunCount: SetBlock.RunCount,
|
||||||
});
|
MinerID: SetBlock.MinerID,
|
||||||
} catch (e) {
|
Percent: SetBlock.Percent,
|
||||||
global.ToError(e);
|
LastNonce: 0,
|
||||||
}
|
};
|
||||||
} else {
|
}
|
||||||
if ("SetBlock" === e.cmd) {
|
if (!idIntervalPump) {
|
||||||
var a = 1e6 * (1 + e.Num);
|
idIntervalPump = setInterval(PumpHash, global.POWRunPeriod);
|
||||||
Block.HashCount && process.send({ cmd: "HASHRATE", CountNonce: Block.HashCount, Hash: Block.Hash }), Block.HashCount = 0, (Block = e).Time = Date.now(),
|
|
||||||
Block.LastNonce = a, Block.Period = global.CONSENSUS_PERIOD_TIME * Block.Percent / 100, 0 < Block.Period && 0 < Block.RunPeriod && (CalcPOWHash(),
|
|
||||||
void 0 !== idInterval && clearInterval(idInterval), idInterval = setInterval(CalcPOWHash, Block.RunPeriod));
|
|
||||||
} else {
|
|
||||||
"Alive" === e.cmd || "Exit" === e.cmd && PROCESS.exit(0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
|
||||||
var idIntervalPump = global.BlockPump = void 0;
|
|
||||||
|
|
||||||
function StartHashPump(e) {
|
|
||||||
(!global.BlockPump || global.BlockPump.BlockNum < e.BlockNum || global.BlockPump.MinerID !== e.MinerID || global.BlockPump.Percent !== e.Percent) && (global.BlockPump = {
|
|
||||||
BlockNum: e.BlockNum,
|
|
||||||
RunCount: e.RunCount, MinerID: e.MinerID, Percent: e.Percent, LastNonce: 0
|
|
||||||
}), idIntervalPump = idIntervalPump || setInterval(PumpHash, global.POWRunPeriod);
|
|
||||||
};
|
};
|
||||||
var StartTime = 1, EndTime = 0;
|
var StartTime = 1;
|
||||||
|
var EndTime = 0;
|
||||||
|
|
||||||
function PumpHash() {
|
function PumpHash() {
|
||||||
if (global.BlockPump) {
|
if (!global.BlockPump)
|
||||||
var e = Date.now();
|
return;
|
||||||
if (EndTime < StartTime) {
|
var CurTime = Date.now();
|
||||||
if (100 * (e - StartTime) / global.CONSENSUS_PERIOD_TIME >= global.BlockPump.Percent)
|
if (StartTime > EndTime) {
|
||||||
return void (EndTime = e);
|
var Delta = CurTime - StartTime;
|
||||||
global.CreatePOWVersionX(global.BlockPump, 1);
|
var PeriodPercent = 100 * Delta / global.CONSENSUS_PERIOD_TIME;
|
||||||
} else {
|
if (PeriodPercent >= global.BlockPump.Percent) {
|
||||||
100 * (e - EndTime) / global.CONSENSUS_PERIOD_TIME > 100 - global.BlockPump.Percent && (StartTime = e);
|
EndTime = CurTime;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
global.CreatePOWVersionX(global.BlockPump, 1);
|
||||||
|
} else {
|
||||||
|
var Delta = CurTime - EndTime;
|
||||||
|
var PeriodPercent = 100 * Delta / global.CONSENSUS_PERIOD_TIME;
|
||||||
|
if (PeriodPercent > 100 - global.BlockPump.Percent) {
|
||||||
|
StartTime = CurTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -41,8 +41,7 @@ process.on('message', function(msg) {
|
|||||||
var Ret;
|
var Ret;
|
||||||
try {
|
try {
|
||||||
Ret = global[msg.Name](msg.Params);
|
Ret = global[msg.Name](msg.Params);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Err = 1;
|
Err = 1;
|
||||||
Ret = "" + e;
|
Ret = "" + e;
|
||||||
}
|
}
|
||||||
@ -243,8 +242,7 @@ function GETREST(msg) {
|
|||||||
global.ToLog("Get bad rest acc hash: " + BlockNumRest + " = " + global.GetHexFromArr(Data.AccHash) + "/" + global.GetHexFromArr(Tree.Root), 2);
|
global.ToLog("Get bad rest acc hash: " + BlockNumRest + " = " + global.GetHexFromArr(Data.AccHash) + "/" + global.GetHexFromArr(Tree.Root), 2);
|
||||||
ArrRest = [];
|
ArrRest = [];
|
||||||
nResult = 0;
|
nResult = 0;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
ArrRest = GetArrRest(BlockNumRest, StartAccount, EndAccount);
|
ArrRest = GetArrRest(BlockNumRest, StartAccount, EndAccount);
|
||||||
ProofHash = Tree.Root;
|
ProofHash = Tree.Root;
|
||||||
var RetProof = global.GetMerkleProof(Tree.LevelsHash, StartAccount, EndAccount);
|
var RetProof = global.GetMerkleProof(Tree.LevelsHash, StartAccount, EndAccount);
|
||||||
@ -254,9 +252,22 @@ function GETREST(msg) {
|
|||||||
BufLength += ProofArrL.length * 32 + ProofArrR.length * 32 + 32;
|
BufLength += ProofArrL.length * 32 + ProofArrR.length * 32 + 32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var Data2 = { Result: nResult, Arr: ArrRest, Version: 1, ProofHash: ProofHash, ProofArrL: ProofArrL, ProofArrR: ProofArrR };
|
var Data2 = {
|
||||||
|
Result: nResult,
|
||||||
|
Arr: ArrRest,
|
||||||
|
Version: 1,
|
||||||
|
ProofHash: ProofHash,
|
||||||
|
ProofArrL: ProofArrL,
|
||||||
|
ProofArrR: ProofArrR
|
||||||
|
};
|
||||||
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_REST_TRANSFER, BufLength, {});
|
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_REST_TRANSFER, BufLength, {});
|
||||||
process.send({ cmd: "Send", addrStr: msg.addrStr, Method: "RETREST", Context: msg.Context, Data: BufWrite });
|
process.send({
|
||||||
|
cmd: "Send",
|
||||||
|
addrStr: msg.addrStr,
|
||||||
|
Method: "RETREST",
|
||||||
|
Context: msg.Context,
|
||||||
|
Data: BufWrite
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
function GETSMART(msg) {
|
function GETSMART(msg) {
|
||||||
@ -278,7 +289,13 @@ function GETSMART(msg) {
|
|||||||
}
|
}
|
||||||
var Data2 = { Result: Arr.length ? 1 : 0, Arr: Arr };
|
var Data2 = { Result: Arr.length ? 1 : 0, Arr: Arr };
|
||||||
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_SMART_TRANSFER, BufLength, {});
|
var BufWrite = global.BufLib.GetBufferFromObject(Data2, global.FORMAT_SMART_TRANSFER, BufLength, {});
|
||||||
process.send({ cmd: "Send", addrStr: msg.addrStr, Method: "RETSMART", Context: msg.Context, Data: BufWrite });
|
process.send({
|
||||||
|
cmd: "Send",
|
||||||
|
addrStr: msg.addrStr,
|
||||||
|
Method: "RETSMART",
|
||||||
|
Context: msg.Context,
|
||||||
|
Data: BufWrite
|
||||||
|
});
|
||||||
};
|
};
|
||||||
var glMapForHash = {};
|
var glMapForHash = {};
|
||||||
|
|
||||||
|
@ -26,7 +26,12 @@ if (process.send) {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
process.send({ cmd: "online", message: "OK" });
|
process.send({ cmd: "online", message: "OK" });
|
||||||
global.ToLogClient = function(Str, StrKey, bFinal) {
|
global.ToLogClient = function(Str, StrKey, bFinal) {
|
||||||
process.send({ cmd: "ToLogClient", Str: "" + Str, StrKey: StrKey, bFinal: bFinal });
|
process.send({
|
||||||
|
cmd: "ToLogClient",
|
||||||
|
Str: "" + Str,
|
||||||
|
StrKey: StrKey,
|
||||||
|
bFinal: bFinal
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
process.on('message', function(msg) {
|
process.on('message', function(msg) {
|
||||||
@ -42,13 +47,17 @@ process.on('message', function(msg) {
|
|||||||
var Ret;
|
var Ret;
|
||||||
try {
|
try {
|
||||||
Ret = global[msg.Name](msg.Params);
|
Ret = global[msg.Name](msg.Params);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Err = 1;
|
Err = 1;
|
||||||
Ret = "" + e;
|
Ret = "" + e;
|
||||||
}
|
}
|
||||||
if (msg.id)
|
if (msg.id)
|
||||||
process.send({ cmd: "retcall", id: msg.id, Err: Err, Params: Ret });
|
process.send({
|
||||||
|
cmd: "retcall",
|
||||||
|
id: msg.id,
|
||||||
|
Err: Err,
|
||||||
|
Params: Ret
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case "FindTX":
|
case "FindTX":
|
||||||
global.TreeFindTX.SaveValue(msg.TX, msg);
|
global.TreeFindTX.SaveValue(msg.TX, msg);
|
||||||
@ -234,7 +243,11 @@ function InitTXProcess() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.ToLog("DETECT NEW VER on BlockNum=" + LastBlockNum, 2);
|
global.ToLog("DETECT NEW VER on BlockNum=" + LastBlockNum, 2);
|
||||||
global.DApps.Accounts.DBStateTX.Write({ Num: 0, BlockNum: LastBlockNum, BlockNumMin: MinimalValidBlock });
|
global.DApps.Accounts.DBStateTX.Write({
|
||||||
|
Num: 0,
|
||||||
|
BlockNum: LastBlockNum,
|
||||||
|
BlockNumMin: MinimalValidBlock
|
||||||
|
});
|
||||||
}
|
}
|
||||||
StateTX = global.DApps.Accounts.DBStateTX.Read(0);
|
StateTX = global.DApps.Accounts.DBStateTX.Read(0);
|
||||||
LastBlockNum = StateTX.BlockNum;
|
LastBlockNum = StateTX.BlockNum;
|
||||||
@ -347,8 +360,7 @@ global.EvalCode = function(Code) {
|
|||||||
try {
|
try {
|
||||||
var ret = eval(Code);
|
var ret = eval(Code);
|
||||||
Result = JSON.stringify(ret, undefined, 4);
|
Result = JSON.stringify(ret, undefined, 4);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Result = "" + e;
|
Result = "" + e;
|
||||||
}
|
}
|
||||||
return Result;
|
return Result;
|
||||||
|
@ -47,8 +47,7 @@ process.on('message', function(msg) {
|
|||||||
var Ret;
|
var Ret;
|
||||||
try {
|
try {
|
||||||
Ret = global[msg.Name](msg.Params);
|
Ret = global[msg.Name](msg.Params);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Err = 1;
|
Err = 1;
|
||||||
Ret = "" + e;
|
Ret = "" + e;
|
||||||
}
|
}
|
||||||
@ -181,8 +180,7 @@ if (global.HTTPS_HOSTING_DOMAIN) {
|
|||||||
global.ToError(err);
|
global.ToError(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
HostingServer = http.createServer(MainHTTPFunction);
|
HostingServer = http.createServer(MainHTTPFunction);
|
||||||
RunListenServer();
|
RunListenServer();
|
||||||
}
|
}
|
||||||
@ -216,16 +214,14 @@ function MainHTTPFunction(request, response) {
|
|||||||
if (postData && postData.length) {
|
if (postData && postData.length) {
|
||||||
try {
|
try {
|
||||||
Data = JSON.parse(postData);
|
Data = JSON.parse(postData);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Response.writeHead(405, { 'Content-Type': 'text/html' });
|
Response.writeHead(405, { 'Content-Type': 'text/html' });
|
||||||
Response.end("Error data parsing");
|
Response.end("Error data parsing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DoCommandNew(response, Type, Path, Data);
|
DoCommandNew(response, Type, Path, Data);
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
DoCommandNew(response, Type, Path, Params);
|
DoCommandNew(response, Type, Path, Params);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -334,8 +330,7 @@ function DoCommandNew(response, Type, Path, Params) {
|
|||||||
var Ret;
|
var Ret;
|
||||||
try {
|
try {
|
||||||
Ret = F(Params, response, ArrPath);
|
Ret = F(Params, response, ArrPath);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Ret = { result: 0, text: e.message, text2: e.stack };
|
Ret = { result: 0, text: e.message, text2: e.stack };
|
||||||
}
|
}
|
||||||
if (Ret === null)
|
if (Ret === null)
|
||||||
@ -347,8 +342,7 @@ function DoCommandNew(response, Type, Path, Params) {
|
|||||||
else
|
else
|
||||||
Str = Ret;
|
Str = Ret;
|
||||||
response.end(Str);
|
response.end(Str);
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
global.ToLog("ERR PATH:" + Path);
|
global.ToLog("ERR PATH:" + Path);
|
||||||
global.ToLog(e);
|
global.ToLog(e);
|
||||||
response.end();
|
response.end();
|
||||||
@ -395,12 +389,10 @@ function DoCommandNew(response, Type, Path, Params) {
|
|||||||
Name = PrefixPath + Name;
|
Name = PrefixPath + Name;
|
||||||
global.SendWebFile(response, Name, Path);
|
global.SendWebFile(response, Name, Path);
|
||||||
return;
|
return;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
if (LangPathMap[Method]) {
|
if (LangPathMap[Method]) {
|
||||||
PrefixPath = "./SITE/" + Method;
|
PrefixPath = "./SITE/" + Method;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
var Name2 = WalletFileMap[Name];
|
var Name2 = WalletFileMap[Name];
|
||||||
if (!Name2)
|
if (!Name2)
|
||||||
PrefixPath = "./SITE";
|
PrefixPath = "./SITE";
|
||||||
@ -610,8 +602,7 @@ HostingCaller.GetAccountListByKey = function(Params, ppp, bRet) {
|
|||||||
Data.SmartState = global.BufLib.GetObjectFromBuffer(Data.Value.Data, Data.SmartObj.StateFormat, {});
|
Data.SmartState = global.BufLib.GetObjectFromBuffer(Data.Value.Data, Data.SmartObj.StateFormat, {});
|
||||||
if (typeof Data.SmartState === "object")
|
if (typeof Data.SmartState === "object")
|
||||||
Data.SmartState.Num = Item.Num;
|
Data.SmartState.Num = Item.Num;
|
||||||
}
|
} catch (e) {
|
||||||
catch (e) {
|
|
||||||
Data.SmartState = {};
|
Data.SmartState = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -793,11 +784,9 @@ process.RunRPC = function(Name, Params, F) {
|
|||||||
try {
|
try {
|
||||||
process.send({ cmd: "call", id: global.GlobalRunID, Name: Name, Params: Params });
|
process.send({ cmd: "call", id: global.GlobalRunID, Name: Name, Params: Params });
|
||||||
global.GlobalRunMap[global.GlobalRunID] = F;
|
global.GlobalRunMap[global.GlobalRunID] = F;
|
||||||
|
} catch (e) {
|
||||||
}
|
}
|
||||||
catch (e) {
|
} else {
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
process.send({ cmd: "call", id: 0, Name: Name, Params: Params });
|
process.send({ cmd: "call", id: 0, Name: Name, Params: Params });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user