Skip to content

Commit

Permalink
Merge branch 'no-restart'
Browse files Browse the repository at this point in the history
  • Loading branch information
ibudisteanu committed Dec 18, 2021
2 parents 43565c0 + 3d783d6 commit c9b60d0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,6 @@ class InterfaceBlockchain extends InterfaceBlockchainBasic{

let block = await this._loadBlock( index, undefined, revertActions);

if (index > 0 && index % 50000 === 0)
await this.db.restart();

if (index > 0 && index % 10000 === 0)
await this.blocks.savingManager.saveBlockchain();

Expand All @@ -307,8 +304,6 @@ class InterfaceBlockchain extends InterfaceBlockchainBasic{

await this.blocks.savingManager.saveBlockchain();

await this.db.restart();

} catch (exception){
console.error("Error loading block", index, exception);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import MiniBlockchain from "./Mini-Blockchain";
import MiniBlockchainAccountantTree from '../state/Mini-Blockchain-Accountant-Tree'
import global from "consts/global"
import Log from 'common/utils/logging/Log';
import Utils from "../../../utils/helpers/Utils";

class MiniBlockchainAdvanced extends MiniBlockchain{

Expand Down Expand Up @@ -87,6 +88,8 @@ class MiniBlockchainAdvanced extends MiniBlockchain{

let save = async () => {

console.info("accountant tree saveMiniBlockchain called!");

let length = this.blocks.length;
let serialization = this.accountantTree.serializeMiniAccountant(true, );

Expand All @@ -98,6 +101,8 @@ class MiniBlockchainAdvanced extends MiniBlockchain{
console.info("accountant tree", this.accountantTree.root.hash.toString("hex"));
console.info("accountant tree", this.accountantTree.root.edges.length, serialization.length );

await Utils.sleep(5000);

if (!(await this.accountantTree.saveMiniAccountant(true, "accountantTree", serialization)))
throw {message: "saveMiniAccountant couldn't be saved"};

Expand All @@ -108,6 +113,8 @@ class MiniBlockchainAdvanced extends MiniBlockchain{

console.info("accountant tree saving profs");

await Utils.sleep(5000);

if ( !(await this.prover.provesCalculated._saveProvesCalculated()) )
throw { message: "save proves calculated couldn't be saved" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class MiniBlockchainAccountantTree extends MiniBlockchainAccountantTreeEvents {
}

async saveMiniAccountant(includeHashes, name, serialization, timeout) {
return await this.saveTree(name || "accountantTree", includeHashes, serialization, timeout);
return this.saveTree(name || "accountantTree", includeHashes, serialization, timeout);
}

async loadMiniAccountant(buffer, offset, includeHashes, name = "accountantTree", showUpdate = true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class PPoWBlockchainProvesCalculated{

try{

let buffer = await this.db.get(key, 20000, 20, true);
let buffer = await this.db.get(key);

if ( !buffer || !Buffer.isBuffer(buffer)) {
console.error("Proof for key "+key+" was not found");
Expand Down
5 changes: 1 addition & 4 deletions src/common/blockchain/utils/saving-manager/Saving-Manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ class SavingManager{

await block.saveBlock();

if (block.height % 5000 === 0)
await this.blockchain.db.restart();

} catch (exception){

Log.error("Saving raised an Error", Log.LOG_TYPE.SAVING_MANAGER, exception);
Expand Down Expand Up @@ -173,7 +170,7 @@ class SavingManager{

async saveBlockchainLength(length ){

let answer = await this.blockchain.db.save( this.blockchain._blockchainFileName, length, 20000, 1000000) ;
let answer = await this.blockchain.db.save( this.blockchain._blockchainFileName, length, 20000 ) ;

if (!answer) {
Log.error("Error saving the blocks.length", Log.LOG_TYPE.SAVING_MANAGER);
Expand Down
Loading

0 comments on commit c9b60d0

Please sign in to comment.