rpc: rename _submitBlock.
This commit is contained in:
parent
9581225b8c
commit
dc6b7b1f10
120
lib/http/rpc.js
120
lib/http/rpc.js
@ -1047,65 +1047,7 @@ RPC.prototype.submitBlock = co(function* submitBlock(args, help) {
|
|||||||
|
|
||||||
block = Block.fromRaw(data);
|
block = Block.fromRaw(data);
|
||||||
|
|
||||||
return yield this._submitBlock(block);
|
return yield this.addBlock(block);
|
||||||
});
|
|
||||||
|
|
||||||
RPC.prototype._submitBlock = co(function* _submitBlock(block) {
|
|
||||||
var unlock1 = yield this.locker.lock();
|
|
||||||
var unlock2 = yield this.chain.locker.lock();
|
|
||||||
try {
|
|
||||||
return yield this.__submitBlock(block);
|
|
||||||
} finally {
|
|
||||||
unlock2();
|
|
||||||
unlock1();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
RPC.prototype.__submitBlock = co(function* __submitBlock(block) {
|
|
||||||
var entry, prev, state, tx;
|
|
||||||
|
|
||||||
this.logger.info('Handling submitted block: %s.', block.rhash());
|
|
||||||
|
|
||||||
prev = yield this.chain.db.getEntry(block.prevBlock);
|
|
||||||
|
|
||||||
if (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);
|
|
||||||
|
|
||||||
// Recreate witness nonce (all zeroes).
|
|
||||||
tx.inputs[0].witness.set(0, encoding.ZERO_HASH);
|
|
||||||
tx.inputs[0].witness.compile();
|
|
||||||
|
|
||||||
tx.refresh();
|
|
||||||
block.refresh();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
entry = yield this.chain._add(block);
|
|
||||||
} catch (err) {
|
|
||||||
if (err.type === 'VerifyError') {
|
|
||||||
this.logger.warning('RPC block rejected: %s (%s).',
|
|
||||||
block.rhash(), err.reason);
|
|
||||||
return 'rejected: ' + err.reason;
|
|
||||||
}
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entry) {
|
|
||||||
this.logger.warning('RPC block rejected: %s (bad-prevblk).',
|
|
||||||
block.rhash());
|
|
||||||
return 'rejected: bad-prevblk';
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) {
|
RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) {
|
||||||
@ -1133,7 +1075,7 @@ RPC.prototype.getBlockTemplate = co(function* getBlockTemplate(args, help) {
|
|||||||
|
|
||||||
block = Block.fromRaw(data);
|
block = Block.fromRaw(data);
|
||||||
|
|
||||||
return yield this._submitBlock(block);
|
return yield this.addBlock(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rules)
|
if (rules)
|
||||||
@ -2230,6 +2172,64 @@ RPC.prototype.updateWork = co(function* updateWork() {
|
|||||||
return attempt;
|
return attempt;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
RPC.prototype.addBlock = co(function* addBlock(block) {
|
||||||
|
var unlock1 = yield this.locker.lock();
|
||||||
|
var unlock2 = yield this.chain.locker.lock();
|
||||||
|
try {
|
||||||
|
return yield this._addBlock(block);
|
||||||
|
} finally {
|
||||||
|
unlock2();
|
||||||
|
unlock1();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
RPC.prototype._addBlock = co(function* _addBlock(block) {
|
||||||
|
var entry, prev, state, tx;
|
||||||
|
|
||||||
|
this.logger.info('Handling submitted block: %s.', block.rhash());
|
||||||
|
|
||||||
|
prev = yield this.chain.db.getEntry(block.prevBlock);
|
||||||
|
|
||||||
|
if (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);
|
||||||
|
|
||||||
|
// Recreate witness nonce (all zeroes).
|
||||||
|
tx.inputs[0].witness.set(0, encoding.ZERO_HASH);
|
||||||
|
tx.inputs[0].witness.compile();
|
||||||
|
|
||||||
|
tx.refresh();
|
||||||
|
block.refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
entry = yield this.chain._add(block);
|
||||||
|
} catch (err) {
|
||||||
|
if (err.type === 'VerifyError') {
|
||||||
|
this.logger.warning('RPC block rejected: %s (%s).',
|
||||||
|
block.rhash(), err.reason);
|
||||||
|
return 'rejected: ' + err.reason;
|
||||||
|
}
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entry) {
|
||||||
|
this.logger.warning('RPC block rejected: %s (bad-prevblk).',
|
||||||
|
block.rhash());
|
||||||
|
return 'rejected: bad-prevblk';
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
RPC.prototype.totalTX = function totalTX() {
|
RPC.prototype.totalTX = function totalTX() {
|
||||||
return this.mempool ? this.mempool.totalTX : 0;
|
return this.mempool ? this.mempool.totalTX : 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user