Upgrades
- Updated to latest bcoin - Gave the db a bit more time to shutdown - Fixed resume functionality if peer disconnects and reconnects later
This commit is contained in:
parent
4e94a374c1
commit
a0031c7e00
@ -119,6 +119,10 @@ DB.prototype.get = function(key, options, callback) {
|
|||||||
|
|
||||||
DB.prototype.put = function(key, value, callback) {
|
DB.prototype.put = function(key, value, callback) {
|
||||||
|
|
||||||
|
if (this._stopping) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
|
||||||
assert(Buffer.isBuffer(key), 'key NOT a buffer as expected.');
|
assert(Buffer.isBuffer(key), 'key NOT a buffer as expected.');
|
||||||
|
|
||||||
if (value) {
|
if (value) {
|
||||||
@ -127,20 +131,12 @@ DB.prototype.put = function(key, value, callback) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var self = this;
|
this._store.put(key, value, callback);
|
||||||
|
|
||||||
if (self._stopping) {
|
|
||||||
callback();
|
|
||||||
}
|
|
||||||
|
|
||||||
self._store.put(key, value, callback);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.batch = function(ops, callback) {
|
DB.prototype.batch = function(ops, callback) {
|
||||||
|
|
||||||
var self = this;
|
if (this._stopping) {
|
||||||
|
|
||||||
if (self._stopping) {
|
|
||||||
return callback();
|
return callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,20 +151,24 @@ DB.prototype.batch = function(ops, callback) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self._store.batch(ops, callback);
|
this._store.batch(ops, callback);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.createReadStream = function(op) {
|
DB.prototype.createReadStream = function(op) {
|
||||||
|
|
||||||
if (this._stopping) {
|
if (this._stopping) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var stream = this._store.createReadStream(op);
|
var stream = this._store.createReadStream(op);
|
||||||
stream.on('error', this._onError.bind(this));
|
stream.on('error', this._onError.bind(this));
|
||||||
return stream;
|
return stream;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.createKeyStream = function(op) {
|
DB.prototype.createKeyStream = function(op) {
|
||||||
|
|
||||||
if (this._stopping) {
|
if (this._stopping) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -183,9 +183,13 @@ DB.prototype.stop = function(callback) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
DB.prototype.close = function(callback) {
|
DB.prototype.close = function(callback) {
|
||||||
if (this._store && this._store.isOpen()) {
|
|
||||||
this._store.close(callback);
|
var self = this;
|
||||||
return;
|
if (self._store && self._store.isOpen()) {
|
||||||
|
// give the db a grace period to settle out
|
||||||
|
return setTimeout(function() {
|
||||||
|
self._store.close(callback);
|
||||||
|
}, 2000);
|
||||||
}
|
}
|
||||||
setImmediate(callback);
|
setImmediate(callback);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -51,8 +51,14 @@ P2P.prototype.getNumberOfPeers = function() {
|
|||||||
|
|
||||||
P2P.prototype.getBlocks = function(filter) {
|
P2P.prototype.getBlocks = function(filter) {
|
||||||
|
|
||||||
|
// this if our peer goes away, but comes back later, we
|
||||||
|
// can restart the last query
|
||||||
|
|
||||||
|
this._currentRequest = filter;
|
||||||
|
|
||||||
var peer = this._getPeer();
|
var peer = this._getPeer();
|
||||||
var blockFilter = this._setResourceFilter(filter, 'blocks');
|
var blockFilter = this._setResourceFilter(filter, 'blocks');
|
||||||
|
|
||||||
peer.sendMessage(this.messages.GetBlocks(blockFilter));
|
peer.sendMessage(this.messages.GetBlocks(blockFilter));
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -255,15 +261,15 @@ P2P.prototype._onPeerBlock = function(peer, message) {
|
|||||||
|
|
||||||
P2P.prototype._onPeerDisconnect = function(peer, addr) {
|
P2P.prototype._onPeerDisconnect = function(peer, addr) {
|
||||||
|
|
||||||
|
this._removePeer(peer);
|
||||||
|
log.info('Disconnected from peer: ' + addr.ip.v4);
|
||||||
|
|
||||||
if (!this.node.stopping) {
|
if (!this.node.stopping) {
|
||||||
log.info('Attempting to reconnect to the p2p network after disconnect signal.');
|
log.info('Attempting to reconnect to the p2p network after disconnect signal.');
|
||||||
this._connect();
|
this._connect();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._removePeer(peer);
|
|
||||||
log.info('Disconnected from peer: ' + addr.ip.v4);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
P2P.prototype._onPeerHeaders = function(peer, message) {
|
P2P.prototype._onPeerHeaders = function(peer, message) {
|
||||||
@ -301,6 +307,13 @@ P2P.prototype._onPeerReady = function(peer, addr) {
|
|||||||
this._addPeer(peer);
|
this._addPeer(peer);
|
||||||
var bestHeight = this._getBestHeight();
|
var bestHeight = this._getBestHeight();
|
||||||
|
|
||||||
|
// if we have a current request, then we will restart that
|
||||||
|
if (this._currentRequest) {
|
||||||
|
log.info('Restarting last query');
|
||||||
|
this.clearInventoryCache();
|
||||||
|
this.getBlocks(this._currentRequest);
|
||||||
|
}
|
||||||
|
|
||||||
if (bestHeight >= 0) {
|
if (bestHeight >= 0) {
|
||||||
this.emit('bestHeight', bestHeight);
|
this.emit('bestHeight', bestHeight);
|
||||||
}
|
}
|
||||||
|
|||||||
1031
package-lock.json
generated
1031
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,7 +2,7 @@
|
|||||||
"name": "bitcore-node",
|
"name": "bitcore-node",
|
||||||
"description": "Full node with extended capabilities using Bitcore and Bitcoin Core",
|
"description": "Full node with extended capabilities using Bitcore and Bitcoin Core",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=8.2.0"
|
"node": ">=8.0.0"
|
||||||
},
|
},
|
||||||
"author": "BitPay <dev@bitpay.com>",
|
"author": "BitPay <dev@bitpay.com>",
|
||||||
"version": "5.0.0-beta.3",
|
"version": "5.0.0-beta.3",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"async": "^2.5.0",
|
"async": "^2.5.0",
|
||||||
"bcoin": "bcoin-org/bcoin#886008a1822ce1da7fa8395ee7db4bcc1750a28a",
|
"bcoin": "bcoin-org/bcoin#57b98b2368c8106a9c215d73e40e1a7ae39042f3",
|
||||||
"bitcoind-rpc": "^0.6.0",
|
"bitcoind-rpc": "^0.6.0",
|
||||||
"bitcore-lib": "5.0.0-beta.1",
|
"bitcore-lib": "5.0.0-beta.1",
|
||||||
"bitcore-p2p": "5.0.0-beta.1",
|
"bitcore-p2p": "5.0.0-beta.1",
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -12,7 +12,6 @@ var bcoin = require('bcoin');
|
|||||||
describe('Address Service', function() {
|
describe('Address Service', function() {
|
||||||
|
|
||||||
var tx = Tx.fromRaw( '0100000004de9b4bb17f627096a9ee0b4528e4eae17df5b5c69edc29704c2e84a7371db29f010000006b483045022100f5b1a0d33b7be291c3953c25f8ae39d98601aa7099a8674daf638a08b86c7173022006ce372da5ad088a1cc6e5c49c2760a1b6f085eb1b51b502211b6bc9508661f9012102ec5e3731e54475dd2902326f43602a03ae3d62753324139163f81f20e787514cffffffff7a1d4e5fc2b8177ec738cd723a16cf2bf493791e55573445fc0df630fe5e2d64010000006b483045022100cf97f6cb8f126703e9768545dfb20ffb10ba78ae3d101aa46775f5a239b075fc02203150c4a89a11eaf5e404f4f96b62efa4455e9525765a025525c7105a7e47b6db012102c01e11b1d331f999bbdb83e8831de503cd52a01e3834a95ccafd615c67703d77ffffffff9e52447116415ca0d0567418a1a4ef8f27be3ff5a96bf87c922f3723d7db5d7c000000006b483045022100f6c117e536701be41a6b0b544d7c3b1091301e4e64a6265b6eb167b15d16959d022076916de4b115e700964194ce36a24cb9105f86482f4abbc63110c3f537cd5770012102ddf84cc7bee2d6a82ac09628a8ad4a26cd449fc528b81e7e6cc615707b8169dfffffffff5815d9750eb3572e30d6fd9df7afb4dbd76e042f3aa4988ac763b3fdf8397f80010000006a473044022028f4402b736066d93d2a32b28ccd3b7a21d84bb58fcd07fe392a611db94cdec5022018902ee0bf2c3c840c1b81ead4e6c87c88c48b2005bf5eea796464e561a620a8012102b6cdd1a6cd129ef796faeedb0b840fcd0ca00c57e16e38e46ee7028d59812ae7ffffffff0220a10700000000001976a914c342bcd1a7784d9842f7386b8b3b8a3d4171a06e88ac59611100000000001976a91449f8c749a9960dc29b5cbe7d2397cea7d26611bb88ac00000000', 'hex');
|
var tx = Tx.fromRaw( '0100000004de9b4bb17f627096a9ee0b4528e4eae17df5b5c69edc29704c2e84a7371db29f010000006b483045022100f5b1a0d33b7be291c3953c25f8ae39d98601aa7099a8674daf638a08b86c7173022006ce372da5ad088a1cc6e5c49c2760a1b6f085eb1b51b502211b6bc9508661f9012102ec5e3731e54475dd2902326f43602a03ae3d62753324139163f81f20e787514cffffffff7a1d4e5fc2b8177ec738cd723a16cf2bf493791e55573445fc0df630fe5e2d64010000006b483045022100cf97f6cb8f126703e9768545dfb20ffb10ba78ae3d101aa46775f5a239b075fc02203150c4a89a11eaf5e404f4f96b62efa4455e9525765a025525c7105a7e47b6db012102c01e11b1d331f999bbdb83e8831de503cd52a01e3834a95ccafd615c67703d77ffffffff9e52447116415ca0d0567418a1a4ef8f27be3ff5a96bf87c922f3723d7db5d7c000000006b483045022100f6c117e536701be41a6b0b544d7c3b1091301e4e64a6265b6eb167b15d16959d022076916de4b115e700964194ce36a24cb9105f86482f4abbc63110c3f537cd5770012102ddf84cc7bee2d6a82ac09628a8ad4a26cd449fc528b81e7e6cc615707b8169dfffffffff5815d9750eb3572e30d6fd9df7afb4dbd76e042f3aa4988ac763b3fdf8397f80010000006a473044022028f4402b736066d93d2a32b28ccd3b7a21d84bb58fcd07fe392a611db94cdec5022018902ee0bf2c3c840c1b81ead4e6c87c88c48b2005bf5eea796464e561a620a8012102b6cdd1a6cd129ef796faeedb0b840fcd0ca00c57e16e38e46ee7028d59812ae7ffffffff0220a10700000000001976a914c342bcd1a7784d9842f7386b8b3b8a3d4171a06e88ac59611100000000001976a91449f8c749a9960dc29b5cbe7d2397cea7d26611bb88ac00000000', 'hex');
|
||||||
var realBlocks = require('../../data/real-data-blocks.json');
|
|
||||||
var blocks = require('../../data/blocks.json');
|
var blocks = require('../../data/blocks.json');
|
||||||
var addressService;
|
var addressService;
|
||||||
var sandbox;
|
var sandbox;
|
||||||
@ -240,22 +239,6 @@ describe('Address Service', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('should reorg when there is something to reorg', function(done ) {
|
|
||||||
|
|
||||||
var commonAncestorHeader = bcoin.block.fromRaw(realBlocks.block0, 'hex').toHeaders().toJSON();
|
|
||||||
var oldBlocks = [bcoin.block.fromRaw(realBlocks.block1, 'hex')];
|
|
||||||
|
|
||||||
|
|
||||||
var getTransaction = sandbox.stub().callsArgWith(1, null, tx);
|
|
||||||
addressService._transaction = { getTransaction: getTransaction };
|
|
||||||
addressService.onReorg([commonAncestorHeader, oldBlocks], function(err, ops) {
|
|
||||||
|
|
||||||
expect(ops.length).to.equal(0);
|
|
||||||
done();
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user