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