Snapshot sync and block gap info in eth_syncing (#2948)
* provide snapshot sync info in eth_syncing * specify block gap in eth_syncing * Extend eth_syncing with warp, format the output properly * adjust serialization tests for sync info * whitespace
This commit is contained in:
committed by
Gav Wood
parent
ff90fac125
commit
8599a11a0b
@@ -153,6 +153,28 @@ export function outSignerRequest (request) {
|
||||
return request;
|
||||
}
|
||||
|
||||
export function outSyncing (syncing) {
|
||||
if (syncing && syncing !== 'false') {
|
||||
Object.keys(syncing).forEach((key) => {
|
||||
switch (key) {
|
||||
case 'currentBlock':
|
||||
case 'highestBlock':
|
||||
case 'startingBlock':
|
||||
case 'warpChunksAmount':
|
||||
case 'warpChunksProcessed':
|
||||
syncing[key] = outNumber(syncing[key]);
|
||||
break;
|
||||
|
||||
case 'blockGap':
|
||||
syncing[key] = syncing[key].map(outNumber);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return syncing;
|
||||
}
|
||||
|
||||
export function outTransaction (tx) {
|
||||
if (tx) {
|
||||
Object.keys(tx).forEach((key) => {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import BigNumber from 'bignumber.js';
|
||||
|
||||
import { outBlock, outAccountInfo, outAddress, outDate, outHistogram, outNumber, outPeers, outReceipt, outTransaction, outTrace } from './output';
|
||||
import { outBlock, outAccountInfo, outAddress, outDate, outHistogram, outNumber, outPeers, outReceipt, outSyncing, outTransaction, outTrace } from './output';
|
||||
import { isAddress, isBigNumber, isInstanceOf } from '../../../test/types';
|
||||
|
||||
describe('api/format/output', () => {
|
||||
@@ -203,6 +203,22 @@ describe('api/format/output', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('outSyncing', () => {
|
||||
['currentBlock', 'highestBlock', 'startingBlock', 'warpChunksAmount', 'warpChunksProcessed'].forEach((input) => {
|
||||
it(`formats ${input} numbers as a number`, () => {
|
||||
expect(outSyncing({ [input]: '0x123' })).to.deep.equal({
|
||||
[input]: new BigNumber('0x123')
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('formats blockGap properly', () => {
|
||||
expect(outSyncing({ blockGap: [0x123, 0x456] })).to.deep.equal({
|
||||
blockGap: [new BigNumber(0x123), new BigNumber(0x456)]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('outTransaction', () => {
|
||||
['from', 'to'].forEach((input) => {
|
||||
it(`formats ${input} address as address`, () => {
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import { inAddress, inBlockNumber, inData, inFilter, inHash, inHex, inNumber16, inOptions } from '../../format/input';
|
||||
import { outAddress, outBlock, outLog, outNumber, outReceipt, outTransaction } from '../../format/output';
|
||||
import { outAddress, outBlock, outLog, outNumber, outReceipt, outSyncing, outTransaction } from '../../format/output';
|
||||
|
||||
export default class Eth {
|
||||
constructor (transport) {
|
||||
@@ -314,7 +314,8 @@ export default class Eth {
|
||||
|
||||
syncing () {
|
||||
return this._transport
|
||||
.execute('eth_syncing');
|
||||
.execute('eth_syncing')
|
||||
.then(outSyncing);
|
||||
}
|
||||
|
||||
uninstallFilter (filterId) {
|
||||
|
||||
@@ -1003,7 +1003,7 @@ export default {
|
||||
details: {
|
||||
startingBlock: {
|
||||
type: Quantity,
|
||||
desc: 'The block at which the import started (will only be reset, after the sync reached his head)'
|
||||
desc: 'The block at which the import started (will only be reset, after the sync reached this head)'
|
||||
},
|
||||
currentBlock: {
|
||||
type: Quantity,
|
||||
@@ -1012,6 +1012,18 @@ export default {
|
||||
highestBlock: {
|
||||
type: Quantity,
|
||||
desc: 'The estimated highest block'
|
||||
},
|
||||
blockGap: {
|
||||
type: Array,
|
||||
desc: 'Array of "first", "last", such that [first, last) are all missing from the chain'
|
||||
},
|
||||
warpChunksAmount: {
|
||||
type: Quantity,
|
||||
desc: 'Total amount of snapshot chunks'
|
||||
},
|
||||
warpChunksProcessed: {
|
||||
type: Quantity,
|
||||
desc: 'Total amount of snapshot chunks processed'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user