Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Disabling broadcasts while round is ticking #82.
Browse files Browse the repository at this point in the history
  • Loading branch information
karmacoma committed May 22, 2016
1 parent e4915df commit c47e373
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions modules/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,8 @@ Blocks.prototype.sandboxApi = function (call, args, cb) {

// Events
Blocks.prototype.onReceiveBlock = function (block) {
// When client is not loaded, is syncing or round is ticking
// Do not receive new blocks as client is not ready to receive them
if (!private.loaded || modules.loader.syncing() || modules.round.ticking()) {
return;
}
Expand Down
4 changes: 3 additions & 1 deletion modules/delegates.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,10 @@ private.loop = function (cb) {
return setImmediate(cb);
}

// When client is not loaded, is syncing or round is ticking
// Do not try to forge new blocks as client is not ready
if (!private.loaded || modules.loader.syncing() || !modules.round.loaded() || modules.round.ticking()) {
library.logger.debug('Loop:', 'node not ready');
library.logger.debug('Loop:', 'client not ready');
return setImmediate(cb);
}

Expand Down
6 changes: 5 additions & 1 deletion modules/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -452,9 +452,13 @@ private.hashsum = function (obj) {

// Public methods
Transport.prototype.broadcast = function (config, options, cb) {
if (modules.loader.syncing() || !private.loaded) {
// When client is not loaded, is syncing or round is ticking
// Skip broadcast as client is not ready to make them
if (!private.loaded || modules.loader.syncing() || modules.round.ticking()) {
library.logger.debug("Skipping broadcast, client is not ready");
return cb && setImmediate(cb);
}

config.limit = config.limit || 1;
modules.peer.list(config, function (err, peers) {
if (!err) {
Expand Down

0 comments on commit c47e373

Please sign in to comment.