forked from circlecloud/tera
feat: add more type def
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
8d0cb723c1
commit
8c849ed49f
@ -176,8 +176,15 @@ export default class CBlock extends CRest {
|
|||||||
this.LoadHistoryMode = true
|
this.LoadHistoryMode = true
|
||||||
this.LoadHistoryMessage = !bSilent
|
this.LoadHistoryMessage = !bSilent
|
||||||
this.LoadHistoryContext = {
|
this.LoadHistoryContext = {
|
||||||
PrevBlockNum: - 1, Node: Node, BlockNum: this.BlockNumDB, MapSend: {}, Foward: 1, Pause: 0, DeltaBlockNum: 10,
|
PrevBlockNum: - 1,
|
||||||
StartTimeHistory: Date.now(), MaxTimeOut: 30 * 1000
|
Node: Node,
|
||||||
|
BlockNum: this.BlockNumDB,
|
||||||
|
MapSend: {},
|
||||||
|
Foward: 1,
|
||||||
|
Pause: 0,
|
||||||
|
DeltaBlockNum: 10,
|
||||||
|
StartTimeHistory: Date.now(),
|
||||||
|
MaxTimeOut: 30 * 1000
|
||||||
}
|
}
|
||||||
if (!bSilent && !bCheckPoint && global.REST_START_COUNT) {
|
if (!bSilent && !bCheckPoint && global.REST_START_COUNT) {
|
||||||
this.CheckSyncRest()
|
this.CheckSyncRest()
|
||||||
|
@ -478,7 +478,7 @@ global.HTTPCaller.GetActList = function(Params) {
|
|||||||
return { arr: arr, result: 1 };
|
return { arr: arr, result: 1 };
|
||||||
};
|
};
|
||||||
global.HTTPCaller.GetHashList = function(Params) {
|
global.HTTPCaller.GetHashList = function(Params) {
|
||||||
var arr = global.DApps.Accounts.DBAccountsHash.GetRows(Params.StartNum, Params.CountNum, Params.Filter);
|
var arr = global.DApps.Accounts.DBAccountsHash.GetRows(Params.StartNum, Params.CountNum);
|
||||||
for (var i = 0; i < arr.length; i++) {
|
for (var i = 0; i < arr.length; i++) {
|
||||||
var item = arr[i];
|
var item = arr[i];
|
||||||
item.BlockNum = item.Num * global.PERIOD_ACCOUNT_HASH;
|
item.BlockNum = item.Num * global.PERIOD_ACCOUNT_HASH;
|
||||||
|
@ -22,6 +22,7 @@ export class TeraSocket extends net.Socket {
|
|||||||
Buf: Buffer;
|
Buf: Buffer;
|
||||||
SocketNum: number;
|
SocketNum: number;
|
||||||
SocketPrioritet: number;
|
SocketPrioritet: number;
|
||||||
|
HashRND: Buffer;
|
||||||
}
|
}
|
||||||
export default class CNode {
|
export default class CNode {
|
||||||
addrStr
|
addrStr
|
||||||
@ -102,6 +103,8 @@ export default class CNode {
|
|||||||
SocketStart
|
SocketStart
|
||||||
WaitConnectFromServer
|
WaitConnectFromServer
|
||||||
WaitConnectIP
|
WaitConnectIP
|
||||||
|
Prioritet
|
||||||
|
WasAddToReconnect
|
||||||
constructor(addrStr, ip, port) {
|
constructor(addrStr, ip, port) {
|
||||||
this.addrStr = addrStr
|
this.addrStr = addrStr
|
||||||
this.ip = ip.trim()
|
this.ip = ip.trim()
|
||||||
|
@ -12,19 +12,50 @@
|
|||||||
import CDB from './db/block-db'
|
import CDB from './db/block-db'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
import { DB_FORMAT } from '../constant/db-format';
|
import { DB_FORMAT } from '../constant/db-format';
|
||||||
|
import CNode from './node';
|
||||||
var MIN_POW_CHAINS = 2;
|
var MIN_POW_CHAINS = 2;
|
||||||
global.COUNT_NODE_PROOF = 6;
|
global.COUNT_NODE_PROOF = 6;
|
||||||
if (global.TEST_NETWORK) {
|
if (global.TEST_NETWORK) {
|
||||||
MIN_POW_CHAINS = 1;
|
MIN_POW_CHAINS = 1;
|
||||||
global.COUNT_NODE_PROOF = 1;
|
global.COUNT_NODE_PROOF = 1;
|
||||||
}
|
}
|
||||||
|
interface ContextTask {
|
||||||
|
StartNum?: number
|
||||||
|
Count?: number
|
||||||
|
Time?: number
|
||||||
|
Node?: CNode
|
||||||
|
MapSend?: {}
|
||||||
|
OK?: boolean
|
||||||
|
}
|
||||||
|
interface LoadContext {
|
||||||
|
Mode?: number,
|
||||||
|
BlockNum?: number,
|
||||||
|
BlockNumRest?: number,
|
||||||
|
WasDelta?: number,
|
||||||
|
BlockNumProof?: number,
|
||||||
|
CountProof?: number,
|
||||||
|
StartTimeHistory?: number,
|
||||||
|
MaxTimeOut?: number,
|
||||||
|
LoopSyncRest?: number,
|
||||||
|
SendGetHeaderCount?: number,
|
||||||
|
ReceiveHeaderCount?: number,
|
||||||
|
ArrProof?: any[],
|
||||||
|
MapSend?: any,
|
||||||
|
BlockProof?,
|
||||||
|
TxProof?,
|
||||||
|
AccTaskList?: ContextTask[],
|
||||||
|
AccTaskFinished?: number,
|
||||||
|
SmartTaskList?: ContextTask[],
|
||||||
|
SmartTaskFinished?: number
|
||||||
|
}
|
||||||
|
|
||||||
export default class CRest extends CDB {
|
export default class CRest extends CDB {
|
||||||
LoadRestContext
|
LoadRestContext: LoadContext
|
||||||
|
LoadHistoryContext: LoadContext
|
||||||
BlockNumDB
|
BlockNumDB
|
||||||
BlockNumDBMin
|
BlockNumDBMin
|
||||||
UseTruncateBlockDB
|
UseTruncateBlockDB
|
||||||
ContextSendLoadToBegin
|
ContextSendLoadToBegin
|
||||||
LoadHistoryContext
|
|
||||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||||
}
|
}
|
||||||
@ -43,9 +74,19 @@ export default class CRest extends CDB {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.LoadRestContext = {
|
this.LoadRestContext = {
|
||||||
Mode: 0, BlockNum: BlockNumRest, BlockNumRest: BlockNumRest, WasDelta: Delta, BlockNumProof: BlockNumRest + global.DELTA_BLOCK_ACCOUNT_HASH,
|
Mode: 0,
|
||||||
CountProof: global.COUNT_BLOCKS_FOR_LOAD, StartTimeHistory: Date.now(), MaxTimeOut: 600 * 1000, LoopSyncRest: 1, SendGetHeaderCount: 0,
|
BlockNum: BlockNumRest,
|
||||||
ReceiveHeaderCount: 0, ArrProof: [], MapSend: {}
|
BlockNumRest: BlockNumRest,
|
||||||
|
WasDelta: Delta,
|
||||||
|
BlockNumProof: BlockNumRest + global.DELTA_BLOCK_ACCOUNT_HASH,
|
||||||
|
CountProof: global.COUNT_BLOCKS_FOR_LOAD,
|
||||||
|
StartTimeHistory: Date.now(),
|
||||||
|
MaxTimeOut: 600 * 1000,
|
||||||
|
LoopSyncRest: 1,
|
||||||
|
SendGetHeaderCount: 0,
|
||||||
|
ReceiveHeaderCount: 0,
|
||||||
|
ArrProof: [],
|
||||||
|
MapSend: {}
|
||||||
}
|
}
|
||||||
for (var i = 0; i < this.NodesArr.length; i++) {
|
for (var i = 0; i < this.NodesArr.length; i++) {
|
||||||
this.NodesArr[i].SendRestGetHeader = 0
|
this.NodesArr[i].SendRestGetHeader = 0
|
||||||
@ -81,7 +122,15 @@ export default class CRest extends CDB {
|
|||||||
Node.SendRestGetHeader = 1
|
Node.SendRestGetHeader = 1
|
||||||
global.ToLog("Send rest get header " + Context.BlockNumProof + " to " + global.NodeName(Node), 2)
|
global.ToLog("Send rest get header " + Context.BlockNumProof + " to " + global.NodeName(Node), 2)
|
||||||
this.SendF(Node, {
|
this.SendF(Node, {
|
||||||
"Method": "GETBLOCKHEADER", "Data": { Foward: 1, BlockNum: Context.BlockNumProof, Hash: [] }, "Context": { F: this.RETBLOCKHEADER_REST.bind(this) },
|
"Method": "GETBLOCKHEADER",
|
||||||
|
"Data": {
|
||||||
|
Foward: 1,
|
||||||
|
BlockNum: Context.BlockNumProof,
|
||||||
|
Hash: []
|
||||||
|
},
|
||||||
|
"Context": {
|
||||||
|
F: this.RETBLOCKHEADER_REST.bind(this)
|
||||||
|
},
|
||||||
})
|
})
|
||||||
Context.SendGetHeaderCount++
|
Context.SendGetHeaderCount++
|
||||||
break;
|
break;
|
||||||
@ -274,7 +323,7 @@ export default class CRest extends CDB {
|
|||||||
global.ToLog("ERROR global.TX_PROCESS")
|
global.ToLog("ERROR global.TX_PROCESS")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Task.OK = 1
|
Task.OK = true
|
||||||
global.TX_PROCESS.RunRPC("TXWriteAccArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
global.TX_PROCESS.RunRPC("TXWriteAccArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
||||||
Context.AccTaskFinished++
|
Context.AccTaskFinished++
|
||||||
})
|
})
|
||||||
@ -315,7 +364,7 @@ export default class CRest extends CDB {
|
|||||||
Task.Node = Info.Node
|
Task.Node = Info.Node
|
||||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
||||||
return;
|
return;
|
||||||
Task.OK = 1
|
Task.OK = true
|
||||||
global.TX_PROCESS.RunRPC("TXWriteSmartArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
global.TX_PROCESS.RunRPC("TXWriteSmartArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
||||||
Context.SmartTaskFinished++
|
Context.SmartTaskFinished++
|
||||||
})
|
})
|
||||||
@ -340,9 +389,8 @@ export default class CRest extends CDB {
|
|||||||
if (!Task) {
|
if (!Task) {
|
||||||
global.ToLog("error task number: " + t)
|
global.ToLog("error task number: " + t)
|
||||||
Context.Mode = 100
|
Context.Mode = 100
|
||||||
}
|
} else {
|
||||||
else {
|
Task.OK = false
|
||||||
Task.OK = 0
|
|
||||||
Context.Mode--
|
Context.Mode--
|
||||||
Context.SmartTaskFinished--
|
Context.SmartTaskFinished--
|
||||||
this.AddToBan(Task.Node, Str)
|
this.AddToBan(Task.Node, Str)
|
||||||
|
@ -632,7 +632,7 @@ export default class CTransport extends CConnect {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Send(Node, Info, TypeData) {
|
Send(Node: CNode, Info, TypeData) {
|
||||||
if (!Node.Socket) {
|
if (!Node.Socket) {
|
||||||
this.DeleteNodeFromActive(Node)
|
this.DeleteNodeFromActive(Node)
|
||||||
return;
|
return;
|
||||||
@ -655,10 +655,10 @@ export default class CTransport extends CConnect {
|
|||||||
Info.TimeNum = Date.now()
|
Info.TimeNum = Date.now()
|
||||||
Node.SendPacket.insert(Info)
|
Node.SendPacket.insert(Info)
|
||||||
}
|
}
|
||||||
DoSendPacketNodeAll(Node) {
|
DoSendPacketNodeAll(Node: CNode) {
|
||||||
while (this.DoSendPacketNode(Node) === 1);
|
while (this.DoSendPacketNode(Node) === 1);
|
||||||
}
|
}
|
||||||
DoSendPacketNode(Node) {
|
DoSendPacketNode(Node: CNode) {
|
||||||
var TimeNum = Date.now();
|
var TimeNum = Date.now();
|
||||||
var Info = Node.SendPacket.max();
|
var Info = Node.SendPacket.max();
|
||||||
if (Info && TimeNum - Info.TimeNum > global.PACKET_ALIVE_PERIOD)
|
if (Info && TimeNum - Info.TimeNum > global.PACKET_ALIVE_PERIOD)
|
||||||
@ -737,7 +737,7 @@ export default class CTransport extends CConnect {
|
|||||||
global.ADD_TO_STAT("SENDDATA(KB):" + global.NodeName(Node), Value, 1)
|
global.ADD_TO_STAT("SENDDATA(KB):" + global.NodeName(Node), Value, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CheckPOWTicketConnect(Socket, data) {
|
CheckPOWTicketConnect(Socket: TeraSocket, data) {
|
||||||
try {
|
try {
|
||||||
var Info = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_SERVER, {});
|
var Info = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_SERVER, {});
|
||||||
}
|
}
|
||||||
@ -749,7 +749,7 @@ export default class CTransport extends CConnect {
|
|||||||
this.SendCloseSocket(Socket, "DEF_NETWORK=" + Info.DEF_NETWORK + " MUST:" + global.GetNetworkName())
|
this.SendCloseSocket(Socket, "DEF_NETWORK=" + Info.DEF_NETWORK + " MUST:" + global.GetNetworkName())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var Node = this.FindRunNodeContext(Info.addrArr, Info.FromIP, Info.FromPort, true);
|
var Node: CNode = this.FindRunNodeContext(Info.addrArr, Info.FromIP, Info.FromPort, true);
|
||||||
if (global.CompareArr(Info.addrArr, this.addrArr) === 0) {
|
if (global.CompareArr(Info.addrArr, this.addrArr) === 0) {
|
||||||
global.AddNodeInfo(Node, "SERV: GET SELF")
|
global.AddNodeInfo(Node, "SERV: GET SELF")
|
||||||
this.SendCloseSocket(Socket, "SELF")
|
this.SendCloseSocket(Socket, "SELF")
|
||||||
@ -855,7 +855,7 @@ export default class CTransport extends CConnect {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let SELF = this;
|
let SELF = this;
|
||||||
this.Server = net.createServer(function(sock: any) {
|
this.Server = net.createServer(function(sock: TeraSocket) {
|
||||||
if (SELF.WasBanIP({ address: sock.remoteAddress })) {
|
if (SELF.WasBanIP({ address: sock.remoteAddress })) {
|
||||||
sock.ConnectID = "new"
|
sock.ConnectID = "new"
|
||||||
global.CloseSocket(sock, "WAS BAN", true)
|
global.CloseSocket(sock, "WAS BAN", true)
|
||||||
@ -889,7 +889,7 @@ export default class CTransport extends CConnect {
|
|||||||
var Buf = SELF.GetDataFromBuf(data);
|
var Buf = SELF.GetDataFromBuf(data);
|
||||||
if (Buf) {
|
if (Buf) {
|
||||||
SELF.CheckPOWTicketConnect(SOCKET, Buf.Data)
|
SELF.CheckPOWTicketConnect(SOCKET, Buf.Data)
|
||||||
SOCKET.ConnectToServer = 0
|
SOCKET.ConnectToServer = false
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
global.CloseSocket(SOCKET, "=SERVER ON DATA=")
|
global.CloseSocket(SOCKET, "=SERVER ON DATA=")
|
||||||
|
@ -202,5 +202,6 @@ global.GetNonceHashArr = function(BlockNum, Miner, StartNonceRnd, CountNonce) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
InitVer3,
|
||||||
CreatePOWVersionX
|
CreatePOWVersionX
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ global.PROCESS_NAME = "POW";
|
|||||||
global.POWPROCESS = 1;
|
global.POWPROCESS = 1;
|
||||||
import "../core/library"
|
import "../core/library"
|
||||||
import "../core/crypto-library"
|
import "../core/crypto-library"
|
||||||
import { CreatePOWVersionX } from "../core/terahashmining"
|
import { InitVer3, CreatePOWVersionX } from "../core/terahashmining"
|
||||||
var PROCESS = process;
|
var PROCESS = process;
|
||||||
if (process.send && !global.DEBUGPROCESS) {
|
if (process.send && !global.DEBUGPROCESS) {
|
||||||
process.send({ cmd: "online", message: "OK" });
|
process.send({ cmd: "online", message: "OK" });
|
||||||
@ -24,6 +24,24 @@ setInterval(CheckAlive, 1000);
|
|||||||
var idInterval = undefined;
|
var idInterval = undefined;
|
||||||
var Block: any = {};
|
var Block: any = {};
|
||||||
|
|
||||||
|
PROCESS.on('message', function(msg) {
|
||||||
|
LastAlive = Date.now();
|
||||||
|
switch (msg.cmd) {
|
||||||
|
case "Alive":
|
||||||
|
if (!powClient.connected) {
|
||||||
|
powClient.connect()
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "InitVer3":
|
||||||
|
InitVer3({
|
||||||
|
ProcessMemorySize: msg.ProcessMemorySize
|
||||||
|
})
|
||||||
|
break
|
||||||
|
case "Exit":
|
||||||
|
PROCESS.exit(0);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
import { powClient } from '../rpc/client'
|
import { powClient } from '../rpc/client'
|
||||||
|
|
||||||
powClient.on('message', (msg) => {
|
powClient.on('message', (msg) => {
|
||||||
@ -65,18 +83,6 @@ function FastCalcBlock(msg) {
|
|||||||
global.ToError(e);
|
global.ToError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PROCESS.on('message', function(msg) {
|
|
||||||
LastAlive = Date.now();
|
|
||||||
switch (msg.cmd) {
|
|
||||||
case "Alive":
|
|
||||||
if (!powClient.connected) {
|
|
||||||
powClient.connect()
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Exit":
|
|
||||||
PROCESS.exit(0);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
function CheckAlive() {
|
function CheckAlive() {
|
||||||
if (global.NOALIVE)
|
if (global.NOALIVE)
|
||||||
|
@ -39,6 +39,10 @@ function RunProcess() {
|
|||||||
function AddPowProcess() {
|
function AddPowProcess() {
|
||||||
let Worker = Fork('./process/pow-process');
|
let Worker = Fork('./process/pow-process');
|
||||||
ArrMiningWrk.push(Worker);
|
ArrMiningWrk.push(Worker);
|
||||||
|
Worker.send({
|
||||||
|
cmd: "InitVer3",
|
||||||
|
ProcessMemorySize
|
||||||
|
})
|
||||||
Worker.Num = ArrMiningWrk.length;
|
Worker.Num = ArrMiningWrk.length;
|
||||||
Worker.on('message', function(msg) {
|
Worker.on('message', function(msg) {
|
||||||
switch (msg.cmd) {
|
switch (msg.cmd) {
|
||||||
|
Loading…
Reference in New Issue
Block a user