forked from circlecloud/tera
feat: alpine 0.0.1 version complate
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@@ -16,12 +16,12 @@ import * as crypto from 'crypto';
|
||||
import * as os from 'os'
|
||||
|
||||
global.glStopNode = false;
|
||||
//const MAX_TIME_NETWORK_TRANSPORT = 1 * 1000;
|
||||
const MAX_TIME_NETWORK_TRANSPORT = 1 * 1000;
|
||||
var GlSumUser;
|
||||
var GlSumSys;
|
||||
var GlSumIdle;
|
||||
global.CountAllNode = 0;
|
||||
module.exports = class CCommon {
|
||||
export default class CCommon {
|
||||
VirtualMode
|
||||
KeyPair
|
||||
PubKeyType
|
||||
@@ -34,8 +34,6 @@ module.exports = class CCommon {
|
||||
CheckName
|
||||
NodesArr
|
||||
CurrentBlockNum
|
||||
ReadBlockHeaderDB
|
||||
GetActualNodes
|
||||
BlockNumDB
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
global.SERVER = this
|
||||
@@ -48,6 +46,18 @@ module.exports = class CCommon {
|
||||
this.HashDBArr = global.shaarr2(this.KeyPair.getPrivateKey(), [0, 0, 0, 0, 0, 0, 0, 1])
|
||||
this.ServerSign = []
|
||||
}
|
||||
SendF(Node, Info, Length?) {
|
||||
// defiend in server.ts
|
||||
}
|
||||
AddCheckErrCount(Node, Count, StrErr) {
|
||||
// defiend in server.ts
|
||||
}
|
||||
GetActualNodes(): any {
|
||||
// defiend in server.ts
|
||||
}
|
||||
ReadBlockHeaderDB(BlockNum): any {
|
||||
// defiend in block-db.ts(CDB)
|
||||
}
|
||||
AddStatOnTimer() {
|
||||
var CountAll = 0;
|
||||
var CurTime = global.GetCurrentTime() - 0;
|
||||
@@ -204,7 +214,7 @@ module.exports = class CCommon {
|
||||
return crypto.randomBytes(32);
|
||||
}
|
||||
};
|
||||
export class SMemBuffer {
|
||||
class SMemBuffer {
|
||||
MetaMap1
|
||||
MetaMap2
|
||||
CheckName
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import CBlock from './block-loader'
|
||||
require('./library');
|
||||
require('./crypto-library');
|
||||
const TX_PROCESS_TIME = 100;
|
||||
@@ -38,14 +39,14 @@ var FORMAT_DATA_TRANSFER = "{\
|
||||
NoSendTx:uint,\
|
||||
}";
|
||||
const WorkStructSend = {};
|
||||
module.exports = class CConsensus extends require("./block-loader")
|
||||
{
|
||||
export default class CConsensus extends CBlock {
|
||||
CurrentBlockNum
|
||||
SendBlockID
|
||||
RelayMode
|
||||
TreeSendPacket
|
||||
idBlockChainTimer
|
||||
OwnBlockCount
|
||||
LevelNodes
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.CurrentBlockNum = 0
|
||||
@@ -175,9 +176,9 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
}
|
||||
Transfer.WasGet = true
|
||||
if (global.DoTxLog && Data.TicketArray.length)
|
||||
global.ToLog("TRANSFER BlockNum:" + Block.BlockNum + " TicketArray=" + Data.TicketArray.length + " from " + NodeName(Node))
|
||||
global.ToLog("TRANSFER BlockNum:" + Block.BlockNum + " TicketArray=" + Data.TicketArray.length + " from " + global.NodeName(Node))
|
||||
if (global.DoTxLog && Data.TxArray.length)
|
||||
global.ToLog("TRANSFER BlockNum:" + Block.BlockNum + " TxArray=" + Data.TxArray.length + " from " + NodeName(Node))
|
||||
global.ToLog("TRANSFER BlockNum:" + Block.BlockNum + " TxArray=" + Data.TxArray.length + " from " + global.NodeName(Node))
|
||||
this.ToMaxPOWList(Data.MaxPOW)
|
||||
this.ToMaxSumList(this.GetMaxSumListFromID(Node, Data.MaxSumID, Data.BlockList))
|
||||
//var WasNewAdd = 0;
|
||||
@@ -343,7 +344,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
Arr = Arr2
|
||||
}
|
||||
if (global.DoTxLog)
|
||||
global.ToLog("SEND TRANSFER BlockNum:" + Block.BlockNum + " Arr=" + Arr.length + " to " + NodeName(Item.Node))
|
||||
global.ToLog("SEND TRANSFER BlockNum:" + Block.BlockNum + " Arr=" + Arr.length + " to " + global.NodeName(Item.Node))
|
||||
var BufData = this.CreateTransferBuffer(Arr, arrPow, arrSum, Block, Item.Node);
|
||||
this.Send(Item.Node, { "Method": "TRANSFER", "Context": {}, "Data": BufData }, 1)
|
||||
if (!Block.JobListTX)
|
||||
@@ -351,6 +352,9 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
Block.JobListTX.push({ Node: Item.Node, TreeLevel: Item.TreeLevel, Time: Date.now() })
|
||||
}
|
||||
}
|
||||
Send(Node, Info, TypeData?) {
|
||||
// defiend in server.ts
|
||||
}
|
||||
TRANSFERTX(Info, CurTime) {
|
||||
var Data = this.DataFromF(Info);
|
||||
var Node = Info.Node;
|
||||
@@ -359,7 +363,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
return;
|
||||
}
|
||||
if (global.DoTxLog)
|
||||
global.ToLog("TRANSFERTX BlockNum:" + Block.BlockNum + " Array=" + Data.Array.length + " from " + NodeName(Node))
|
||||
global.ToLog("TRANSFERTX BlockNum:" + Block.BlockNum + " Array=" + Data.Array.length + " from " + global.NodeName(Node))
|
||||
for (var i = 0; i < Data.Array.length; i++) {
|
||||
this.AddTrToBlockQuote(Block, Data.Array[i], 1)
|
||||
}
|
||||
@@ -434,7 +438,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
return;
|
||||
}
|
||||
if (global.DoTxLog)
|
||||
global.ToLog("RETTRANSFERTX BlockNum:" + Block.BlockNum + " Array=" + Data.Array.length + " from " + NodeName(Node))
|
||||
global.ToLog("RETTRANSFERTX BlockNum:" + Block.BlockNum + " Array=" + Data.Array.length + " from " + global.NodeName(Node))
|
||||
for (var i = 0; i < Data.Array.length; i++) {
|
||||
var Tr = Data.Array[i];
|
||||
this.CheckCreateTransactionObject(Tr)
|
||||
@@ -464,7 +468,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
if (!Arr.length)
|
||||
return;
|
||||
if (global.DoTxLog)
|
||||
global.ToLog("DoJobListTX BlockNum:" + Block.BlockNum + " Arr=" + Arr.length + " to " + NodeName(JobItem.Node))
|
||||
global.ToLog("DoJobListTX BlockNum:" + Block.BlockNum + " Arr=" + Arr.length + " to " + global.NodeName(JobItem.Node))
|
||||
var SendData = { "Method": "TRANSFERTX", "Context": {}, "Data": { BlockNum: Block.BlockNum, Array: Arr, } };
|
||||
this.SendF(JobItem.Node, SendData, global.MAX_BLOCK_SIZE + 1000)
|
||||
}
|
||||
@@ -570,7 +574,7 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
for (var n = 0; n < ArrNodesArr.length; n++) {
|
||||
var ElArr = ArrNodesArr[n];
|
||||
if (global.DoTxLog)
|
||||
global.ToLog("CheckTxExchange BlockNum:" + Block.BlockNum + " Array=" + ElArr.Arr.length + " to " + NodeName(ElArr.Node))
|
||||
global.ToLog("CheckTxExchange BlockNum:" + Block.BlockNum + " Array=" + ElArr.Arr.length + " to " + global.NodeName(ElArr.Node))
|
||||
var SendData = { "Method": "GETTRANSFERTX", "Context": {}, "Data": { BlockNum: Block.BlockNum, TicketArray: ElArr.Arr, } };
|
||||
this.SendF(ElArr.Node, SendData, ElArr.Arr.length * global.TR_TICKET_HASH_LENGTH + 1000)
|
||||
}
|
||||
@@ -865,7 +869,25 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
CheckPrioritetTx(Tr) {
|
||||
if (Tr.Prioritet === undefined) {
|
||||
var Body = Tr.body;
|
||||
Tr.Prioritet = global.MAX_LENGTH_SENDER_MAP
|
||||
var App = global.DAppByType[Body[0]];
|
||||
if (App) {
|
||||
Tr.SenderNum = App.GetSenderNum(Tr.num, Body)
|
||||
if (Tr.SenderNum && Tr.SenderNum > 0) {
|
||||
Tr.Prioritet = this.GetSenderPrioritet(Tr.num, Tr.SenderNum)
|
||||
Tr.TimePow = Tr.Prioritet + Tr.power
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GetSenderPrioritet(BlockNum, SenderNum) {
|
||||
//defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
AddToQuote(Tree, Tr) {
|
||||
this.CheckPrioritetTx(Tr)
|
||||
var Tr0 = Tree.find(Tr);
|
||||
if (Tr0) {
|
||||
return 3;
|
||||
@@ -881,6 +903,15 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
IsValidTicket(Tr, BlockNum): any {
|
||||
// defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
IsValidTransaction(Tr, BlockNum): any {
|
||||
// defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
AddDAppTransactions(BlockNum, Arr) {
|
||||
// defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
AddTicketToBlockQuote(Block, Tr) {
|
||||
if (Block.PowTicketTree) {
|
||||
var Res = this.IsValidTicket(Tr, Block.BlockNum);
|
||||
@@ -1267,14 +1298,14 @@ module.exports = class CConsensus extends require("./block-loader")
|
||||
}
|
||||
}
|
||||
var MaxNumBlockDB = this.GetMaxNumBlockDB();
|
||||
if (CURRENTBLOCKNUM + global.BLOCK_PROCESSING_LENGTH2 > MaxNumBlockDB)
|
||||
if (CURRENTBLOCKNUM + global.BLOCK_PROCESSING_LENGTH2 > MaxNumBlockDB && CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2 < MaxNumBlockDB)
|
||||
for (var BlockNum = CURRENTBLOCKNUM - global.BLOCK_PROCESSING_LENGTH2; BlockNum > global.BLOCK_PROCESSING_LENGTH2 && BlockNum < start_save; BlockNum++) {
|
||||
var Block = this.GetBlock(BlockNum);
|
||||
if (Block && !Block.bSave && Block.TrCount && Block.TreeHash && !global.IsZeroArr(Block.TreeHash) && !Block.WasSaveDataTree) {
|
||||
this.PreSaveDataTreeToDB(Block)
|
||||
Block.WasSaveDataTree = 1
|
||||
global.AddInfoBlock(Block, "*PRESAVE DATA TREE*")
|
||||
global.ToLog("PRESAVE DATA: " + Block.BlockNum)
|
||||
global.ToLog("PRESAVE DATA: " + Block.BlockNum, 2)
|
||||
}
|
||||
}
|
||||
this.RelayMode = !bWasSave
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
//const fs = require("fs");
|
||||
import * as fs from 'fs'
|
||||
import CRest from './rest-loader'
|
||||
//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")
|
||||
{
|
||||
export default class CBlock extends CRest {
|
||||
MapMapLoaded
|
||||
BlockChain
|
||||
ChainID
|
||||
@@ -32,6 +32,7 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
LoadHistoryContext
|
||||
LoadBlockStatNum
|
||||
BADHashCount
|
||||
ActualNodes
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.MapMapLoaded = {}
|
||||
@@ -594,7 +595,7 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
}
|
||||
if (chain.LoadCountDB >= global.COUNT_BLOCKS_FOR_CHECK_POW) {
|
||||
if (chain.LoadSumDB - chain.LoadSum > global.MAX_DELTA_COUNT_SUM_FOR_LOAD) {
|
||||
var Str = "ERR LOADED SUM POW chains: SumDB > Sum loaded from: " + NodeInfo(Info.Node);
|
||||
var Str = "ERR LOADED SUM POW chains: SumDB > Sum loaded from: " + global.NodeInfo(Info.Node);
|
||||
chain.StopSend = true
|
||||
chain.AddInfo(Str)
|
||||
}
|
||||
@@ -764,7 +765,7 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
return;
|
||||
}
|
||||
}
|
||||
var Res = 0;
|
||||
var Res: any = 0;
|
||||
if (Block.TreeEq) {
|
||||
this.ReadBlockBodyDB(Block)
|
||||
Res = this.WriteBlockDBFinaly(Block)
|
||||
@@ -804,6 +805,9 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
this.FREE_ALL_MEM_CHAINS()
|
||||
global.ADD_TO_STAT_TIME("WRITECHAIN_TO_DB_TIME", startTime)
|
||||
}
|
||||
SetNoPOW(BlockNumFrom, bReload, RefBlockNum) {
|
||||
//defiend in block-exchange.js
|
||||
}
|
||||
CopyBlock(Block, BlockDst) {
|
||||
BlockDst.BlockNum = Block.BlockNum
|
||||
BlockDst.TreeHash = Block.TreeHash
|
||||
@@ -830,6 +834,9 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
}
|
||||
this.AddToStatBlockConfirmation(Block)
|
||||
}
|
||||
RecreateMaxPOW(Block) {
|
||||
//defiend in block-exchange.js
|
||||
}
|
||||
ClearMaxInBlock(Block) {
|
||||
Block.MaxPOW = {}
|
||||
var POW = Block.MaxPOW;
|
||||
@@ -947,7 +954,7 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
FreeGet -= Node.CanGetBlocks
|
||||
Node.SendBlockCount = 0
|
||||
Node.LoadBlockCount = 0
|
||||
global.ADD_TO_STAT("NODE_CAN_GET:" + NodeName(Node), Node.CanGetBlocks, 1)
|
||||
global.ADD_TO_STAT("NODE_CAN_GET:" + global.NodeName(Node), Node.CanGetBlocks, 1)
|
||||
}
|
||||
}
|
||||
static
|
||||
@@ -974,7 +981,7 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
var arrContent = Data.arrContent;
|
||||
var TreeHash = global.CalcTreeHashFromArrBody(Block.BlockNum, arrContent);
|
||||
if (global.CompareArr(Block.TreeHash, TreeHash) !== 0) {
|
||||
global.ToLog("2. BAD CMP TreeHash block=" + Block.BlockNum + " from:" + NodeName(Info.Node) + " TreeHash=" + global.GetHexFromArr(TreeHash) + " BlockTreeHash=" + global.GetHexFromArr(Block.TreeHash))
|
||||
global.ToLog("2. BAD CMP TreeHash block=" + Block.BlockNum + " from:" + global.NodeName(Info.Node) + " TreeHash=" + global.GetHexFromArr(TreeHash) + " BlockTreeHash=" + global.GetHexFromArr(Block.TreeHash))
|
||||
this.SetBlockNOSendToNode(Block, Info.Node, "BAD CMP TreeHash")
|
||||
return;
|
||||
}
|
||||
@@ -982,10 +989,11 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
var TR = arrContent[0];
|
||||
if (TR[0] === global.TYPE_TRANSACTION_ACC_HASH) {
|
||||
if (!global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum)) {
|
||||
global.ToLog(`global.DApps.Accounts.TRCheckAccountHash(TR, Data.BlockNum) ${JSON.stringify(TR)}, ${Data.BlockNum}`)
|
||||
if (!this.BADHashCount)
|
||||
this.BADHashCount = 0
|
||||
this.BADHashCount++
|
||||
global.ToLog("**** BAD ACCOUNT Hash in block=" + Block.BlockNum + " from:" + NodeName(Info.Node) + " ****")
|
||||
global.ToLog("**** BAD ACCOUNT Hash in block=" + Block.BlockNum + " from:" + global.NodeName(Info.Node) + " ****")
|
||||
global.ToLog("May be need to Rewrite transactions from: " + (Block.BlockNum - 2 * global.DELTA_BLOCK_ACCOUNT_HASH))
|
||||
this.SetBlockNOSendToNode(Block, Info.Node, "BAD CMP ACC HASH")
|
||||
if (global.WATCHDOG_BADACCOUNT && this.BADHashCount > 60) {
|
||||
@@ -1046,6 +1054,9 @@ module.exports = class CBlock extends require("./rest-loader")
|
||||
Info.Node.LoadBlockCount++
|
||||
}
|
||||
}
|
||||
DataFromF(Info, bSendFormat?): any {
|
||||
//defiend in server.js
|
||||
}
|
||||
SetBlockNOSendToNode(Block, Node, Str) {
|
||||
var Str = global.GetHexFromArr(Block.TreeHash);
|
||||
var Str2 = this.GetStrFromHashShort(Block.TreeHash);
|
||||
@@ -1276,11 +1287,11 @@ global.LoadBlockFromNetwork = function(Params, F) {
|
||||
var Block = global.BufLib.GetObjectFromBuffer(Info.Data, global.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
||||
Info.Data = undefined;
|
||||
if (!Block.BlockNum || Block.BlockNum !== Params.BlockNum) {
|
||||
global.ToLog("Error get BlockNum:" + Params.BlockNum + " from " + NodeName(Info.Node), 2);
|
||||
global.ToLog("Error get BlockNum:" + Params.BlockNum + " from " + global.NodeName(Info.Node), 2);
|
||||
F(1);
|
||||
return;
|
||||
}
|
||||
global.ToLog("Got BlockFromNetwork:" + Params.BlockNum + " from " + NodeName(Info.Node), 2);
|
||||
global.ToLog("Got BlockFromNetwork:" + Params.BlockNum + " from " + global.NodeName(Info.Node), 2);
|
||||
var ResError;
|
||||
if (!Block.arrContent || Block.arrContent.length === 0) {
|
||||
ResError = 1;
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
import CCommon from './base'
|
||||
// const FORMAT_EVAL_SEND = "{MaxBlockNum:uint,Code:str,Sign:arr64}";
|
||||
module.exports = class CCode extends require("./base")
|
||||
{
|
||||
export default class CCode extends CCommon {
|
||||
LastEvalCodeNum
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
|
||||
"use strict";
|
||||
// import * as crypto from 'crypto';
|
||||
const CNode = require("./node");
|
||||
import CNode from './node'
|
||||
import CMessages from './transfer-msg'
|
||||
global.PERIOD_FOR_RECONNECT = 3600 * 1000;
|
||||
global.CHECK_DELTA_TIME = { Num: 0, bUse: 0, StartBlockNum: 0, EndBlockNum: 0, bAddTime: 0, DeltaTime: 0, Sign: [] };
|
||||
global.CHECK_POINT = { BlockNum: 0, Hash: [], Sign: [] };
|
||||
@@ -30,8 +31,9 @@ global.MAX_PING_FOR_CONNECT = 400;
|
||||
var MAX_TIME_CORRECT = 3 * 3600 * 1000;
|
||||
global.MAX_WAIT_PERIOD_FOR_HOT = 4 * global.CONSENSUS_PERIOD_TIME;
|
||||
const PERIOD_FOR_START_CHECK_TIME = 300;
|
||||
module.exports = class CConnect extends require("./transfer-msg")
|
||||
{
|
||||
export default class CConnect extends CMessages {
|
||||
ip
|
||||
port
|
||||
StartTime
|
||||
WasNodesSort
|
||||
LevelNodes
|
||||
@@ -50,6 +52,9 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
StopDetectGrayMode
|
||||
LastNotZeroNodesTime
|
||||
TransferTree
|
||||
СтатБлок
|
||||
BusyLevel
|
||||
SendTrafficFree
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.StartTime = Date.now()
|
||||
@@ -103,7 +108,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
StartConnectTry(Node) {
|
||||
var Delta = Date.now() - Node.StartTimeConnect;
|
||||
if (Delta >= Node.NextConnectDelta && this.IsCanConnect(Node)) {
|
||||
if (!GetSocketStatus(Node.Socket)) {
|
||||
if (!global.GetSocketStatus(Node.Socket)) {
|
||||
Node.StartTimeConnect = Date.now()
|
||||
if (Delta < 60 * 1000)
|
||||
Node.NextConnectDelta = Node.NextConnectDelta * 2
|
||||
@@ -312,7 +317,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
this.CheckCodeVersion(Data, Info.Node)
|
||||
if (!global.CAN_START) {
|
||||
if (DeltaTime > global.MAX_PING_FOR_CONNECT)
|
||||
global.ToLog("DeltaTime=" + DeltaTime + ">" + global.MAX_PING_FOR_CONNECT + " ms - " + NodeInfo(Node), 2)
|
||||
global.ToLog("DeltaTime=" + DeltaTime + ">" + global.MAX_PING_FOR_CONNECT + " ms - " + global.NodeInfo(Node), 2)
|
||||
}
|
||||
var Times;
|
||||
if (DeltaTime <= global.MAX_PING_FOR_CONNECT) {
|
||||
@@ -367,7 +372,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign CheckPoint=" + Data.CheckPoint.BlockNum + " from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign CheckPoint=" + Data.CheckPoint.BlockNum + " from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign CheckPoint")
|
||||
}
|
||||
}
|
||||
@@ -382,7 +387,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign CheckDeltaTime Num=" + Data.CheckDeltaTime.Num + " from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign CheckDeltaTime Num=" + Data.CheckDeltaTime.Num + " from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign CheckDeltaTime")
|
||||
}
|
||||
}
|
||||
@@ -409,7 +414,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign CheckNetConstant Num=" + Data.NetConstant.Num + " from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign CheckNetConstant Num=" + Data.NetConstant.Num + " from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign CheckNetConstant")
|
||||
}
|
||||
}
|
||||
@@ -462,7 +467,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
}
|
||||
else {
|
||||
global.ToLog("Error Sign CodeVersion=" + CodeVersion.VersionNum + " from " + 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))
|
||||
global.ToLog(JSON.stringify(CodeVersion))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign CodeVersion")
|
||||
@@ -592,6 +597,9 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
NodeInBan(Node) {
|
||||
//defiend in
|
||||
}
|
||||
GetDirectNodesArray(bAll, bWebPort?, bGetAddrArr?) {
|
||||
var ret = [];
|
||||
var Value: any = {
|
||||
@@ -802,6 +810,9 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
Info.Node.LevelCount = Data.Count
|
||||
}
|
||||
AddCheckErrCount(Node, Count, StrErr?) {
|
||||
//defiend in server.ts
|
||||
}
|
||||
DeleteBadConnectingByTimer() {
|
||||
if (global.glStopNode)
|
||||
return;
|
||||
@@ -809,7 +820,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
var arr = global.SERVER.NodesArr;
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var Node = arr[i];
|
||||
var Status = GetSocketStatus(Node.Socket);
|
||||
var Status = global.GetSocketStatus(Node.Socket);
|
||||
if (Node.Active && Status < 100) {
|
||||
var Delta = CurTime - Node.LastTime;
|
||||
if (Delta > global.MAX_WAIT_PERIOD_FOR_STATUS) {
|
||||
@@ -882,7 +893,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
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))
|
||||
global.ToLog("Send time: " + Time + " to " + global.NodeInfo(Node))
|
||||
this.SendF(Node, { "Method": "TIME", "Data": { Time: Time, Sign: this.SignCurrentTimeDev } })
|
||||
return 1;
|
||||
}
|
||||
@@ -907,7 +918,7 @@ module.exports = class CConnect extends require("./transfer-msg")
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign TIME from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign TIME from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign TIME")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
*/
|
||||
|
||||
global.UPDATE_CODE_VERSION_NUM = 1127;
|
||||
global.MIN_CODE_VERSION_NUM = 1094;
|
||||
global.MIN_CODE_VERSION_NUM = 1114;
|
||||
global.MINING_VERSION_NUM = 0;
|
||||
global.InitParamsArg = InitParamsArg;
|
||||
global.CONST_NAME_ARR = [
|
||||
|
||||
@@ -10,9 +10,10 @@
|
||||
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
const DBLib = require("./db");
|
||||
const DBRow = require("./db-row");
|
||||
global.BlockDB = new DBLib();
|
||||
import Db from './db'
|
||||
import DBRow from './db-row'
|
||||
import CCode from '../code'
|
||||
global.BlockDB = new Db();
|
||||
global.BLOCK_HEADER_SIZE = 150;
|
||||
const FILE_NAME_HEADER = "block-header";
|
||||
const FILE_NAME_BODY = "block-body";
|
||||
@@ -33,8 +34,7 @@ const FORMAT_HEADER_VERSION2 = "{FilePos:uint}";
|
||||
const FILE_NAME_HEADER2 = "block-header2";
|
||||
const WorkStructHeader2 = {};
|
||||
const DEFAULT_DB_VERSION = 2;
|
||||
module.exports = class CDB extends require("../code")
|
||||
{
|
||||
export default class CDB extends CCode {
|
||||
DBHeader100
|
||||
BlockNumDB
|
||||
BlockNumDBMin
|
||||
@@ -70,6 +70,9 @@ module.exports = class CDB extends require("../code")
|
||||
this.BlockNumDBMin = StateTX.BlockNumMin
|
||||
}
|
||||
}
|
||||
GetBlock(num, bToMem, bReadBody): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
LoadMemBlocksOnStart() {
|
||||
this.CurrentBlockNum = global.GetCurrentBlockNumByTime()
|
||||
for (var i = this.BlockNumDB - global.BLOCK_COUNT_IN_MEMORY; i <= this.BlockNumDB; i++)
|
||||
@@ -223,6 +226,9 @@ module.exports = class CDB extends require("../code")
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
OnWriteBlock(Block) {
|
||||
//defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
PreSaveDataTreeToDB(Block) {
|
||||
var Ret = this.WriteBodyDB(Block);
|
||||
if (Ret) {
|
||||
@@ -290,6 +296,9 @@ module.exports = class CDB extends require("../code")
|
||||
Block.TrDataLen = TrDataLen
|
||||
return true;
|
||||
}
|
||||
CheckSeqHashDB(Block, StrError): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
WriteBlockHeaderDB(Block, bPreSave?) {
|
||||
if (!bPreSave && Block.BlockNum > this.BlockNumDBMin + global.BLOCK_PROCESSING_LENGTH2) {
|
||||
if (global.USE_CHECK_SAVE_DB)
|
||||
@@ -570,6 +579,12 @@ module.exports = class CDB extends require("../code")
|
||||
this.CreateGenesisBlocks()
|
||||
this.StartSyncBlockchain()
|
||||
}
|
||||
CreateGenesisBlocks() {
|
||||
// defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
StartSyncBlockchain(Node?, bSilent?, bCheckPoint?) {
|
||||
// defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
ClearBufMap() {
|
||||
this.MapHeader = {}
|
||||
}
|
||||
@@ -888,7 +903,7 @@ module.exports = class CDB extends require("../code")
|
||||
var SeqHash = global.CalcHashFromArray(arr, true);
|
||||
return SeqHash;
|
||||
}
|
||||
CheckCreateTicketObject(Tr, BlockNum, SetTxID) {
|
||||
CheckCreateTicketObject(Tr, BlockNum?, SetTxID?) {
|
||||
if (!Tr.HashPow && Tr.HashTicket) {
|
||||
Tr.num = BlockNum
|
||||
var FullHashTicket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
||||
@@ -902,7 +917,7 @@ module.exports = class CDB extends require("../code")
|
||||
Tr.TxID = global.GetHexFromArr(FullHashTicket.slice(0, global.TR_TICKET_HASH_LENGTH + 6))
|
||||
}
|
||||
}
|
||||
CheckCreateTransactionObject(Tr, SetTxID, NotPrioritet?) {
|
||||
CheckCreateTransactionObject(Tr, SetTxID?, NotPrioritet?) {
|
||||
if (!Tr.HashPow) {
|
||||
var Body = Tr.body;
|
||||
Tr.IsTx = 1
|
||||
@@ -913,17 +928,6 @@ module.exports = class CDB extends require("../code")
|
||||
Tr.HASH = global.shaarr(Body)
|
||||
Tr.HashTicket = Tr.HASH.slice(0, global.TR_TICKET_HASH_LENGTH)
|
||||
this.CheckCreateTicketObject(Tr, Tr.num, SetTxID)
|
||||
Tr.Prioritet = global.MAX_LENGTH_SENDER_MAP
|
||||
if (!NotPrioritet && this.GetSenderPrioritet) {
|
||||
var App = global.DAppByType[Body[0]];
|
||||
if (App) {
|
||||
Tr.SenderNum = App.GetSenderNum(Tr.num, Body)
|
||||
if (Tr.SenderNum && Tr.SenderNum > 0) {
|
||||
Tr.Prioritet = this.GetSenderPrioritet(Tr.num, Tr.SenderNum)
|
||||
Tr.TimePow = Tr.Prioritet + Tr.power
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockChainToBuf(WriteNum, StartNum, EndBlockNum) {
|
||||
@@ -1033,3 +1037,19 @@ global.GetNodeStrPort = function(Node) {
|
||||
return "" + arr[2] + "." + arr[3];
|
||||
}
|
||||
};
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
//#region block-db.ts
|
||||
BlockDB: any;
|
||||
BLOCK_HEADER_SIZE: number;
|
||||
BLOCK_HEADER_SIZE2: number;
|
||||
DB_VERSION: number;
|
||||
AddInfoChain: Function;
|
||||
AddInfoBlock: Function;
|
||||
GetNodeStrPort: Function;
|
||||
NO_CHECK_BLOCKNUM_ONSTART: number;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,18 @@
|
||||
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
import Db from './db'
|
||||
|
||||
module.exports = class CDBState extends require("./db")
|
||||
{
|
||||
private FileName;
|
||||
private DataSize;
|
||||
private Format;
|
||||
private WorkStruct;
|
||||
// private FileNameFull;
|
||||
// private LastHash;
|
||||
// private WasUpdate;
|
||||
private BufMap;
|
||||
private BufMapCount;
|
||||
class DBRow extends Db {
|
||||
FileName;
|
||||
DataSize;
|
||||
Format;
|
||||
WorkStruct;
|
||||
FileNameFull;
|
||||
LastHash;
|
||||
WasUpdate;
|
||||
BufMap;
|
||||
BufMapCount;
|
||||
|
||||
constructor(FileName, DataSize, Format, bReadOnly) {
|
||||
super()
|
||||
@@ -29,10 +29,10 @@ module.exports = class CDBState extends require("./db")
|
||||
this.DataSize = DataSize
|
||||
this.Format = Format
|
||||
this.WorkStruct = {}
|
||||
// var FI = this.OpenDBFile(this.FileName, !bReadOnly);
|
||||
// this.FileNameFull = FI.fname
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
var FI = this.OpenDBFile(this.FileName, !bReadOnly);
|
||||
this.FileNameFull = FI.fname
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
this.BufMap = {}
|
||||
this.BufMapCount = 0
|
||||
setInterval(this.CheckBufMap.bind(this), 1000)
|
||||
@@ -48,8 +48,8 @@ module.exports = class CDBState extends require("./db")
|
||||
}
|
||||
Write(Data, RetBuf) {
|
||||
var startTime = process.hrtime();
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
this.CheckNewNum(Data)
|
||||
Data.Num = Math.trunc(Data.Num)
|
||||
this.DeleteMap(Data.Num)
|
||||
@@ -118,8 +118,8 @@ module.exports = class CDBState extends require("./db")
|
||||
Position = 0
|
||||
var FI = this.OpenDBFile(this.FileName, 1);
|
||||
if (Position < FI.size) {
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
if (LastNum < 0)
|
||||
global.ToLog("Truncate " + this.FileName + " from 0", 2)
|
||||
FI.size = Position
|
||||
@@ -227,3 +227,5 @@ module.exports = class CDBState extends require("./db")
|
||||
this.CloseDBFile(this.FileName)
|
||||
}
|
||||
};
|
||||
|
||||
export default DBRow
|
||||
@@ -11,11 +11,11 @@
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
|
||||
module.exports = class {
|
||||
private DBMap;
|
||||
// private LastHash;
|
||||
// private WasUpdate;
|
||||
private WasCheckPathDB;
|
||||
class Db {
|
||||
DBMap;
|
||||
LastHash;
|
||||
WasUpdate;
|
||||
WasCheckPathDB;
|
||||
|
||||
constructor() {
|
||||
this.DBMap = {}
|
||||
@@ -24,9 +24,9 @@ module.exports = class {
|
||||
var Path = global.GetDataPath("DB");
|
||||
global.CheckCreateDir(Path)
|
||||
}
|
||||
CloseDBFile(name, bdelete) {
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
CloseDBFile(name, bdelete?) {
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
var Item = this.DBMap[name];
|
||||
if (Item) {
|
||||
let bDelete = bdelete;
|
||||
@@ -40,23 +40,23 @@ module.exports = class {
|
||||
global.ToLog(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
global.ToLog(err)
|
||||
}
|
||||
})
|
||||
delete this.DBMap[name]
|
||||
}
|
||||
}
|
||||
OpenDBFile(name, bWrite, bExist) {
|
||||
OpenDBFile(name, bWrite?, bExist?) {
|
||||
if (bWrite && global.READ_ONLY_DB) {
|
||||
global.ToLogTrace("CANNOT WRITE - DB IN READ_ONLY MODE!!!")
|
||||
process.exit()
|
||||
}
|
||||
if (bWrite)
|
||||
if (bWrite) {
|
||||
CheckStartOneProcess(name + "-run")
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
}
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
var Item = this.DBMap[name];
|
||||
if (Item === undefined) {
|
||||
if (!this.WasCheckPathDB) {
|
||||
@@ -82,7 +82,7 @@ module.exports = class {
|
||||
}
|
||||
};
|
||||
var MapCheckProcess = {};
|
||||
var BlockDB = new module.exports();
|
||||
var BlockDB = new Db();
|
||||
|
||||
function CheckStartOneProcess(Name) {
|
||||
if (global.UpdateMode)
|
||||
@@ -96,11 +96,21 @@ function CheckStartOneProcess(Name) {
|
||||
}
|
||||
try {
|
||||
BlockDB.OpenDBFile(Name);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
global.ToLog("****** DETECT START ANOTHER PROCESS for: " + Name);
|
||||
global.ToLogTrace("EXIT");
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
global.CheckStartOneProcess = CheckStartOneProcess;
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
//#region dapp.ts
|
||||
CheckStartOneProcess: Function;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Db;
|
||||
@@ -64,7 +64,7 @@ function Init() {
|
||||
if (a) {
|
||||
0;
|
||||
var u = r[10];
|
||||
u || (u = r[7]), u || (u = r[5]), MapNames[a] = u;
|
||||
u = (u = u || r[7]) || r[5], MapNames[a] = u;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ HTTPCaller.DappStaticCall = function(Params, response) {
|
||||
glBlock0 = global.SERVER.ReadBlockHeaderDB(0);
|
||||
var RetValue;
|
||||
try {
|
||||
RetValue = RunSmartMethod(glBlock0, Account.Value.Smart, Account, 0, 0, undefined, Params.MethodName, Params.Params, 1);
|
||||
RetValue = global.RunSmartMethod(glBlock0, Account.Value.Smart, Account, 0, 0, undefined, Params.MethodName, Params.Params, 1);
|
||||
}
|
||||
catch (e) {
|
||||
return { result: 0, RetValue: "" + e };
|
||||
@@ -651,7 +651,7 @@ HTTPCaller.SendECode = function(Param) {
|
||||
}
|
||||
return { result: 1, text: "Sent to " + arr.length + " nodes" };
|
||||
}
|
||||
var Node = FindNodeByAddr(Param.Addr, 1);
|
||||
var Node = global.FindNodeByAddr(Param.Addr, 1);
|
||||
if (Node === undefined)
|
||||
return { result: 0, text: "Node not found" };
|
||||
if (Node === false)
|
||||
@@ -1574,19 +1574,19 @@ if (global.ELECTRON) {
|
||||
});
|
||||
}
|
||||
exports.SendData = OnGetData;
|
||||
|
||||
// function RunConsole(StrRun) {
|
||||
// var Str = fs.readFileSync("./EXPERIMENTAL/!run-console.js", { encoding: "utf8" });
|
||||
// if (StrRun)
|
||||
// Str += "\n" + StrRun;
|
||||
// try {
|
||||
// var ret = eval(Str);
|
||||
// }
|
||||
// catch (e) {
|
||||
// ret = e.message + "\n" + e.stack;
|
||||
// }
|
||||
// return ret;
|
||||
// };
|
||||
//@ts-ignore
|
||||
function RunConsole(StrRun) {
|
||||
var Str = fs.readFileSync("./EXPERIMENTAL/_run-console.js", { encoding: "utf8" });
|
||||
if (StrRun)
|
||||
Str += "\n" + StrRun;
|
||||
try {
|
||||
var ret = eval(Str);
|
||||
}
|
||||
catch (e) {
|
||||
ret = e.message + "\n" + e.stack;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
var WebWalletUser = {};
|
||||
|
||||
function GetUserContext(Params) {
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
*/
|
||||
import * as fs from 'fs'
|
||||
import * as os from 'os'
|
||||
import { RBTree } from 'bintrees'
|
||||
import * as secp256k1 from 'secp256k1';
|
||||
import * as ntpClient from 'ntp-client'
|
||||
import * as stun from 'stun'
|
||||
import * as zip from 'zip'
|
||||
|
||||
import './constant'
|
||||
import './log'
|
||||
@@ -27,14 +32,20 @@ String.prototype.right = function(count) {
|
||||
else
|
||||
return this.substr(0, this.length);
|
||||
};
|
||||
global.RBTree = require('bintrees').RBTree;
|
||||
global.ntpClient = require('ntp-client');
|
||||
global.Stun = require('stun');
|
||||
global.ZIP = require("zip");
|
||||
// var strOS = os.platform() + "_" + os.arch();
|
||||
if (!global.secp256k1) {
|
||||
global.secp256k1 = require('secp256k1');
|
||||
global.RBTree = RBTree;
|
||||
global.ntpClient = ntpClient;
|
||||
global.Stun = stun;
|
||||
global.ZIP = zip;
|
||||
global.secp256k1 = secp256k1;
|
||||
|
||||
export {
|
||||
RBTree,
|
||||
ntpClient,
|
||||
stun,
|
||||
zip,
|
||||
secp256k1
|
||||
}
|
||||
|
||||
require('../HTML/JS/terahashlib.js');
|
||||
require("./crypto-library");
|
||||
if (global.USE_PARAM_JS) {
|
||||
|
||||
@@ -33,7 +33,7 @@ function ToLogFile(e, t, r?) {
|
||||
|
||||
function ToLogClient(e, t, r) {
|
||||
let ArrLogClient = global.ArrLogClient;
|
||||
e && (ToLogFile(file_name_log, e), t || (t = ""), ArrLogClient.push({ text: global.GetStrOnlyTime() + " " + e, key: t, final: r }), 13 < ArrLogClient.length && ArrLogClient.shift());
|
||||
e && (ToLogFile(file_name_log, e), t = t || "", ArrLogClient.push({ text: global.GetStrOnlyTime() + " " + e, key: t, final: r }), 13 < ArrLogClient.length && ArrLogClient.shift());
|
||||
};
|
||||
global.CheckSizeLogFile(file_name_error, file_name_errorPrev), global.ToLog = function(e, t) {
|
||||
void 0 === t && (t = 1), t && t > global.LOG_LEVEL || (global.ALL_LOG_TO_CLIENT ? ToLogClient(e, void 0, void 0) : ToLogFile(file_name_log,
|
||||
@@ -103,7 +103,7 @@ function CalcInterval(e, t, r) {
|
||||
function AddToStatContext(e, t, r?) {
|
||||
void 0 === r && (r = 1);
|
||||
var o = e.Total[t];
|
||||
o || (o = 0), "MAX:" === t.substr(0, 4) ? o = Math.max(o, r) : o += r, e.Total[t] = o, StartStatTime || (StartStatTime = global.GetStrOnlyTime(0));
|
||||
o = o || 0, "MAX:" === t.substr(0, 4) ? o = Math.max(o, r) : o += r, e.Total[t] = o, StartStatTime = StartStatTime || global.GetCurrentTime(0);
|
||||
};
|
||||
|
||||
function CopyStatInterval(e, t) {
|
||||
@@ -153,7 +153,7 @@ global.HASH_RATE = 0, global.ADD_HASH_RATE = function(e) {
|
||||
}
|
||||
global.GET_STAT = function(e) {
|
||||
var t = CONTEXT_STATS.Total[e];
|
||||
return t || (t = 0), t;
|
||||
return t = t || 0;
|
||||
}
|
||||
global.ADD_TO_STAT_TIME = function(e, t, r) {
|
||||
if (global.STAT_MODE) {
|
||||
@@ -230,13 +230,13 @@ global.GetStrOnlyTime = function(e) {
|
||||
if (!global.GetCurrentTime)
|
||||
return ":::";
|
||||
e || (e = global.GetCurrentTime());
|
||||
var t = "" + e.getHours().toStringZ(2);
|
||||
var t = "" + (e = e || global.GetCurrentTime()).getHours().toStringZ(2);
|
||||
return t = (t = (t = t + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
|
||||
}
|
||||
global.GetStrTime = function(e) {
|
||||
if (!global.GetCurrentTime)
|
||||
return ":::";
|
||||
e || (e = global.GetCurrentTime());
|
||||
var t = "" + e.getDate().toStringZ(2);
|
||||
var t = "" + (e = e || global.GetCurrentTime()).getDate().toStringZ(2);
|
||||
return t = (t = (t = (t = (t = (t = t + "." + (1 + e.getMonth()).toStringZ(2)) + "." + e.getFullYear()) + " " + e.getHours().toStringZ(2)) + ":" + e.getMinutes().toStringZ(2)) + ":" + e.getSeconds().toStringZ(2)) + "." + e.getMilliseconds().toStringZ(3);
|
||||
};
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
require("./library");
|
||||
const net = require("net");
|
||||
import "./library"
|
||||
import net = require("net");
|
||||
var ConnectIDCount = 1;
|
||||
module.exports = class CNode {
|
||||
export default class CNode {
|
||||
addrStr
|
||||
ip
|
||||
port
|
||||
|
||||
@@ -9,13 +9,14 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
module.exports = class CRest extends require("./db/block-db")
|
||||
{
|
||||
import CDB from './db/block-db'
|
||||
export default class CRest extends CDB {
|
||||
LoadRestContext
|
||||
BlockNumDB
|
||||
BlockNumDBMin
|
||||
UseTruncateBlockDB
|
||||
ContextSendLoadToBegin
|
||||
LoadHistoryContext
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
}
|
||||
@@ -47,6 +48,15 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
this.LoadRestContext = undefined
|
||||
}
|
||||
}
|
||||
GetNextNode(task, keyid, checktime?, BlockNum?): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
DataFromF(Info, bSendFormat?): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
AddToBan(Node, Str) {
|
||||
//defiend in server.ts(CTransport)
|
||||
}
|
||||
LoopSyncRest() {
|
||||
let Context = this.LoadRestContext;
|
||||
switch (Context.Mode) {
|
||||
@@ -58,7 +68,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
continue;
|
||||
}
|
||||
Node.SendRestGetHeader = 1
|
||||
global.ToLog("Send rest get headers from " + Context.BlockNumProof + " to " + NodeName(Node), 2)
|
||||
global.ToLog("Send rest get headers from " + Context.BlockNumProof + " to " + global.NodeName(Node), 2)
|
||||
this.SendF(Node, {
|
||||
"Method": "GETBLOCKHEADER", "Data": { Foward: 1, BlockNum: Context.BlockNumProof, Hash: [] }, "Context": { F: this.RETBLOCKHEADER_REST.bind(this) },
|
||||
})
|
||||
@@ -96,7 +106,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
var Item = Context.ArrProof[i];
|
||||
if (Item.SumPower !== MaxPow) {
|
||||
var Str = "BAD SumPower: " + Item.SumPower + "/" + MaxPow;
|
||||
global.ToLog(Str + " from: " + NodeName(Item.Node), 2)
|
||||
global.ToLog(Str + " from: " + global.NodeName(Item.Node), 2)
|
||||
}
|
||||
else
|
||||
if (Item.SumPower && Item.arr.length >= Context.CountProof) {
|
||||
@@ -116,6 +126,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
this.BlockNumDBMin = Block.BlockNum
|
||||
this.WriteBlockHeaderDB(Block)
|
||||
this.UseTruncateBlockDB = undefined
|
||||
global.ToLog("Start run TXPrepareLoadRest", 2)
|
||||
global.TX_PROCESS.RunRPC("TXPrepareLoadRest", Block.BlockNum, function(Err, Params) {
|
||||
Context.Mode++
|
||||
global.ToLog("Next mode: " + Context.Mode, 2)
|
||||
@@ -132,7 +143,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
let Item = Context.ArrProof[i];
|
||||
if (Item.OK) {
|
||||
SendCount++
|
||||
global.ToLog("Send rest get block proof:" + BlockProof.BlockNum + " to " + NodeName(Item.Node), 2)
|
||||
global.ToLog("Send rest get block proof:" + BlockProof.BlockNum + " to " + global.NodeName(Item.Node), 2)
|
||||
this.SendF(Item.Node, {
|
||||
"Method": "GETBLOCK", "Data": { BlockNum: BlockProof.BlockNum, TreeHash: BlockProof.TreeHash }, "Context": {
|
||||
F: function(Info) {
|
||||
@@ -141,15 +152,15 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
var Data = global.BufLib.GetObjectFromBuffer(Info.Data, global.FORMAT_BLOCK_TRANSFER, global.WRK_BLOCK_TRANSFER);
|
||||
Info.Data = undefined
|
||||
if (Data.BlockNum !== BlockProof.BlockNum || global.CompareArr(Data.TreeHash, BlockProof.TreeHash) !== 0) {
|
||||
global.ToLog("Error get proof block from " + NodeName(Item.Node), 2)
|
||||
global.ToLog("Error get proof block from " + global.NodeName(Item.Node), 2)
|
||||
return;
|
||||
}
|
||||
var TreeHash = global.CalcTreeHashFromArrBody(Data.BlockNum, Data.arrContent);
|
||||
if (global.CompareArr(BlockProof.TreeHash, TreeHash) !== 0) {
|
||||
global.ToLog("Error TreeHash in proof block from " + NodeName(Item.Node), 2)
|
||||
global.ToLog("Error TreeHash in proof block from " + global.NodeName(Item.Node), 2)
|
||||
return;
|
||||
}
|
||||
global.ToLog("GET BLOCK proof from " + NodeName(Item.Node), 2)
|
||||
global.ToLog("GET BLOCK proof from " + global.NodeName(Item.Node), 2)
|
||||
var FindTx = undefined;
|
||||
for (var n = 0; n < Data.arrContent.length; n++) {
|
||||
var Body = Data.arrContent[n];
|
||||
@@ -211,7 +222,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
if (Delta > 5 * 1000 && !Task.OK) {
|
||||
var Ret = this.GetNextNode(Task, "", 1);
|
||||
if (Ret.Result) {
|
||||
global.ToLog("Send GETREST Num:" + Task.StartNum + "-" + Task.Count + " to " + NodeName(Ret.Node), 2)
|
||||
global.ToLog("Send GETREST Num:" + Task.StartNum + "-" + Task.Count + " to " + global.NodeName(Ret.Node), 2)
|
||||
var SELF = this;
|
||||
this.SendF(Ret.Node, {
|
||||
"Method": "GETREST", "Data": { BlockNum: Context.BlockNumRest, AccNum: Task.StartNum, Count: Task.Count, AccHash: Context.TxProof.AccHash },
|
||||
@@ -223,11 +234,11 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
if (!Data.Result)
|
||||
return;
|
||||
if (Data.Version !== 1) {
|
||||
global.ToLog("ERROR Version Result GETREST Num:" + Task.StartNum + " from " + NodeName(Info.Node), 2)
|
||||
global.ToLog("ERROR Version Result GETREST Num:" + Task.StartNum + " from " + global.NodeName(Info.Node), 2)
|
||||
return;
|
||||
}
|
||||
if (global.CompareArrL(Data.ProofHash, Context.TxProof.AccHash) !== 0) {
|
||||
global.ToLog("ERROR PROOF HASH Result GETREST Num:" + Task.StartNum + " Hash: " + global.GetHexFromArr(Data.ProofHash) + "/" + global.GetHexFromArr(Context.TxProof.AccHash) + " from " + NodeName(Info.Node),
|
||||
global.ToLog("ERROR PROOF HASH Result GETREST Num:" + Task.StartNum + " Hash: " + global.GetHexFromArr(Data.ProofHash) + "/" + global.GetHexFromArr(Context.TxProof.AccHash) + " from " + global.NodeName(Info.Node),
|
||||
2)
|
||||
return;
|
||||
}
|
||||
@@ -237,11 +248,11 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
}
|
||||
var GetHash = global.CheckMerkleProof(Data.ProofArrL, ArrM, Data.ProofArrR);
|
||||
if (global.CompareArrL(GetHash, Context.TxProof.AccHash) !== 0) {
|
||||
global.ToLog("ERROR CALC PROOF HASH Result GETREST Num:" + Task.StartNum + " Hash: " + global.GetHexFromArr(GetHash) + "/" + global.GetHexFromArr(Context.TxProof.AccHash) + " from " + NodeName(Info.Node),
|
||||
global.ToLog("ERROR CALC PROOF HASH Result GETREST Num:" + Task.StartNum + " Hash: " + global.GetHexFromArr(GetHash) + "/" + global.GetHexFromArr(Context.TxProof.AccHash) + " from " + global.NodeName(Info.Node),
|
||||
2)
|
||||
return;
|
||||
}
|
||||
global.ToLog("OK Result GETREST Num:" + Task.StartNum + " arr=" + Data.Arr.length + " from " + NodeName(Info.Node), 2)
|
||||
global.ToLog("OK Result GETREST Num:" + Task.StartNum + " arr=" + Data.Arr.length + " from " + global.NodeName(Info.Node), 2)
|
||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC) {
|
||||
global.ToLog("ERROR global.TX_PROCESS")
|
||||
return;
|
||||
@@ -272,7 +283,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
if (Delta > 3 * 1000 && !Task.OK) {
|
||||
var Ret = this.GetNextNode(Task, "", 1);
|
||||
if (Ret.Result) {
|
||||
global.ToLog("Send GETSMART Num:" + Task.StartNum + "-" + Task.Count + " to " + NodeName(Ret.Node), 2)
|
||||
global.ToLog("Send GETSMART Num:" + Task.StartNum + "-" + Task.Count + " to " + global.NodeName(Ret.Node), 2)
|
||||
var SELF = this;
|
||||
this.SendF(Ret.Node, {
|
||||
"Method": "GETSMART", "Data": { BlockNum: Context.BlockNumRest, SmartNum: Task.StartNum, Count: Task.Count },
|
||||
@@ -283,7 +294,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
var Data = SELF.DataFromF(Info);
|
||||
if (!Data.Result)
|
||||
return;
|
||||
global.ToLog("Result GETSMART Num:" + Task.StartNum + " arr=" + Data.Arr.length + " from " + NodeName(Info.Node), 2)
|
||||
global.ToLog("Result GETSMART Num:" + Task.StartNum + " arr=" + Data.Arr.length + " from " + global.NodeName(Info.Node), 2)
|
||||
Task.Node = Info.Node
|
||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
||||
return;
|
||||
@@ -358,6 +369,9 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
global.ToLog("Error state!")
|
||||
break;
|
||||
}
|
||||
}
|
||||
GetBlockArrFromBuffer_Load(BufRead, Info?): any {
|
||||
|
||||
}
|
||||
RETBLOCKHEADER_REST(Info, CurTime) {
|
||||
if (Info.Node.SendRestGetHeader === 2)
|
||||
@@ -366,7 +380,7 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
var Context = this.LoadRestContext;
|
||||
var BufRead = global.BufLib.GetReadBuffer(Info.Data);
|
||||
var arr = this.GetBlockArrFromBuffer_Load(BufRead, Info);
|
||||
global.ToLog("RETBLOCKHEADER_FOWARD SyncRest from " + NodeName(Info.Node) + " arr=" + arr.length, 2)
|
||||
global.ToLog("RETBLOCKHEADER_FOWARD SyncRest from " + global.NodeName(Info.Node) + " arr=" + arr.length, 2)
|
||||
Context.ReceiveHeaderCount++
|
||||
var MinSumPow = 10 * Context.CountProof;
|
||||
var SumPower = 0;
|
||||
@@ -420,13 +434,13 @@ module.exports = class CRest extends require("./db/block-db")
|
||||
var Ret = this.GetNextNode(Context, Context.BlockNum, 1);
|
||||
if (Ret.Result) {
|
||||
var Node = Ret.Node;
|
||||
global.ToLog("LOAD_TO_BEGIN - from: " + BlockDB.BlockNum + " to " + NodeName(Node), 2)
|
||||
global.ToLog("LOAD_TO_BEGIN - from: " + BlockDB.BlockNum + " to " + global.NodeName(Node), 2)
|
||||
Context.Time = CurTime
|
||||
this.SendF(Node, {
|
||||
"Method": "GETBLOCKHEADER", "Data": { Foward: 0, BlockNum: Context.BlockNum, Hash: BlockDB.Hash, IsSum: 0, Count: global.COUNT_HISTORY_BLOCKS_FOR_LOAD },
|
||||
"Context": {
|
||||
F: function(Info) {
|
||||
global.ToLog("GET LOAD_TO_BEGIN from " + NodeName(Info.Node) + " Length=" + Info.Data.length, 2)
|
||||
global.ToLog("GET LOAD_TO_BEGIN from " + global.NodeName(Info.Node) + " Length=" + Info.Data.length, 2)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -14,6 +14,7 @@ import net = require("net");
|
||||
import * as crypto from 'crypto';
|
||||
import "./library"
|
||||
import "./crypto-library"
|
||||
import CConnect from './connect'
|
||||
const HARD_PACKET_PERIOD = 20;
|
||||
global.BUF_TYPE = 1;
|
||||
global.STR_TYPE = 2;
|
||||
@@ -57,12 +58,9 @@ const FORMAT_PACKET_SEND_TCP = "{\
|
||||
Hash:hash,\
|
||||
Data:data,\
|
||||
}";
|
||||
export default class CTransport extends require("./connect")
|
||||
{
|
||||
export default class CTransport extends CConnect {
|
||||
UseRNDHeader
|
||||
BAN_IP
|
||||
ip
|
||||
port
|
||||
CanSend
|
||||
SendFormatMap
|
||||
ActualNodes
|
||||
@@ -233,7 +231,7 @@ export default class CTransport extends require("./connect")
|
||||
this.SendTrafficFree -= Node.SendTrafficLimit
|
||||
}
|
||||
Node.SendTrafficCurrent = 0
|
||||
global.ADD_TO_STAT("MAX:NODE_TRAFFIC_LIMIT:" + NodeName(Node), 1000 / global.STAT_PERIOD * Node.SendTrafficLimit / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_TRAFFIC_LIMIT:" + global.NodeName(Node), 1000 / global.STAT_PERIOD * Node.SendTrafficLimit / 1024, 1)
|
||||
}
|
||||
this.SendTrafficFree += TRAFIC_LIMIT_NODE
|
||||
global.ADD_TO_STAT("SEND_TRAFFIC_FREE", this.SendTrafficFree / 1024)
|
||||
@@ -243,7 +241,7 @@ export default class CTransport extends require("./connect")
|
||||
var Str = "";
|
||||
if (Info.Data && Info.Data.Length)
|
||||
Str = " LENGTH=" + Info.Data.Length
|
||||
global.TO_DEBUG_LOG("GET:" + Info.Method + Str + " from: Node=" + NodeInfo(Info.Node))
|
||||
global.TO_DEBUG_LOG("GET:" + Info.Method + Str + " from: Node=" + global.NodeInfo(Info.Node))
|
||||
}
|
||||
if (global.ADDRLIST_MODE) {
|
||||
var StrOK = ",HAND,GETNODES,";
|
||||
@@ -269,7 +267,7 @@ export default class CTransport extends require("./connect")
|
||||
var Arr = [];
|
||||
var it = this.ActualNodes.iterator(), Item;
|
||||
while ((Item = it.next()) !== null) {
|
||||
if (GetSocketStatus(Item.Socket) >= 100)
|
||||
if (global.GetSocketStatus(Item.Socket) >= 100)
|
||||
Arr.push(Item)
|
||||
else {
|
||||
this.DeleteNodeFromActive(Item)
|
||||
@@ -467,7 +465,7 @@ export default class CTransport extends require("./connect")
|
||||
return 0;
|
||||
var startTime = process.hrtime();
|
||||
global.ADD_TO_STAT("GETDATA(KB)", buf.length / 1024)
|
||||
global.ADD_TO_STAT("GETDATA(KB):" + NodeName(Node), buf.length / 1024, 1)
|
||||
global.ADD_TO_STAT("GETDATA(KB):" + global.NodeName(Node), buf.length / 1024, 1)
|
||||
if (!Node.TransferSize)
|
||||
Node.TransferSize = 0
|
||||
Node.TransferSize += buf.length / 1024
|
||||
@@ -480,7 +478,7 @@ export default class CTransport extends require("./connect")
|
||||
}
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method)
|
||||
global.ADD_TO_STAT("GET:(KB)" + Buf.Method, buf.length / 1024)
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method + ":" + NodeName(Node), 1, 1)
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method + ":" + global.NodeName(Node), 1, 1)
|
||||
var Param = this.MethodTiming[Buf.Method];
|
||||
if (this.StopDoSendPacket(Param, Node, Buf.Method)) {
|
||||
return 1;
|
||||
@@ -679,8 +677,8 @@ export default class CTransport extends require("./connect")
|
||||
Info = Node.SendPacket.min()
|
||||
if (!Info)
|
||||
return 0;
|
||||
global.ADD_TO_STAT("MAX:NODE_BUF_WRITE:" + NodeName(Node), Node.BufWrite.length / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_SEND_BUF_PACKET_COUNT:" + NodeName(Node), Node.SendPacket.size, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_BUF_WRITE:" + global.NodeName(Node), Node.BufWrite.length / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_SEND_BUF_PACKET_COUNT:" + global.NodeName(Node), Node.SendPacket.size, 1)
|
||||
if (Node.BufWrite.length > 2 * TRAFIC_LIMIT_1S) {
|
||||
return 2;
|
||||
}
|
||||
@@ -698,8 +696,8 @@ export default class CTransport extends require("./connect")
|
||||
Node.BufWrite = Buffer.concat([Node.BufWrite, BufWrite])
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method)
|
||||
global.ADD_TO_STAT("SEND:(KB)" + Info.Method, BufWrite.length / 1024)
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method + ":" + NodeName(Node), 1, 1)
|
||||
global.TO_DEBUG_LOG("SEND " + Info.Method + " to " + NodeInfo(Node) + " LENGTH=" + BufWrite.length)
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method + ":" + global.NodeName(Node), 1, 1)
|
||||
global.TO_DEBUG_LOG("SEND " + Info.Method + " to " + global.NodeInfo(Node) + " LENGTH=" + BufWrite.length)
|
||||
return 1;
|
||||
}
|
||||
DoSendPacket() {
|
||||
@@ -728,7 +726,7 @@ export default class CTransport extends require("./connect")
|
||||
var CanCountSend = Node.SendTrafficLimit - Node.SendTrafficCurrent;
|
||||
if (CanCountSend < CountSend) {
|
||||
if (this.SendTrafficFree < CountSend) {
|
||||
global.ADD_TO_STAT("LIMIT_SENDDATA:" + NodeName(Node), Value, 1)
|
||||
global.ADD_TO_STAT("LIMIT_SENDDATA:" + global.NodeName(Node), Value, 1)
|
||||
continue NEXT_NODE;
|
||||
}
|
||||
this.SendTrafficFree -= CountSend
|
||||
@@ -739,7 +737,7 @@ export default class CTransport extends require("./connect")
|
||||
Node.BufWrite = Node.BufWrite.slice(CountSend)
|
||||
this.ADD_CURRENT_STAT_TIME("SEND_DATA", Value)
|
||||
global.ADD_TO_STAT("SENDDATA(KB)", Value)
|
||||
global.ADD_TO_STAT("SENDDATA(KB):" + NodeName(Node), Value, 1)
|
||||
global.ADD_TO_STAT("SENDDATA(KB):" + global.NodeName(Node), Value, 1)
|
||||
}
|
||||
}
|
||||
CheckPOWTicketConnect(Socket, data) {
|
||||
@@ -773,18 +771,18 @@ export default class CTransport extends require("./connect")
|
||||
Node.NextConnectDelta = 1000
|
||||
Node.WaitConnectFromServer = 0
|
||||
Node.GrayConnect = 0
|
||||
global.AddNodeInfo(Node, "3. SERVER OK CONNECT for client node " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "3. SERVER OK CONNECT for client node " + global.SocketInfo(Socket))
|
||||
this.AddNodeToActive(Node)
|
||||
Node.Socket = Socket
|
||||
SetSocketStatus(Socket, 3)
|
||||
SetSocketStatus(Socket, 100)
|
||||
global.SetSocketStatus(Socket, 3)
|
||||
global.SetSocketStatus(Socket, 100)
|
||||
Socket.Node = Node
|
||||
Socket.write(this.GetBufFromData("POW_CONNECT0", "OK", 2))
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign Node from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign Node from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign Node")
|
||||
}
|
||||
}
|
||||
@@ -820,7 +818,7 @@ export default class CTransport extends require("./connect")
|
||||
this.AddToBanIP(Socket.remoteAddress, "ERROR_SIGN_CLIENT")
|
||||
return;
|
||||
}
|
||||
global.AddNodeInfo(Node, "1. SERVER OK POW for client node " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "1. SERVER OK POW for client node " + global.SocketInfo(Socket))
|
||||
Node.FromIP = Info.FromIP
|
||||
Node.FromPort = Info.FromPort
|
||||
Node.SecretForReconnect = crypto.randomBytes(20)
|
||||
@@ -829,11 +827,11 @@ export default class CTransport extends require("./connect")
|
||||
Node.NextConnectDelta = 1000
|
||||
Node.WaitConnectFromServer = 0
|
||||
Node.GrayConnect = 1
|
||||
global.AddNodeInfo(Node, "5. CLIENT OK GRAY CONNECT " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "5. CLIENT OK GRAY CONNECT " + global.SocketInfo(Socket))
|
||||
this.AddNodeToActive(Node)
|
||||
Node.Socket = Socket
|
||||
SetSocketStatus(Socket, 3)
|
||||
SetSocketStatus(Socket, 100)
|
||||
global.SetSocketStatus(Socket, 3)
|
||||
global.SetSocketStatus(Socket, 100)
|
||||
Socket.Node = Node
|
||||
Socket.write(this.GetBufFromData("POW_CONNECT0", "OK", 2))
|
||||
return;
|
||||
@@ -865,7 +863,7 @@ export default class CTransport extends require("./connect")
|
||||
}
|
||||
let SOCKET = sock;
|
||||
global.socketInit(SOCKET, "c")
|
||||
SetSocketStatus(SOCKET, 0)
|
||||
global.SetSocketStatus(SOCKET, 0)
|
||||
global.AddNodeInfo(SOCKET, "Client *" + SOCKET.ConnectID + " connected from " + SOCKET.remoteAddress + ":" + SOCKET.remotePort, 1)
|
||||
global.ADD_TO_STAT("ClientConnected")
|
||||
SOCKET.HashRND = crypto.randomBytes(32)
|
||||
@@ -904,9 +902,9 @@ export default class CTransport extends require("./connect")
|
||||
SOCKET.on('end', function() {
|
||||
global.ADD_TO_STAT("ClientEnd")
|
||||
var Node = SOCKET.Node;
|
||||
var Status = GetSocketStatus(SOCKET);
|
||||
var Status = global.GetSocketStatus(SOCKET);
|
||||
if (Status)
|
||||
global.AddNodeInfo(Node, "Get socket end *" + SOCKET.ConnectID + " from client Stat: " + SocketStatistic(SOCKET))
|
||||
global.AddNodeInfo(Node, "Get socket end *" + SOCKET.ConnectID + " from client Stat: " + global.SocketStatistic(SOCKET))
|
||||
if (Node && Status === 200) {
|
||||
Node.SwapSockets()
|
||||
SOCKET.WasClose = 1
|
||||
@@ -914,12 +912,12 @@ export default class CTransport extends require("./connect")
|
||||
})
|
||||
SOCKET.on('close', function(err) {
|
||||
global.ADD_TO_STAT("ClientClose")
|
||||
if (SOCKET.ConnectID && GetSocketStatus(SOCKET))
|
||||
global.AddNodeInfo(SOCKET.Node, "Get socket close *" + SOCKET.ConnectID + " from client Stat: " + SocketStatistic(SOCKET))
|
||||
if (SOCKET.ConnectID && global.GetSocketStatus(SOCKET))
|
||||
global.AddNodeInfo(SOCKET.Node, "Get socket close *" + SOCKET.ConnectID + " from client Stat: " + global.SocketStatistic(SOCKET))
|
||||
if (!SOCKET.WasClose && SOCKET.Node) {
|
||||
global.CloseSocket(SOCKET, "GET CLOSE")
|
||||
}
|
||||
SetSocketStatus(SOCKET, 0)
|
||||
global.SetSocketStatus(SOCKET, 0)
|
||||
})
|
||||
SOCKET.on('error', function(err) {
|
||||
global.ADD_TO_STAT("ERRORS")
|
||||
@@ -999,7 +997,7 @@ export default class CTransport extends require("./connect")
|
||||
global.CloseSocket(Context.Socket, "CLOSE_SOCKET")
|
||||
}
|
||||
SendCloseSocket(Socket, Str) {
|
||||
global.AddNodeInfo(Socket.Node, "CLOSE_SOCKET " + SocketInfo(Socket) + " - " + Str)
|
||||
global.AddNodeInfo(Socket.Node, "CLOSE_SOCKET " + global.SocketInfo(Socket) + " - " + Str)
|
||||
if (Socket.WasClose) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import CConsensus from './block-exchange'
|
||||
require("../system/dapp");
|
||||
require("../system/accounts");
|
||||
require("../system/smart");
|
||||
@@ -17,13 +18,20 @@ require("../system/messager");
|
||||
require("../system/names");
|
||||
if (global.PROCESS_NAME === "MAIN" || global.PROCESS_NAME === "TX")
|
||||
require("./wallet");
|
||||
module.exports = class CSmartContract extends require("./block-exchange")
|
||||
{
|
||||
export default class CSmartContract extends CConsensus {
|
||||
BufHashTree
|
||||
SenderBlockHashMap
|
||||
SenderMap
|
||||
WasReloadSenderMapFromDB
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.BufHashTree = new global.RBTree(global.CompareArr)
|
||||
this.BufHashTree.LastAddNum = 0
|
||||
this.SenderBlockHashMap = {}
|
||||
this.SenderMap = {}
|
||||
if (!global.ADDRLIST_MODE && !this.VirtualMode && global.START_SERVER) {
|
||||
setInterval(this.ClearOldSenderMapItem.bind(this), 10000)
|
||||
}
|
||||
}
|
||||
AddBlockToHashTree(Block) {
|
||||
this.BufHashTree.LastAddNum = Block.BlockNum
|
||||
@@ -45,6 +53,9 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
}
|
||||
}
|
||||
OnWriteBlock(Block) {
|
||||
this.AddToSenderMap(Block)
|
||||
}
|
||||
OnDelete(Block) {
|
||||
}
|
||||
BlockProcessTX(Block) {
|
||||
if (Block.BlockNum < 1)
|
||||
@@ -82,7 +93,7 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
var arr = Block.arrContent;
|
||||
if (arr)
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var HASH = global.shaarr(arr[i]);
|
||||
var HASH = global.sha3(arr[i]);
|
||||
if (this.BufHashTree.find(HASH)) {
|
||||
continue;
|
||||
}
|
||||
@@ -91,7 +102,7 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
if (App) {
|
||||
App.ResultTx = 0
|
||||
global.DApps.Accounts.BeginTransaction()
|
||||
var StrHex = global.GetHexFromArr(global.sha3(arr[i]));
|
||||
var StrHex = global.GetHexFromArr(HASH);
|
||||
var item;
|
||||
global.CurTrItem = undefined
|
||||
if (global.TreeFindTX) {
|
||||
@@ -148,8 +159,6 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
global.DApps[key].OnDeleteBlock(Block)
|
||||
}
|
||||
}
|
||||
OnDelete(Block) {
|
||||
}
|
||||
IsValidTicket(Tr, BlockNum) {
|
||||
this.CheckCreateTicketObject(Tr, BlockNum)
|
||||
if (Tr.power < global.MIN_POWER_POW_TR)
|
||||
@@ -218,4 +227,87 @@ module.exports = class CSmartContract extends require("./block-exchange")
|
||||
global.TX_PROCESS.Worker.send({ cmd: "FindTX", TX: StrHex })
|
||||
return this.AddTransaction(Tr, 1);
|
||||
}
|
||||
AddTransaction(Tr, ToAll) {
|
||||
// transfer-msg.ts(CMessages)
|
||||
}
|
||||
AddToSenderMap(Block) {
|
||||
var BlockNum = Block.BlockNum;
|
||||
var StrBlockHash = global.GetHexFromArr(Block.Hash);
|
||||
this.SenderBlockHashMap[BlockNum] = StrBlockHash
|
||||
var arr = Block.arrContent;
|
||||
if (arr) {
|
||||
for (var i = 0; i < arr.length; i++) {
|
||||
var type = arr[i][0];
|
||||
var App = global.DAppByType[type];
|
||||
if (App) {
|
||||
var Body = arr[i];
|
||||
var SenderNum = App.GetSenderNum(BlockNum, Body);
|
||||
if (SenderNum < 0)
|
||||
continue;
|
||||
var ItemArr = this.SenderMap[SenderNum];
|
||||
if (!ItemArr) {
|
||||
ItemArr = []
|
||||
this.SenderMap[SenderNum] = ItemArr
|
||||
}
|
||||
ItemArr.push({ BlockNum: BlockNum, StrHash: StrBlockHash })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GetSenderPrioritet(BlockNum, SenderNum) {
|
||||
if (!this.WasReloadSenderMapFromDB)
|
||||
this.ReloadSenderMapFromDB()
|
||||
if (SenderNum < 0)
|
||||
return global.MAX_LENGTH_SENDER_MAP;
|
||||
var MaxBlockNum = BlockNum - global.DELTA_START_SENDER_MAP;
|
||||
if (MaxBlockNum > this.BlockNumDB)
|
||||
return global.MAX_LENGTH_SENDER_MAP;
|
||||
var ItemArr = this.SenderMap[SenderNum];
|
||||
if (!ItemArr) {
|
||||
return global.MAX_LENGTH_SENDER_MAP;
|
||||
}
|
||||
for (var i = ItemArr.length - 1; i--; i >= 0) {
|
||||
var Item = ItemArr[i];
|
||||
if (Item.BlockNum <= MaxBlockNum && this.SenderBlockHashMap[Item.BlockNum] === Item.StrHash) {
|
||||
var Delta = MaxBlockNum - Item.BlockNum;
|
||||
if (Delta > global.MAX_LENGTH_SENDER_MAP)
|
||||
Delta = global.MAX_LENGTH_SENDER_MAP
|
||||
return Delta;
|
||||
}
|
||||
}
|
||||
return global.MAX_LENGTH_SENDER_MAP;
|
||||
}
|
||||
ReloadSenderMapFromDB() {
|
||||
this.SenderMap = {}
|
||||
this.SenderBlockHashMap = {}
|
||||
var EndNum = global.GetCurrentBlockNumByTime();
|
||||
var StartNum = EndNum - global.MAX_LENGTH_SENDER_MAP - global.DELTA_START_SENDER_MAP;
|
||||
if (StartNum < 0)
|
||||
StartNum = 0
|
||||
for (var Num = StartNum; Num < EndNum; Num++) {
|
||||
var Block = this.ReadBlockDB(Num);
|
||||
if (!Block)
|
||||
break;
|
||||
this.AddToSenderMap(Block)
|
||||
}
|
||||
this.WasReloadSenderMapFromDB = 1
|
||||
}
|
||||
ClearOldSenderMapItem() {
|
||||
var MinBlockNum = global.GetCurrentBlockNumByTime() - global.MAX_LENGTH_SENDER_MAP * 2;
|
||||
var ArrForDel = [];
|
||||
for (var key in this.SenderMap) {
|
||||
var ItemArr = this.SenderMap[key];
|
||||
while (ItemArr.length) {
|
||||
var Item = ItemArr[0];
|
||||
if (Item.BlockNum > MinBlockNum)
|
||||
break;
|
||||
ItemArr.shift()
|
||||
}
|
||||
if (ItemArr.length === 0)
|
||||
ArrForDel.push(key)
|
||||
}
|
||||
for (var i = 0; i < ArrForDel.length; i++) {
|
||||
delete this.SenderMap[ArrForDel[i]]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,11 +9,10 @@
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
import CSmartContract from './transaction-validator'
|
||||
const MAX_MESSAGE_COUNT = 1000;
|
||||
module.exports = class CMessages extends require("./transaction-validator")
|
||||
{
|
||||
export default class CMessages extends CSmartContract {
|
||||
MemPoolMsg
|
||||
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.MemPoolMsg = []
|
||||
@@ -194,7 +193,7 @@ module.exports = class CMessages extends require("./transaction-validator")
|
||||
}
|
||||
Node.TaskLastSend = CurTime
|
||||
this.SendF(Node, { "Method": "TRANSACTION", "Data": Tr }, Tr.body.length + 1000)
|
||||
ToLogContext("Send " + TrName(Tr) + " to " + NodeName(Node))
|
||||
ToLogContext("Send " + TrName(Tr) + " to " + global.NodeName(Node))
|
||||
Count--
|
||||
if (Count <= 0)
|
||||
break;
|
||||
@@ -206,7 +205,7 @@ module.exports = class CMessages extends require("./transaction-validator")
|
||||
}
|
||||
TRANSACTION(Info, CurTime) {
|
||||
var Tr = this.DataFromF(Info);
|
||||
ToLogContext("Receive " + TrName(Tr) + " from " + NodeName(Info.Node))
|
||||
ToLogContext("Receive " + TrName(Tr) + " from " + global.NodeName(Info.Node))
|
||||
this.AddTransaction(Tr, 0)
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* Twitter: https://twitter.com/terafoundation
|
||||
* Telegram: https://t.me/terafoundation
|
||||
*/
|
||||
|
||||
const fs = require('fs')
|
||||
global.RunOnUpdate = RunOnUpdate;
|
||||
|
||||
function RunOnUpdate() {
|
||||
@@ -146,10 +146,11 @@ function RecreateAccountHashDB3() {
|
||||
}
|
||||
};
|
||||
|
||||
import '../core/db/db-row'
|
||||
|
||||
function ReWriteDBSmartWrite() {
|
||||
global.UpdateMode = 1;
|
||||
global.ToLog("Start ReWriteDBSmartWrite");
|
||||
require("../core/db/db-row");
|
||||
for (var num = 0; true; num++) {
|
||||
var Item = global.DApps.Smart.DBSmart.Read(num);
|
||||
if (!Item)
|
||||
|
||||
Reference in New Issue
Block a user