refactor: split pow cacl process
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
375134fdc3
commit
a11f96e775
@ -1325,7 +1325,7 @@ export default class CConsensus extends CBlock {
|
||||
return SumPow / Count;
|
||||
}
|
||||
CreatePOWNew(Block) {
|
||||
CreateHashMinimal(Block, global.GENERATE_BLOCK_ACCOUNT)
|
||||
global.CreateHashMinimal(Block, global.GENERATE_BLOCK_ACCOUNT)
|
||||
this.AddToMaxPOW(Block, {
|
||||
SeqHash: Block.SeqHash, AddrHash: Block.AddrHash, PrevHash: Block.PrevHash, TreeHash: Block.TreeHash,
|
||||
})
|
||||
|
@ -170,8 +170,7 @@ export default class CBlock extends CRest {
|
||||
if (StartBlockNum <= 0)
|
||||
StartBlockNum = 15
|
||||
global.ToLog("Current DeltaNum=" + DeltaNum + " StartBlockNum=" + StartBlockNum, 2)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
StartBlockNum = this.BlockNumDB
|
||||
}
|
||||
this.LoadHistoryMode = true
|
||||
|
@ -401,8 +401,7 @@ export default class CConnect extends CMessages {
|
||||
var SignArr = this.GetSignCheckDeltaTime(Data.CheckDeltaTime);
|
||||
if (global.CheckDevelopSign(SignArr, Data.CheckDeltaTime.Sign)) {
|
||||
global.CHECK_DELTA_TIME = Data.CheckDeltaTime
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign CheckDeltaTime Num=" + Data.CheckDeltaTime.Num + " from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign CheckDeltaTime")
|
||||
@ -475,12 +474,10 @@ export default class CConnect extends CMessages {
|
||||
global.ToLog("Get new CodeVersion = " + CodeVersion.VersionNum + " HASH:" + global.GetHexFromArr(CodeVersion.Hash).substr(0, 20))
|
||||
if (CodeVersion.VersionNum > global.CODE_VERSION.VersionNum && CodeVersion.VersionNum > global.START_LOAD_CODE.StartLoadVersionNum) {
|
||||
this.StartLoadCode(Node, CodeVersion)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
global.CODE_VERSION = CodeVersion
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
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")
|
||||
|
@ -20,7 +20,6 @@ require('./crypto-library');
|
||||
require('../HTML/JS/terahashlib.js');
|
||||
var DELTA_NONCE = Math.pow(2, 40) * global.MINING_VERSION_NUM;
|
||||
global.CreateHashMinimal = CreateHashMinimal;
|
||||
global.CreatePOWVersionX = CreatePOWVersion3;
|
||||
|
||||
function CreateHashMinimal(Block, MinerID) {
|
||||
if (Block.BlockNum < BLOCKNUM_ALGO2) {
|
||||
@ -73,7 +72,7 @@ function InitVer3(Block) {
|
||||
}
|
||||
};
|
||||
|
||||
function CreatePOWVersion3(Block, bHashPump) {
|
||||
let CreatePOWVersionX = function CreatePOWVersion3(Block, bHashPump?) {
|
||||
if (!bWasInitVer3)
|
||||
InitVer3(Block);
|
||||
if (!bWasInitVerOK3)
|
||||
@ -201,3 +200,7 @@ global.GetNonceHashArr = function(BlockNum, Miner, StartNonceRnd, CountNonce) {
|
||||
}
|
||||
return { ArrNonce: ArrNonce, ArrHash: ArrHash };
|
||||
};
|
||||
|
||||
export {
|
||||
CreatePOWVersionX
|
||||
}
|
||||
|
12
src/global.d.ts
vendored
12
src/global.d.ts
vendored
@ -1,5 +1,6 @@
|
||||
export { };
|
||||
|
||||
import { ChildProcess } from 'child_process'
|
||||
import CSmartContract from './core/transaction-validator'
|
||||
import CConsensus from './core/block-exchange'
|
||||
import CTransport from './core/server'
|
||||
@ -234,7 +235,7 @@ declare global {
|
||||
|
||||
//#region main-process.ts:375
|
||||
MiningPaused: number;
|
||||
ArrMiningWrk: any[];
|
||||
ArrMiningWrk: TeraChildProcess[];
|
||||
//#endregion
|
||||
|
||||
//#region library.ts:118
|
||||
@ -614,7 +615,6 @@ declare global {
|
||||
|
||||
//#region terahashmining.ts
|
||||
CreateHashMinimal: Function;
|
||||
CreatePOWVersionX: Function;
|
||||
GetNonceHashArr: Function;
|
||||
//#endregion
|
||||
|
||||
@ -667,14 +667,20 @@ declare global {
|
||||
interface Process {
|
||||
RunRPC: Function;
|
||||
}
|
||||
|
||||
}
|
||||
interface TeraChildProcess extends ChildProcess {
|
||||
Num: number;
|
||||
bOnline: boolean
|
||||
}
|
||||
interface TeraProcess {
|
||||
pid?: number;
|
||||
Name: string;
|
||||
idInterval: number | any;
|
||||
idInterval1: number | any;
|
||||
idInterval2: number | any;
|
||||
LastAlive: number;
|
||||
Worker: Worker;
|
||||
Worker: TeraChildProcess;
|
||||
Path: string;
|
||||
OnMessage: Function;
|
||||
PeriodAlive: number;
|
||||
|
@ -222,7 +222,7 @@ function StartAllProcess(bClose) {
|
||||
var GlobalRunID = 0;
|
||||
var GlobalRunMap = {};
|
||||
|
||||
function StartChildProcess(Item) {
|
||||
function StartChildProcess(Item: TeraProcess) {
|
||||
let ITEM = Item;
|
||||
ITEM.idInterval = setInterval(function() {
|
||||
var Delta0 = Date.now() - ITEM.LastAlive;
|
||||
@ -670,8 +670,9 @@ function RunOnce() {
|
||||
};
|
||||
var glPortDebug = 49800;
|
||||
|
||||
function Fork(Path, ArrArgs?) {
|
||||
const child_process = require('child_process');
|
||||
import { fork } from 'child_process'
|
||||
|
||||
function Fork(Path, ArrArgs?): TeraChildProcess {
|
||||
ArrArgs = ArrArgs || [];
|
||||
if (global.LOCAL_RUN)
|
||||
ArrArgs.push("LOCALRUN");
|
||||
@ -690,8 +691,8 @@ function Fork(Path, ArrArgs?) {
|
||||
ArrArgs.push("DEV_MODE");
|
||||
glPortDebug++;
|
||||
var execArgv = [];
|
||||
var Worker = child_process.fork(Path, ArrArgs, { execArgv: execArgv });
|
||||
return Worker;
|
||||
var Worker = fork(Path, ArrArgs, { execArgv: execArgv });
|
||||
return Worker as any;
|
||||
};
|
||||
global.SpeedSignLib = 0;
|
||||
global.TestSignLib = TestSignLib;
|
||||
|
@ -12,10 +12,18 @@ global.PROCESS_NAME = "POW";
|
||||
global.POWPROCESS = 1;
|
||||
import "../core/library"
|
||||
import "../core/crypto-library"
|
||||
import "../core/terahashmining"
|
||||
import { CreatePOWVersionX } from "../core/terahashmining"
|
||||
var PROCESS = process;
|
||||
if (process.send && !global.DEBUGPROCESS) {
|
||||
process.send({ cmd: "online", message: "OK" });
|
||||
global.ToLogClient = function(Str, StrKey, bFinal) {
|
||||
process.send({
|
||||
cmd: "ToLogClient",
|
||||
Str: "" + Str,
|
||||
StrKey: StrKey,
|
||||
bFinal: bFinal
|
||||
});
|
||||
};
|
||||
} else {
|
||||
PROCESS = global.DEBUGPROCESS;
|
||||
}
|
||||
@ -30,7 +38,7 @@ PROCESS.on('message', function(msg) {
|
||||
StartHashPump(FastBlock);
|
||||
FastBlock.RunCount = 0;
|
||||
try {
|
||||
if (global.CreatePOWVersionX(FastBlock))
|
||||
if (CreatePOWVersionX(FastBlock))
|
||||
process.send({
|
||||
cmd: "POW",
|
||||
BlockNum: FastBlock.BlockNum,
|
||||
@ -88,9 +96,14 @@ function CalcPOWHash() {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (global.CreatePOWVersionX(Block))
|
||||
if (CreatePOWVersionX(Block))
|
||||
process.send({
|
||||
cmd: "POW", BlockNum: Block.BlockNum, SeqHash: Block.SeqHash, Hash: Block.Hash, PowHash: Block.PowHash, AddrHash: Block.AddrHash,
|
||||
cmd: "POW",
|
||||
BlockNum: Block.BlockNum,
|
||||
SeqHash: Block.SeqHash,
|
||||
Hash: Block.Hash,
|
||||
PowHash: Block.PowHash,
|
||||
AddrHash: Block.AddrHash,
|
||||
Num: Block.Num
|
||||
});
|
||||
} catch (e) {
|
||||
@ -128,7 +141,7 @@ function PumpHash() {
|
||||
EndTime = CurTime;
|
||||
return;
|
||||
}
|
||||
global.CreatePOWVersionX(global.BlockPump, 1);
|
||||
CreatePOWVersionX(global.BlockPump, 1);
|
||||
} else {
|
||||
var Delta = CurTime - EndTime;
|
||||
var PeriodPercent = 100 * Delta / global.CONSENSUS_PERIOD_TIME;
|
||||
|
Loading…
Reference in New Issue
Block a user