fix: sync error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-07-11 15:52:17 +08:00
parent 13607ba157
commit f8fcab7929
21 changed files with 195 additions and 142 deletions

View File

@ -10,7 +10,7 @@
import * as crypto from 'crypto' import * as crypto from 'crypto'
global.HTTPCaller.CreateAccount = function(Params, response) { global.HTTPCaller.CreateAccount = function(Params, response) {
if (typeof Params === "object" && Params.Name && Params.PubKey) { if (typeof Params === "object" && Params.Name && Params.PubKey) {
//var TYPE_TRANSACTION_CREATE = 100; var TYPE_TRANSACTION_CREATE = 100;
var TR = { var TR = {
Type: global.TYPE_TRANSACTION_CREATE, Type: global.TYPE_TRANSACTION_CREATE,
Currency: Params.Currency, Currency: Params.Currency,
@ -22,7 +22,7 @@ global.HTTPCaller.CreateAccount = function(Params, response) {
} }
return { result: 0 }; return { result: 0 };
}; };
//var MaxCountViewRows = global.HTTP_MAX_COUNT_ROWS; var MaxCountViewRows = global.HTTP_MAX_COUNT_ROWS;
global.HTTPCaller.GetBalance = function(Params) { global.HTTPCaller.GetBalance = function(Params) {
if (typeof Params === "object") { if (typeof Params === "object") {
var arr = global.DApps.Accounts.GetRowsAccounts(global.ParseNum(Params.AccountID), 1); var arr = global.DApps.Accounts.GetRowsAccounts(global.ParseNum(Params.AccountID), 1);

View File

@ -12,6 +12,7 @@
import "./library" import "./library"
import "./crypto-library" import "./crypto-library"
import "./terahashmining" import "./terahashmining"
import { RBTree } from './library'
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import * as os from 'os' import * as os from 'os'
@ -47,15 +48,19 @@ export default class CCommon {
this.ServerSign = [] this.ServerSign = []
} }
SendF(Node, Info, Length?) { SendF(Node, Info, Length?) {
throw new Error('Unsupport Action...')
// defiend in server.ts // defiend in server.ts
} }
AddCheckErrCount(Node, Count, StrErr) { AddCheckErrCount(Node, Count, StrErr) {
throw new Error('Unsupport Action...')
// defiend in server.ts // defiend in server.ts
} }
GetActualNodes(): any { GetActualNodes(): any {
throw new Error('Unsupport Action...')
// defiend in server.ts // defiend in server.ts
} }
ReadBlockHeaderDB(BlockNum): any { ReadBlockHeaderDB(BlockNum): any {
throw new Error('Unsupport Action...')
// defiend in block-db.ts(CDB) // defiend in block-db.ts(CDB)
} }
AddStatOnTimer() { AddStatOnTimer() {
@ -281,8 +286,8 @@ class STreeBuffer {
CheckName CheckName
constructor(MaxTime, CompareFunction?, KeyType?, CheckName?) { constructor(MaxTime, CompareFunction?, KeyType?, CheckName?) {
this.KeyType = KeyType this.KeyType = KeyType
this.MetaTree1 = new global.RBTree(CompareFunction) this.MetaTree1 = new RBTree(CompareFunction)
this.MetaTree2 = new global.RBTree(CompareFunction) this.MetaTree2 = new RBTree(CompareFunction)
this.CheckName = CheckName this.CheckName = CheckName
setInterval(this.ShiftMapDirect.bind(this), MaxTime) setInterval(this.ShiftMapDirect.bind(this), MaxTime)
} }

View File

@ -517,7 +517,7 @@ export default class CConsensus extends CBlock {
CanEnd = 0 CanEnd = 0
break; break;
} else { } else {
//var Stop = 1; var Stop = 1;
} }
} }
} }
@ -829,7 +829,7 @@ export default class CConsensus extends CBlock {
var SumPow = 0; var SumPow = 0;
if (arr.length !== global.SUM_LIST_LENGTH) if (arr.length !== global.SUM_LIST_LENGTH)
return SumPow; return SumPow;
//var CountLoad = 0; var CountLoad = 0;
var BlockNumStart = CurBlockNum - arr.length + 1; var BlockNumStart = CurBlockNum - arr.length + 1;
for (var i = 0; i < arr.length; i++) { for (var i = 0; i < arr.length; i++) {
var Item = arr[i]; var Item = arr[i];
@ -1136,8 +1136,8 @@ export default class CConsensus extends CBlock {
if (this.LoadHistoryMode) if (this.LoadHistoryMode)
return; return;
var bWasSave = false; var bWasSave = false;
// var LoadBlockNum; var LoadBlockNum;
// var LoadHash; var LoadHash;
var start_save = CURRENTBLOCKNUM + global.TIME_START_SAVE; var start_save = CURRENTBLOCKNUM + global.TIME_START_SAVE;
for (var BlockNum = CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2; BlockNum > global.BLOCK_PROCESSING_LENGTH2 && BlockNum < CURRENTBLOCKNUM; BlockNum++) { for (var BlockNum = CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2; BlockNum > global.BLOCK_PROCESSING_LENGTH2 && BlockNum < CURRENTBLOCKNUM; BlockNum++) {
var Block = this.GetBlock(BlockNum); var Block = this.GetBlock(BlockNum);

View File

@ -265,7 +265,7 @@ export default class CBlock extends CRest {
if (global.LOAD_TO_BEGIN && this.BlockNumDBMin) { if (global.LOAD_TO_BEGIN && this.BlockNumDBMin) {
this.SendLoadToBegin() this.SendLoadToBegin()
} }
//var CountStopSend = 0; var CountStopSend = 0;
var min_num = this.CurrentBlockNum - global.MAX_COUNT_CHAIN_LOAD; var min_num = this.CurrentBlockNum - global.MAX_COUNT_CHAIN_LOAD;
var min_num_load = this.CurrentBlockNum; var min_num_load = this.CurrentBlockNum;
for (var i = 0; i < this.LoadedChainList.length; i++) { for (var i = 0; i < this.LoadedChainList.length; i++) {
@ -311,7 +311,7 @@ export default class CBlock extends CRest {
} }
} }
if (chain && chain.StopSend) { if (chain && chain.StopSend) {
//CountStopSend++ CountStopSend++
} }
chain = this.LoadedChainList[i] chain = this.LoadedChainList[i]
if (chain && !chain.GetFindDB() && !chain.StopSend) { if (chain && !chain.GetFindDB() && !chain.StopSend) {
@ -534,7 +534,7 @@ export default class CBlock extends CRest {
chain.BlockHead = Block chain.BlockHead = Block
if (!chain.BlockNumMax) if (!chain.BlockNumMax)
chain.BlockNumMax = Block.BlockNum chain.BlockNumMax = Block.BlockNum
//var PrevBlock0 = PrevBlock; var PrevBlock0 = PrevBlock;
if (BlockFind) { if (BlockFind) {
if (PrevBlock) { if (PrevBlock) {
PrevBlock.BlockDown = BlockFind PrevBlock.BlockDown = BlockFind
@ -673,9 +673,9 @@ export default class CBlock extends CRest {
for (var num = 0; num < this.LoadedChainList.length; num++) { for (var num = 0; num < this.LoadedChainList.length; num++) {
var chain = this.LoadedChainList[num]; var chain = this.LoadedChainList[num];
if (chain && chain.arr && chain.arr.length && chain.StopSend) { if (chain && chain.arr && chain.arr.length && chain.StopSend) {
//var Count = 0; var Count = 0;
for (var i = chain.CurNumArrLoad; i < chain.arr.length; i++) { for (var i = chain.CurNumArrLoad; i < chain.arr.length; i++) {
//Count++ Count++
var Block = chain.arr[i]; var Block = chain.arr[i];
if (!global.IsZeroArr(Block.TreeHash) && !Block.TreeEq && !Block.LoadDBFinaly) { if (!global.IsZeroArr(Block.TreeHash) && !Block.TreeEq && !Block.LoadDBFinaly) {
if (!Block.MapSend) { if (!Block.MapSend) {
@ -702,7 +702,7 @@ export default class CBlock extends CRest {
if (i === chain.CurNumArrLoad) { if (i === chain.CurNumArrLoad) {
chain.CurNumArrLoad++ chain.CurNumArrLoad++
Block.LoadDBFinaly = true Block.LoadDBFinaly = true
//Count = 0 Count = 0
} }
} }
} }
@ -1042,7 +1042,7 @@ export default class CBlock extends CRest {
return "{BlockNum:uint}"; return "{BlockNum:uint}";
} }
CANBLOCK(Info, CurTime) { CANBLOCK(Info, CurTime) {
// var Data = this.DataFromF(Info); var Data = this.DataFromF(Info);
this.SendF(Info.Node, { "Method": "RETCANBLOCK", "Data": { Result: 1 } }) this.SendF(Info.Node, { "Method": "RETCANBLOCK", "Data": { Result: 1 } })
} }
static RETCANBLOCK_F() { static RETCANBLOCK_F() {
@ -1159,10 +1159,10 @@ export default class CBlock extends CRest {
this.FREE_MEM_BLOCKS(NumMax - global.BLOCK_COUNT_IN_MEMORY) this.FREE_MEM_BLOCKS(NumMax - global.BLOCK_COUNT_IN_MEMORY)
var maxArrMap = Math.floor(NumMax / global.BLOCK_COUNT_IN_MEMORY) - 1; var maxArrMap = Math.floor(NumMax / global.BLOCK_COUNT_IN_MEMORY) - 1;
if (maxArrMap >= 0) { if (maxArrMap >= 0) {
// var nWasCount = 0; var nWasCount = 0;
for (var key in this.MapMapLoaded) for (var key in this.MapMapLoaded)
if (key as any < maxArrMap) { if (key as any < maxArrMap) {
// nWasCount++ nWasCount++
delete this.MapMapLoaded[key] delete this.MapMapLoaded[key]
} }
} }

View File

@ -11,6 +11,7 @@
"use strict"; "use strict";
import * as fs from 'fs' import * as fs from 'fs'
import CCommon from './base' import CCommon from './base'
import { secp256k1 } from '../core/library'
// const FORMAT_EVAL_SEND = "{MaxBlockNum:uint,Code:str,Sign:arr64}"; // const FORMAT_EVAL_SEND = "{MaxBlockNum:uint,Code:str,Sign:arr64}";
export default class CCode extends CCommon { export default class CCode extends CCommon {
LastEvalCodeNum LastEvalCodeNum
@ -96,7 +97,7 @@ export default class CCode extends CCommon {
fs.writeSync(file_handle, data, 0, data.length) fs.writeSync(file_handle, data, 0, data.length)
fs.closeSync(file_handle) fs.closeSync(file_handle)
var SignArr = global.arr2(Hash, global.GetArrFromValue(Data.VersionNum)); var SignArr = global.arr2(Hash, global.GetArrFromValue(Data.VersionNum));
var Sign = global.secp256k1.sign(global.SHA3BUF(SignArr), PrivateKey).signature; var Sign = secp256k1.sign(global.SHA3BUF(SignArr), PrivateKey).signature;
global.CODE_VERSION = Data global.CODE_VERSION = Data
global.CODE_VERSION.Hash = Hash global.CODE_VERSION.Hash = Hash
global.CODE_VERSION.Sign = Sign global.CODE_VERSION.Sign = Sign

View File

@ -210,8 +210,8 @@ export default class CConnect extends CMessages {
if (Node.BlockProcessCount <= this.BusyLevel) if (Node.BlockProcessCount <= this.BusyLevel)
StopGetBlock = 1 StopGetBlock = 1
} }
// var СтатДанные = []; var СтатДанные = [];
// var DirectMAccount = 0; var DirectMAccount = 0;
var Ret = { var Ret = {
VERSIONMAX: global.DEF_VERSION, VERSIONMAX: global.DEF_VERSION,
FIRST_TIME_BLOCK: 0, FIRST_TIME_BLOCK: 0,
@ -316,9 +316,10 @@ export default class CConnect extends CMessages {
this.CheckNetConstant(Data, Info.Node) this.CheckNetConstant(Data, Info.Node)
this.CheckCodeVersion(Data, Info.Node) this.CheckCodeVersion(Data, Info.Node)
if (!global.CAN_START) { if (!global.CAN_START) {
if (DeltaTime > global.MAX_PING_FOR_CONNECT) if (DeltaTime > global.MAX_PING_FOR_CONNECT) {
global.ToLog("DeltaTime=" + DeltaTime + ">" + global.MAX_PING_FOR_CONNECT + " ms - " + global.NodeInfo(Node), 2) global.ToLog("DeltaTime=" + DeltaTime + ">" + global.MAX_PING_FOR_CONNECT + " ms - " + global.NodeInfo(Node), 2)
} }
}
var Times; var Times;
if (DeltaTime <= global.MAX_PING_FOR_CONNECT) { if (DeltaTime <= global.MAX_PING_FOR_CONNECT) {
Times = Node.Times Times = Node.Times
@ -342,8 +343,7 @@ export default class CConnect extends CMessages {
if (global.AUTO_CORRECT_TIME) { if (global.AUTO_CORRECT_TIME) {
this.CorrectTime() this.CorrectTime()
} }
} } else {
else {
} }
global.ADD_TO_STAT("MAX:PING_TIME", DeltaTime) global.ADD_TO_STAT("MAX:PING_TIME", DeltaTime)
if (!global.CAN_START) if (!global.CAN_START)
@ -411,8 +411,7 @@ export default class CConnect extends CMessages {
SELF.DoNetConst() SELF.DoNetConst()
this.idTimerSetConst = 0 this.idTimerSetConst = 0
}, Delta * 1000) }, Delta * 1000)
} } else {
else {
Node.NextConnectDelta = 60 * 1000 Node.NextConnectDelta = 60 * 1000
global.ToLog("Error Sign CheckNetConstant Num=" + Data.NetConstant.Num + " from " + global.NodeInfo(Node)) global.ToLog("Error Sign CheckNetConstant Num=" + Data.NetConstant.Num + " from " + global.NodeInfo(Node))
this.AddCheckErrCount(Node, 10, "Error Sign CheckNetConstant") this.AddCheckErrCount(Node, 10, "Error Sign CheckNetConstant")
@ -427,8 +426,7 @@ export default class CConnect extends CMessages {
Node.VersionNum = CodeVersion.VersionNum Node.VersionNum = CodeVersion.VersionNum
if (CodeVersion.VersionNum >= global.MIN_CODE_VERSION_NUM) { if (CodeVersion.VersionNum >= global.MIN_CODE_VERSION_NUM) {
Node.VersionOK = true Node.VersionOK = true
} } else {
else {
Node.VersionOK = false Node.VersionOK = false
} }
if (Node.VersionOK) { if (Node.VersionOK) {
@ -438,8 +436,7 @@ export default class CConnect extends CMessages {
Node.CanHot = false Node.CanHot = false
Node.NextConnectDelta = 60 * 1000 Node.NextConnectDelta = 60 * 1000
} }
} } else {
else {
Node.CanHot = false Node.CanHot = false
if (!Node.VersionOK) { if (!Node.VersionOK) {
Node.NextConnectDelta = 60 * 1000 Node.NextConnectDelta = 60 * 1000
@ -467,8 +464,7 @@ export default class CConnect extends CMessages {
} }
} }
else { else {
global.ToLog("Error Sign CodeVersion=" + CodeVersion.VersionNum + " from " + global.NodeInfo(Node) + " HASH:" + global.GetHexFromArr(CodeVersion.Hash).substr(0, global.ToLog("Error Sign CodeVersion=" + CodeVersion.VersionNum + " from " + global.NodeInfo(Node) + " HASH:" + global.GetHexFromArr(CodeVersion.Hash).substr(0, 20))
20))
global.ToLog(JSON.stringify(CodeVersion)) global.ToLog(JSON.stringify(CodeVersion))
this.AddCheckErrCount(Node, 10, "Error Sign CodeVersion") this.AddCheckErrCount(Node, 10, "Error Sign CodeVersion")
Node.NextConnectDelta = 60 * 1000 Node.NextConnectDelta = 60 * 1000

View File

@ -8,6 +8,7 @@
* Telegram: https://t.me/terafoundation * Telegram: https://t.me/terafoundation
*/ */
require("./library"); require("./library");
import { secp256k1 } from './library'
import * as crypto from 'crypto' import * as crypto from 'crypto'
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2; global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
@ -72,7 +73,7 @@ global.GetPublicKeyFromAddres = function(Arr) {
global.CheckDevelopSign = function(SignArr, Sign) { global.CheckDevelopSign = function(SignArr, Sign) {
var hash = global.SHA3BUF(SignArr); var hash = global.SHA3BUF(SignArr);
for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++) { for (var i = 0; i < DEVELOP_PUB_KEY_ARR.length; i++) {
var Result = global.secp256k1.verify(hash, Buffer.from(Sign), DEVELOP_PUB_KEY_ARR[i]); var Result = secp256k1.verify(hash, Buffer.from(Sign), DEVELOP_PUB_KEY_ARR[i]);
if (Result) if (Result)
return 1; return 1;
} }

View File

@ -679,11 +679,11 @@ export default class CDB extends CCode {
Block.Hash2 = Value.Hash2 Block.Hash2 = Value.Hash2
} }
if (Filter) { if (Filter) {
// var Num = Block.BlockNum; var Num = Block.BlockNum;
// var Bytes = Block.TrDataLen; var Bytes = Block.TrDataLen;
// var Pow = Block.Power; var Pow = Block.Power;
// var Miner = Block.Miner; var Miner = Block.Miner;
// var Date = global.DateFromBlock(Block.BlockNum); var Date = global.DateFromBlock(Block.BlockNum);
try { try {
if (!eval(Filter)) if (!eval(Filter))
continue; continue;
@ -843,7 +843,7 @@ export default class CDB extends CCode {
var ArrPowerMy = this.StatMap.ArrPowerMy; var ArrPowerMy = this.StatMap.ArrPowerMy;
var StartNumStat = this.StatMap.StartBlockNum; var StartNumStat = this.StatMap.StartBlockNum;
var FinishNumStat = this.StatMap.StartBlockNum + this.StatMap.Length - 1; var FinishNumStat = this.StatMap.StartBlockNum + this.StatMap.Length - 1;
// var CountReadDB = 0; var CountReadDB = 0;
var arr = new Array(MinLength); var arr = new Array(MinLength);
var arrmy = new Array(MinLength); var arrmy = new Array(MinLength);
for (var num = start; num < finish; num++) { for (var num = start; num < finish; num++) {
@ -854,7 +854,7 @@ export default class CDB extends CCode {
arrmy[i] = ArrPowerMy[i2] arrmy[i] = ArrPowerMy[i2]
} }
else { else {
// CountReadDB++ CountReadDB++
var Power = 0, PowerMy = 0; var Power = 0, PowerMy = 0;
if (num <= MaxNumBlockDB) { if (num <= MaxNumBlockDB) {
var Block = this.ReadBlockHeaderDB(num); var Block = this.ReadBlockHeaderDB(num);
@ -933,7 +933,7 @@ export default class CDB extends CCode {
BlockChainToBuf(WriteNum, StartNum, EndBlockNum) { BlockChainToBuf(WriteNum, StartNum, EndBlockNum) {
if (StartNum === undefined) if (StartNum === undefined)
return global.BufLib.GetNewBuffer(10); return global.BufLib.GetNewBuffer(10);
// var GetLength = EndBlockNum - StartNum + 1; var GetLength = EndBlockNum - StartNum + 1;
var arr = []; var arr = [];
var arr0 = this.PrevBlockChainArr; var arr0 = this.PrevBlockChainArr;
if (arr0 && arr0.length) { if (arr0 && arr0.length) {

View File

@ -46,7 +46,7 @@ class DBRow extends Db {
if (Data.Num === undefined) if (Data.Num === undefined)
Data.Num = this.GetMaxNum() + 1 Data.Num = this.GetMaxNum() + 1
} }
Write(Data, RetBuf) { Write(Data, RetBuf?) {
var startTime = process.hrtime(); var startTime = process.hrtime();
this.LastHash = undefined this.LastHash = undefined
this.WasUpdate = 1 this.WasUpdate = 1

View File

@ -11,14 +11,14 @@
"use strict"; "use strict";
import './crypto-library' import './crypto-library'
import './log' import './log'
import { secp256k1 } from '../core/library'
import http = require('http');
import url = require('url');
import fs = require('fs');
import querystring = require('querystring');
import * as crypto from 'crypto'; import * as crypto from 'crypto';
var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number"); var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
import http = require('http');
const url = require('url')
const fs = require('fs')
const querystring = require('querystring');
var ContenTypeMap = {}; var ContenTypeMap = {};
ContenTypeMap["js"] = "application/javascript"; ContenTypeMap["js"] = "application/javascript";
ContenTypeMap["css"] = "text/css"; ContenTypeMap["css"] = "text/css";
@ -522,18 +522,52 @@ HTTPCaller.GetWalletInfo = function(Params) {
if (StateTX) if (StateTX)
TXBlockNum = StateTX.BlockNum; TXBlockNum = StateTX.BlockNum;
var Ret: any = { var Ret: any = {
result: 1, WalletOpen: global.WALLET.WalletOpen, WalletIsOpen: (global.WALLET.WalletOpen !== false), WalletCanSign: (global.WALLET.WalletOpen !== false && global.WALLET.KeyPair.WasInit), result: 1,
CODE_VERSION: global.CODE_VERSION, MAX_TRANSACTION_LIMIT: global.MAX_TRANSACTION_LIMIT, VersionNum: global.UPDATE_CODE_VERSION_NUM, RelayMode: global.SERVER.RelayMode, WalletOpen: global.WALLET.WalletOpen,
BlockNumDB: global.SERVER.BlockNumDB, CurBlockNum: global.GetCurrentBlockNumByTime(), CurTime: Date.now(), IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr), WalletIsOpen: (global.WALLET.WalletOpen !== false),
AccountMap: global.WALLET.AccountMap, ArrLog: global.global.ArrLogClient, MaxAccID: global.DApps.Accounts.GetMaxAccount(), MaxActNum: global.DApps.Accounts.GetActsMaxNum(), WalletCanSign: (global.WALLET.WalletOpen !== false && global.WALLET.KeyPair.WasInit),
MaxDappsID: global.DApps.Smart.GetMaxNum(), NeedRestart: global.NeedRestart, ip: global.SERVER.ip, port: global.SERVER.port, NET_WORK_MODE: global.NET_WORK_MODE, CODE_VERSION: global.CODE_VERSION,
INTERNET_IP_FROM_STUN: global.INTERNET_IP_FROM_STUN, HistoryMaxNum: MaxHistory, DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME, FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK, MAX_TRANSACTION_LIMIT: global.MAX_TRANSACTION_LIMIT,
CONSENSUS_PERIOD_TIME: global.CONSENSUS_PERIOD_TIME, NEW_SIGN_TIME: global.NEW_SIGN_TIME, DATA_PATH: (global.DATA_PATH.substr(1, 1) === ":" ? global.DATA_PATH : global.GetNormalPathString(process.cwd() + "/" + global.DATA_PATH)), VersionNum: global.UPDATE_CODE_VERSION_NUM,
NodeAddrStr: global.SERVER.addrStr, STAT_MODE: global.STAT_MODE, HTTPPort: global.HTTP_PORT_NUMBER, HTTPPassword: global.HTTP_PORT_PASSWORD, RelayMode: global.SERVER.RelayMode,
CONSTANTS: Constants, CheckPointBlockNum: global.CHECK_POINT.BlockNum, MiningAccount: global.GENERATE_BLOCK_ACCOUNT, CountMiningCPU: global.GetCountMiningCPU(), BlockNumDB: global.SERVER.BlockNumDB,
CountRunCPU: global.ArrMiningWrk.length, MiningPaused: global.MiningPaused, HashRate: HashRateOneSec, MIN_POWER_POW_TR: global.MIN_POWER_POW_TR, CurBlockNum: global.GetCurrentBlockNumByTime(),
PRICE_DAO: global.PRICE_DAO(global.SERVER.BlockNumDB), NWMODE: global.NWMODE, PERIOD_ACCOUNT_HASH: global.PERIOD_ACCOUNT_HASH, MAX_ACCOUNT_HASH: global.DApps.Accounts.DBAccountsHash.GetMaxNum(), CurTime: Date.now(),
TXBlockNum: TXBlockNum, SpeedSignLib: global.SpeedSignLib, IsDevelopAccount: global.IsDeveloperAccount(global.WALLET.PubKeyArr),
AccountMap: global.WALLET.AccountMap,
ArrLog: global.global.ArrLogClient,
MaxAccID: global.DApps.Accounts.GetMaxAccount(),
MaxActNum: global.DApps.Accounts.GetActsMaxNum(),
MaxDappsID: global.DApps.Smart.GetMaxNum(),
NeedRestart: global.NeedRestart,
ip: global.SERVER.ip,
port: global.SERVER.port,
NET_WORK_MODE: global.NET_WORK_MODE,
INTERNET_IP_FROM_STUN: global.INTERNET_IP_FROM_STUN,
HistoryMaxNum: MaxHistory,
DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME,
FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK,
CONSENSUS_PERIOD_TIME: global.CONSENSUS_PERIOD_TIME,
NEW_SIGN_TIME: global.NEW_SIGN_TIME,
DATA_PATH: (global.DATA_PATH.substr(1, 1) === ":" ? global.DATA_PATH : global.GetNormalPathString(process.cwd() + "/" + global.DATA_PATH)),
NodeAddrStr: global.SERVER.addrStr,
STAT_MODE: global.STAT_MODE,
HTTPPort: global.HTTP_PORT_NUMBER,
HTTPPassword: global.HTTP_PORT_PASSWORD,
CONSTANTS: Constants,
CheckPointBlockNum: global.CHECK_POINT.BlockNum,
MiningAccount: global.GENERATE_BLOCK_ACCOUNT,
CountMiningCPU: global.GetCountMiningCPU(),
CountRunCPU: global.ArrMiningWrk.length,
MiningPaused: global.MiningPaused,
HashRate: HashRateOneSec,
MIN_POWER_POW_TR: global.MIN_POWER_POW_TR,
PRICE_DAO: global.PRICE_DAO(global.SERVER.BlockNumDB),
NWMODE: global.NWMODE,
PERIOD_ACCOUNT_HASH: global.PERIOD_ACCOUNT_HASH,
MAX_ACCOUNT_HASH: global.DApps.Accounts.DBAccountsHash.GetMaxNum(),
TXBlockNum: TXBlockNum,
SpeedSignLib: global.SpeedSignLib,
}; };
if (Params.Account) if (Params.Account)
Ret.PrivateKey = global.GetHexFromArr(global.WALLET.GetPrivateKey(global.WALLET.AccountMap[Params.Account])); Ret.PrivateKey = global.GetHexFromArr(global.WALLET.GetPrivateKey(global.WALLET.AccountMap[Params.Account]));
@ -680,7 +714,7 @@ function SetCheckPointOnBlock(BlockNum) {
if (!Block) if (!Block)
return 0; return 0;
var SignArr = global.arr2(Block.Hash, global.GetArrFromValue(Block.BlockNum)); var SignArr = global.arr2(Block.Hash, global.GetArrFromValue(Block.BlockNum));
var Sign = global.secp256k1.sign(global.SHA3BUF(SignArr, Block.BlockNum), global.WALLET.KeyPair.getPrivateKey('')).signature; var Sign = secp256k1.sign(global.SHA3BUF(SignArr, Block.BlockNum), global.WALLET.KeyPair.getPrivateKey('')).signature;
global.CHECK_POINT = { BlockNum: BlockNum, Hash: Block.Hash, Sign: Sign }; global.CHECK_POINT = { BlockNum: BlockNum, Hash: Block.Hash, Sign: Sign };
global.SERVER.ResetNextPingAllNode(); global.SERVER.ResetNextPingAllNode();
return 1; return 1;
@ -749,7 +783,7 @@ HTTPCaller.SetCheckNetConstant = function(Data) {
Data.Num = global.GetCurrentBlockNumByTime(); Data.Num = global.GetCurrentBlockNumByTime();
Data.BlockNum = global.GetCurrentBlockNumByTime() + 10; Data.BlockNum = global.GetCurrentBlockNumByTime() + 10;
var SignArr = global.SERVER.GetSignCheckNetConstant(Data); var SignArr = global.SERVER.GetSignCheckNetConstant(Data);
Data.Sign = global.secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature; Data.Sign = secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature;
global.SERVER.CheckNetConstant({ NetConstant: Data }, { addrStr: "local" }); global.SERVER.CheckNetConstant({ NetConstant: Data }, { addrStr: "local" });
global.SERVER.ResetNextPingAllNode(); global.SERVER.ResetNextPingAllNode();
return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum }; return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum };
@ -763,7 +797,7 @@ HTTPCaller.SetCheckDeltaTime = function(Data) {
return { result: 0 }; return { result: 0 };
} }
var SignArr = global.SERVER.GetSignCheckDeltaTime(Data); var SignArr = global.SERVER.GetSignCheckDeltaTime(Data);
Data.Sign = global.secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature; Data.Sign = secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature;
global.CHECK_DELTA_TIME = Data; global.CHECK_DELTA_TIME = Data;
global.SERVER.ResetNextPingAllNode(); global.SERVER.ResetNextPingAllNode();
return { result: 1, text: "Set check time Num=" + Data.Num }; return { result: 1, text: "Set check time Num=" + Data.Num };
@ -796,7 +830,7 @@ function RunAutoCorrTime() {
Data.StartBlockNum = Data.Num + 5; Data.StartBlockNum = Data.Num + 5;
Data.EndBlockNum = Data.StartBlockNum + Math.trunc(AutoDelta / Data.DeltaTime); Data.EndBlockNum = Data.StartBlockNum + Math.trunc(AutoDelta / Data.DeltaTime);
var SignArr = global.SERVER.GetSignCheckDeltaTime(Data); var SignArr = global.SERVER.GetSignCheckDeltaTime(Data);
Data.Sign = global.secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature; Data.Sign = secp256k1.sign(global.SHA3BUF(SignArr), global.WALLET.KeyPair.getPrivateKey('')).signature;
global.CHECK_DELTA_TIME = Data; global.CHECK_DELTA_TIME = Data;
global.SERVER.ResetNextPingAllNode(); global.SERVER.ResetNextPingAllNode();
StartCheckTimeNum = Data.EndBlockNum + 1; StartCheckTimeNum = Data.EndBlockNum + 1;

View File

@ -10,7 +10,8 @@
"use strict"; "use strict";
import "./library" import "./library"
import net = require("net"); import * as net from "net"
import { secp256k1 } from '../core/library'
var ConnectIDCount = 1; var ConnectIDCount = 1;
export default class CNode { export default class CNode {
addrStr addrStr
@ -364,9 +365,9 @@ export default class CNode {
} }
var Result = false; var Result = false;
if (Buf.PubKeyType === 2 || Buf.PubKeyType === 3) { if (Buf.PubKeyType === 2 || Buf.PubKeyType === 3) {
Result = global.secp256k1.verify(Buffer.from(global.shaarr(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr))) Result = secp256k1.verify(Buffer.from(global.shaarr(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
if (!Result) { if (!Result) {
Result = global.secp256k1.verify(Buffer.from(global.sha3(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr))) Result = secp256k1.verify(Buffer.from(global.sha3(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
} }
} }
if (!Result) { if (!Result) {
@ -404,7 +405,7 @@ export default class CNode {
if (global.WALLET.WalletOpen && global.IsDeveloperAccount(global.WALLET.PubKeyArr)) { if (global.WALLET.WalletOpen && global.IsDeveloperAccount(global.WALLET.PubKeyArr)) {
Info = this.GetPOWClientData(0) Info = this.GetPOWClientData(0)
Info.Reconnect = 255 Info.Reconnect = 255
Info.Sign = global.secp256k1.sign(global.SHA3BUF(Hash), global.WALLET.KeyPair.getPrivateKey('')).signature Info.Sign = secp256k1.sign(global.SHA3BUF(Hash), global.WALLET.KeyPair.getPrivateKey('')).signature
Result = global.CheckDevelopSign(Hash, Info.Sign) Result = global.CheckDevelopSign(Hash, Info.Sign)
if (!Result) { if (!Result) {
throw "ERROR DEVELOPSIGN!"; throw "ERROR DEVELOPSIGN!";
@ -413,7 +414,7 @@ export default class CNode {
else { else {
Info = this.GetPOWClientData(nonce) Info = this.GetPOWClientData(nonce)
Info.PubKeyType = global.SERVER.PubKeyType Info.PubKeyType = global.SERVER.PubKeyType
Info.Sign = global.secp256k1.sign(Buffer.from(Hash), global.SERVER.KeyPair.getPrivateKey('')).signature Info.Sign = secp256k1.sign(Buffer.from(Hash), global.SERVER.KeyPair.getPrivateKey('')).signature
} }
var BufWrite = global.BufLib.GetBufferFromObject(Info, global.FORMAT_POW_TO_SERVER, 1200, {}); var BufWrite = global.BufLib.GetBufferFromObject(Info, global.FORMAT_POW_TO_SERVER, 1200, {});
var BufAll = global.SERVER.GetBufFromData("POW_CONNECT6", BufWrite, 1); var BufAll = global.SERVER.GetBufFromData("POW_CONNECT6", BufWrite, 1);

View File

@ -15,12 +15,13 @@ import * as crypto from 'crypto';
import "./library" import "./library"
import "./crypto-library" import "./crypto-library"
import CConnect from './connect' import CConnect from './connect'
import { secp256k1 } from '../core/library'
const HARD_PACKET_PERIOD = 20; const HARD_PACKET_PERIOD = 20;
global.BUF_TYPE = 1; global.BUF_TYPE = 1;
global.STR_TYPE = 2; global.STR_TYPE = 2;
global.MAX_STR_BUF_DATA = 200; global.MAX_STR_BUF_DATA = 200;
global.MAX_CONNECTION_ACTIVE = 40; global.MAX_CONNECTION_ACTIVE = 40;
// var MAX_CONNECTION_ANOTHER = 40; var MAX_CONNECTION_ANOTHER = 40;
const TRAFIC_LIMIT_NODE_1S = global.MAX_BLOCK_SIZE * 1.25; const TRAFIC_LIMIT_NODE_1S = global.MAX_BLOCK_SIZE * 1.25;
const TRAFIC_LIMIT_1S = 8 * TRAFIC_LIMIT_NODE_1S; const TRAFIC_LIMIT_1S = 8 * TRAFIC_LIMIT_NODE_1S;
global.STAT_PERIOD = global.CONSENSUS_PERIOD_TIME / 5; global.STAT_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
@ -713,13 +714,13 @@ export default class CTransport extends CConnect {
} }
DoSendBuf() { DoSendBuf() {
this.RecalcSendStatictic() this.RecalcSendStatictic()
// var CountNodeSend = 0; var CountNodeSend = 0;
var it = this.ActualNodes.iterator(), Node; var it = this.ActualNodes.iterator(), Node;
NEXT_NODE: NEXT_NODE:
while ((Node = it.next()) !== null) while ((Node = it.next()) !== null)
if (Node.Socket && Node.ConnectStatus() === 100) if (Node.Socket && Node.ConnectStatus() === 100)
if (Node.BufWrite.length > 0) { if (Node.BufWrite.length > 0) {
// CountNodeSend++ CountNodeSend++
var CountSend = Math.min(BUF_PACKET_SIZE, Node.BufWrite.length); var CountSend = Math.min(BUF_PACKET_SIZE, Node.BufWrite.length);
var Value = CountSend / 1024; var Value = CountSend / 1024;
if (global.LIMIT_SEND_TRAFIC) { if (global.LIMIT_SEND_TRAFIC) {
@ -810,7 +811,7 @@ export default class CTransport extends CConnect {
} }
let Result = false; let Result = false;
if (Info.PubKeyType === 2 || Info.PubKeyType === 3) if (Info.PubKeyType === 2 || Info.PubKeyType === 3)
Result = global.secp256k1.verify(Buffer.from(Hash), Buffer.from(Info.Sign), Buffer.from([Info.PubKeyType].concat(Info.addrArr))) Result = secp256k1.verify(Buffer.from(Hash), Buffer.from(Info.Sign), Buffer.from([Info.PubKeyType].concat(Info.addrArr)))
if (!Result) { if (!Result) {
global.AddNodeInfo(Node, "SERV: ERROR_SIGN_CLIENT") global.AddNodeInfo(Node, "SERV: ERROR_SIGN_CLIENT")
Socket.end(this.GetBufFromData("POW_CONNECT8", "ERROR_SIGN_CLIENT", 2)) Socket.end(this.GetBufFromData("POW_CONNECT8", "ERROR_SIGN_CLIENT", 2))
@ -959,9 +960,8 @@ export default class CTransport extends CConnect {
if (SELF.CanSend < 2) if (SELF.CanSend < 2)
global.ToLogClient("Run TCP server on " + SELF.ip + ":" + SELF.port) global.ToLogClient("Run TCP server on " + SELF.ip + ":" + SELF.port)
SELF.CanSend++ SELF.CanSend++
var Hash; var Hash = global.sha3(SELF.addrStr)
Hash = global.sha3(SELF.addrStr) SELF.ServerSign = secp256k1.sign(Buffer.from(Hash), SELF.KeyPair.getPrivateKey('')).signature
SELF.ServerSign = global.secp256k1.sign(Buffer.from(Hash), SELF.KeyPair.getPrivateKey('')).signature
}) })
} }
FindInternetIP() { FindInternetIP() {

View File

@ -30,7 +30,7 @@ function RunOnUpdate() {
function CreateHeadersHash100() { function CreateHeadersHash100() {
global.ToLog("CreateHeadersHash100"); global.ToLog("CreateHeadersHash100");
// const DBRow = require("./db/db-row"); const DBRow = require("./db/db-row");
global.UpdateMode = 1; global.UpdateMode = 1;
var DB = global.SERVER.DBHeader100; var DB = global.SERVER.DBHeader100;
var Num = 0; var Num = 0;

View File

@ -9,6 +9,7 @@
*/ */
"use strict"; "use strict";
import { secp256k1 } from './library'
// const fs = require('fs'); // const fs = require('fs');
import * as crypto from 'crypto'; import * as crypto from 'crypto';
require("./library"); require("./library");
@ -25,7 +26,7 @@ class CApp {
PubKeyArr PubKeyArr
constructor() { constructor() {
global.CheckCreateDir(global.GetDataPath(WalletPath)) global.CheckCreateDir(global.GetDataPath(WalletPath))
// var bReadOnly = (global.PROCESS_NAME !== "TX"); var bReadOnly = (global.PROCESS_NAME !== "TX");
this.Password = "" this.Password = ""
this.WalletOpen = undefined this.WalletOpen = undefined
var Params = global.LoadParams(CONFIG_NAME, undefined); var Params = global.LoadParams(CONFIG_NAME, undefined);
@ -218,7 +219,7 @@ class CApp {
if (!this.KeyPair.WasInit) if (!this.KeyPair.WasInit)
return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
var PrivKey = this.GetPrivateKey(Num); var PrivKey = this.GetPrivateKey(Num);
var sigObj = global.secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey)); var sigObj = secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey));
return global.GetHexFromArr(sigObj.signature); return global.GetHexFromArr(sigObj.signature);
} }
GetSignTransaction(TR) { GetSignTransaction(TR) {

View File

@ -14,6 +14,7 @@ import fs = require('fs');
import os = require('os'); import os = require('os');
// import path = require('path') // import path = require('path')
import * as crypto from 'crypto'; import * as crypto from 'crypto';
import { secp256k1 } from '../core/library'
global.START_SERVER = 1; global.START_SERVER = 1;
global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH); global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
@ -37,18 +38,25 @@ global.glCurNumFindArr = 0;
global.ArrReconnect = []; global.ArrReconnect = [];
global.ArrConnect = []; global.ArrConnect = [];
var FindList = [ var FindList = [
{ "ip": "91.235.136.81", "port": 30005 },
{ "ip": "149.154.70.158", "port": 30000 },
{ "ip": "185.240.243.182", "port": 30000 },
{ "ip": "212.109.197.205", "port": 30000 },
{ "ip": "212.109.197.209", "port": 30000 },
{ "ip": "80.87.192.24", "port": 30000 },
{ "ip": "60.12.241.181", "port": 30000 }, { "ip": "60.12.241.181", "port": 30000 },
{ "ip": "60.12.241.181", "port": 30001 }, { "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 },
{ "ip": "60.12.241.181", "port": 30005 }, { "ip": "60.12.241.181", "port": 30005 },
{ "ip": "60.12.241.181", "port": 30006 },
{ "ip": "60.12.241.181", "port": 30007 },
{ "ip": "60.12.241.181", "port": 30008 },
{ "ip": "60.12.241.181", "port": 30009 },
{ "ip": "60.12.241.181", "port": 30010 },
{ "ip": "60.12.241.181", "port": 30011 },
{ "ip": "60.12.241.181", "port": 30012 },
{ "ip": "60.12.241.181", "port": 30013 },
{ "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": 30017 },
{ "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 }];
@ -369,23 +377,22 @@ var StartCheckMining = 0;
global.MiningPaused = 0; global.MiningPaused = 0;
var ProcessMemorySize = 0; var ProcessMemorySize = 0;
global.ArrMiningWrk = []; global.ArrMiningWrk = [];
// var BlockMining; var BlockMining;
if (global.ADDRLIST_MODE) { if (global.ADDRLIST_MODE) {
// @ts-ignore // @ts-ignore
return; return;
} }
let ArrMiningWrk = global.ArrMiningWrk
function AllAlive() { function AllAlive() {
for (var i = 0; i < ArrMiningWrk.length; i++) { for (var i = 0; i < global.ArrMiningWrk.length; i++) {
ArrMiningWrk[i].send({ cmd: "Alive" }); global.ArrMiningWrk[i].send({ cmd: "Alive" });
} }
}; };
function ClearArrMining() { function ClearArrMining() {
for (var i = 0; i < ArrMiningWrk.length; i++) { for (var i = 0; i < global.ArrMiningWrk.length; i++) {
ArrMiningWrk[i].send({ cmd: "Exit" }); global.ArrMiningWrk[i].send({ cmd: "Exit" });
} }
ArrMiningWrk = []; global.ArrMiningWrk = [];
}; };
function RunStopPOWProcess(Mode) { function RunStopPOWProcess(Mode) {
@ -415,13 +422,13 @@ function RunStopPOWProcess(Mode) {
global.MiningPaused = 0; global.MiningPaused = 0;
} }
} }
if (ArrMiningWrk.length && global.MiningPaused) { if (global.ArrMiningWrk.length && global.MiningPaused) {
global.ToLog("------------ MINING MUST STOP ON TIME"); global.ToLog("------------ MINING MUST STOP ON TIME");
ClearArrMining(); ClearArrMining();
return; return;
} }
else else
if (!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 {
@ -435,7 +442,7 @@ function RunStopPOWProcess(Mode) {
ClearArrMining(); ClearArrMining();
return; return;
} }
if (global.USE_MINING && ArrMiningWrk.length) if (global.USE_MINING && global.ArrMiningWrk.length)
return; return;
if (global.SERVER.LoadHistoryMode) if (global.SERVER.LoadHistoryMode)
return; return;
@ -444,7 +451,7 @@ function RunStopPOWProcess(Mode) {
var PathMiner = global.GetCodePath("../miner.js"); var PathMiner = global.GetCodePath("../miner.js");
if (!fs.existsSync(PathMiner)) if (!fs.existsSync(PathMiner))
PathMiner = "./process/pow-process.js"; PathMiner = "./process/pow-process.js";
if (ArrMiningWrk.length >= global.GetCountMiningCPU()) if (global.ArrMiningWrk.length >= global.GetCountMiningCPU())
return; return;
if (global.GrayConnect()) { if (global.GrayConnect()) {
global.ToLog("CANNOT START MINER IN NOT DIRECT IP MODE"); global.ToLog("CANNOT START MINER IN NOT DIRECT IP MODE");
@ -464,8 +471,8 @@ function RunStopPOWProcess(Mode) {
global.ToLog("START MINER PROCESS COUNT: " + global.GetCountMiningCPU() + " Memory: " + ProcessMemorySize / 1024 / 1024 + " Mb for each process"); global.ToLog("START MINER PROCESS COUNT: " + global.GetCountMiningCPU() + " Memory: " + ProcessMemorySize / 1024 / 1024 + " Mb for each process");
for (var R = 0; R < global.GetCountMiningCPU(); R++) { for (var R = 0; R < global.GetCountMiningCPU(); R++) {
let Worker = Fork(PathMiner); let Worker = Fork(PathMiner);
ArrMiningWrk.push(Worker); global.ArrMiningWrk.push(Worker);
Worker.Num = ArrMiningWrk.length; Worker.Num = global.ArrMiningWrk.length;
Worker.on('message', function(msg) { Worker.on('message', function(msg) {
if (msg.cmd === "log") { if (msg.cmd === "log") {
global.ToLog(msg.message); global.ToLog(msg.message);
@ -485,16 +492,16 @@ function RunStopPOWProcess(Mode) {
} }
}); });
Worker.on('error', function(err) { Worker.on('error', function(err) {
if (!ArrMiningWrk.length) if (!global.ArrMiningWrk.length)
return; return;
global.ToError('ERROR IN PROCESS: ' + err); global.ToError('ERROR IN PROCESS: ' + err);
}); });
Worker.on('close', function(code) { Worker.on('close', function(code) {
global.ToLog("STOP PROCESS: " + Worker.Num + " pid:" + Worker.pid); global.ToLog("STOP PROCESS: " + Worker.Num + " pid:" + Worker.pid);
for (var i = 0; i < ArrMiningWrk.length; i++) { for (var i = 0; i < global.ArrMiningWrk.length; i++) {
if (ArrMiningWrk[i].pid === Worker.pid) { if (global.ArrMiningWrk[i].pid === Worker.pid) {
global.ToLog("Delete wrk from arr - pid:" + Worker.pid); global.ToLog("Delete wrk from arr - pid:" + Worker.pid);
ArrMiningWrk.splice(i, 1); global.ArrMiningWrk.splice(i, 1);
} }
} }
}); });
@ -504,11 +511,11 @@ function RunStopPOWProcess(Mode) {
function SetCalcPOW(Block, cmd) { function SetCalcPOW(Block, cmd) {
if (!global.USE_MINING) if (!global.USE_MINING)
return; return;
if (ArrMiningWrk.length !== global.GetCountMiningCPU()) if (global.ArrMiningWrk.length !== global.GetCountMiningCPU())
return; return;
// BlockMining = Block; BlockMining = Block;
for (var i = 0; i < ArrMiningWrk.length; i++) { for (var i = 0; i < global.ArrMiningWrk.length; i++) {
var CurWorker = ArrMiningWrk[i]; var CurWorker = global.ArrMiningWrk[i];
if (!CurWorker.bOnline) if (!CurWorker.bOnline)
continue; continue;
CurWorker.send({ CurWorker.send({
@ -650,7 +657,7 @@ function RunOnce() {
}, 10000); }, 10000);
} }
}; };
// var glPortDebug = 49800; var glPortDebug = 49800;
function Fork(Path, ArrArgs?) { function Fork(Path, ArrArgs?) {
const child_process = require('child_process'); const child_process = require('child_process');
@ -670,7 +677,7 @@ function Fork(Path, ArrArgs?) {
ArrArgs.push("NOALIVE"); ArrArgs.push("NOALIVE");
if (global.DEV_MODE) if (global.DEV_MODE)
ArrArgs.push("DEV_MODE"); ArrArgs.push("DEV_MODE");
// glPortDebug++; glPortDebug++;
var execArgv = []; var execArgv = [];
var Worker = child_process.fork(Path, ArrArgs, { execArgv: execArgv }); var Worker = child_process.fork(Path, ArrArgs, { execArgv: execArgv });
return Worker; return Worker;
@ -687,7 +694,7 @@ function TestSignLib(MaxTime) {
var startTime = process.hrtime(); var startTime = process.hrtime();
var deltaTime = 1; var deltaTime = 1;
for (var Num = 0; Num < 1000; Num++) { for (var Num = 0; Num < 1000; Num++) {
var Result = global.secp256k1.verify(hash, Sign, PubKey); var Result = secp256k1.verify(hash, Sign, PubKey);
if (!Result) { if (!Result) {
global.ToError("Error test sign"); global.ToError("Error test sign");
process.exit(0); process.exit(0);

View File

@ -50,20 +50,20 @@ PROCESS.on("message", function(e) {
cmd: "POW", BlockNum: o.BlockNum, SeqHash: o.SeqHash, Hash: o.Hash, PowHash: o.PowHash, AddrHash: o.AddrHash, cmd: "POW", BlockNum: o.BlockNum, SeqHash: o.SeqHash, Hash: o.Hash, PowHash: o.PowHash, AddrHash: o.AddrHash,
Num: o.Num Num: o.Num
}); });
} } catch (e) {
catch (e) {
global.ToError(e); global.ToError(e);
} }
} } else {
else
if ("SetBlock" === e.cmd) { if ("SetBlock" === e.cmd) {
var a = 1e6 * (1 + e.Num); var a = 1e6 * (1 + e.Num);
Block.HashCount && process.send({ cmd: "HASHRATE", CountNonce: Block.HashCount, Hash: Block.Hash }), Block.HashCount = 0, (Block = e).Time = Date.now(), 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(), 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)); void 0 !== idInterval && clearInterval(idInterval), idInterval = setInterval(CalcPOWHash, Block.RunPeriod));
} } else {
else
"Alive" === e.cmd || "Exit" === e.cmd && PROCESS.exit(0); "Alive" === e.cmd || "Exit" === e.cmd && PROCESS.exit(0);
}
}
}); });
var idIntervalPump = global.BlockPump = void 0; var idIntervalPump = global.BlockPump = void 0;
@ -83,8 +83,7 @@ function PumpHash() {
if (100 * (e - StartTime) / global.CONSENSUS_PERIOD_TIME >= global.BlockPump.Percent) if (100 * (e - StartTime) / global.CONSENSUS_PERIOD_TIME >= global.BlockPump.Percent)
return void (EndTime = e); return void (EndTime = e);
global.CreatePOWVersionX(global.BlockPump, 1); global.CreatePOWVersionX(global.BlockPump, 1);
} } else {
else {
100 * (e - EndTime) / global.CONSENSUS_PERIOD_TIME > 100 - global.BlockPump.Percent && (StartTime = e); 100 * (e - EndTime) / global.CONSENSUS_PERIOD_TIME > 100 - global.BlockPump.Percent && (StartTime = e);
} }
} }

View File

@ -111,7 +111,7 @@ function GETBLOCKHEADER100(msg) {
return; return;
var EndNum100 = BlockNum / 100; var EndNum100 = BlockNum / 100;
var LoadHash100 = Data.Hash; var LoadHash100 = Data.Hash;
// var Hash100; var Hash100;
var Count = Data.Count; var Count = Data.Count;
if (!Count || Count < 0 || !EndNum100) if (!Count || Count < 0 || !EndNum100)
return; return;
@ -151,8 +151,7 @@ function GETBLOCKHEADER(msg) {
if (BlockNum > global.SERVER.GetMaxNumBlockDB()) if (BlockNum > global.SERVER.GetMaxNumBlockDB())
BlockNum = global.SERVER.GetMaxNumBlockDB(); BlockNum = global.SERVER.GetMaxNumBlockDB();
} }
} } else {
else {
BlockNum = Data.BlockNum; BlockNum = Data.BlockNum;
var IsSum = Data.IsSum; var IsSum = Data.IsSum;
var Count = Data.Count; var Count = Data.Count;
@ -228,8 +227,8 @@ function GETREST(msg) {
var ProofArrR = []; var ProofArrR = [];
var ArrRest = []; var ArrRest = [];
if (nResult) { if (nResult) {
// var WorkStruct = {}; var WorkStruct = {};
// var WorkFormat = global.DApps.Accounts.FORMAT_ACCOUNT_ROW; var WorkFormat = global.DApps.Accounts.FORMAT_ACCOUNT_ROW;
var WorkFormatLength = global.DApps.Accounts.SIZE_ACCOUNT_ROW; var WorkFormatLength = global.DApps.Accounts.SIZE_ACCOUNT_ROW;
var Max = global.DApps.Accounts.DBState.GetMaxNum(); var Max = global.DApps.Accounts.DBState.GetMaxNum();
var LengthAccount = Data.Count; var LengthAccount = Data.Count;

View File

@ -121,7 +121,7 @@ function DoTXProcess() {
var StartTime = Date.now(); var StartTime = Date.now();
if (global.bShowDetail) if (global.bShowDetail)
global.ToLog("BlockMin: " + BlockMin.BlockNum + " LastBlockNum=" + LastBlockNum); global.ToLog("BlockMin: " + BlockMin.BlockNum + " LastBlockNum=" + LastBlockNum);
// var CountTX = 0; var CountTX = 0;
for (var Num = BlockMin.BlockNum; Num < BlockMin.BlockNum + 200; Num++) { for (var Num = BlockMin.BlockNum; Num < BlockMin.BlockNum + 200; Num++) {
var EndTime = Date.now(); var EndTime = Date.now();
var Delta = EndTime - StartTime; var Delta = EndTime - StartTime;
@ -154,7 +154,7 @@ function DoTXProcess() {
global.SERVER.BlockProcessTX(Block); global.SERVER.BlockProcessTX(Block);
if (Num % 100000 === 0) if (Num % 100000 === 0)
global.ToLog("CALC: " + Num); global.ToLog("CALC: " + Num);
// CountTX++; CountTX++;
if (global.bShowDetail) if (global.bShowDetail)
global.ToLog(" CALC: " + Num + " SumHash: " + global.GetHexFromArr(Block.SumHash).substr(0, 12)); global.ToLog(" CALC: " + Num + " SumHash: " + global.GetHexFromArr(Block.SumHash).substr(0, 12));
BlockTree.SaveValue(Block.BlockNum, { BlockNum: Block.BlockNum, SumHash: Block.SumHash }); BlockTree.SaveValue(Block.BlockNum, { BlockNum: Block.BlockNum, SumHash: Block.SumHash });
@ -331,8 +331,7 @@ function TXWriteAccHash() {
var Item = global.DApps.Smart.DBSmart.Read(num); var Item = global.DApps.Smart.DBSmart.Read(num);
if (!Item) if (!Item)
break; break;
// var Body = var Body = global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {});
global.BufLib.GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {});
global.DApps.Smart.DBSmartWrite(Item); global.DApps.Smart.DBSmartWrite(Item);
} }
global.DApps.Accounts.CalcMerkleTree(1); global.DApps.Accounts.CalcMerkleTree(1);

View File

@ -447,9 +447,19 @@ function DoCommandNew(response, Type, Path, Params) {
HostingCaller.GetCurrentInfo = function(Params) { HostingCaller.GetCurrentInfo = function(Params) {
var MaxNumBlockDB = global.SERVER.GetMaxNumBlockDB(); var MaxNumBlockDB = global.SERVER.GetMaxNumBlockDB();
var Ret: any = { var Ret: any = {
result: 1, VersionNum: global.UPDATE_CODE_VERSION_NUM, NETWORK: global.NETWORK, MaxNumBlockDB: MaxNumBlockDB, CurBlockNum: global.GetCurrentBlockNumByTime(), result: 1,
MaxAccID: global.DApps.Accounts.GetMaxAccount(), MaxDappsID: global.DApps.Smart.GetMaxNum(), CurTime: Date.now(), DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME, VersionNum: global.UPDATE_CODE_VERSION_NUM,
MIN_POWER_POW_TR: global.MIN_POWER_POW_TR, FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK, CONSENSUS_PERIOD_TIME: global.CONSENSUS_PERIOD_TIME, NEW_SIGN_TIME: global.NEW_SIGN_TIME, NETWORK: global.NETWORK,
MaxNumBlockDB: MaxNumBlockDB,
CurBlockNum: global.GetCurrentBlockNumByTime(),
MaxAccID: global.DApps.Accounts.GetMaxAccount(),
MaxDappsID: global.DApps.Smart.GetMaxNum(),
CurTime: Date.now(),
DELTA_CURRENT_TIME: global.DELTA_CURRENT_TIME,
MIN_POWER_POW_TR: global.MIN_POWER_POW_TR,
FIRST_TIME_BLOCK: global.FIRST_TIME_BLOCK,
CONSENSUS_PERIOD_TIME: global.CONSENSUS_PERIOD_TIME,
NEW_SIGN_TIME: global.NEW_SIGN_TIME,
PRICE_DAO: global.PRICE_DAO(MaxNumBlockDB), PRICE_DAO: global.PRICE_DAO(MaxNumBlockDB),
}; };
if (typeof Params === "object" && Params.Diagram == 1) { if (typeof Params === "object" && Params.Diagram == 1) {

View File

@ -13,6 +13,7 @@ import * as fs from 'fs'
import DApp from './dapp' import DApp from './dapp'
import DBRow from '../core/db/db-row' import DBRow from '../core/db/db-row'
import DBLib from "../core/db/db" import DBLib from "../core/db/db"
import { secp256k1 } from '../core/library'
require('../core/rest_tables'); require('../core/rest_tables');
const MAX_SUM_TER = 1e9; const MAX_SUM_TER = 1e9;
const MAX_SUM_CENT = 1e9; const MAX_SUM_CENT = 1e9;
@ -149,7 +150,7 @@ class AccountApp extends DApp {
FORMAT_STATE_HISTORY FORMAT_STATE_HISTORY
DBStateHistory DBStateHistory
HistoryFormatArr HistoryFormatArr
DBStateTX DBStateTX: DBRow
DBAccountsHash DBAccountsHash
WasCheckRestDB WasCheckRestDB
ResultTx ResultTx
@ -750,12 +751,11 @@ class AccountApp extends DApp {
else { else {
return "Error transaction version"; return "Error transaction version";
} }
var Result = 0; var Result: any = 0;
if (Data.PubKey[0] === 2 || Data.PubKey[0] === 3) if (Data.PubKey[0] === 2 || Data.PubKey[0] === 3)
try { try {
Result = global.secp256k1.verify(hash, TR.Sign, Data.PubKey) Result = secp256k1.verify(hash, TR.Sign, Data.PubKey)
} } catch (e) {
catch (e) {
} }
if (!Result) { if (!Result) {
return "Error sign transaction"; return "Error sign transaction";
@ -1316,7 +1316,7 @@ class AccountApp extends DApp {
else { else {
Arr = global.BufLib.GetBufferFromObject(TR, global.FORMAT_MONEY_TRANSFER_BODY, global.MAX_TRANSACTION_SIZE, {}) Arr = global.BufLib.GetBufferFromObject(TR, global.FORMAT_MONEY_TRANSFER_BODY, global.MAX_TRANSACTION_SIZE, {})
} }
var sigObj = global.secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey)); var sigObj = secp256k1.sign(global.SHA3BUF(Arr), Buffer.from(PrivKey));
return sigObj.signature; return sigObj.signature;
} }
SaveHistory(Data) { SaveHistory(Data) {

View File

@ -11,6 +11,7 @@
"use strict"; "use strict";
import DApp from './dapp' import DApp from './dapp'
import DBRow from '../core/db/db-row' import DBRow from '../core/db/db-row'
import { secp256k1 } from '../core/library'
const LOC_ADD_NAME = "$"; const LOC_ADD_NAME = "$";
require("../HTML/JS/lexer.js"); require("../HTML/JS/lexer.js");
@ -272,12 +273,11 @@ class SmartApp extends DApp {
if (TR.OperationID > AccountFrom.Value.OperationID + MaxCountOperationID) if (TR.OperationID > AccountFrom.Value.OperationID + MaxCountOperationID)
return "Error too much OperationID (expected max: " + (AccountFrom.Value.OperationID + MaxCountOperationID) + " for ID: " + TR.FromNum + ")"; return "Error too much OperationID (expected max: " + (AccountFrom.Value.OperationID + MaxCountOperationID) + " for ID: " + TR.FromNum + ")";
var hash = global.SHA3BUF(Body.slice(0, Body.length - 64 - 12), BlockNum); var hash = global.SHA3BUF(Body.slice(0, Body.length - 64 - 12), BlockNum);
var Result = 0; var Result: any = 0;
if (AccountFrom.PubKey[0] === 2 || AccountFrom.PubKey[0] === 3) if (AccountFrom.PubKey[0] === 2 || AccountFrom.PubKey[0] === 3)
try { try {
Result = global.secp256k1.verify(hash, TR.Sign, AccountFrom.PubKey) Result = secp256k1.verify(hash, TR.Sign, AccountFrom.PubKey)
} } catch (e) {
catch (e) {
} }
if (!Result) { if (!Result) {
return "Error sign transaction"; return "Error sign transaction";
@ -371,7 +371,7 @@ class SmartApp extends DApp {
} }
if (Category) if (Category)
Category = global.global.ParseNum(Category) Category = global.global.ParseNum(Category)
// var WasError = 0; var WasError = 0;
var arr = []; var arr = [];
var Data; var Data;
for (var num = start; true; num++) { for (var num = start; true; num++) {
@ -1178,10 +1178,10 @@ var mask = 0xffffffff;
function MathRandom() { function MathRandom() {
DO(5); DO(5);
// function seed(i) { function seed(i) {
// m_w = i; m_w = i;
// m_z = 987654321; m_z = 987654321;
// }; };
function random() { function random() {
m_z = (36969 * (m_z & 65535) + (m_z >> 16)) & mask; m_z = (36969 * (m_z & 65535) + (m_z >> 16)) & mask;