rpc: hold chain lock during submitblock.

This commit is contained in:
Christopher Jeffrey 2017-03-15 03:59:46 -07:00
parent de50a62b00
commit 9581225b8c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -1051,11 +1051,13 @@ RPC.prototype.submitBlock = co(function* submitBlock(args, help) {
}); });
RPC.prototype._submitBlock = co(function* _submitBlock(block) { RPC.prototype._submitBlock = co(function* _submitBlock(block) {
var unlock = yield this.locker.lock(); var unlock1 = yield this.locker.lock();
var unlock2 = yield this.chain.locker.lock();
try { try {
return yield this.__submitBlock(block); return yield this.__submitBlock(block);
} finally { } finally {
unlock(); unlock2();
unlock1();
} }
}); });
@ -1066,29 +1068,28 @@ RPC.prototype.__submitBlock = co(function* __submitBlock(block) {
prev = yield this.chain.db.getEntry(block.prevBlock); prev = yield this.chain.db.getEntry(block.prevBlock);
if (!prev) if (prev) {
return 'rejected: bad-prevblk'; state = yield this.chain.getDeployments(block.ts, prev);
state = yield this.chain.getDeployments(block.ts, prev); // Fix eloipool bug (witness nonce is not present).
if (state.hasWitness() && block.getCommitmentHash()) {
tx = block.txs[0];
if (!tx.hasWitness()) {
this.logger.warning('Submitted block had no witness nonce.');
this.logger.debug(tx);
// Fix eloipool bug (witness nonce is not present). // Recreate witness nonce (all zeroes).
if (state.hasWitness() && block.getCommitmentHash()) { tx.inputs[0].witness.set(0, encoding.ZERO_HASH);
tx = block.txs[0]; tx.inputs[0].witness.compile();
if (!tx.hasWitness()) {
this.logger.warning('Submitted block had no witness nonce.');
this.logger.debug(tx);
// Recreate witness nonce (all zeroes). tx.refresh();
tx.inputs[0].witness.set(0, encoding.ZERO_HASH); block.refresh();
tx.inputs[0].witness.compile(); }
tx.refresh();
block.refresh();
} }
} }
try { try {
entry = yield this.chain.add(block); entry = yield this.chain._add(block);
} catch (err) { } catch (err) {
if (err.type === 'VerifyError') { if (err.type === 'VerifyError') {
this.logger.warning('RPC block rejected: %s (%s).', this.logger.warning('RPC block rejected: %s (%s).',