pool wallets. chain errors. checkpoint failure.
This commit is contained in:
parent
d109eaba6c
commit
82983af52b
@ -142,7 +142,7 @@ Chain.prototype._probeIndex = function _probeIndex(hash, ts) {
|
|||||||
|
|
||||||
Chain.prototype._addIndex = function _addIndex(hash, ts, height) {
|
Chain.prototype._addIndex = function _addIndex(hash, ts, height) {
|
||||||
if (this._probeIndex(hash, ts))
|
if (this._probeIndex(hash, ts))
|
||||||
return;
|
return new Error('Already added.');
|
||||||
|
|
||||||
var pos = utils.binaryInsert(this.index.ts, ts, compareTs, true);
|
var pos = utils.binaryInsert(this.index.ts, ts, compareTs, true);
|
||||||
|
|
||||||
@ -150,16 +150,18 @@ Chain.prototype._addIndex = function _addIndex(hash, ts, height) {
|
|||||||
if (this.index.hashes[pos] === hash ||
|
if (this.index.hashes[pos] === hash ||
|
||||||
this.index.hashes[pos - 1] === hash ||
|
this.index.hashes[pos - 1] === hash ||
|
||||||
this.index.hashes[pos + 1] === hash) {
|
this.index.hashes[pos + 1] === hash) {
|
||||||
return;
|
return new Error('Duplicate height.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// var checkpoint = network.checkpoints[height];
|
var checkpoint = network.checkpoints[height];
|
||||||
// if (checkpoint) {
|
if (checkpoint) {
|
||||||
// this.emit('checkpoint', height, hash, checkpoint);
|
this.emit('checkpoint', height, hash, checkpoint);
|
||||||
// if (hash !== checkpoint) {
|
if (hash !== checkpoint) {
|
||||||
// this.resetLastCheckpoint(height);
|
// this.resetLastCheckpoint(height);
|
||||||
// }
|
this.emit('fork', height, hash, checkpoint);
|
||||||
// }
|
return new Error('Forked chain at checkpoint.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.index.ts.splice(pos, 0, ts);
|
this.index.ts.splice(pos, 0, ts);
|
||||||
this.index.hashes.splice(pos, 0, hash);
|
this.index.hashes.splice(pos, 0, hash);
|
||||||
@ -187,6 +189,7 @@ Chain.prototype.resetLastCheckpoint = function resetLastCheckpoint(height) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Chain.prototype.resetHeight = function resetHeight(height) {
|
Chain.prototype.resetHeight = function resetHeight(height) {
|
||||||
|
var self = this;
|
||||||
var index = this.index.heights.indexOf(height);
|
var index = this.index.heights.indexOf(height);
|
||||||
|
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
@ -201,6 +204,9 @@ Chain.prototype.resetHeight = function resetHeight(height) {
|
|||||||
this.index.hashes = this.index.hashes.slice(0, index + 1);
|
this.index.hashes = this.index.hashes.slice(0, index + 1);
|
||||||
this.index.heights = this.index.heights.slice(0, index + 1);
|
this.index.heights = this.index.heights.slice(0, index + 1);
|
||||||
this.index.bloom.reset();
|
this.index.bloom.reset();
|
||||||
|
this.index.hashes.forEach(function(hash) {
|
||||||
|
self.index.bloom.add(hash, 'hex');
|
||||||
|
});
|
||||||
this.index.lastTs = this.index.ts[this.index.ts.length - 1];
|
this.index.lastTs = this.index.ts[this.index.ts.length - 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -298,8 +304,10 @@ Chain.prototype.add = function add(block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validated known block at this point - add it to index
|
// Validated known block at this point - add it to index
|
||||||
if (prevProbe)
|
if (prevProbe) {
|
||||||
this._addIndex(hash, block.ts, prevProbe.height + 1);
|
this._addIndex(hash, block.ts, prevProbe.height + 1);
|
||||||
|
block.height = prevProbe.height + 1;
|
||||||
|
}
|
||||||
|
|
||||||
// At least one block was added
|
// At least one block was added
|
||||||
res = true;
|
res = true;
|
||||||
|
|||||||
@ -33,11 +33,11 @@ function Peer(pool, createSocket, options) {
|
|||||||
if (this.options.backoff) {
|
if (this.options.backoff) {
|
||||||
var self = this;
|
var self = this;
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
self.socket = createSocket();
|
self.socket = createSocket(self);
|
||||||
self.emit('socket');
|
self.emit('socket');
|
||||||
}, this.options.backoff);
|
}, this.options.backoff);
|
||||||
} else {
|
} else {
|
||||||
this.socket = createSocket();
|
this.socket = createSocket(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._broadcast = {
|
this._broadcast = {
|
||||||
|
|||||||
@ -16,6 +16,10 @@ function Pool(options) {
|
|||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
|
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
|
|
||||||
|
if (this.options.network)
|
||||||
|
network.set(this.options.network);
|
||||||
|
|
||||||
this.options.fullNode = !!this.options.fullNode;
|
this.options.fullNode = !!this.options.fullNode;
|
||||||
this.options.relay == null
|
this.options.relay == null
|
||||||
? (this.options.fullNode ? false : true)
|
? (this.options.fullNode ? false : true)
|
||||||
@ -91,6 +95,7 @@ function Pool(options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Added and watched wallets
|
// Added and watched wallets
|
||||||
|
this.options.wallets = this.options.wallets || [];
|
||||||
this.wallets = [];
|
this.wallets = [];
|
||||||
|
|
||||||
this.createSocket = options.createConnection || options.createSocket;
|
this.createSocket = options.createConnection || options.createSocket;
|
||||||
@ -126,6 +131,10 @@ Pool.prototype._init = function _init() {
|
|||||||
self._scheduleRequests();
|
self._scheduleRequests();
|
||||||
self._loadRange(preload);
|
self._loadRange(preload);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.options.wallets.forEach(function(w) {
|
||||||
|
self.addWallet(w);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Pool.prototype._addLoader = function _addLoader() {
|
Pool.prototype._addLoader = function _addLoader() {
|
||||||
@ -355,15 +364,6 @@ Pool.prototype._addPeer = function _addPeer(backoff) {
|
|||||||
if (self.chain.index.hashes.length === len)
|
if (self.chain.index.hashes.length === len)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var height = self.chain.index.heights.length[self.chain.index.heights.length - 1];
|
|
||||||
|
|
||||||
var checkpoint = network.checkpoints[height];
|
|
||||||
if (checkpoint) {
|
|
||||||
self.emit('checkpoint', block, height, checkpoint, peer);
|
|
||||||
// if (checkpoint !== hash)
|
|
||||||
// self.chain.resetLastCheckpoint(height);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.emit('chain-progress', self.chain.fillPercent(), peer);
|
self.emit('chain-progress', self.chain.fillPercent(), peer);
|
||||||
self.emit('block', block, peer);
|
self.emit('block', block, peer);
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user