@@ -65,11 +65,19 @@ export default class CBlock extends CRest {
|
||||
if (Num < 0)
|
||||
return undefined;
|
||||
var Block: any = {
|
||||
BlockNum: Num, TreeHash: [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], AddrHash: global.DEVELOP_PUB_KEY0, Hash: this.GetHashGenesis(Num), PowHash: this.GetHashGenesis(Num), PrevHash: [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], SeqHash: [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], SumHash: [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], Comment1: "GENESIS", Comment2: "", TrCount: 0, TrDataPos: 0, TrDataLen: 0,
|
||||
BlockNum: Num,
|
||||
TreeHash: [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],
|
||||
AddrHash: global.DEVELOP_PUB_KEY0,
|
||||
Hash: this.GetHashGenesis(Num),
|
||||
PowHash: this.GetHashGenesis(Num),
|
||||
PrevHash: [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],
|
||||
SeqHash: [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],
|
||||
SumHash: [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],
|
||||
Comment1: "GENESIS",
|
||||
Comment2: "",
|
||||
TrCount: 0,
|
||||
TrDataPos: 0,
|
||||
TrDataLen: 0,
|
||||
};
|
||||
Block.SeqHash = this.GetSeqHash(Block.BlockNum, Block.PrevHash, Block.TreeHash)
|
||||
Block.SumPow = 0
|
||||
@@ -138,7 +146,7 @@ export default class CBlock extends CRest {
|
||||
var PrevHash = global.CalcHashFromArray(arr, true);
|
||||
return PrevHash;
|
||||
}
|
||||
StartSyncBlockchain(Node?, bSilent?, bCheckPoint?) {
|
||||
StartSyncBlockchain(Node?, bSilent?, bCheckPoint?, PrevStartedBlockNum?) {
|
||||
this.FREE_ALL_MEM_CHAINS()
|
||||
if (global.NO_HISTORY_MODE) {
|
||||
this.LoadHistoryMode = 0
|
||||
@@ -152,6 +160,19 @@ export default class CBlock extends CRest {
|
||||
this.RelayMode = false
|
||||
if (!bSilent)
|
||||
this.RelayMode = true
|
||||
var StartBlockNum;
|
||||
if (PrevStartedBlockNum) {
|
||||
var DeltaNum = Math.floor(1.2 * (this.BlockNumDB - PrevStartedBlockNum));
|
||||
if (DeltaNum < 1000)
|
||||
DeltaNum = 1000
|
||||
StartBlockNum = this.BlockNumDB - DeltaNum
|
||||
if (StartBlockNum <= 0)
|
||||
StartBlockNum = 15
|
||||
global.ToLog("Current DeltaNum=" + DeltaNum + " StartBlockNum=" + StartBlockNum, 2)
|
||||
}
|
||||
else {
|
||||
StartBlockNum = this.BlockNumDB
|
||||
}
|
||||
this.LoadHistoryMode = true
|
||||
this.LoadHistoryMessage = !bSilent
|
||||
this.LoadHistoryContext = {
|
||||
@@ -182,7 +203,7 @@ export default class CBlock extends CRest {
|
||||
var DeltaTime = Date.now() - Context.StartTimeHistory;
|
||||
if (DeltaTime > Context.MaxTimeOut) {
|
||||
global.ToLog("DETECT TIMEOUT LOAD")
|
||||
this.StartSyncBlockchain()
|
||||
this.StartSyncBlockchain(undefined, undefined, undefined, Context.BlockNum)
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -230,9 +251,28 @@ export default class CBlock extends CRest {
|
||||
return false;
|
||||
Tree.insert({ hash: LoadHash })
|
||||
var chain: any = {
|
||||
id: 0, Count: 16, BlockNum: Num, IsSum: bIsSum, Hash: LoadHash, time: undefined, FindBlockDB: false, LoadDB: false, LoadCountDB: 0,
|
||||
LoadSumDB: 0, LoadSum: 0, ParentChain: undefined, RootChain: undefined, BlockNumStart: Num, HashStart: LoadHash, IsSumStart: bIsSum,
|
||||
BlockHead: undefined, MapSend: {}, Comment2: "", StopSend: false, Info: "", Error: false,
|
||||
id: 0,
|
||||
Count: 16,
|
||||
BlockNum: Num,
|
||||
IsSum: bIsSum,
|
||||
Hash: LoadHash,
|
||||
time: undefined,
|
||||
FindBlockDB: false,
|
||||
LoadDB: false,
|
||||
LoadCountDB: 0,
|
||||
LoadSumDB: 0,
|
||||
LoadSum: 0,
|
||||
ParentChain: undefined,
|
||||
RootChain: undefined,
|
||||
BlockNumStart: Num,
|
||||
HashStart: LoadHash,
|
||||
IsSumStart: bIsSum,
|
||||
BlockHead: undefined,
|
||||
MapSend: {},
|
||||
Comment2: "",
|
||||
StopSend: false,
|
||||
Info: "",
|
||||
Error: false,
|
||||
};
|
||||
this.ChainBindMethods(chain)
|
||||
chain.AddInfo(StrInfo)
|
||||
@@ -491,6 +531,7 @@ export default class CBlock extends CRest {
|
||||
}
|
||||
else {
|
||||
if (!Context.WasLoadNum) {
|
||||
global.ToLog("Not found: " + Context.BlockNum + " from node:" + global.NodeName(Info.Node), 2)
|
||||
Context.BlockNum = Math.floor(Context.BlockNum - Context.DeltaBlockNum)
|
||||
Context.DeltaBlockNum = Context.DeltaBlockNum * 1.2
|
||||
if (Context.BlockNum < global.BLOCK_PROCESSING_LENGTH2)
|
||||
@@ -775,8 +816,8 @@ export default class CBlock extends CRest {
|
||||
if (global.IsZeroArr(Block.TreeHash)) {
|
||||
Res = this.WriteBlockDB(Block)
|
||||
} else {
|
||||
global.ToLogTrace("global.IsZeroArr(Block.TreeHash)")
|
||||
throw "global.IsZeroArr(Block.TreeHash)";
|
||||
global.ToLogTrace("IsZeroArr(Block.TreeHash)")
|
||||
throw "IsZeroArr(Block.TreeHash)";
|
||||
}
|
||||
}
|
||||
if (!Res) {
|
||||
|
||||
Reference in New Issue
Block a user