forked from circlecloud/tera
fix: method refactor error
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
87a863a228
commit
812813da8d
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,3 +38,4 @@ screenshot
|
||||
.eslintcache
|
||||
|
||||
build
|
||||
DATA
|
||||
|
@ -15,8 +15,11 @@
|
||||
"author": "MiaoWoo<admin@yumc.pw>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "",
|
||||
"prebuild": "yarn clean"
|
||||
"clean": "npx rimraf dist",
|
||||
"prebuild": "yarn clean",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "npx tsc",
|
||||
"start": "node dist/run-node.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bintrees": "^1.0.2",
|
||||
@ -29,6 +32,8 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^12.6.1",
|
||||
"rimraf": "^2.6.3",
|
||||
"ts-node-dev": "^1.0.0-pre.40",
|
||||
"typescript": "^3.5.3"
|
||||
}
|
||||
}
|
@ -271,8 +271,8 @@ class STreeBuffer {
|
||||
CheckName
|
||||
constructor(MaxTime, CompareFunction?, KeyType?, CheckName?) {
|
||||
this.KeyType = KeyType
|
||||
this.MetaTree1 = new RBTree(CompareFunction)
|
||||
this.MetaTree2 = new RBTree(CompareFunction)
|
||||
this.MetaTree1 = new global.RBTree(CompareFunction)
|
||||
this.MetaTree2 = new global.RBTree(CompareFunction)
|
||||
this.CheckName = CheckName
|
||||
setInterval(this.ShiftMapDirect.bind(this), MaxTime)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
this.CurrentBlockNum = 0
|
||||
this.SendBlockID = 0
|
||||
this.RelayMode = false
|
||||
this.TreeSendPacket = new RBTree(global.CompareItemHash)
|
||||
this.TreeSendPacket = new global.RBTree(global.CompareItemHash)
|
||||
if (!global.ADDRLIST_MODE && !this.VirtualMode) {
|
||||
this.idBlockChainTimer = setInterval(this.StartBlockChain.bind(this), global.CONSENSUS_PERIOD_TIME - 5)
|
||||
setInterval(this.DoTransfer.bind(this), global.CONSENSUS_CHECK_TIME)
|
||||
@ -85,8 +85,8 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
Context.TransferFromAddr = {}
|
||||
Context.LevelsTransfer = []
|
||||
Context.ErrRun = ""
|
||||
Context.PowTxTree = new RBTree(global.CompareItemTimePow)
|
||||
Context.PowTicketTree = new RBTree(global.CompareItemTimePow)
|
||||
Context.PowTxTree = new global.RBTree(global.CompareItemTimePow)
|
||||
Context.PowTicketTree = new global.RBTree(global.CompareItemTimePow)
|
||||
Context.bSave = false
|
||||
Context.PrevHash = undefined
|
||||
Context.TreeHash = undefined
|
||||
@ -692,7 +692,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
}
|
||||
AddPOWToMaxTree(POW, item) {
|
||||
if (!POW.MaxTree) {
|
||||
POW.MaxTree = new RBTree(function(a, b) {
|
||||
POW.MaxTree = new global.RBTree(function(a, b) {
|
||||
return global.CompareArr(a.PowHash, b.PowHash);
|
||||
})
|
||||
}
|
||||
@ -1367,8 +1367,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
}
|
||||
}
|
||||
};
|
||||
let STreeBuffer = global.STreeBuffer;
|
||||
global.TreeBlockBuf = new STreeBuffer(50 * 1000, global.CompareItemHashSimple, "string");
|
||||
global.TreeBlockBuf = new global.STreeBuffer(50 * 1000, global.CompareItemHashSimple, "string");
|
||||
var PrevTimeIdle = 0;
|
||||
OnTimeIdle();
|
||||
|
||||
|
@ -13,7 +13,7 @@ const fs = require("fs");
|
||||
import * as crypto from 'crypto';
|
||||
require('./block-loader-const');
|
||||
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
||||
module.exports = class CBlock extends require("./rest-loader.js")
|
||||
module.exports = class CBlock extends require("./rest-loader")
|
||||
{
|
||||
MapMapLoaded
|
||||
BlockChain
|
||||
@ -1188,7 +1188,7 @@ module.exports = class CBlock extends require("./rest-loader.js")
|
||||
GetHistoryTree(typedata) {
|
||||
var Tree = global.HistoryBlockBuf.LoadValue(typedata, 1);
|
||||
if (!Tree) {
|
||||
Tree = new RBTree(global.CompareItemHash)
|
||||
Tree = new global.RBTree(global.CompareItemHash)
|
||||
global.HistoryBlockBuf.SaveValue(typedata, Tree)
|
||||
}
|
||||
return Tree;
|
||||
@ -1300,4 +1300,4 @@ global.LoadBlockFromNetwork = function(Params, F) {
|
||||
F(1);
|
||||
}
|
||||
};
|
||||
global.HistoryBlockBuf = new STreeBuffer(global.HISTORY_BLOCK_COUNT * 1000, global.CompareItemHashSimple, "string");
|
||||
global.HistoryBlockBuf = new global.STreeBuffer(global.HISTORY_BLOCK_COUNT * 1000, global.CompareItemHashSimple, "string");
|
||||
|
@ -352,7 +352,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
if (global.CREATE_ON_START)
|
||||
return;
|
||||
if (Data.CheckPoint.BlockNum && Data.CheckPoint.BlockNum > global.CHECK_POINT.BlockNum) {
|
||||
var SignArr = global.arr2(Data.CheckPoint.Hash, global.SaveToFile(Data.CheckPoint.BlockNum));
|
||||
var SignArr = global.arr2(Data.CheckPoint.Hash, global.GetArrFromValue(Data.CheckPoint.BlockNum));
|
||||
if (global.CheckDevelopSign(SignArr, Data.CheckPoint.Sign)) {
|
||||
global.CHECK_POINT = Data.CheckPoint
|
||||
this.ResetNextPingAllNode()
|
||||
@ -451,7 +451,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
Level += Delta / CodeVersion.BlockPeriod
|
||||
}
|
||||
if (Level >= CodeVersion.LevelUpdate) {
|
||||
var SignArr = global.arr2(CodeVersion.Hash, global.SaveToFile(CodeVersion.VersionNum));
|
||||
var SignArr = global.arr2(CodeVersion.Hash, global.GetArrFromValue(CodeVersion.VersionNum));
|
||||
if (global.CheckDevelopSign(SignArr, CodeVersion.Sign)) {
|
||||
global.ToLog("Get new CodeVersion = " + CodeVersion.VersionNum + " HASH:" + global.GetHexFromArr(CodeVersion.Hash).substr(0, 20))
|
||||
if (CodeVersion.VersionNum > global.CODE_VERSION.VersionNum && CodeVersion.VersionNum > global.START_LOAD_CODE.StartLoadVersionNum) {
|
||||
@ -879,7 +879,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
if (!this.SignCurrentTimeDev) {
|
||||
var SignArr = global.GetArrFromHex(global.SERVER.addrStr);
|
||||
this.SignCurrentTimeDev = global.SaveToFile(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||
this.SignCurrentTimeDev = global.GetArrFromValue(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||
}
|
||||
var Time = global.GetCurrentTime() - 0;
|
||||
global.ToLog("Send time: " + Time + " to " + NodeInfo(Node))
|
||||
|
@ -8,7 +8,7 @@
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
|
||||
global.UPDATE_CODE_VERSION_NUM = 1102;
|
||||
global.UPDATE_CODE_VERSION_NUM = 1127;
|
||||
global.MIN_CODE_VERSION_NUM = 1094;
|
||||
global.MINING_VERSION_NUM = 0;
|
||||
global.InitParamsArg = InitParamsArg;
|
||||
@ -115,7 +115,7 @@ global.HTTP_HOSTING_PORT = 0;
|
||||
global.HTTPS_HOSTING_DOMAIN = "";
|
||||
global.HTTP_MAX_COUNT_ROWS = 20;
|
||||
global.HTTP_ADMIN_PASSORD = "";
|
||||
require("./startlib.js");
|
||||
require("./startlib");
|
||||
global.MIN_POWER_POW_HANDSHAKE = 12;
|
||||
global.USE_HINT = 0;
|
||||
global.ALL_VIEW_ROWS = 0;
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Twitter: https://twitter.com/terafoundation
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
require("./library.js");
|
||||
require("./library");
|
||||
import * as crypto from 'crypto'
|
||||
|
||||
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
|
||||
|
@ -15,7 +15,7 @@ import './log'
|
||||
import * as crypto from 'crypto';
|
||||
const os = require('os');
|
||||
|
||||
var BlockTree = new STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
||||
var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
||||
const http = require('http'), net = require('net'), url = require('url'), fs = require('fs'), querystring = require('querystring');
|
||||
var ContenTypeMap = {};
|
||||
ContenTypeMap["js"] = "application/javascript";
|
||||
|
@ -13,17 +13,6 @@ import * as os from 'os'
|
||||
import './constant'
|
||||
import './log'
|
||||
|
||||
let {
|
||||
TO_ERROR_LOG,
|
||||
TimeStart,
|
||||
LOAD_CONST,
|
||||
LoadParams,
|
||||
CONST_NAME_ARR,
|
||||
SaveParams,
|
||||
SAVE_CONST,
|
||||
GetDeltaCurrentTime,
|
||||
} = global
|
||||
|
||||
Number.prototype.toStringZ = function(count) {
|
||||
var strnum = this.toString();
|
||||
if (strnum.length > count)
|
||||
@ -144,7 +133,7 @@ global.LoadParams = function(filename, DefaultValue) {
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
|
||||
global.TO_ERROR_LOG("MAINLIB", 100, "Error in file:" + filename + "\n" + err);
|
||||
}
|
||||
return DefaultValue;
|
||||
};
|
||||
@ -157,7 +146,7 @@ global.StartTime = function() {
|
||||
global.FinishTime = function(Str) {
|
||||
Str = Str || "";
|
||||
var TimeFinish = global.GetCurrentTime();
|
||||
var delta = TimeFinish - TimeStart;
|
||||
var delta = TimeFinish - global.TimeStart;
|
||||
console.log(Str + " time: " + delta + " ms");
|
||||
};
|
||||
global.CompareItemBufFD = function(a, b) {
|
||||
@ -229,10 +218,10 @@ global.CompareItemTimePow = function(a, b) {
|
||||
};
|
||||
global.LOAD_CONST = function() {
|
||||
var Count = 0;
|
||||
var constants = LoadParams(global.GetDataPath("const.lst"), {});
|
||||
var constants = global.LoadParams(global.GetDataPath("const.lst"), {});
|
||||
if (constants) {
|
||||
for (var i = 0; i < CONST_NAME_ARR.length; i++) {
|
||||
var key = CONST_NAME_ARR[i];
|
||||
for (var i = 0; i < global.CONST_NAME_ARR.length; i++) {
|
||||
var key = global.CONST_NAME_ARR[i];
|
||||
if (constants[key] !== undefined) {
|
||||
Count++;
|
||||
global[key] = constants[key];
|
||||
@ -245,12 +234,12 @@ var WasStartSaveConst = false;
|
||||
|
||||
function SaveConst() {
|
||||
var constants = {};
|
||||
for (var i = 0; i < CONST_NAME_ARR.length; i++) {
|
||||
var key = CONST_NAME_ARR[i];
|
||||
for (var i = 0; i < global.CONST_NAME_ARR.length; i++) {
|
||||
var key = global.CONST_NAME_ARR[i];
|
||||
if (global[key] !== undefined)
|
||||
constants[key] = global[key];
|
||||
}
|
||||
SaveParams(global.GetDataPath("const.lst"), constants);
|
||||
global.SaveParams(global.GetDataPath("const.lst"), constants);
|
||||
WasStartSaveConst = false;
|
||||
};
|
||||
global.SAVE_CONST = function(bForce) {
|
||||
@ -267,7 +256,7 @@ global.SAVE_CONST = function(bForce) {
|
||||
function CheckGlobalTime() {
|
||||
global.ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, NetTime) {
|
||||
if (err) {
|
||||
TO_ERROR_LOG("MAINLIB", 110, err);
|
||||
global.TO_ERROR_LOG("MAINLIB", 110, err);
|
||||
return;
|
||||
}
|
||||
var curTime = new Date;
|
||||
@ -278,9 +267,9 @@ function CheckGlobalTime() {
|
||||
if (Math.abs(global.DELTA_CURRENT_TIME) > 24 * 3600 * 1000)
|
||||
global.DELTA_CURRENT_TIME = 0;
|
||||
global.ToLog("Get global time: " + NetTime);
|
||||
SAVE_CONST();
|
||||
global.SAVE_CONST();
|
||||
});
|
||||
SAVE_CONST();
|
||||
global.SAVE_CONST();
|
||||
};
|
||||
global.CheckGlobalTime = CheckGlobalTime;
|
||||
global.GetDeltaCurrentTime = function() {
|
||||
@ -326,7 +315,7 @@ function GetSecFromStrTime(Str) {
|
||||
global.GetSecFromStrTime = GetSecFromStrTime;
|
||||
global.GetCurrentTime = function(Delta_Time) {
|
||||
if (Delta_Time === undefined)
|
||||
Delta_Time = GetDeltaCurrentTime();
|
||||
Delta_Time = global.GetDeltaCurrentTime();
|
||||
var curTime: any = new Date;
|
||||
var Time = new Date(curTime - (- Delta_Time));
|
||||
return Time;
|
||||
@ -393,7 +382,7 @@ function GrayConnect() {
|
||||
return 0;
|
||||
};
|
||||
global.GrayConnect = GrayConnect;
|
||||
var ResConst = LOAD_CONST();
|
||||
var ResConst = global.LOAD_CONST();
|
||||
if (global.START_SERVER) {
|
||||
if (!ResConst) {
|
||||
CheckGlobalTime();
|
||||
|
@ -9,10 +9,9 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
require("./library.js");
|
||||
require("./library");
|
||||
const net = require("net");
|
||||
var ConnectIDCount = 1;
|
||||
let RBTree = global.RBTree;
|
||||
module.exports = class CNode {
|
||||
addrStr
|
||||
ip
|
||||
@ -154,7 +153,7 @@ module.exports = class CNode {
|
||||
this.CanHardTraffic = 0
|
||||
this.BufWriteLength = 0
|
||||
this.BufWrite = Buffer.alloc(0)
|
||||
this.SendPacket = new RBTree(function(a, b) {
|
||||
this.SendPacket = new global.RBTree(function(a, b) {
|
||||
return b.PacketNum - a.PacketNum;
|
||||
})
|
||||
this.ConnectCount = 0
|
||||
@ -343,19 +342,19 @@ module.exports = class CNode {
|
||||
var Buf = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_CLIENT, {});
|
||||
}
|
||||
catch (e) {
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
||||
global.SERVER.SendCloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
||||
return 0;
|
||||
}
|
||||
if (global.CompareArr(Buf.addrArr, global.SERVER.addrArr) === 0) {
|
||||
Node.Self = true
|
||||
global.AddNodeInfo(Node, "END: SELF")
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "SELF")
|
||||
global.SERVER.SendCloseSocket(Socket, "SELF")
|
||||
return;
|
||||
}
|
||||
var addrStr = global.GetHexFromAddres(Buf.addrArr);
|
||||
if (!Node.StartFindList && addrStr !== Node.addrStr) {
|
||||
global.AddNodeInfo(Node, "END: CHANGED ADDR: " + Node.addrStr.substr(0, 16) + "->" + addrStr.substr(0, 16))
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "ADDRESS_HAS_BEEN_CHANGED")
|
||||
global.SERVER.SendCloseSocket(Socket, "ADDRESS_HAS_BEEN_CHANGED")
|
||||
return;
|
||||
}
|
||||
if (Node.addrStrTemp) {
|
||||
@ -373,7 +372,7 @@ module.exports = class CNode {
|
||||
if (!Result) {
|
||||
global.ToLog("END: ERROR_SIGN_SERVER ADDR: " + addrStr.substr(0, 16) + " from ip: " + Socket.remoteAddress)
|
||||
global.AddNodeInfo(Node, "END: ERROR_SIGN_SERVER ADDR: " + addrStr.substr(0, 16) + " from ip: " + Socket.remoteAddress)
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "ERROR_SIGN_SERVER")
|
||||
global.SERVER.SendCloseSocket(Socket, "ERROR_SIGN_SERVER")
|
||||
return;
|
||||
}
|
||||
if (Buf.MIN_POWER_POW_HANDSHAKE > 1 + global.MIN_POWER_POW_HANDSHAKE) {
|
||||
|
@ -9,11 +9,11 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
const net = require("net");
|
||||
const dgram = require("dgram");
|
||||
import net = require("net");
|
||||
import dgram = require("dgram");
|
||||
import * as crypto from 'crypto';
|
||||
require("./library.js");
|
||||
require("./crypto-library");
|
||||
import "./library"
|
||||
import "./crypto-library"
|
||||
const HARD_PACKET_PERIOD = 20;
|
||||
global.BUF_TYPE = 1;
|
||||
global.STR_TYPE = 2;
|
||||
@ -57,9 +57,7 @@ const FORMAT_PACKET_SEND_TCP = "{\
|
||||
Hash:hash,\
|
||||
Data:data,\
|
||||
}";
|
||||
let RBTree = global.RBTree;
|
||||
let STreeBuffer = global.STreeBuffer;
|
||||
module.exports = class CTransport extends require("./connect")
|
||||
export default class CTransport extends require("./connect")
|
||||
{
|
||||
UseRNDHeader
|
||||
BAN_IP
|
||||
@ -90,7 +88,7 @@ module.exports = class CTransport extends require("./connect")
|
||||
this.port = RunPort
|
||||
this.CanSend = 0
|
||||
this.SendFormatMap = {}
|
||||
this.ActualNodes = new RBTree(function(a, b) {
|
||||
this.ActualNodes = new global.RBTree(function(a, b) {
|
||||
if (b.Prioritet !== a.Prioritet)
|
||||
return b.Prioritet - a.Prioritet;
|
||||
return global.CompareArr(a.addrArr, b.addrArr);
|
||||
@ -99,7 +97,7 @@ module.exports = class CTransport extends require("./connect")
|
||||
this.LoadedPacketNum = 0
|
||||
this.LoadedSocketNum = 0
|
||||
setInterval(this.DoLoadBuf.bind(this), 1)
|
||||
this.LoadBufSocketList = new RBTree(function(a, b) {
|
||||
this.LoadBufSocketList = new global.RBTree(function(a, b) {
|
||||
if (b.SocketPrioritet !== a.SocketPrioritet)
|
||||
return b.SocketPrioritet - a.SocketPrioritet;
|
||||
return a.SocketNum - b.SocketNum;
|
||||
@ -108,7 +106,7 @@ module.exports = class CTransport extends require("./connect")
|
||||
this.LastTimeHard = 0
|
||||
this.LastTimeHardOK = 0
|
||||
setInterval(this.DoHardPacketForSend.bind(this), HARD_PACKET_PERIOD)
|
||||
this.HardPacketForSend = new RBTree(function(a, b) {
|
||||
this.HardPacketForSend = new global.RBTree(function(a, b) {
|
||||
if (b.BlockProcessCount === a.BlockProcessCount)
|
||||
return a.PacketNum - b.PacketNum;
|
||||
else
|
||||
@ -859,7 +857,7 @@ module.exports = class CTransport extends require("./connect")
|
||||
return;
|
||||
}
|
||||
let SELF = this;
|
||||
this.Server = net.createServer(function(sock) {
|
||||
this.Server = net.createServer(function(sock: any) {
|
||||
if (SELF.WasBanIP({ address: sock.remoteAddress })) {
|
||||
sock.ConnectID = "new"
|
||||
global.CloseSocket(sock, "WAS BAN", true)
|
||||
@ -1040,7 +1038,7 @@ module.exports = class CTransport extends require("./connect")
|
||||
}
|
||||
}
|
||||
};
|
||||
global.ContextPackets = new STreeBuffer(10 * 1000, global.CompareItemHash32, "object");
|
||||
global.ContextPackets = new global.STreeBuffer(10 * 1000, global.CompareItemHash32, "object");
|
||||
|
||||
function CalcStatArr(arr, arrAvg, arrNext, Period) {
|
||||
var arrSum = [arr[0]];
|
||||
|
@ -15,8 +15,8 @@ var BLOCKNUM_ALGO2 = 6560000;
|
||||
if (global.LOCAL_RUN || global.TEST_NETWORK) {
|
||||
BLOCKNUM_ALGO2 = 0;
|
||||
}
|
||||
require('./library.js');
|
||||
require('./crypto-library.js');
|
||||
require('./library');
|
||||
require('./crypto-library');
|
||||
require('../HTML/JS/terahashlib.js');
|
||||
var DELTA_NONCE = Math.pow(2, 40) * global.MINING_VERSION_NUM;
|
||||
global.CreateHashMinimal = CreateHashMinimal;
|
||||
|
@ -22,7 +22,7 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
BufHashTree
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.BufHashTree = new RBTree(global.CompareArr)
|
||||
this.BufHashTree = new global.RBTree(global.CompareArr)
|
||||
this.BufHashTree.LastAddNum = 0
|
||||
}
|
||||
AddBlockToHashTree(Block) {
|
||||
|
@ -18,7 +18,7 @@ module.exports = class CMessages extends require("./transaction-validator")
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.MemPoolMsg = []
|
||||
for (var i = 0; i <= global.MAX_LEVEL_SPECIALIZATION; i++)
|
||||
this.MemPoolMsg[i] = new RBTree(global.CompareItemTimePow)
|
||||
this.MemPoolMsg[i] = new global.RBTree(global.CompareItemTimePow)
|
||||
}
|
||||
AddMsgToQuote(Msg) {
|
||||
var Tree = this.MemPoolMsg[Msg.Level];
|
||||
|
@ -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;
|
||||
|
@ -5,4 +5,4 @@ global.HTTP_PORT_NUMBER = 8080;
|
||||
if (global.LOCAL_RUN === undefined)
|
||||
global.LOCAL_RUN = 0;
|
||||
|
||||
require('./process/main-process');
|
||||
import './process/main-process'
|
||||
|
@ -11,7 +11,7 @@
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
const DBRow = require("../core/db/db-row");
|
||||
require('../core/rest_tables.js');
|
||||
require('../core/rest_tables');
|
||||
const MAX_SUM_TER = 1e9;
|
||||
const MAX_SUM_CENT = 1e9;
|
||||
const DBLib = require("../core/db/db");
|
||||
|
@ -7,6 +7,7 @@
|
||||
},
|
||||
"include": [
|
||||
"./src/**/*",
|
||||
"./src/**/**/*",
|
||||
"global.d.ts"
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user