Skip to content

Commit

Permalink
Syncing works too
Browse files Browse the repository at this point in the history
  • Loading branch information
Insoleet committed Jul 12, 2016
1 parent fd981c9 commit 4f79d74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
14 changes: 8 additions & 6 deletions app/lib/pulling.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ module.exports = {
* Sugar function. Apply a bunch of blocks instead of one.
* @param blocks
*/
dao.applyBranch = (blocks) => co(function *() {
for (const block of blocks) {
yield dao.applyMainBranch(block);
}
return true;
});
if (!dao.applyBranch) {
dao.applyBranch = (blocks) => co(function *() {
for (const block of blocks) {
yield dao.applyMainBranch(block);
}
return true;
});
}

/**
* Binary search algorithm to find the common root block between a local and a remote blockchain.
Expand Down
13 changes: 10 additions & 3 deletions app/lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,24 @@ function Synchroniser (server, host, port, conf, interactive) {
return blocks;
}),

applyMainBranch: (blocks) => co(function *() {

applyBranch: (blocks) => co(function *() {
if (cautious) {
for (const block of blocks) {
const addedBlock = yield server.BlockchainService.submitBlock(block, true, constants.FORK_ALLOWED);
server.streamPush(addedBlock);
yield dao.applyMainBranch(block);
}
} else {
yield server.BlockchainService.saveBlocksInMainBranch(blocks);
}
this.lastBlock = blocks[blocks.length - 1];
watcher.appliedPercent(Math.floor(blocks[blocks.length - 1].number / to * 100));
return true;
}),

applyMainBranch: (block) => co(function *() {
const addedBlock = yield server.BlockchainService.submitBlock(block, true, constants.FORK_ALLOWED);
server.streamPush(addedBlock);
watcher.appliedPercent(Math.floor(block.number / to * 100));
}),

// Eventually remove forks later on
Expand Down

0 comments on commit 4f79d74

Please sign in to comment.