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.LoadHistoryMessage = !bSilent
|
||||
this.LoadHistoryContext = {
|
||||
PrevBlockNum: - 1, Node: Node, BlockNum: this.BlockNumDB, MapSend: {}, Foward: 1, Pause: 0, DeltaBlockNum: 10,
|
||||
StartTimeHistory: Date.now(), MaxTimeOut: 30 * 1000
|
||||
PrevBlockNum: - 1,
|
||||
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) {
|
||||
this.CheckSyncRest()
|
||||
|
@ -478,7 +478,7 @@ global.HTTPCaller.GetActList = function(Params) {
|
||||
return { arr: arr, result: 1 };
|
||||
};
|
||||
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++) {
|
||||
var item = arr[i];
|
||||
item.BlockNum = item.Num * global.PERIOD_ACCOUNT_HASH;
|
||||
|
@ -22,6 +22,7 @@ export class TeraSocket extends net.Socket {
|
||||
Buf: Buffer;
|
||||
SocketNum: number;
|
||||
SocketPrioritet: number;
|
||||
HashRND: Buffer;
|
||||
}
|
||||
export default class CNode {
|
||||
addrStr
|
||||
@ -102,6 +103,8 @@ export default class CNode {
|
||||
SocketStart
|
||||
WaitConnectFromServer
|
||||
WaitConnectIP
|
||||
Prioritet
|
||||
WasAddToReconnect
|
||||
constructor(addrStr, ip, port) {
|
||||
this.addrStr = addrStr
|
||||
this.ip = ip.trim()
|
||||
|
@ -12,19 +12,50 @@
|
||||
import CDB from './db/block-db'
|
||||
import { TYPE_TRANSACTION } from '../constant/account';
|
||||
import { DB_FORMAT } from '../constant/db-format';
|
||||
import CNode from './node';
|
||||
var MIN_POW_CHAINS = 2;
|
||||
global.COUNT_NODE_PROOF = 6;
|
||||
if (global.TEST_NETWORK) {
|
||||
MIN_POW_CHAINS = 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 {
|
||||
LoadRestContext
|
||||
LoadRestContext: LoadContext
|
||||
LoadHistoryContext: LoadContext
|
||||
BlockNumDB
|
||||
BlockNumDBMin
|
||||
UseTruncateBlockDB
|
||||
ContextSendLoadToBegin
|
||||
LoadHistoryContext
|
||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
}
|
||||
@ -43,9 +74,19 @@ export default class CRest extends CDB {
|
||||
return;
|
||||
}
|
||||
this.LoadRestContext = {
|
||||
Mode: 0, BlockNum: BlockNumRest, 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: {}
|
||||
Mode: 0,
|
||||
BlockNum: BlockNumRest,
|
||||
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++) {
|
||||
this.NodesArr[i].SendRestGetHeader = 0
|
||||
@ -81,7 +122,15 @@ export default class CRest extends CDB {
|
||||
Node.SendRestGetHeader = 1
|
||||
global.ToLog("Send rest get header " + 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) },
|
||||
"Method": "GETBLOCKHEADER",
|
||||
"Data": {
|
||||
Foward: 1,
|
||||
BlockNum: Context.BlockNumProof,
|
||||
Hash: []
|
||||
},
|
||||
"Context": {
|
||||
F: this.RETBLOCKHEADER_REST.bind(this)
|
||||
},
|
||||
})
|
||||
Context.SendGetHeaderCount++
|
||||
break;
|
||||
@ -274,7 +323,7 @@ export default class CRest extends CDB {
|
||||
global.ToLog("ERROR global.TX_PROCESS")
|
||||
return;
|
||||
}
|
||||
Task.OK = 1
|
||||
Task.OK = true
|
||||
global.TX_PROCESS.RunRPC("TXWriteAccArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
||||
Context.AccTaskFinished++
|
||||
})
|
||||
@ -315,7 +364,7 @@ export default class CRest extends CDB {
|
||||
Task.Node = Info.Node
|
||||
if (!global.TX_PROCESS || !global.TX_PROCESS.RunRPC)
|
||||
return;
|
||||
Task.OK = 1
|
||||
Task.OK = true
|
||||
global.TX_PROCESS.RunRPC("TXWriteSmartArr", { StartNum: Task.StartNum, Arr: Data.Arr }, function(Err, Params) {
|
||||
Context.SmartTaskFinished++
|
||||
})
|
||||
@ -340,9 +389,8 @@ export default class CRest extends CDB {
|
||||
if (!Task) {
|
||||
global.ToLog("error task number: " + t)
|
||||
Context.Mode = 100
|
||||
}
|
||||
else {
|
||||
Task.OK = 0
|
||||
} else {
|
||||
Task.OK = false
|
||||
Context.Mode--
|
||||
Context.SmartTaskFinished--
|
||||
this.AddToBan(Task.Node, Str)
|
||||
|
@ -632,7 +632,7 @@ export default class CTransport extends CConnect {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Send(Node, Info, TypeData) {
|
||||
Send(Node: CNode, Info, TypeData) {
|
||||
if (!Node.Socket) {
|
||||
this.DeleteNodeFromActive(Node)
|
||||
return;
|
||||
@ -655,10 +655,10 @@ export default class CTransport extends CConnect {
|
||||
Info.TimeNum = Date.now()
|
||||
Node.SendPacket.insert(Info)
|
||||
}
|
||||
DoSendPacketNodeAll(Node) {
|
||||
DoSendPacketNodeAll(Node: CNode) {
|
||||
while (this.DoSendPacketNode(Node) === 1);
|
||||
}
|
||||
DoSendPacketNode(Node) {
|
||||
DoSendPacketNode(Node: CNode) {
|
||||
var TimeNum = Date.now();
|
||||
var Info = Node.SendPacket.max();
|
||||
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)
|
||||
}
|
||||
}
|
||||
CheckPOWTicketConnect(Socket, data) {
|
||||
CheckPOWTicketConnect(Socket: TeraSocket, data) {
|
||||
try {
|
||||
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())
|
||||
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) {
|
||||
global.AddNodeInfo(Node, "SERV: GET SELF")
|
||||
this.SendCloseSocket(Socket, "SELF")
|
||||
@ -855,7 +855,7 @@ export default class CTransport extends CConnect {
|
||||
return;
|
||||
}
|
||||
let SELF = this;
|
||||
this.Server = net.createServer(function(sock: any) {
|
||||
this.Server = net.createServer(function(sock: TeraSocket) {
|
||||
if (SELF.WasBanIP({ address: sock.remoteAddress })) {
|
||||
sock.ConnectID = "new"
|
||||
global.CloseSocket(sock, "WAS BAN", true)
|
||||
@ -889,7 +889,7 @@ export default class CTransport extends CConnect {
|
||||
var Buf = SELF.GetDataFromBuf(data);
|
||||
if (Buf) {
|
||||
SELF.CheckPOWTicketConnect(SOCKET, Buf.Data)
|
||||
SOCKET.ConnectToServer = 0
|
||||
SOCKET.ConnectToServer = false
|
||||
return;
|
||||
}
|
||||
global.CloseSocket(SOCKET, "=SERVER ON DATA=")
|
||||
|
@ -202,5 +202,6 @@ global.GetNonceHashArr = function(BlockNum, Miner, StartNonceRnd, CountNonce) {
|
||||
};
|
||||
|
||||
export {
|
||||
InitVer3,
|
||||
CreatePOWVersionX
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ global.PROCESS_NAME = "POW";
|
||||
global.POWPROCESS = 1;
|
||||
import "../core/library"
|
||||
import "../core/crypto-library"
|
||||
import { CreatePOWVersionX } from "../core/terahashmining"
|
||||
import { InitVer3, CreatePOWVersionX } from "../core/terahashmining"
|
||||
var PROCESS = process;
|
||||
if (process.send && !global.DEBUGPROCESS) {
|
||||
process.send({ cmd: "online", message: "OK" });
|
||||
@ -24,6 +24,24 @@ setInterval(CheckAlive, 1000);
|
||||
var idInterval = undefined;
|
||||
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'
|
||||
|
||||
powClient.on('message', (msg) => {
|
||||
@ -65,18 +83,6 @@ function FastCalcBlock(msg) {
|
||||
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() {
|
||||
if (global.NOALIVE)
|
||||
|
@ -39,6 +39,10 @@ function RunProcess() {
|
||||
function AddPowProcess() {
|
||||
let Worker = Fork('./process/pow-process');
|
||||
ArrMiningWrk.push(Worker);
|
||||
Worker.send({
|
||||
cmd: "InitVer3",
|
||||
ProcessMemorySize
|
||||
})
|
||||
Worker.Num = ArrMiningWrk.length;
|
||||
Worker.on('message', function(msg) {
|
||||
switch (msg.cmd) {
|
||||
|
Loading…
Reference in New Issue
Block a user