1
0
forked from circlecloud/tera

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

View File

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

View File

@ -517,7 +517,7 @@ export default class CConsensus extends CBlock {
CanEnd = 0
break;
} else {
//var Stop = 1;
var Stop = 1;
}
}
}
@ -829,7 +829,7 @@ export default class CConsensus extends CBlock {
var SumPow = 0;
if (arr.length !== global.SUM_LIST_LENGTH)
return SumPow;
//var CountLoad = 0;
var CountLoad = 0;
var BlockNumStart = CurBlockNum - arr.length + 1;
for (var i = 0; i < arr.length; i++) {
var Item = arr[i];
@ -1136,8 +1136,8 @@ export default class CConsensus extends CBlock {
if (this.LoadHistoryMode)
return;
var bWasSave = false;
// var LoadBlockNum;
// var LoadHash;
var LoadBlockNum;
var LoadHash;
var start_save = CURRENTBLOCKNUM + global.TIME_START_SAVE;
for (var BlockNum = CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2; BlockNum > global.BLOCK_PROCESSING_LENGTH2 && BlockNum < CURRENTBLOCKNUM; 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) {
this.SendLoadToBegin()
}
//var CountStopSend = 0;
var CountStopSend = 0;
var min_num = this.CurrentBlockNum - global.MAX_COUNT_CHAIN_LOAD;
var min_num_load = this.CurrentBlockNum;
for (var i = 0; i < this.LoadedChainList.length; i++) {
@ -311,7 +311,7 @@ export default class CBlock extends CRest {
}
}
if (chain && chain.StopSend) {
//CountStopSend++
CountStopSend++
}
chain = this.LoadedChainList[i]
if (chain && !chain.GetFindDB() && !chain.StopSend) {
@ -534,7 +534,7 @@ export default class CBlock extends CRest {
chain.BlockHead = Block
if (!chain.BlockNumMax)
chain.BlockNumMax = Block.BlockNum
//var PrevBlock0 = PrevBlock;
var PrevBlock0 = PrevBlock;
if (BlockFind) {
if (PrevBlock) {
PrevBlock.BlockDown = BlockFind
@ -673,9 +673,9 @@ export default class CBlock extends CRest {
for (var num = 0; num < this.LoadedChainList.length; num++) {
var chain = this.LoadedChainList[num];
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++) {
//Count++
Count++
var Block = chain.arr[i];
if (!global.IsZeroArr(Block.TreeHash) && !Block.TreeEq && !Block.LoadDBFinaly) {
if (!Block.MapSend) {
@ -702,7 +702,7 @@ export default class CBlock extends CRest {
if (i === chain.CurNumArrLoad) {
chain.CurNumArrLoad++
Block.LoadDBFinaly = true
//Count = 0
Count = 0
}
}
}
@ -1042,7 +1042,7 @@ export default class CBlock extends CRest {
return "{BlockNum:uint}";
}
CANBLOCK(Info, CurTime) {
// var Data = this.DataFromF(Info);
var Data = this.DataFromF(Info);
this.SendF(Info.Node, { "Method": "RETCANBLOCK", "Data": { Result: 1 } })
}
static RETCANBLOCK_F() {
@ -1159,10 +1159,10 @@ export default class CBlock extends CRest {
this.FREE_MEM_BLOCKS(NumMax - global.BLOCK_COUNT_IN_MEMORY)
var maxArrMap = Math.floor(NumMax / global.BLOCK_COUNT_IN_MEMORY) - 1;
if (maxArrMap >= 0) {
// var nWasCount = 0;
var nWasCount = 0;
for (var key in this.MapMapLoaded)
if (key as any < maxArrMap) {
// nWasCount++
nWasCount++
delete this.MapMapLoaded[key]
}
}

View File

@ -11,6 +11,7 @@
"use strict";
import * as fs from 'fs'
import CCommon from './base'
import { secp256k1 } from '../core/library'
// const FORMAT_EVAL_SEND = "{MaxBlockNum:uint,Code:str,Sign:arr64}";
export default class CCode extends CCommon {
LastEvalCodeNum
@ -96,7 +97,7 @@ export default class CCode extends CCommon {
fs.writeSync(file_handle, data, 0, data.length)
fs.closeSync(file_handle)
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.Hash = Hash
global.CODE_VERSION.Sign = Sign

View File

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

View File

@ -8,6 +8,7 @@
* Telegram: https://t.me/terafoundation
*/
require("./library");
import { secp256k1 } from './library'
import * as crypto from 'crypto'
global.MAX_SUPER_VALUE_POW = (1 << 30) * 2;
@ -72,7 +73,7 @@ global.GetPublicKeyFromAddres = function(Arr) {
global.CheckDevelopSign = function(SignArr, Sign) {
var hash = global.SHA3BUF(SignArr);
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)
return 1;
}

View File

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

View File

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

View File

@ -11,14 +11,14 @@
"use strict";
import './crypto-library'
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';
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 = {};
ContenTypeMap["js"] = "application/javascript";
ContenTypeMap["css"] = "text/css";
@ -522,18 +522,52 @@ HTTPCaller.GetWalletInfo = function(Params) {
if (StateTX)
TXBlockNum = StateTX.BlockNum;
var Ret: any = {
result: 1, WalletOpen: global.WALLET.WalletOpen, WalletIsOpen: (global.WALLET.WalletOpen !== false), WalletCanSign: (global.WALLET.WalletOpen !== false && global.WALLET.KeyPair.WasInit),
CODE_VERSION: global.CODE_VERSION, MAX_TRANSACTION_LIMIT: global.MAX_TRANSACTION_LIMIT, VersionNum: global.UPDATE_CODE_VERSION_NUM, RelayMode: global.SERVER.RelayMode,
BlockNumDB: global.SERVER.BlockNumDB, CurBlockNum: global.GetCurrentBlockNumByTime(), CurTime: Date.now(), 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,
result: 1,
WalletOpen: global.WALLET.WalletOpen,
WalletIsOpen: (global.WALLET.WalletOpen !== false),
WalletCanSign: (global.WALLET.WalletOpen !== false && global.WALLET.KeyPair.WasInit),
CODE_VERSION: global.CODE_VERSION,
MAX_TRANSACTION_LIMIT: global.MAX_TRANSACTION_LIMIT,
VersionNum: global.UPDATE_CODE_VERSION_NUM,
RelayMode: global.SERVER.RelayMode,
BlockNumDB: global.SERVER.BlockNumDB,
CurBlockNum: global.GetCurrentBlockNumByTime(),
CurTime: Date.now(),
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)
Ret.PrivateKey = global.GetHexFromArr(global.WALLET.GetPrivateKey(global.WALLET.AccountMap[Params.Account]));
@ -680,7 +714,7 @@ function SetCheckPointOnBlock(BlockNum) {
if (!Block)
return 0;
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.SERVER.ResetNextPingAllNode();
return 1;
@ -749,7 +783,7 @@ HTTPCaller.SetCheckNetConstant = function(Data) {
Data.Num = global.GetCurrentBlockNumByTime();
Data.BlockNum = global.GetCurrentBlockNumByTime() + 10;
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.ResetNextPingAllNode();
return { result: 1, text: "Set NET_CONSTANT BlockNum=" + Data.BlockNum };
@ -763,7 +797,7 @@ HTTPCaller.SetCheckDeltaTime = function(Data) {
return { result: 0 };
}
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.SERVER.ResetNextPingAllNode();
return { result: 1, text: "Set check time Num=" + Data.Num };
@ -796,7 +830,7 @@ function RunAutoCorrTime() {
Data.StartBlockNum = Data.Num + 5;
Data.EndBlockNum = Data.StartBlockNum + Math.trunc(AutoDelta / Data.DeltaTime);
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.SERVER.ResetNextPingAllNode();
StartCheckTimeNum = Data.EndBlockNum + 1;

View File

@ -10,7 +10,8 @@
"use strict";
import "./library"
import net = require("net");
import * as net from "net"
import { secp256k1 } from '../core/library'
var ConnectIDCount = 1;
export default class CNode {
addrStr
@ -364,9 +365,9 @@ export default class CNode {
}
var Result = false;
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) {
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) {
@ -404,7 +405,7 @@ export default class CNode {
if (global.WALLET.WalletOpen && global.IsDeveloperAccount(global.WALLET.PubKeyArr)) {
Info = this.GetPOWClientData(0)
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)
if (!Result) {
throw "ERROR DEVELOPSIGN!";
@ -413,7 +414,7 @@ export default class CNode {
else {
Info = this.GetPOWClientData(nonce)
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 BufAll = global.SERVER.GetBufFromData("POW_CONNECT6", BufWrite, 1);

View File

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

View File

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

View File

@ -9,6 +9,7 @@
*/
"use strict";
import { secp256k1 } from './library'
// const fs = require('fs');
import * as crypto from 'crypto';
require("./library");
@ -25,7 +26,7 @@ class CApp {
PubKeyArr
constructor() {
global.CheckCreateDir(global.GetDataPath(WalletPath))
// var bReadOnly = (global.PROCESS_NAME !== "TX");
var bReadOnly = (global.PROCESS_NAME !== "TX");
this.Password = ""
this.WalletOpen = undefined
var Params = global.LoadParams(CONFIG_NAME, undefined);
@ -218,7 +219,7 @@ class CApp {
if (!this.KeyPair.WasInit)
return "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
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);
}
GetSignTransaction(TR) {

View File

@ -14,6 +14,7 @@ import fs = require('fs');
import os = require('os');
// import path = require('path')
import * as crypto from 'crypto';
import { secp256k1 } from '../core/library'
global.START_SERVER = 1;
global.DATA_PATH = global.GetNormalPathString(global.DATA_PATH);
@ -37,18 +38,25 @@ global.glCurNumFindArr = 0;
global.ArrReconnect = [];
global.ArrConnect = [];
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": 30001 },
{ "ip": "60.12.241.181", "port": 30002 },
{ "ip": "60.12.241.181", "port": 30003 },
{ "ip": "60.12.241.181", "port": 30004 },
{ "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) {
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;
var ProcessMemorySize = 0;
global.ArrMiningWrk = [];
// var BlockMining;
var BlockMining;
if (global.ADDRLIST_MODE) {
// @ts-ignore
return;
}
let ArrMiningWrk = global.ArrMiningWrk
function AllAlive() {
for (var i = 0; i < ArrMiningWrk.length; i++) {
ArrMiningWrk[i].send({ cmd: "Alive" });
for (var i = 0; i < global.ArrMiningWrk.length; i++) {
global.ArrMiningWrk[i].send({ cmd: "Alive" });
}
};
function ClearArrMining() {
for (var i = 0; i < ArrMiningWrk.length; i++) {
ArrMiningWrk[i].send({ cmd: "Exit" });
for (var i = 0; i < global.ArrMiningWrk.length; i++) {
global.ArrMiningWrk[i].send({ cmd: "Exit" });
}
ArrMiningWrk = [];
global.ArrMiningWrk = [];
};
function RunStopPOWProcess(Mode) {
@ -415,13 +422,13 @@ function RunStopPOWProcess(Mode) {
global.MiningPaused = 0;
}
}
if (ArrMiningWrk.length && global.MiningPaused) {
if (global.ArrMiningWrk.length && global.MiningPaused) {
global.ToLog("------------ MINING MUST STOP ON TIME");
ClearArrMining();
return;
}
else
if (!ArrMiningWrk.length && !global.MiningPaused) {
if (!global.ArrMiningWrk.length && !global.MiningPaused) {
global.ToLog("*********** MINING MUST START ON TIME");
}
else {
@ -435,7 +442,7 @@ function RunStopPOWProcess(Mode) {
ClearArrMining();
return;
}
if (global.USE_MINING && ArrMiningWrk.length)
if (global.USE_MINING && global.ArrMiningWrk.length)
return;
if (global.SERVER.LoadHistoryMode)
return;
@ -444,7 +451,7 @@ function RunStopPOWProcess(Mode) {
var PathMiner = global.GetCodePath("../miner.js");
if (!fs.existsSync(PathMiner))
PathMiner = "./process/pow-process.js";
if (ArrMiningWrk.length >= global.GetCountMiningCPU())
if (global.ArrMiningWrk.length >= global.GetCountMiningCPU())
return;
if (global.GrayConnect()) {
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");
for (var R = 0; R < global.GetCountMiningCPU(); R++) {
let Worker = Fork(PathMiner);
ArrMiningWrk.push(Worker);
Worker.Num = ArrMiningWrk.length;
global.ArrMiningWrk.push(Worker);
Worker.Num = global.ArrMiningWrk.length;
Worker.on('message', function(msg) {
if (msg.cmd === "log") {
global.ToLog(msg.message);
@ -485,16 +492,16 @@ function RunStopPOWProcess(Mode) {
}
});
Worker.on('error', function(err) {
if (!ArrMiningWrk.length)
if (!global.ArrMiningWrk.length)
return;
global.ToError('ERROR IN PROCESS: ' + err);
});
Worker.on('close', function(code) {
global.ToLog("STOP PROCESS: " + Worker.Num + " pid:" + Worker.pid);
for (var i = 0; i < ArrMiningWrk.length; i++) {
if (ArrMiningWrk[i].pid === Worker.pid) {
for (var i = 0; i < global.ArrMiningWrk.length; i++) {
if (global.ArrMiningWrk[i].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) {
if (!global.USE_MINING)
return;
if (ArrMiningWrk.length !== global.GetCountMiningCPU())
if (global.ArrMiningWrk.length !== global.GetCountMiningCPU())
return;
// BlockMining = Block;
for (var i = 0; i < ArrMiningWrk.length; i++) {
var CurWorker = ArrMiningWrk[i];
BlockMining = Block;
for (var i = 0; i < global.ArrMiningWrk.length; i++) {
var CurWorker = global.ArrMiningWrk[i];
if (!CurWorker.bOnline)
continue;
CurWorker.send({
@ -650,7 +657,7 @@ function RunOnce() {
}, 10000);
}
};
// var glPortDebug = 49800;
var glPortDebug = 49800;
function Fork(Path, ArrArgs?) {
const child_process = require('child_process');
@ -670,7 +677,7 @@ function Fork(Path, ArrArgs?) {
ArrArgs.push("NOALIVE");
if (global.DEV_MODE)
ArrArgs.push("DEV_MODE");
// glPortDebug++;
glPortDebug++;
var execArgv = [];
var Worker = child_process.fork(Path, ArrArgs, { execArgv: execArgv });
return Worker;
@ -687,7 +694,7 @@ function TestSignLib(MaxTime) {
var startTime = process.hrtime();
var deltaTime = 1;
for (var Num = 0; Num < 1000; Num++) {
var Result = global.secp256k1.verify(hash, Sign, PubKey);
var Result = secp256k1.verify(hash, Sign, PubKey);
if (!Result) {
global.ToError("Error test sign");
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,
Num: o.Num
});
}
catch (e) {
} catch (e) {
global.ToError(e);
}
}
else
} else {
if ("SetBlock" === e.cmd) {
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.LastNonce = a, Block.Period = global.CONSENSUS_PERIOD_TIME * Block.Percent / 100, 0 < Block.Period && 0 < Block.RunPeriod && (CalcPOWHash(),
void 0 !== idInterval && clearInterval(idInterval), idInterval = setInterval(CalcPOWHash, Block.RunPeriod));
}
else
} else {
"Alive" === e.cmd || "Exit" === e.cmd && PROCESS.exit(0);
}
}
});
var idIntervalPump = global.BlockPump = void 0;
@ -83,8 +83,7 @@ function PumpHash() {
if (100 * (e - StartTime) / global.CONSENSUS_PERIOD_TIME >= global.BlockPump.Percent)
return void (EndTime = e);
global.CreatePOWVersionX(global.BlockPump, 1);
}
else {
} else {
100 * (e - EndTime) / global.CONSENSUS_PERIOD_TIME > 100 - global.BlockPump.Percent && (StartTime = e);
}
}

View File

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

View File

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

View File

@ -447,9 +447,19 @@ function DoCommandNew(response, Type, Path, Params) {
HostingCaller.GetCurrentInfo = function(Params) {
var MaxNumBlockDB = global.SERVER.GetMaxNumBlockDB();
var Ret: any = {
result: 1, VersionNum: global.UPDATE_CODE_VERSION_NUM, 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,
result: 1,
VersionNum: global.UPDATE_CODE_VERSION_NUM,
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),
};
if (typeof Params === "object" && Params.Diagram == 1) {

View File

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

View File

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