Fix bug with feedback loop during shutdown
- Use height to indicate tip change by comparing heights - Give undefined for callback when shutting down
This commit is contained in:
parent
4189e3548a
commit
93ed8bfd8d
|
@ -235,7 +235,7 @@ describe('Daemon Binding Functionality', function() {
|
||||||
describe('tip updates', function() {
|
describe('tip updates', function() {
|
||||||
it('will get an event when the tip is new', function(done) {
|
it('will get an event when the tip is new', function(done) {
|
||||||
this.timeout(4000);
|
this.timeout(4000);
|
||||||
bitcoind.once('tip', function(height) {
|
bitcoind.on('tip', function(height) {
|
||||||
height.should.equal(152);
|
height.should.equal(152);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,8 +10,6 @@ var $ = bitcore.util.preconditions;
|
||||||
|
|
||||||
var daemon = Daemon;
|
var daemon = Daemon;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function Daemon(options) {
|
function Daemon(options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -202,22 +200,20 @@ Daemon.prototype.start = function(options, callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
bitcoindjs.onBlocksReady(function(err, result) {
|
bitcoindjs.onBlocksReady(function(err, result) {
|
||||||
self.emit('ready', result);
|
|
||||||
});
|
|
||||||
|
|
||||||
function onTipUpdateListener(err, result) {
|
function onTipUpdateListener(result) {
|
||||||
if (err) {
|
if (result) {
|
||||||
self.emit('error', err);
|
// Emit and event that the tip was updated
|
||||||
} else {
|
self.emit('tip', result);
|
||||||
// Emit and event that the tip was updated
|
// Recursively wait until the next update
|
||||||
self.emit('tip', result);
|
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursively wait until the next update
|
|
||||||
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
||||||
}
|
|
||||||
|
|
||||||
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
self.emit('ready', result);
|
||||||
|
});
|
||||||
|
|
||||||
setTimeout(function callee() {
|
setTimeout(function callee() {
|
||||||
// Wait until wallet is loaded:
|
// Wait until wallet is loaded:
|
||||||
|
|
|
@ -229,9 +229,9 @@ static void
|
||||||
async_tip_update(uv_work_t *req) {
|
async_tip_update(uv_work_t *req) {
|
||||||
async_tip_update_data *data = static_cast<async_tip_update_data*>(req->data);
|
async_tip_update_data *data = static_cast<async_tip_update_data*>(req->data);
|
||||||
|
|
||||||
int64_t nLastBest = nTimeBestReceived;
|
size_t lastHeight = chainActive.Height();
|
||||||
|
|
||||||
while(nLastBest == nTimeBestReceived && !shutdown_complete) {
|
while(lastHeight == (size_t)chainActive.Height() && !shutdown_complete) {
|
||||||
usleep(1E6);
|
usleep(1E6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,10 +246,13 @@ async_tip_update_after(uv_work_t *req) {
|
||||||
async_tip_update_data *data = static_cast<async_tip_update_data*>(req->data);
|
async_tip_update_data *data = static_cast<async_tip_update_data*>(req->data);
|
||||||
|
|
||||||
Local<Function> cb = data->callback.Get(isolate);
|
Local<Function> cb = data->callback.Get(isolate);
|
||||||
const unsigned argc = 2;
|
const unsigned argc = 1;
|
||||||
|
Local<Value> result = Undefined(isolate);
|
||||||
|
if (!shutdown_complete) {
|
||||||
|
result = NanNew<Number>(data->result);
|
||||||
|
}
|
||||||
Local<Value> argv[argc] = {
|
Local<Value> argv[argc] = {
|
||||||
v8::Null(isolate),
|
Local<Value>::New(isolate, result)
|
||||||
Local<Value>::New(isolate, NanNew<Number>(data->result))
|
|
||||||
};
|
};
|
||||||
TryCatch try_catch;
|
TryCatch try_catch;
|
||||||
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
|
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
|
||||||
|
@ -259,7 +262,6 @@ async_tip_update_after(uv_work_t *req) {
|
||||||
|
|
||||||
delete data;
|
delete data;
|
||||||
delete req;
|
delete req;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NAN_METHOD(OnBlocksReady) {
|
NAN_METHOD(OnBlocksReady) {
|
||||||
|
|
Loading…
Reference in New Issue