feat: alpine 0.0.1 version complate
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@@ -10,9 +10,10 @@
|
||||
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
const DBLib = require("./db");
|
||||
const DBRow = require("./db-row");
|
||||
global.BlockDB = new DBLib();
|
||||
import Db from './db'
|
||||
import DBRow from './db-row'
|
||||
import CCode from '../code'
|
||||
global.BlockDB = new Db();
|
||||
global.BLOCK_HEADER_SIZE = 150;
|
||||
const FILE_NAME_HEADER = "block-header";
|
||||
const FILE_NAME_BODY = "block-body";
|
||||
@@ -33,8 +34,7 @@ const FORMAT_HEADER_VERSION2 = "{FilePos:uint}";
|
||||
const FILE_NAME_HEADER2 = "block-header2";
|
||||
const WorkStructHeader2 = {};
|
||||
const DEFAULT_DB_VERSION = 2;
|
||||
module.exports = class CDB extends require("../code")
|
||||
{
|
||||
export default class CDB extends CCode {
|
||||
DBHeader100
|
||||
BlockNumDB
|
||||
BlockNumDBMin
|
||||
@@ -70,6 +70,9 @@ module.exports = class CDB extends require("../code")
|
||||
this.BlockNumDBMin = StateTX.BlockNumMin
|
||||
}
|
||||
}
|
||||
GetBlock(num, bToMem, bReadBody): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
LoadMemBlocksOnStart() {
|
||||
this.CurrentBlockNum = global.GetCurrentBlockNumByTime()
|
||||
for (var i = this.BlockNumDB - global.BLOCK_COUNT_IN_MEMORY; i <= this.BlockNumDB; i++)
|
||||
@@ -223,6 +226,9 @@ module.exports = class CDB extends require("../code")
|
||||
}
|
||||
return Ret;
|
||||
}
|
||||
OnWriteBlock(Block) {
|
||||
//defiend in transaction-validator.ts(CSmartContract)
|
||||
}
|
||||
PreSaveDataTreeToDB(Block) {
|
||||
var Ret = this.WriteBodyDB(Block);
|
||||
if (Ret) {
|
||||
@@ -290,6 +296,9 @@ module.exports = class CDB extends require("../code")
|
||||
Block.TrDataLen = TrDataLen
|
||||
return true;
|
||||
}
|
||||
CheckSeqHashDB(Block, StrError): any {
|
||||
//defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
WriteBlockHeaderDB(Block, bPreSave?) {
|
||||
if (!bPreSave && Block.BlockNum > this.BlockNumDBMin + global.BLOCK_PROCESSING_LENGTH2) {
|
||||
if (global.USE_CHECK_SAVE_DB)
|
||||
@@ -570,6 +579,12 @@ module.exports = class CDB extends require("../code")
|
||||
this.CreateGenesisBlocks()
|
||||
this.StartSyncBlockchain()
|
||||
}
|
||||
CreateGenesisBlocks() {
|
||||
// defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
StartSyncBlockchain(Node?, bSilent?, bCheckPoint?) {
|
||||
// defiend in block-loader.ts(CBlock)
|
||||
}
|
||||
ClearBufMap() {
|
||||
this.MapHeader = {}
|
||||
}
|
||||
@@ -888,7 +903,7 @@ module.exports = class CDB extends require("../code")
|
||||
var SeqHash = global.CalcHashFromArray(arr, true);
|
||||
return SeqHash;
|
||||
}
|
||||
CheckCreateTicketObject(Tr, BlockNum, SetTxID) {
|
||||
CheckCreateTicketObject(Tr, BlockNum?, SetTxID?) {
|
||||
if (!Tr.HashPow && Tr.HashTicket) {
|
||||
Tr.num = BlockNum
|
||||
var FullHashTicket = [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];
|
||||
@@ -902,7 +917,7 @@ module.exports = class CDB extends require("../code")
|
||||
Tr.TxID = global.GetHexFromArr(FullHashTicket.slice(0, global.TR_TICKET_HASH_LENGTH + 6))
|
||||
}
|
||||
}
|
||||
CheckCreateTransactionObject(Tr, SetTxID, NotPrioritet?) {
|
||||
CheckCreateTransactionObject(Tr, SetTxID?, NotPrioritet?) {
|
||||
if (!Tr.HashPow) {
|
||||
var Body = Tr.body;
|
||||
Tr.IsTx = 1
|
||||
@@ -913,17 +928,6 @@ module.exports = class CDB extends require("../code")
|
||||
Tr.HASH = global.shaarr(Body)
|
||||
Tr.HashTicket = Tr.HASH.slice(0, global.TR_TICKET_HASH_LENGTH)
|
||||
this.CheckCreateTicketObject(Tr, Tr.num, SetTxID)
|
||||
Tr.Prioritet = global.MAX_LENGTH_SENDER_MAP
|
||||
if (!NotPrioritet && this.GetSenderPrioritet) {
|
||||
var App = global.DAppByType[Body[0]];
|
||||
if (App) {
|
||||
Tr.SenderNum = App.GetSenderNum(Tr.num, Body)
|
||||
if (Tr.SenderNum && Tr.SenderNum > 0) {
|
||||
Tr.Prioritet = this.GetSenderPrioritet(Tr.num, Tr.SenderNum)
|
||||
Tr.TimePow = Tr.Prioritet + Tr.power
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
BlockChainToBuf(WriteNum, StartNum, EndBlockNum) {
|
||||
@@ -1033,3 +1037,19 @@ global.GetNodeStrPort = function(Node) {
|
||||
return "" + arr[2] + "." + arr[3];
|
||||
}
|
||||
};
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
//#region block-db.ts
|
||||
BlockDB: any;
|
||||
BLOCK_HEADER_SIZE: number;
|
||||
BLOCK_HEADER_SIZE2: number;
|
||||
DB_VERSION: number;
|
||||
AddInfoChain: Function;
|
||||
AddInfoBlock: Function;
|
||||
GetNodeStrPort: Function;
|
||||
NO_CHECK_BLOCKNUM_ONSTART: number;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,18 @@
|
||||
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
import Db from './db'
|
||||
|
||||
module.exports = class CDBState extends require("./db")
|
||||
{
|
||||
private FileName;
|
||||
private DataSize;
|
||||
private Format;
|
||||
private WorkStruct;
|
||||
// private FileNameFull;
|
||||
// private LastHash;
|
||||
// private WasUpdate;
|
||||
private BufMap;
|
||||
private BufMapCount;
|
||||
class DBRow extends Db {
|
||||
FileName;
|
||||
DataSize;
|
||||
Format;
|
||||
WorkStruct;
|
||||
FileNameFull;
|
||||
LastHash;
|
||||
WasUpdate;
|
||||
BufMap;
|
||||
BufMapCount;
|
||||
|
||||
constructor(FileName, DataSize, Format, bReadOnly) {
|
||||
super()
|
||||
@@ -29,10 +29,10 @@ module.exports = class CDBState extends require("./db")
|
||||
this.DataSize = DataSize
|
||||
this.Format = Format
|
||||
this.WorkStruct = {}
|
||||
// var FI = this.OpenDBFile(this.FileName, !bReadOnly);
|
||||
// this.FileNameFull = FI.fname
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
var FI = this.OpenDBFile(this.FileName, !bReadOnly);
|
||||
this.FileNameFull = FI.fname
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
this.BufMap = {}
|
||||
this.BufMapCount = 0
|
||||
setInterval(this.CheckBufMap.bind(this), 1000)
|
||||
@@ -48,8 +48,8 @@ module.exports = class CDBState extends require("./db")
|
||||
}
|
||||
Write(Data, RetBuf) {
|
||||
var startTime = process.hrtime();
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
this.CheckNewNum(Data)
|
||||
Data.Num = Math.trunc(Data.Num)
|
||||
this.DeleteMap(Data.Num)
|
||||
@@ -118,8 +118,8 @@ module.exports = class CDBState extends require("./db")
|
||||
Position = 0
|
||||
var FI = this.OpenDBFile(this.FileName, 1);
|
||||
if (Position < FI.size) {
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
if (LastNum < 0)
|
||||
global.ToLog("Truncate " + this.FileName + " from 0", 2)
|
||||
FI.size = Position
|
||||
@@ -227,3 +227,5 @@ module.exports = class CDBState extends require("./db")
|
||||
this.CloseDBFile(this.FileName)
|
||||
}
|
||||
};
|
||||
|
||||
export default DBRow
|
||||
@@ -11,11 +11,11 @@
|
||||
"use strict";
|
||||
import * as fs from 'fs'
|
||||
|
||||
module.exports = class {
|
||||
private DBMap;
|
||||
// private LastHash;
|
||||
// private WasUpdate;
|
||||
private WasCheckPathDB;
|
||||
class Db {
|
||||
DBMap;
|
||||
LastHash;
|
||||
WasUpdate;
|
||||
WasCheckPathDB;
|
||||
|
||||
constructor() {
|
||||
this.DBMap = {}
|
||||
@@ -24,9 +24,9 @@ module.exports = class {
|
||||
var Path = global.GetDataPath("DB");
|
||||
global.CheckCreateDir(Path)
|
||||
}
|
||||
CloseDBFile(name, bdelete) {
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
CloseDBFile(name, bdelete?) {
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
var Item = this.DBMap[name];
|
||||
if (Item) {
|
||||
let bDelete = bdelete;
|
||||
@@ -40,23 +40,23 @@ module.exports = class {
|
||||
global.ToLog(err)
|
||||
})
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
global.ToLog(err)
|
||||
}
|
||||
})
|
||||
delete this.DBMap[name]
|
||||
}
|
||||
}
|
||||
OpenDBFile(name, bWrite, bExist) {
|
||||
OpenDBFile(name, bWrite?, bExist?) {
|
||||
if (bWrite && global.READ_ONLY_DB) {
|
||||
global.ToLogTrace("CANNOT WRITE - DB IN READ_ONLY MODE!!!")
|
||||
process.exit()
|
||||
}
|
||||
if (bWrite)
|
||||
if (bWrite) {
|
||||
CheckStartOneProcess(name + "-run")
|
||||
// this.LastHash = undefined
|
||||
// this.WasUpdate = 1
|
||||
}
|
||||
this.LastHash = undefined
|
||||
this.WasUpdate = 1
|
||||
var Item = this.DBMap[name];
|
||||
if (Item === undefined) {
|
||||
if (!this.WasCheckPathDB) {
|
||||
@@ -82,7 +82,7 @@ module.exports = class {
|
||||
}
|
||||
};
|
||||
var MapCheckProcess = {};
|
||||
var BlockDB = new module.exports();
|
||||
var BlockDB = new Db();
|
||||
|
||||
function CheckStartOneProcess(Name) {
|
||||
if (global.UpdateMode)
|
||||
@@ -96,11 +96,21 @@ function CheckStartOneProcess(Name) {
|
||||
}
|
||||
try {
|
||||
BlockDB.OpenDBFile(Name);
|
||||
}
|
||||
catch (e) {
|
||||
} catch (e) {
|
||||
global.ToLog("****** DETECT START ANOTHER PROCESS for: " + Name);
|
||||
global.ToLogTrace("EXIT");
|
||||
process.exit();
|
||||
}
|
||||
};
|
||||
global.CheckStartOneProcess = CheckStartOneProcess;
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
//#region dapp.ts
|
||||
CheckStartOneProcess: Function;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Db;
|
||||
Reference in New Issue
Block a user