Skip to content
Snippets Groups Projects
Commit 4f79d74c authored by inso's avatar inso
Browse files

Syncing works too

parent fd981c9e
No related branches found
No related tags found
No related merge requests found
...@@ -15,12 +15,14 @@ module.exports = { ...@@ -15,12 +15,14 @@ module.exports = {
* Sugar function. Apply a bunch of blocks instead of one. * Sugar function. Apply a bunch of blocks instead of one.
* @param blocks * @param blocks
*/ */
if (!dao.applyBranch) {
dao.applyBranch = (blocks) => co(function *() { dao.applyBranch = (blocks) => co(function *() {
for (const block of blocks) { for (const block of blocks) {
yield dao.applyMainBranch(block); yield dao.applyMainBranch(block);
} }
return true; return true;
}); });
}
/** /**
* Binary search algorithm to find the common root block between a local and a remote blockchain. * Binary search algorithm to find the common root block between a local and a remote blockchain.
......
...@@ -140,17 +140,24 @@ function Synchroniser (server, host, port, conf, interactive) { ...@@ -140,17 +140,24 @@ function Synchroniser (server, host, port, conf, interactive) {
return blocks; return blocks;
}), }),
applyMainBranch: (blocks) => co(function *() {
applyBranch: (blocks) => co(function *() {
if (cautious) { if (cautious) {
for (const block of blocks) { for (const block of blocks) {
const addedBlock = yield server.BlockchainService.submitBlock(block, true, constants.FORK_ALLOWED); yield dao.applyMainBranch(block);
server.streamPush(addedBlock);
} }
} else { } else {
yield server.BlockchainService.saveBlocksInMainBranch(blocks); yield server.BlockchainService.saveBlocksInMainBranch(blocks);
} }
this.lastBlock = blocks[blocks.length - 1]; this.lastBlock = blocks[blocks.length - 1];
watcher.appliedPercent(Math.floor(blocks[blocks.length - 1].number / to * 100)); 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 // Eventually remove forks later on
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment