Skip to content

Commit

Permalink
Rename cummulativeDifficulty -> cumulativeDifficulty
Browse files Browse the repository at this point in the history
  • Loading branch information
mpicco committed Apr 21, 2020
1 parent 3258672 commit 7076314
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
6 changes: 3 additions & 3 deletions src/api/lib/hashrateCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ export class HashrateCalculator {
diffPerMiner[block.miner] = new BigNumber(0)
}

// cummulativeDifficulty = block.diff + sum(uncle.diff)
// If no cummulativeDifficulty is present, use an estimation under the supposition that the block diff
// cumulativeDifficulty = block.diff + sum(uncle.diff)
// If no cumulativeDifficulty is present, use an estimation under the supposition that the block diff
// is similar to its uncles' difficulty.
const bnDiff = block.cummulativeDifficulty ? new BigNumber(block.cummulativeDifficulty) :
const bnDiff = block.cumulativeDifficulty ? new BigNumber(block.cumulativeDifficulty) :
new BigNumber(block.difficulty).multipliedBy((block.uncles ? block.uncles.length : 0) + 1)
diffPerMiner[block.miner] = diffPerMiner[block.miner].plus(bnDiff)
}
Expand Down
6 changes: 3 additions & 3 deletions src/api/modules/ExtendedStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ExtendedStats extends DataCollectorItem {
const start = end - timeSpan

const blocks = await this.db.find({ timestamp: { $gte: start, $lte: end } })
.project({ _id: 0, miner: 1, timestamp: 1, difficulty: 1, cummulativeDifficulty: 1, uncles: 1 })
.project({ _id: 0, miner: 1, timestamp: 1, difficulty: 1, cumulativeDifficulty: 1, uncles: 1 })
.toArray()

extendedStats.hashrates[period] = this.hashrateCalculator.hashrates(blocks, timeSpan)
Expand All @@ -162,7 +162,7 @@ export class ExtendedStats extends DataCollectorItem {
const timeSpan = PERIODS[period].timeSpan

const blocks = await this.db.find({ timestamp: { $gte: blockDate - timeSpan, $lte: blockDate } })
.project({ _id: 0, miner: 1, difficulty: 1, cummulativeDifficulty: 1, uncles: 1 })
.project({ _id: 0, miner: 1, difficulty: 1, cumulativeDifficulty: 1, uncles: 1 })
.toArray()

hashrates[period] = this.hashrateCalculator.hashrates(blocks, timeSpan)
Expand All @@ -182,7 +182,7 @@ export class ExtendedStats extends DataCollectorItem {
const start = end - timeSpan

const blocks = await this.db.find({ timestamp: { $gte: start, $lte: end } })
.project({ _id: 0, timestamp: 1, difficulty: 1, cummulativeDifficulty: 1, uncles: 1 })
.project({ _id: 0, timestamp: 1, difficulty: 1, cumulativeDifficulty: 1, uncles: 1 })
.toArray()

difficulties[period] = this.difficultyCalculator.difficulties(blocks, start, end, DIFFICULTY_BUCKET_SIZE)
Expand Down
136 changes: 68 additions & 68 deletions test/services/hashrateCalculator.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ describe('hashrateCalculator', () => {
})
})

context('hashratePercentagePerMiner, cummulativeDifficulty', () => {
context('hashratePercentagePerMiner, cumulativeDifficulty', () => {
it('returns 1 for only one miner and 1 block', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -60,8 +60,8 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cummulativeDifficulty: '0x11f36beaf6690ac7e6' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cumulativeDifficulty: '0x11f36beaf6690ac7e6' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -75,10 +75,10 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e3' },
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e2' },
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e1' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e3' },
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e2' },
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e1' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -91,10 +91,10 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0c', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0d', cummulativeDifficulty: '0x11f36beaf6690ac7e6' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0c', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0d', cumulativeDifficulty: '0x11f36beaf6690ac7e6' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -110,10 +110,10 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cummulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0c', cummulativeDifficulty: '0x0f54a7810c212d7df0' },
{ miner: '0x0d', cummulativeDifficulty: '0x0f54a7810c212d7df0' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cumulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0c', cumulativeDifficulty: '0x0f54a7810c212d7df0' },
{ miner: '0x0d', cumulativeDifficulty: '0x0f54a7810c212d7df0' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -129,17 +129,17 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cummulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0a', cummulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0c', cummulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0d', cummulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0d', cummulativeDifficulty: '0x0f54a7810c212d7df0' },
{ miner: '0x0a', cummulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0d', cummulativeDifficulty: '0x0f54a7810c212d7d00' },
{ miner: '0x0c', cummulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0b', cummulativeDifficulty: '0x10050a0cc225820fff' },
{ miner: '0x0d', cummulativeDifficulty: '0x11f36beaf6690ac7e6' }
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0b', cumulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0a', cumulativeDifficulty: '0x13b768fb4f683f5fd5' },
{ miner: '0x0c', cumulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0d', cumulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0d', cumulativeDifficulty: '0x0f54a7810c212d7df0' },
{ miner: '0x0a', cumulativeDifficulty: '0x11f36beaf6690ac7e6' },
{ miner: '0x0d', cumulativeDifficulty: '0x0f54a7810c212d7d00' },
{ miner: '0x0c', cumulativeDifficulty: '0x10050a0cc225820cdd' },
{ miner: '0x0b', cumulativeDifficulty: '0x10050a0cc225820fff' },
{ miner: '0x0d', cumulativeDifficulty: '0x11f36beaf6690ac7e6' }
]
const hashrate = calc.hashratePercentagePerMiner(blocks)

Expand All @@ -152,14 +152,14 @@ describe('hashrateCalculator', () => {
})
})

context('hashratePerMiner, cummulativeDifficulty', () => {
context('hashratePerMiner, cumulativeDifficulty', () => {
const START = 1

it('returns the same diff as hashrate for one block', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START }
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START }
]
const hashrate = calc.hashratePerMiner(blocks, 0)

Expand All @@ -172,11 +172,11 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START + 1 },
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START + 2 },
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START + 3 },
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START + 4 }
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START + 1 },
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START + 2 },
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START + 3 },
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START + 4 }
]
const hashrate = calc.hashratePerMiner(blocks, (START + 4) - START)

Expand All @@ -189,17 +189,17 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0b', cummulativeDifficulty: exa(2), timestamp: START + 1 },
{ miner: '0x0a', cummulativeDifficulty: exa(3), timestamp: START + 2 },
{ miner: '0x0c', cummulativeDifficulty: exa(4), timestamp: START + 3 },
{ miner: '0x0d', cummulativeDifficulty: exa(5), timestamp: START + 4 },
{ miner: '0x0a', cummulativeDifficulty: exa(6), timestamp: START + 5 },
{ miner: '0x0a', cummulativeDifficulty: exa(7), timestamp: START + 6 },
{ miner: '0x0b', cummulativeDifficulty: exa(8), timestamp: START + 7 },
{ miner: '0x0a', cummulativeDifficulty: exa(9), timestamp: START + 8 },
{ miner: '0x0c', cummulativeDifficulty: exa(10), timestamp: START + 9 },
{ miner: '0x0c', cummulativeDifficulty: exa(11), timestamp: START + 10 }
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0b', cumulativeDifficulty: exa(2), timestamp: START + 1 },
{ miner: '0x0a', cumulativeDifficulty: exa(3), timestamp: START + 2 },
{ miner: '0x0c', cumulativeDifficulty: exa(4), timestamp: START + 3 },
{ miner: '0x0d', cumulativeDifficulty: exa(5), timestamp: START + 4 },
{ miner: '0x0a', cumulativeDifficulty: exa(6), timestamp: START + 5 },
{ miner: '0x0a', cumulativeDifficulty: exa(7), timestamp: START + 6 },
{ miner: '0x0b', cumulativeDifficulty: exa(8), timestamp: START + 7 },
{ miner: '0x0a', cumulativeDifficulty: exa(9), timestamp: START + 8 },
{ miner: '0x0c', cumulativeDifficulty: exa(10), timestamp: START + 9 },
{ miner: '0x0c', cumulativeDifficulty: exa(11), timestamp: START + 10 }
]
const hashrate = calc.hashratePerMiner(blocks, (START + 10) - START)

