Skip to content

Commit

Permalink
Removed the automatic interval loop from 'finalizePersistingOfChunkBu…
Browse files Browse the repository at this point in the history
…ndle()' due to it causing many bugs with concurrent PoW

(cherry picked from commit d6946e5)
  • Loading branch information
loehnertz committed Feb 8, 2018
1 parent b7d4f94 commit 23d48b9
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions app/tanglestash.js
Expand Up @@ -252,9 +252,11 @@ class Tanglestash {
await this.persistChunk(this.chunkBundle[chunk]);
}

return await this.finalizePersistingOfChunkBundle().catch((err) => {
try {
return await this.finalizePersistingOfChunkBundle();
} catch (err) {
throw err;
});
}
}

/**
Expand Down Expand Up @@ -297,25 +299,20 @@ class Tanglestash {
* Kicks off the persisting of the Chunk Table once every chunk containing content is successfully persisted.
*/
async finalizePersistingOfChunkBundle() {
return new Promise((resolve, reject) => {
let finishedCheck = setInterval(async () => {
if (this.successfulChunks === this.totalChunkAmount) {
clearInterval(finishedCheck);
try {
resolve(await this.finalizeChunkTable());
} catch (err) {
reject(err);
}
} else {
for (let chunk in this.failedChunks) {
let failedChunk = this.chunkBundle[this.failedChunks[chunk]];
if (!failedChunk["persisted"]) {
await this.persistChunk(failedChunk);
}
}
while (this.successfulChunks !== this.totalChunkAmount) {
for (let chunk in this.failedChunks) {
let failedChunk = this.chunkBundle[this.failedChunks[chunk]];
if (!failedChunk["persisted"]) {
await this.persistChunk(failedChunk);
}
}, 1234);
});
}
}

try {
return await this.finalizeChunkTable();
} catch (err) {
throw err;
}
}

/**
Expand Down

0 comments on commit 23d48b9

Please sign in to comment.