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() {
|
||||
it('will get an event when the tip is new', function(done) {
|
||||
this.timeout(4000);
|
||||
bitcoind.once('tip', function(height) {
|
||||
bitcoind.on('tip', function(height) {
|
||||
height.should.equal(152);
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -10,8 +10,6 @@ var $ = bitcore.util.preconditions;
|
|||
|
||||
var daemon = Daemon;
|
||||
|
||||
|
||||
|
||||
function Daemon(options) {
|
||||
var self = this;
|
||||
|
||||
|
@ -202,23 +200,21 @@ Daemon.prototype.start = function(options, callback) {
|
|||
});
|
||||
|
||||
bitcoindjs.onBlocksReady(function(err, result) {
|
||||
self.emit('ready', result);
|
||||
});
|
||||
|
||||
function onTipUpdateListener(err, result) {
|
||||
if (err) {
|
||||
self.emit('error', err);
|
||||
} else {
|
||||
function onTipUpdateListener(result) {
|
||||
if (result) {
|
||||
// Emit and event that the tip was updated
|
||||
self.emit('tip', result);
|
||||
}
|
||||
|
||||
// Recursively wait until the next update
|
||||
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
||||
}
|
||||
}
|
||||
|
||||
bitcoindjs.onTipUpdate(onTipUpdateListener);
|
||||
|
||||
self.emit('ready', result);
|
||||
});
|
||||
|
||||
setTimeout(function callee() {
|
||||
// Wait until wallet is loaded:
|
||||
if (callback) {
|
||||
|
|
|
@ -229,9 +229,9 @@ static void
|
|||
async_tip_update(uv_work_t *req) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
||||
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] = {
|
||||
v8::Null(isolate),
|
||||
Local<Value>::New(isolate, NanNew<Number>(data->result))
|
||||
Local<Value>::New(isolate, result)
|
||||
};
|
||||
TryCatch try_catch;
|
||||
cb->Call(isolate->GetCurrentContext()->Global(), argc, argv);
|
||||
|
@ -259,7 +262,6 @@ async_tip_update_after(uv_work_t *req) {
|
|||
|
||||
delete data;
|
||||
delete req;
|
||||
|
||||
}
|
||||
|
||||
NAN_METHOD(OnBlocksReady) {
|
||||
|
|
Loading…
Reference in New Issue