Expand All @@ -219,17 +219,17 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0b', cummulativeDifficulty: exa(2), timestamp: START + 1 },
{ miner: '0x0a', cummulativeDifficulty: exa(3), timestamp: START + 2 },
{ miner: '0x0c', cummulativeDifficulty: exa(4), timestamp: START + 3 },
{ miner: '0x0d', cummulativeDifficulty: exa(5), timestamp: START + 4 },
{ miner: '0x0a', cummulativeDifficulty: exa(6), timestamp: START + 5 },
{ miner: '0x0a', cummulativeDifficulty: exa(7), timestamp: START + 6 },
{ miner: '0x0b', cummulativeDifficulty: exa(8), timestamp: START + 7 },
{ miner: '0x0a', cummulativeDifficulty: exa(9), timestamp: START + 8 },
{ miner: '0x0c', cummulativeDifficulty: exa(10), timestamp: START + 9 },
{ miner: '0x0c', cummulativeDifficulty: exa(11), timestamp: START + 10 }
{ miner: '0x0a', cumulativeDifficulty: exa(1), timestamp: START },
{ miner: '0x0b', cumulativeDifficulty: exa(2), timestamp: START + 1 },
{ miner: '0x0a', cumulativeDifficulty: exa(3), timestamp: START + 2 },
{ miner: '0x0c', cumulativeDifficulty: exa(4), timestamp: START + 3 },
{ miner: '0x0d', cumulativeDifficulty: exa(5), timestamp: START + 4 },
{ miner: '0x0a', cumulativeDifficulty: exa(6), timestamp: START + 5 },
{ miner: '0x0a', cumulativeDifficulty: exa(7), timestamp: START + 6 },
{ miner: '0x0b', cumulativeDifficulty: exa(8), timestamp: START + 7 },
{ miner: '0x0a', cumulativeDifficulty: exa(9), timestamp: START + 8 },
{ miner: '0x0c', cumulativeDifficulty: exa(10), timestamp: START + 9 },
{ miner: '0x0c', cumulativeDifficulty: exa(11), timestamp: START + 10 }
]
const hashrate = calc.hashrates(blocks, (START + 10) - START)

Expand All @@ -246,17 +246,17 @@ describe('hashrateCalculator', () => {
const calc = new HashrateCalculator()

const blocks = [
{ miner: '0x0a', cummulativeDifficulty: hexExa(1), timestamp: START },
{ miner: '0x0b', cummulativeDifficulty: hexExa(2), timestamp: START + 1 },
{ miner: '0x0a', cummulativeDifficulty: hexExa(3), timestamp: START + 2 },
{ miner: '0x0c', cummulativeDifficulty: hexExa(4), timestamp: START + 3 },
{ miner: '0x0d', cummulativeDifficulty: hexExa(5), timestamp: START + 4 },
{ miner: '0x0a', cummulativeDifficulty: hexExa(6), timestamp: START + 5 },
{ miner: '0x0a', cummulativeDifficulty: hexExa(7), timestamp: START + 6 },
{ miner: '0x0b', cummulativeDifficulty: hexExa(8), timestamp: START + 7 },
{ miner: '0x0a', cummulativeDifficulty: hexExa(9), timestamp: START + 8 },
{ miner: '0x0c', cummulativeDifficulty: hexExa(10), timestamp: START + 9 },
{ miner: '0x0c', cummulativeDifficulty: hexExa(11), timestamp: START + 10 }
{ miner: '0x0a', cumulativeDifficulty: hexExa(1), timestamp: START },
{ miner: '0x0b', cumulativeDifficulty: hexExa(2), timestamp: START + 1 },
{ miner: '0x0a', cumulativeDifficulty: hexExa(3), timestamp: START + 2 },
{ miner: '0x0c', cumulativeDifficulty: hexExa(4), timestamp: START + 3 },
{ miner: '0x0d', cumulativeDifficulty: hexExa(5), timestamp: START + 4 },
{ miner: '0x0a', cumulativeDifficulty: hexExa(6), timestamp: START + 5 },
{ miner: '0x0a', cumulativeDifficulty: hexExa(7), timestamp: START + 6 },
{ miner: '0x0b', cumulativeDifficulty: hexExa(8), timestamp: START + 7 },
{ miner: '0x0a', cumulativeDifficulty: hexExa(9), timestamp: START + 8 },
{ miner: '0x0c', cumulativeDifficulty: hexExa(10), timestamp: START + 9 },
{ miner: '0x0c', cumulativeDifficulty: hexExa(11), timestamp: START + 10 }
]
const hashrate = calc.hashrates(blocks, (START + 10) - START)

Expand Down Expand Up @@ -366,7 +366,7 @@ describe('hashrateCalculator', () => {
})
})

context('hashratePerMiner, cummulativeDifficulty', () => {
context('hashratePerMiner, cumulativeDifficulty', () => {
const START = 1

it('returns the same diff as hashrate for one block', () => {
Expand Down

0 comments on commit 7076314

Please sign in to comment.