2019-07-10 04:01:15 +00:00
|
|
|
/*
|
|
|
|
* @project: TERA
|
|
|
|
* @version: Development (beta)
|
|
|
|
* @license: MIT (not for evil)
|
|
|
|
* @copyright: Yuriy Ivanov (Vtools) 2017-2019 [progr76@gmail.com]
|
|
|
|
* Web: https://terafoundation.org
|
|
|
|
* Twitter: https://twitter.com/terafoundation
|
|
|
|
* Telegram: https://t.me/terafoundation
|
|
|
|
*/
|
2019-07-11 05:35:16 +00:00
|
|
|
const fs = require('fs')
|
2019-07-10 04:01:15 +00:00
|
|
|
global.RunOnUpdate = RunOnUpdate;
|
|
|
|
|
|
|
|
function RunOnUpdate() {
|
|
|
|
var fname = global.GetDataPath("DB/update.lst");
|
2019-07-10 07:59:04 +00:00
|
|
|
var UpdateInfo = global.LoadParams(fname, { UPDATE_NUM_COMPLETE: 1071 });
|
2019-07-10 04:01:15 +00:00
|
|
|
if (!UpdateInfo.UPDATE_NUM_COMPLETE)
|
|
|
|
UpdateInfo.UPDATE_NUM_COMPLETE = 0;
|
|
|
|
var CurNum = UpdateInfo.UPDATE_NUM_COMPLETE;
|
2019-07-10 07:59:04 +00:00
|
|
|
if (CurNum !== global.UPDATE_CODE_VERSION_NUM) {
|
|
|
|
UpdateInfo.UPDATE_NUM_COMPLETE = global.UPDATE_CODE_VERSION_NUM;
|
2019-07-10 04:01:15 +00:00
|
|
|
global.ToLog("UPDATER Start");
|
2019-07-10 07:59:04 +00:00
|
|
|
global.SaveParams(fname, UpdateInfo);
|
2019-07-10 04:01:15 +00:00
|
|
|
if (global.TEST_NETWORK || global.LOCAL_RUN) {
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
}
|
|
|
|
global.ToLog("UPDATER Finish");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function CreateHeadersHash100() {
|
|
|
|
global.ToLog("CreateHeadersHash100");
|
2019-07-10 09:53:52 +00:00
|
|
|
// const DBRow = require("./db/db-row");
|
2019-07-10 04:01:15 +00:00
|
|
|
global.UpdateMode = 1;
|
|
|
|
var DB = global.SERVER.DBHeader100;
|
|
|
|
var Num = 0;
|
|
|
|
var PrevHash100 = [];
|
|
|
|
while (1) {
|
|
|
|
var Block = global.SERVER.ReadBlockHeaderDB(Num);
|
|
|
|
if (!Block)
|
|
|
|
break;
|
|
|
|
var Hash100;
|
|
|
|
if (Num === 0)
|
|
|
|
Hash100 = [];
|
|
|
|
else
|
2019-07-10 07:59:04 +00:00
|
|
|
Hash100 = global.sha3arr2(PrevHash100, Block.Hash);
|
2019-07-10 04:01:15 +00:00
|
|
|
DB.Write({ Num: Num / 100, Hash100: Hash100, Hash: Block.Hash });
|
|
|
|
if (Num % 1000000 === 0)
|
|
|
|
global.ToLog("Create Hash100:" + Num);
|
|
|
|
PrevHash100 = Hash100;
|
|
|
|
Num += 100;
|
|
|
|
}
|
|
|
|
global.UpdateMode = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
function CheckRewriteTr(Num, StrHash, StartRewrite) {
|
2019-07-10 07:59:04 +00:00
|
|
|
if (global.SERVER.BlockNumDB < StartRewrite)
|
2019-07-10 04:01:15 +00:00
|
|
|
return "NO";
|
|
|
|
var AccountsHash = global.DApps.Accounts.GetHashOrUndefined(Num);
|
|
|
|
if (!AccountsHash || global.GetHexFromArr(AccountsHash) !== StrHash) {
|
|
|
|
global.ToLog("START REWRITE ERR ACTS TRANSACTIONS");
|
2019-07-10 07:59:04 +00:00
|
|
|
global.SERVER.ReWriteDAppTransactions(global.SERVER.BlockNumDB - StartRewrite);
|
2019-07-10 04:01:15 +00:00
|
|
|
return "Rewrite";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function CheckRewriteAllTr2(Num, StrHash, Num2, StrHash2) {
|
|
|
|
if (global.LOCAL_RUN || global.TEST_NETWORK)
|
|
|
|
return "NONE";
|
|
|
|
var MaxNum = global.SERVER.GetMaxNumBlockDB();
|
2019-07-10 07:59:04 +00:00
|
|
|
if (MaxNum < global.START_BLOCK_ACCOUNT_HASH)
|
2019-07-10 04:01:15 +00:00
|
|
|
return "NONE";
|
|
|
|
var AccountsHash = global.DApps.Accounts.GetHashOrUndefined(Num);
|
|
|
|
var AccountsHash2 = global.DApps.Accounts.GetHashOrUndefined(Num2);
|
|
|
|
if (AccountsHash2 && global.GetHexFromArr(AccountsHash2) === StrHash2)
|
|
|
|
return "OK";
|
|
|
|
if (AccountsHash && global.GetHexFromArr(AccountsHash) !== StrHash) {
|
|
|
|
global.ToLog("***************** START REWRITE ALL DAPPS");
|
|
|
|
global.UpdateMode = 1;
|
2019-07-10 07:59:04 +00:00
|
|
|
for (var key in global.DApps) {
|
|
|
|
global.DApps[key].ClearDataBase();
|
2019-07-10 04:01:15 +00:00
|
|
|
}
|
|
|
|
global.UpdateMode = 0;
|
|
|
|
return "Rewrite";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function CheckRewriteAllTr(Num, StrHash, Num2, StrHash2) {
|
|
|
|
if (global.LOCAL_RUN || global.TEST_NETWORK)
|
|
|
|
return "NONE";
|
|
|
|
var MaxNum = global.SERVER.GetMaxNumBlockDB();
|
2019-07-10 07:59:04 +00:00
|
|
|
if (MaxNum < global.START_BLOCK_ACCOUNT_HASH)
|
2019-07-10 04:01:15 +00:00
|
|
|
return "NONE";
|
|
|
|
var AccountsHash = global.DApps.Accounts.GetHashOrUndefined(Num);
|
|
|
|
if (AccountsHash && global.GetHexFromArr(AccountsHash) !== StrHash) {
|
|
|
|
global.ToLog("***************** START REWRITE ALL DAPPS");
|
|
|
|
global.UpdateMode = 1;
|
2019-07-10 07:59:04 +00:00
|
|
|
for (var key in global.DApps) {
|
|
|
|
global.DApps[key].ClearDataBase();
|
2019-07-10 04:01:15 +00:00
|
|
|
}
|
|
|
|
global.UpdateMode = 0;
|
|
|
|
return "Rewrite";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "OK";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
global.CheckRewriteTr = CheckRewriteTr;
|
|
|
|
|
|
|
|
function RecreateAccountRest1() {
|
|
|
|
var name = "accounts-rest";
|
|
|
|
var fname = global.GetDataPath("DB/" + name);
|
|
|
|
if (fs.existsSync(fname)) {
|
|
|
|
global.ToLog("Delete " + fname);
|
|
|
|
fs.unlinkSync(fname);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function RecreateAccountHashDB3() {
|
|
|
|
var name = "accounts-hash2";
|
|
|
|
var fname = global.GetDataPath("DB/" + name);
|
|
|
|
if (fs.existsSync(fname)) {
|
|
|
|
global.UpdateMode = 1;
|
|
|
|
global.ToLog("Start updating " + name);
|
|
|
|
const DBRow = require("../core/db/db-row");
|
|
|
|
var DB0 = new DBRow(name, 6 + 32 + 32 + 10, "{BlockNum:uint, Hash:hash, SumHash:hash, Reserve: arr10}");
|
|
|
|
var DB3 = global.DApps.Accounts.DBAccountsHash;
|
|
|
|
for (var num = 0; true; num++) {
|
|
|
|
var Item = DB0.Read(num);
|
|
|
|
if (!Item)
|
|
|
|
break;
|
|
|
|
Item.AccHash = Item.Hash;
|
|
|
|
DB3.Write(Item);
|
|
|
|
}
|
|
|
|
global.ToLog("Finish updating " + name);
|
|
|
|
DB0.Close();
|
|
|
|
DB3.Close();
|
|
|
|
global.UpdateMode = 0;
|
|
|
|
fs.unlinkSync(fname);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-07-11 05:35:16 +00:00
|
|
|
import '../core/db/db-row'
|
|
|
|
|
2019-07-10 04:01:15 +00:00
|
|
|
function ReWriteDBSmartWrite() {
|
|
|
|
global.UpdateMode = 1;
|
|
|
|
global.ToLog("Start ReWriteDBSmartWrite");
|
|
|
|
for (var num = 0; true; num++) {
|
|
|
|
var Item = global.DApps.Smart.DBSmart.Read(num);
|
|
|
|
if (!Item)
|
|
|
|
break;
|
2019-07-10 07:59:04 +00:00
|
|
|
var Body = global.GetArrFromHex(GetBufferFromObject(Item, global.DApps.Smart.FORMAT_ROW, 20000, {}));
|
2019-07-10 04:01:15 +00:00
|
|
|
if (Body.length > 15000)
|
|
|
|
global.ToLog("Smart " + Item.Num + ". " + Item.Name + " length=" + Body.length);
|
|
|
|
global.DApps.Smart.DBSmartWrite(Item);
|
|
|
|
}
|
|
|
|
global.ToLog("Finish ReWriteDBSmartWrite");
|
|
|
|
global.DApps.Smart.DBSmart.Close();
|
|
|
|
global.UpdateMode = 0;
|
|
|
|
};
|