rpc: misc fixes.
This commit is contained in:
parent
ede25e8c9e
commit
de50a62b00
@ -65,7 +65,7 @@ function RPC(node) {
|
||||
this.boundChain = false;
|
||||
this.nonce1 = 0;
|
||||
this.nonce2 = 0;
|
||||
this.jobs = {};
|
||||
this.merkleMap = {};
|
||||
this.pollers = [];
|
||||
|
||||
this.init();
|
||||
@ -214,7 +214,8 @@ RPC.prototype.getNetworkInfo = co(function* getNetworkInfo(args, help) {
|
||||
version: pkg.version,
|
||||
subversion: this.pool.options.agent,
|
||||
protocolversion: this.pool.options.version,
|
||||
localservices: this.pool.options.services,
|
||||
localservices: util.hex32(this.pool.options.services),
|
||||
localrelay: true,
|
||||
timeoffset: this.network.time.offset,
|
||||
connections: this.pool.peers.size(),
|
||||
networks: [],
|
||||
@ -340,6 +341,7 @@ RPC.prototype.getPeerInfo = co(function* getPeerInfo(args, help) {
|
||||
addrlocal: !peer.local.isNull()
|
||||
? peer.local.hostname
|
||||
: undefined,
|
||||
services: util.hex32(peer.services),
|
||||
relaytxes: !peer.noRelay,
|
||||
lastsend: peer.lastSend / 1000 | 0,
|
||||
lastrecv: peer.lastRecv / 1000 | 0,
|
||||
@ -442,7 +444,9 @@ RPC.prototype.getBlockchainInfo = co(function* getBlockchainInfo(args, help) {
|
||||
throw new RPCError('getblockchaininfo');
|
||||
|
||||
return {
|
||||
chain: this.network.type,
|
||||
chain: this.network.type !== 'testnet'
|
||||
? this.network.type
|
||||
: 'test',
|
||||
blocks: this.chain.height,
|
||||
headers: this.chain.height,
|
||||
bestblockhash: this.chain.tip.rhash(),
|
||||
@ -921,7 +925,7 @@ RPC.prototype._submitWork = co(function* _submitWork(data) {
|
||||
var header = Headers.fromAbbr(data);
|
||||
var nonce = header.nonce;
|
||||
var ts = header.ts;
|
||||
var job, n1, n2, proof, block, entry;
|
||||
var nonces, n1, n2, proof, block, entry;
|
||||
|
||||
if (!attempt)
|
||||
return false;
|
||||
@ -940,13 +944,13 @@ RPC.prototype._submitWork = co(function* _submitWork(data) {
|
||||
if (!header.verify())
|
||||
return false;
|
||||
|
||||
job = this.jobs[header.merkleRoot];
|
||||
nonces = this.merkleMap[header.merkleRoot];
|
||||
|
||||
if (!job)
|
||||
if (!nonces)
|
||||
return false;
|
||||
|
||||
n1 = job.nonce1;
|
||||
n2 = job.nonce2;
|
||||
n1 = nonces.nonce1;
|
||||
n2 = nonces.nonce2;
|
||||
|
||||
proof = attempt.getProof(n1, n2, ts, nonce);
|
||||
|
||||
@ -1323,22 +1327,38 @@ RPC.prototype._createTemplate = co(function* _createTemplate(version, coinbase,
|
||||
|
||||
RPC.prototype.getMiningInfo = co(function* getMiningInfo(args, help) {
|
||||
var attempt = this.attempt;
|
||||
var scale = attempt.witness ? 1 : consensus.WITNESS_SCALE_FACTOR;
|
||||
var size = 0;
|
||||
var weight = 0;
|
||||
var txs = 0;
|
||||
var i, item;
|
||||
|
||||
if (help || args.length !== 0)
|
||||
throw new RPCError('getmininginfo');
|
||||
|
||||
if (attempt) {
|
||||
weight = attempt.weight;
|
||||
txs = attempt.items.length + 1;
|
||||
size = 1000;
|
||||
for (i = 0; i < attempt.items.length; i++) {
|
||||
item = attempt.items[i];
|
||||
size += item.tx.getBaseSize();
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
blocks: this.chain.height,
|
||||
currentblocksize: attempt ? attempt.weight / scale | 0 : 0,
|
||||
currentblocktx: attempt ? attempt.items.length + 1 : 0,
|
||||
currentblocksize: size,
|
||||
currentblockweight: weight,
|
||||
currentblocktx: txs,
|
||||
difficulty: this.difficulty(),
|
||||
errors: '',
|
||||
genproclimit: this.procLimit,
|
||||
networkhashps: yield this.getHashRate(120),
|
||||
pooledtx: this.totalTX(),
|
||||
testnet: this.network !== Network.main,
|
||||
chain: 'main',
|
||||
chain: this.network.type !== 'testnet'
|
||||
? this.network.type
|
||||
: 'test',
|
||||
generate: this.mining
|
||||
};
|
||||
});
|
||||
@ -2115,7 +2135,7 @@ RPC.prototype.refreshBlock = function refreshBlock() {
|
||||
|
||||
this.attempt = null;
|
||||
this.lastActivity = 0;
|
||||
this.jobs = {};
|
||||
this.merkleMap = {};
|
||||
this.nonce1 = 0;
|
||||
this.nonce2 = 0;
|
||||
this.pollers = [];
|
||||
@ -2171,30 +2191,40 @@ RPC.prototype.getTemplate = co(function* getTemplate() {
|
||||
|
||||
RPC.prototype.updateWork = co(function* updateWork() {
|
||||
var attempt = this.attempt;
|
||||
var root;
|
||||
var root, n1, n2;
|
||||
|
||||
this.bindChain();
|
||||
|
||||
if (attempt) {
|
||||
this.miner.updateTime(attempt);
|
||||
|
||||
if (++this.nonce2 === 0x100000000) {
|
||||
this.nonce2 = 0;
|
||||
this.nonce1++;
|
||||
}
|
||||
root = attempt.getRoot(this.nonce1, this.nonce2);
|
||||
|
||||
n1 = this.nonce1;
|
||||
n2 = this.nonce2;
|
||||
|
||||
root = attempt.getRoot(n1, n2);
|
||||
root = root.toString('hex');
|
||||
this.jobs[root] = new Nonces(this);
|
||||
|
||||
this.merkleMap[root] = new Nonces(n1, n2);
|
||||
|
||||
return attempt;
|
||||
}
|
||||
|
||||
attempt = yield this.miner.createBlock();
|
||||
|
||||
root = attempt.getRoot(this.nonce1, this.nonce2);
|
||||
n1 = this.nonce1;
|
||||
n2 = this.nonce2;
|
||||
|
||||
root = attempt.getRoot(n1, n2);
|
||||
root = root.toString('hex');
|
||||
|
||||
this.attempt = attempt;
|
||||
this.lastActivity = util.now();
|
||||
this.jobs[root] = new Nonces(this);
|
||||
this.merkleMap[root] = new Nonces(n1, n2);
|
||||
|
||||
return attempt;
|
||||
});
|
||||
@ -2445,6 +2475,7 @@ RPC.prototype.headerToJSON = co(function* headerToJSON(entry) {
|
||||
confirmations: this.chain.height - entry.height + 1,
|
||||
height: entry.height,
|
||||
version: entry.version,
|
||||
versionHex: util.hex32(entry.version),
|
||||
merkleroot: util.revHex(entry.merkleRoot),
|
||||
time: entry.ts,
|
||||
mediantime: medianTime,
|
||||
@ -2484,6 +2515,7 @@ RPC.prototype.blockToJSON = co(function* blockToJSON(entry, block, details) {
|
||||
weight: block.getWeight(),
|
||||
height: entry.height,
|
||||
version: entry.version,
|
||||
versionHex: util.hex32(entry.version),
|
||||
merkleroot: util.revHex(entry.merkleRoot),
|
||||
tx: txs,
|
||||
time: entry.ts,
|
||||
@ -2509,7 +2541,7 @@ RPC.prototype.entryToJSON = function entryToJSON(entry) {
|
||||
currentpriority: entry.getPriority(this.chain.height),
|
||||
descendantcount: this.mempool.countDescendants(entry),
|
||||
descendantsize: entry.descSize,
|
||||
descendantfees: Amount.btc(entry.descFee, true),
|
||||
descendantfees: entry.descFee,
|
||||
ancestorcount: this.mempool.countAncestors(entry),
|
||||
ancestorsize: 0,
|
||||
ancestorfees: 0,
|
||||
@ -2555,9 +2587,9 @@ function toDeployment(id, version, status) {
|
||||
};
|
||||
}
|
||||
|
||||
function Nonces(rpc) {
|
||||
this.nonce1 = rpc.nonce1;
|
||||
this.nonce2 = rpc.nonce2;
|
||||
function Nonces(n1, n2) {
|
||||
this.nonce1 = n1;
|
||||
this.nonce2 = n2;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user