forked from circlecloud/tera
		
	@@ -10,8 +10,9 @@
 | 
			
		||||
 | 
			
		||||
import '../core/constant'
 | 
			
		||||
global.PROCESS_NAME = "MAIN";
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
const os = require('os');
 | 
			
		||||
import fs = require('fs');
 | 
			
		||||
import os = require('os');
 | 
			
		||||
import path = require('path')
 | 
			
		||||
import * as crypto from 'crypto';
 | 
			
		||||
 | 
			
		||||
global.START_SERVER = 1;
 | 
			
		||||
@@ -19,7 +20,7 @@ global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
 | 
			
		||||
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
 | 
			
		||||
console.log("DATA DIR: " + global.DATA_PATH);
 | 
			
		||||
console.log("PROGRAM DIR: " + global.CODE_PATH);
 | 
			
		||||
require("../core/library");
 | 
			
		||||
import "../core/library"
 | 
			
		||||
global.ToLog(os.platform() + " (" + os.arch() + ") " + os.release());
 | 
			
		||||
var VerArr = process.versions.node.split('.');
 | 
			
		||||
global.ToLog("nodejs: " + process.versions.node);
 | 
			
		||||
@@ -27,7 +28,7 @@ if ((VerArr[0] as any as number) < 8) {
 | 
			
		||||
    global.ToError("Error version of NodeJS=" + VerArr[0] + "  Pls, download new version from www.nodejs.org and update it. The minimum version must be 8");
 | 
			
		||||
    process.exit();
 | 
			
		||||
}
 | 
			
		||||
var CServer = require("../core/server");
 | 
			
		||||
import CServer from '../core/server'
 | 
			
		||||
const DEF_PERIOD_SIGN_LIB = 500;
 | 
			
		||||
