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