setTimeout(function() {
 | 
			
		||||
    TestSignLib(DEF_PERIOD_SIGN_LIB);
 | 
			
		||||
@@ -384,22 +385,12 @@ function ClearArrMining() {
 | 
			
		||||
    ArrMiningWrk = [];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
let {
 | 
			
		||||
    GetCountMiningCPU,
 | 
			
		||||
    CHECK_RUN_MINING,
 | 
			
		||||
    GetSecFromStrTime,
 | 
			
		||||
    SERVER,
 | 
			
		||||
    GENERATE_BLOCK_ACCOUNT,
 | 
			
		||||
    GetCodePath,
 | 
			
		||||
    GrayConnect
 | 
			
		||||
} = global
 | 
			
		||||
 | 
			
		||||
function RunStopPOWProcess(Mode) {
 | 
			
		||||
    if (!GetCountMiningCPU() || GetCountMiningCPU() <= 0)
 | 
			
		||||
    if (!global.GetCountMiningCPU() || global.GetCountMiningCPU() <= 0)
 | 
			
		||||
        return;
 | 
			
		||||
    if (!StartCheckMining) {
 | 
			
		||||
        StartCheckMining = 1;
 | 
			
		||||
        setInterval(RunStopPOWProcess, CHECK_RUN_MINING);
 | 
			
		||||
        setInterval(RunStopPOWProcess, global.CHECK_RUN_MINING);
 | 
			
		||||
        setInterval(AllAlive, 1000);
 | 
			
		||||
    }
 | 
			
		||||
    if (global.NeedRestart)
 | 
			
		||||
@@ -407,8 +398,8 @@ function RunStopPOWProcess(Mode) {
 | 
			
		||||
    if (global.USE_MINING && global.MINING_START_TIME && global.MINING_PERIOD_TIME) {
 | 
			
		||||
        var Time = global.GetCurrentTime();
 | 
			
		||||
        var TimeCur = Time.getUTCHours() * 3600 + Time.getUTCMinutes() * 60 + Time.getUTCSeconds();
 | 
			
		||||
        var StartTime = GetSecFromStrTime(global.MINING_START_TIME);
 | 
			
		||||
        var RunPeriod = GetSecFromStrTime(global.MINING_PERIOD_TIME);
 | 
			
		||||
        var StartTime = global.GetSecFromStrTime(global.MINING_START_TIME);
 | 
			
		||||
        var RunPeriod = global.GetSecFromStrTime(global.MINING_PERIOD_TIME);
 | 
			
		||||
        var TimeEnd = StartTime + RunPeriod;
 | 
			
		||||
        global.MiningPaused = 1;
 | 
			
		||||
        if (TimeCur >= StartTime && TimeCur <= TimeEnd) {
 | 
			
		||||
@@ -443,16 +434,16 @@ function RunStopPOWProcess(Mode) {
 | 
			
		||||
    }
 | 
			
		||||
    if (global.USE_MINING && ArrMiningWrk.length)
 | 
			
		||||
        return;
 | 
			
		||||
    if (SERVER.LoadHistoryMode)
 | 
			
		||||
    if (global.SERVER.LoadHistoryMode)
 | 
			
		||||
        return;
 | 
			
		||||
    if (GENERATE_BLOCK_ACCOUNT < 8)
 | 
			
		||||
    if (global.GENERATE_BLOCK_ACCOUNT < 8)
 | 
			
		||||
        return;
 | 
			
		||||
    var PathMiner = global.GetCodePath("../miner.js");
 | 
			
		||||
    if (!fs.existsSync(PathMiner))
 | 
			
		||||
        PathMiner = "./process/pow-process.js";
 | 
			
		||||
    if (ArrMiningWrk.length >= GetCountMiningCPU())
 | 
			
		||||
    if (ArrMiningWrk.length >= global.GetCountMiningCPU())
 | 
			
		||||
        return;
 | 
			
		||||
    if (GrayConnect()) {
 | 
			
		||||
    if (global.GrayConnect()) {
 | 
			
		||||
        global.ToLog("CANNOT START MINER IN NOT DIRECT IP MODE");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
@@ -460,15 +451,15 @@ function RunStopPOWProcess(Mode) {
 | 
			
		||||
    if (global.SIZE_MINING_MEMORY)
 | 
			
		||||
        Memory = global.SIZE_MINING_MEMORY;
 | 
			
		||||
    else {
 | 
			
		||||
        Memory = os.freemem() - (512 + GetCountMiningCPU() * 100) * 1024 * 1014;
 | 
			
		||||
        Memory = os.freemem() - (512 + global.GetCountMiningCPU() * 100) * 1024 * 1014;
 | 
			
		||||
        if (Memory < 0) {
 | 
			
		||||
            global.ToLog("Not enough memory to start processes.");
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    ProcessMemorySize = Math.trunc(Memory / GetCountMiningCPU());
 | 
			
		||||
    global.ToLog("START MINER PROCESS COUNT: " + GetCountMiningCPU() + " Memory: " + ProcessMemorySize / 1024 / 1024 + " Mb for each process");
 | 
			
		||||
    for (var R = 0; R < GetCountMiningCPU(); R++) {
 | 
			
		||||
    ProcessMemorySize = Math.trunc(Memory / global.GetCountMiningCPU());
 | 
			
		||||
    global.ToLog("START MINER PROCESS COUNT: " + global.GetCountMiningCPU() + " Memory: " + ProcessMemorySize / 1024 / 1024 + " Mb for each process");
 | 
			
		||||
    for (var R = 0; R < global.GetCountMiningCPU(); R++) {
 | 
			
		||||
        let Worker = Fork(PathMiner);
 | 
			
		||||
        ArrMiningWrk.push(Worker);
 | 
			
		||||
        Worker.Num = ArrMiningWrk.length;
 | 
			
		||||
@@ -510,7 +501,7 @@ function RunStopPOWProcess(Mode) {
 | 
			
		||||
function SetCalcPOW(Block, cmd) {
 | 
			
		||||
    if (!global.USE_MINING)
 | 
			
		||||
        return;
 | 
			
		||||
    if (ArrMiningWrk.length !== GetCountMiningCPU())
 | 
			
		||||
    if (ArrMiningWrk.length !== global.GetCountMiningCPU())
 | 
			
		||||
        return;
 | 
			
		||||
    BlockMining = Block;
 | 
			
		||||
    for (var i = 0; i < ArrMiningWrk.length; i++) {
 | 
			
		||||
@@ -518,9 +509,9 @@ function SetCalcPOW(Block, cmd) {
 | 
			
		||||
        if (!CurWorker.bOnline)
 | 
			
		||||
            continue;
 | 
			
		||||
        CurWorker.send({
 | 
			
		||||
            cmd: cmd, BlockNum: Block.BlockNum, Account: GENERATE_BLOCK_ACCOUNT, MinerID: GENERATE_BLOCK_ACCOUNT, SeqHash: Block.SeqHash,
 | 
			
		||||
            cmd: cmd, BlockNum: Block.BlockNum, 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: GetCountMiningCPU(), ProcessMemorySize: ProcessMemorySize,
 | 
			
		||||
            Percent: global.POW_MAX_PERCENT, CountMiningCPU: global.GetCountMiningCPU(), ProcessMemorySize: ProcessMemorySize,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
@@ -528,11 +519,11 @@ global.SetCalcPOW = SetCalcPOW;
 | 
			
		||||
global.RunStopPOWProcess = RunStopPOWProcess;
 | 
			
		||||
 | 
			
		||||
function DoGetNodes() {
 | 
			
		||||
    if (!SERVER)
 | 
			
		||||
    if (!global.SERVER)
 | 
			
		||||
        return;
 | 
			
		||||
    if (!GrayConnect() && global.SERVER.CanSend < 2)
 | 
			
		||||
    if (!global.GrayConnect() && global.SERVER.CanSend < 2)
 | 
			
		||||
        return;
 | 
			
		||||
    if (!SERVER.NodesArrUnSort || !SERVER.NodesArrUnSort.length)
 | 
			
		||||
    if (!global.SERVER.NodesArrUnSort || !global.SERVER.NodesArrUnSort.length)
 | 
			
		||||
        return;
 | 
			
		||||
    var Num = global.glCurNumFindArr % global.SERVER.NodesArrUnSort.length;
 | 
			
		||||
    var Node = global.SERVER.NodesArrUnSort[Num];
 | 
			
		||||
@@ -541,9 +532,9 @@ function DoGetNodes() {
 | 
			
		||||
    global.glCurNumFindArr++;
 | 
			
		||||
    if (Node.Delete)
 | 
			
		||||
        return;
 | 
			
		||||
    if (SERVER.NodeInBan(Node))
 | 
			
		||||
    if (global.SERVER.NodeInBan(Node))
 | 
			
		||||
        return;
 | 
			
		||||
    if (SERVER.BusyLevel && Node.BlockProcessCount <= global.SERVER.BusyLevel)
 | 
			
		||||
    if (global.SERVER.BusyLevel && Node.BlockProcessCount <= global.SERVER.BusyLevel)
 | 
			
		||||
        return;
 | 
			
		||||
    if (GetSocketStatus(Node.Socket) === 100) {
 | 
			
		||||
        global.SERVER.StartGetNodes(Node);
 | 
			
		||||
@@ -551,12 +542,12 @@ function DoGetNodes() {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
function DoConnectToNodes(Arr, Mode) {
 | 
			
		||||
    if (!SERVER)
 | 
			
		||||
    if (!global.SERVER)
 | 
			
		||||
        return;
 | 
			
		||||
    if (!GrayConnect() && global.SERVER.CanSend < 2) {
 | 
			
		||||
    if (!global.GrayConnect() && global.SERVER.CanSend < 2) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    if (GrayConnect() && global.SERVER.ActualNodes.size > global.GetGrayServerConnections())
 | 
			
		||||
    if (global.GrayConnect() && global.SERVER.ActualNodes.size > global.GetGrayServerConnections())
 | 
			
		||||
        return;
 | 
			
		||||
    if (Arr.length) {
 | 
			
		||||
        var MinProcessCount = global.SERVER.BusyLevel - 1;
 | 
			
		||||
 
 | 
			
		||||
@@ -93,8 +93,7 @@ process.on('error' as any, function(err: TeraError) {
 | 
			
		||||
});
 | 
			
		||||
var CServerDB = require("../core/db/block-db");
 | 
			
		||||
var KeyPair = crypto.createECDH('secp256k1');
 | 
			
		||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
 | 
			
		||||
    77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
 | 
			
		||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
 | 
			
		||||
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
 | 
			
		||||
global.HTTP_PORT_NUMBER = 0;
 | 
			
		||||
setInterval(function() {
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,6 @@
 | 
			
		||||
 | 
			
		||||
global.PROCESS_NAME = "TX";
 | 
			
		||||
import * as crypto from 'crypto';
 | 
			
		||||
const fs = require('fs');
 | 
			
		||||
require("../core/constant");
 | 
			
		||||
global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
 | 
			
		||||
global.CODE_PATH = global.GetNormalPathString(global.CODE_PATH);
 | 
			
		||||
@@ -96,14 +95,14 @@ var KeyPair = crypto.createECDH('secp256k1');
 | 
			
		||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
 | 
			
		||||
    77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
 | 
			
		||||
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
 | 
			
		||||
global.TreeFindTX = new STreeBuffer(30 * 1000, global.CompareItemHashSimple, "string");
 | 
			
		||||
global.TreeFindTX = new global.STreeBuffer(30 * 1000, global.CompareItemHashSimple, "string");
 | 
			
		||||
setInterval(function() {
 | 
			
		||||
    if (global.SERVER) {
 | 
			
		||||
        global.SERVER.Close();
 | 
			
		||||
    }
 | 
			
		||||
    DoTXProcess();
 | 
			
		||||
}, 10);
 | 
			
		||||
var BlockTree = new STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
 | 
			
		||||
var BlockTree = new global.STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
 | 
			
		||||
global.bShowDetail = 0;
 | 
			
		||||
var StopTxProcess = 0;
 | 
			
		||||
var MinimalValidBlock = 0;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user