From 0288158ffe38c8e271b68fe2a32eefab3db50dbe Mon Sep 17 00:00:00 2001 From: Brian Faust Date: Mon, 18 Mar 2019 15:28:59 +0200 Subject: [PATCH] refactor: remove missed blocks and productivity (#2257) --- .../integration/core-api/__support__/setup.ts | 1 - __tests__/integration/core-api/v1/utils.ts | 2 - .../core-api/v2/handlers/delegates.test.ts | 93 ------------------- __tests__/integration/core-api/v2/utils.ts | 2 - .../__fixtures__/delegates-page-1.json | 14 +-- .../__fixtures__/delegates-page-2.json | 16 +--- .../delegates-business-repository.test.ts | 1 - .../core-utils/delegate-calculator.test.ts | 23 +---- deprecated/core-graphql/src/defs/types.ts | 1 - .../src/versions/1/delegates/transformer.ts | 2 - .../src/versions/2/delegates/schema.ts | 8 -- .../src/versions/2/delegates/transformer.ts | 2 - .../core-api/src/versions/2/wallets/schema.ts | 6 -- .../src/integrity-verifier.ts | 1 - .../src/models/index.ts | 1 - .../src/models/wallet.ts | 79 ---------------- .../core-database/src/database-service.ts | 7 +- .../delegates-business-repository.ts | 20 +--- packages/core-database/src/wallet.ts | 2 - .../src/core-database/wallet-manager.ts | 1 - .../core-utils/src/delegate-calculator.ts | 18 +--- packages/core-utils/src/index.ts | 4 +- 22 files changed, 15 insertions(+), 289 deletions(-) delete mode 100644 packages/core-database-postgres/src/models/wallet.ts diff --git a/__tests__/integration/core-api/__support__/setup.ts b/__tests__/integration/core-api/__support__/setup.ts index 297441f358..e191472ded 100644 --- a/__tests__/integration/core-api/__support__/setup.ts +++ b/__tests__/integration/core-api/__support__/setup.ts @@ -54,7 +54,6 @@ async function calculateRanks() { sortBy(delegateWallets, "publicKey").forEach((delegate, i) => { const wallet = databaseService.walletManager.findByPublicKey(delegate.publicKey); - wallet.missedBlocks = +delegate.missedBlocks; (wallet as any).rate = i + 1; databaseService.walletManager.reindex(wallet); diff --git a/__tests__/integration/core-api/v1/utils.ts b/__tests__/integration/core-api/v1/utils.ts index e9962923a6..ba05a73740 100644 --- a/__tests__/integration/core-api/v1/utils.ts +++ b/__tests__/integration/core-api/v1/utils.ts @@ -55,10 +55,8 @@ class Helpers { expect(delegate.publicKey).toBeString(); expect(delegate.vote).toBeString(); expect(delegate.rate).toBeNumber(); - expect(delegate.missedblocks).toBeNumber(); expect(delegate.producedblocks).toBeNumber(); expect(delegate.approval).toBeNumber(); - expect(delegate.productivity).toBeNumber(); Object.keys(expected || {}).forEach(attr => { expect(delegate[attr]).toBe(expected[attr]); diff --git a/__tests__/integration/core-api/v2/handlers/delegates.test.ts b/__tests__/integration/core-api/v2/handlers/delegates.test.ts index d58c5a42b1..339274fa91 100644 --- a/__tests__/integration/core-api/v2/handlers/delegates.test.ts +++ b/__tests__/integration/core-api/v2/handlers/delegates.test.ts @@ -18,8 +18,6 @@ const delegate = { forgedRewards: 50, forgedTotal: 100, producedBlocks: 75, - missedBlocks: 25, - productivity: 75, voteBalance: 100000, }; @@ -36,7 +34,6 @@ beforeAll(async () => { wallet.forgedFees = new Bignum(delegate.forgedFees); wallet.forgedRewards = new Bignum(delegate.forgedRewards); wallet.producedBlocks = 75; - wallet.missedBlocks = 25; wallet.voteBalance = new Bignum(delegate.voteBalance); wm.reindex(wallet); }); @@ -103,22 +100,6 @@ describe("API 2.0 - Delegates", () => { }, ); - describe.each([["API-Version", "request"], ["Accept", "requestWithAcceptHeader"]])( - "using the %s header", - (header, request) => { - it("should GET all the delegates ordered by descending productivity", async () => { - const response = await utils[request]("GET", "delegates", { orderBy: "productivity:desc" }); - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - - response.data.data.forEach(utils.expectDelegate); - expect( - response.data.data.sort((a, b) => a.production.productivity > b.production.productivity), - ).toEqual(response.data.data); - }); - }, - ); - describe.each([["API-Version", "request"], ["Accept", "requestWithAcceptHeader"]])( "using the %s header", (header, request) => { @@ -462,80 +443,6 @@ describe("API 2.0 - Delegates", () => { } }); - it("should POST a search for delegates with the exact specified missed blocks", async () => { - const response = await utils[request]("POST", "delegates/search", { - missedBlocks: { - from: delegate.missedBlocks, - to: delegate.missedBlocks, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(1); - - for (const elem of response.data.data) { - utils.expectDelegate(elem); - expect(elem.blocks.missed).toEqual(delegate.missedBlocks); - } - }); - - it("should POST a search for delegates with the specified missed blocks range", async () => { - const response = await utils[request]("POST", "delegates/search", { - missedBlocks: { - from: 0, - to: delegate.missedBlocks, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(51); - - for (const elem of response.data.data) { - utils.expectDelegate(elem); - expect(elem.blocks.missed).toBeGreaterThanOrEqual(0); - expect(elem.blocks.missed).toBeLessThanOrEqual(delegate.missedBlocks); - } - }); - - it("should POST a search for delegates with the exact specified productivity", async () => { - const response = await utils[request]("POST", "delegates/search", { - productivity: { - from: delegate.productivity, - to: delegate.productivity, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(1); - - for (const elem of response.data.data) { - utils.expectDelegate(elem); - expect(elem.production.productivity).toEqual(delegate.productivity); - } - }); - - it("should POST a search for delegates with the specified productivity range", async () => { - const response = await utils[request]("POST", "delegates/search", { - productivity: { - from: 0, - to: delegate.productivity, - }, - }); - - expect(response).toBeSuccessfulResponse(); - expect(response.data.data).toBeArray(); - expect(response.data.data).toHaveLength(51); - - for (const elem of response.data.data) { - utils.expectDelegate(elem); - expect(elem.production.productivity).toBeGreaterThanOrEqual(0); - expect(elem.production.productivity).toBeLessThanOrEqual(delegate.productivity); - } - }); - it("should POST a search for delegates with the exact specified vote balance", async () => { const response = await utils[request]("POST", "delegates/search", { voteBalance: { diff --git a/__tests__/integration/core-api/v2/utils.ts b/__tests__/integration/core-api/v2/utils.ts index ba8ef666d9..32571a9ffe 100644 --- a/__tests__/integration/core-api/v2/utils.ts +++ b/__tests__/integration/core-api/v2/utils.ts @@ -121,11 +121,9 @@ class Helpers { expect(delegate.votes).toBeNumber(); expect(delegate.rank).toBeNumber(); expect(delegate.blocks).toBeObject(); - expect(delegate.blocks.missed).toBeNumber(); expect(delegate.blocks.produced).toBeNumber(); expect(delegate.production).toBeObject(); expect(delegate.production.approval).toBeNumber(); - expect(delegate.production.productivity).toBeNumber(); expect(delegate.forged.fees).toBeNumber(); expect(delegate.forged.rewards).toBeNumber(); expect(delegate.forged.total).toBeNumber(); diff --git a/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-1.json b/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-1.json index 259580076b..2caa75a4da 100644 --- a/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-1.json +++ b/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-1.json @@ -18,7 +18,6 @@ "rank": 1, "blocks": { "produced": 15605, - "missed": 709, "last": { "id": "9508080167740922063", "timestamp": { @@ -29,8 +28,7 @@ } }, "production": { - "approval": 0.34, - "productivity": 95.65 + "approval": 0.34 }, "forged": { "fees": 74694705072, @@ -46,7 +44,6 @@ "rank": 2, "blocks": { "produced": 15104, - "missed": 493, "last": { "id": "6408769526029163610", "timestamp": { @@ -57,8 +54,7 @@ } }, "production": { - "approval": 0.06, - "productivity": 96.84 + "approval": 0.06 }, "forged": { "fees": 50980000000, @@ -73,12 +69,10 @@ "votes": 6343253260000, "rank": 3, "blocks": { - "produced": 4165, - "missed": 785 + "produced": 4165 }, "production": { - "approval": 0.05, - "productivity": 84.14 + "approval": 0.05 }, "forged": { "fees": 3550000000, diff --git a/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-2.json b/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-2.json index c3d3a340e1..5841e31024 100644 --- a/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-2.json +++ b/__tests__/integration/core-tester-cli/__fixtures__/delegates-page-2.json @@ -18,7 +18,6 @@ "rank": 4, "blocks": { "produced": 1551, - "missed": 180, "last": { "id": "3658545612136752676", "timestamp": { @@ -29,8 +28,7 @@ } }, "production": { - "approval": 0.05, - "productivity": 89.6 + "approval": 0.05 }, "forged": { "fees": 5060000000, @@ -45,12 +43,10 @@ "votes": 4500000000000, "rank": 5, "blocks": { - "produced": 14572, - "missed": 772 + "produced": 14572 }, "production": { - "approval": 0.04, - "productivity": 94.97 + "approval": 0.04 }, "forged": { "fees": 29670020960, @@ -65,12 +61,10 @@ "votes": 4013860773791, "rank": 6, "blocks": { - "produced": 2650, - "missed": 950 + "produced": 2650 }, "production": { - "approval": 0.03, - "productivity": 73.61 + "approval": 0.03 }, "forged": { "fees": 3000000000, diff --git a/__tests__/unit/core-database/repositories/delegates-business-repository.test.ts b/__tests__/unit/core-database/repositories/delegates-business-repository.test.ts index 6b29cad2dc..519e2c9604 100644 --- a/__tests__/unit/core-database/repositories/delegates-business-repository.test.ts +++ b/__tests__/unit/core-database/repositories/delegates-business-repository.test.ts @@ -371,7 +371,6 @@ describe("Delegate Repository", () => { publicKey: "test", voteBalance: new Bignum(10000 * constants.SATOSHI), producedBlocks: 1000, - missedBlocks: 500, }; const height = 1; diff --git a/__tests__/unit/core-utils/delegate-calculator.test.ts b/__tests__/unit/core-utils/delegate-calculator.test.ts index c0bb51d4bd..bf6df11a10 100644 --- a/__tests__/unit/core-utils/delegate-calculator.test.ts +++ b/__tests__/unit/core-utils/delegate-calculator.test.ts @@ -3,18 +3,13 @@ import "./mocks/core-container-calculator"; import { Wallet } from "@arkecosystem/core-database"; import { Bignum } from "@arkecosystem/crypto"; -import { - calculateApproval, - calculateForgedTotal, - calculateProductivity, -} from "../../../packages/core-utils/src/delegate-calculator"; +import { calculateApproval, calculateForgedTotal } from "../../../packages/core-utils/src/delegate-calculator"; let delegate: Wallet; beforeEach(() => { delegate = new Wallet("D61xc3yoBQDitwjqUspMPx1ooET6r1XLt7"); delegate.producedBlocks = 0; - delegate.missedBlocks = 0; }); describe("Delegate Calculator", () => { @@ -38,22 +33,6 @@ describe("Delegate Calculator", () => { }); }); - describe("calculateProductivity", () => { - it("should calculate correctly for a value above 0", () => { - delegate.missedBlocks = 10; - delegate.producedBlocks = 100; - - expect(calculateProductivity(delegate)).toBe(90.91); - }); - - it("should calculate correctly for a value of 0", () => { - delegate.missedBlocks = 0; - delegate.producedBlocks = 0; - - expect(calculateProductivity(delegate)).toBe(0.0); - }); - }); - describe("calculateForgedTotal", () => { it("should calculate correctly", () => { delegate.forgedFees = new Bignum(10); diff --git a/deprecated/core-graphql/src/defs/types.ts b/deprecated/core-graphql/src/defs/types.ts index 22db2aa611..a9197aacf4 100644 --- a/deprecated/core-graphql/src/defs/types.ts +++ b/deprecated/core-graphql/src/defs/types.ts @@ -42,7 +42,6 @@ export const types = ` balance: Float voteBalance: Float producedBlocks: Float - missedBlocks: Float transactions(limit: Limit, offset: Offset, orderBy: OrderByInput): [Transaction] blocks(limit: Limit, offset: Offset, orderBy: OrderByInput): [Block] } diff --git a/packages/core-api/src/versions/1/delegates/transformer.ts b/packages/core-api/src/versions/1/delegates/transformer.ts index 84cff93572..584cbbea2f 100644 --- a/packages/core-api/src/versions/1/delegates/transformer.ts +++ b/packages/core-api/src/versions/1/delegates/transformer.ts @@ -7,10 +7,8 @@ export function transformDelegateLegacy(model) { publicKey: model.publicKey, vote: `${model.voteBalance}`, producedblocks: model.producedBlocks, - missedblocks: model.missedBlocks, forged: model.forged, rate: model.rate, approval: delegateCalculator.calculateApproval(model), - productivity: delegateCalculator.calculateProductivity(model), }; } diff --git a/packages/core-api/src/versions/2/delegates/schema.ts b/packages/core-api/src/versions/2/delegates/schema.ts index a351fa20b6..9ffbe7d664 100644 --- a/packages/core-api/src/versions/2/delegates/schema.ts +++ b/packages/core-api/src/versions/2/delegates/schema.ts @@ -62,9 +62,6 @@ export const index: object = { producedBlocks: Joi.number() .integer() .min(0), - missedBlocks: Joi.number() - .integer() - .min(0), }, }, }; @@ -107,9 +104,7 @@ export const search: object = { forgedFees: schemaIntegerBetween, forgedRewards: schemaIntegerBetween, forgedTotal: schemaIntegerBetween, - missedBlocks: schemaIntegerBetween, producedBlocks: schemaIntegerBetween, - productivity: schemaPercentage, voteBalance: schemaIntegerBetween, }, }; @@ -187,9 +182,6 @@ export const voters: object = { producedBlocks: Joi.number() .integer() .min(0), - missedBlocks: Joi.number() - .integer() - .min(0), }, }, }; diff --git a/packages/core-api/src/versions/2/delegates/transformer.ts b/packages/core-api/src/versions/2/delegates/transformer.ts index 1ca260088f..b0956cf12b 100644 --- a/packages/core-api/src/versions/2/delegates/transformer.ts +++ b/packages/core-api/src/versions/2/delegates/transformer.ts @@ -9,11 +9,9 @@ export function transformDelegate(delegate) { rank: delegate.rate, blocks: { produced: delegate.producedBlocks, - missed: delegate.missedBlocks, }, production: { approval: delegateCalculator.calculateApproval(delegate), - productivity: delegateCalculator.calculateProductivity(delegate), }, forged: { fees: +delegate.forgedFees.toFixed(), diff --git a/packages/core-api/src/versions/2/wallets/schema.ts b/packages/core-api/src/versions/2/wallets/schema.ts index cd85bcd18a..75213f3693 100644 --- a/packages/core-api/src/versions/2/wallets/schema.ts +++ b/packages/core-api/src/versions/2/wallets/schema.ts @@ -27,9 +27,6 @@ export const index: object = { producedBlocks: Joi.number() .integer() .min(0), - missedBlocks: Joi.number() - .integer() - .min(0), }, }, }; @@ -201,9 +198,6 @@ export const search: object = { producedBlocks: Joi.number() .integer() .min(0), - missedBlocks: Joi.number() - .integer() - .min(0), balance: Joi.object().keys({ from: Joi.number().integer(), to: Joi.number().integer(), diff --git a/packages/core-database-postgres/src/integrity-verifier.ts b/packages/core-database-postgres/src/integrity-verifier.ts index 1b6508d4e7..7e0a4dab78 100644 --- a/packages/core-database-postgres/src/integrity-verifier.ts +++ b/packages/core-database-postgres/src/integrity-verifier.ts @@ -179,7 +179,6 @@ export class IntegrityVerifier { wallet.producedBlocks = +block.totalProduced; }); - // NOTE: This is unreliable but the number of missed blocks is NOT used for the consensus, only for the public API. const delegateWallets = this.walletManager .allByUsername() .sort((a: Database.IWallet, b: Database.IWallet) => b.voteBalance.comparedTo(a.voteBalance)); diff --git a/packages/core-database-postgres/src/models/index.ts b/packages/core-database-postgres/src/models/index.ts index 5fdb934052..62d8bb4408 100644 --- a/packages/core-database-postgres/src/models/index.ts +++ b/packages/core-database-postgres/src/models/index.ts @@ -3,4 +3,3 @@ export * from "./block"; export * from "./migration"; export * from "./round"; export * from "./transaction"; -export * from "./wallet"; diff --git a/packages/core-database-postgres/src/models/wallet.ts b/packages/core-database-postgres/src/models/wallet.ts deleted file mode 100644 index 18e3c0b33d..0000000000 --- a/packages/core-database-postgres/src/models/wallet.ts +++ /dev/null @@ -1,79 +0,0 @@ -import { Database } from "@arkecosystem/core-interfaces"; -import { bignumify } from "@arkecosystem/core-utils"; -import { Model } from "./model"; - -export class Wallet extends Model { - constructor(pgp) { - super(pgp); - - this.columnsDescriptor = [ - { - name: "address", - supportedOperators: [Database.SearchOperator.OP_EQ, Database.SearchOperator.OP_IN], - }, - { - name: "public_key", - prop: "publicKey", - supportedOperators: [Database.SearchOperator.OP_EQ, Database.SearchOperator.OP_IN], - }, - { - name: "second_public_key", - prop: "secondPublicKey", - supportedOperators: [Database.SearchOperator.OP_EQ, Database.SearchOperator.OP_IN], - }, - { - name: "vote", - supportedOperators: [Database.SearchOperator.OP_EQ], - }, - { - name: "username", - supportedOperators: [Database.SearchOperator.OP_EQ, Database.SearchOperator.OP_LIKE], - }, - { - name: "balance", - init: col => bignumify(col.value).toFixed(), - supportedOperators: [ - Database.SearchOperator.OP_EQ, - Database.SearchOperator.OP_GTE, - Database.SearchOperator.OP_LTE, - ], - }, - { - name: "vote_balance", - prop: "voteBalance", - init: col => (col.value ? bignumify(col.value).toFixed() : null), - supportedOperators: [ - Database.SearchOperator.OP_EQ, - Database.SearchOperator.OP_GTE, - Database.SearchOperator.OP_LTE, - ], - }, - { - name: "produced_blocks", - prop: "producedBlocks", - supportedOperators: [ - Database.SearchOperator.OP_EQ, - Database.SearchOperator.OP_GTE, - Database.SearchOperator.OP_LTE, - ], - }, - { - name: "missed_blocks", - prop: "missedBlocks", - supportedOperators: [ - Database.SearchOperator.OP_EQ, - Database.SearchOperator.OP_GTE, - Database.SearchOperator.OP_LTE, - ], - }, - ]; - } - - /** - * The table associated with the model. - * @return {String} - */ - public getTable() { - return "wallets"; - } -} diff --git a/packages/core-database/src/database-service.ts b/packages/core-database/src/database-service.ts index c2be937477..420777d3a7 100644 --- a/packages/core-database/src/database-service.ts +++ b/packages/core-database/src/database-service.ts @@ -415,12 +415,7 @@ export class DatabaseService implements Database.IDatabaseService { const wallet = this.walletManager.findByPublicKey(delegate.publicKey); if (producedBlocks.length === 0) { - wallet.missedBlocks++; - this.logger.debug( - `Delegate ${wallet.username} (${wallet.publicKey}) just missed a block. Total: ${ - wallet.missedBlocks - }`, - ); + this.logger.debug(`Delegate ${wallet.username} (${wallet.publicKey}) just missed a block.`); wallet.dirty = true; this.emitter.emit("forger.missing", { delegate: wallet, diff --git a/packages/core-database/src/repositories/delegates-business-repository.ts b/packages/core-database/src/repositories/delegates-business-repository.ts index 9c17183ca8..3f4406855e 100644 --- a/packages/core-database/src/repositories/delegates-business-repository.ts +++ b/packages/core-database/src/repositories/delegates-business-repository.ts @@ -26,7 +26,6 @@ export class DelegatesBusinessRepository implements Database.IDelegatesBusinessR const manipulators = { approval: delegateCalculator.calculateApproval, - productivity: delegateCalculator.calculateProductivity, forgedTotal: delegateCalculator.calculateForgedTotal, }; @@ -84,15 +83,9 @@ export class DelegatesBusinessRepository implements Database.IDelegatesBusinessR * @param {Object} [params.forgedTotal] - Search by forgedTotal * @param {Number} [params.forgedTotal.from] - Search by forgedTotal (minimum) * @param {Number} [params.forgedTotal.to] - Search by forgedTotal (maximum) - * @param {Object} [params.missedBlocks] - Search by missedBlocks - * @param {Number} [params.missedBlocks.from] - Search by missedBlocks (minimum) - * @param {Number} [params.missedBlocks.to] - Search by missedBlocks (maximum) * @param {Object} [params.producedBlocks] - Search by producedBlocks * @param {Number} [params.producedBlocks.from] - Search by producedBlocks (minimum) * @param {Number} [params.producedBlocks.to] - Search by producedBlocks (maximum) - * @param {Object} [params.productivity] - Search by productivity - * @param {Number} [params.productivity.from] - Search by productivity (minimum) - * @param {Number} [params.productivity.to] - Search by productivity (maximum) * @param {Object} [params.voteBalance] - Search by voteBalance * @param {Number} [params.voteBalance.from] - Search by voteBalance (minimum) * @param {Number} [params.voteBalance.to] - Search by voteBalance (maximum) @@ -101,16 +94,7 @@ export class DelegatesBusinessRepository implements Database.IDelegatesBusinessR const query: any = { exact: ["address", "publicKey"], like: ["username"], - between: [ - "approval", - "forgedFees", - "forgedRewards", - "forgedTotal", - "missedBlocks", - "producedBlocks", - "productivity", - "voteBalance", - ], + between: ["approval", "forgedFees", "forgedRewards", "forgedTotal", "producedBlocks", "voteBalance"], }; if (params.usernames) { @@ -175,8 +159,6 @@ export class DelegatesBusinessRepository implements Database.IDelegatesBusinessR switch (iteratee) { case "approval": return delegateCalculator.calculateApproval; - case "productivity": - return delegateCalculator.calculateProductivity; case "forgedTotal": return delegateCalculator.calculateForgedTotal; case "rank": diff --git a/packages/core-database/src/wallet.ts b/packages/core-database/src/wallet.ts index cdec7e9d7e..e178ba16ac 100644 --- a/packages/core-database/src/wallet.ts +++ b/packages/core-database/src/wallet.ts @@ -24,7 +24,6 @@ export class Wallet implements Database.IWallet { public multisignature?: IMultiSignatureAsset; public dirty: boolean; public producedBlocks: number; - public missedBlocks: number; public forgedFees: Bignum; public forgedRewards: Bignum; public rate?: number; @@ -42,7 +41,6 @@ export class Wallet implements Database.IWallet { this.multisignature = null; this.dirty = true; this.producedBlocks = 0; - this.missedBlocks = 0; this.forgedFees = Bignum.ZERO; this.forgedRewards = Bignum.ZERO; } diff --git a/packages/core-interfaces/src/core-database/wallet-manager.ts b/packages/core-interfaces/src/core-database/wallet-manager.ts index 8852054fb0..f692735b1d 100644 --- a/packages/core-interfaces/src/core-database/wallet-manager.ts +++ b/packages/core-interfaces/src/core-database/wallet-manager.ts @@ -14,7 +14,6 @@ export interface IWallet { multisignature?: IMultiSignatureAsset; dirty: boolean; producedBlocks: number; - missedBlocks: number; forgedFees: Bignum; forgedRewards: Bignum; rate?: number; diff --git a/packages/core-utils/src/delegate-calculator.ts b/packages/core-utils/src/delegate-calculator.ts index 9cba6a1911..8aa47a1be4 100644 --- a/packages/core-utils/src/delegate-calculator.ts +++ b/packages/core-utils/src/delegate-calculator.ts @@ -29,22 +29,6 @@ function calculateApproval(delegate, height: any = null) { .toFixed(2); } -/** - * Calculate the productivity of the given delegate. - * @param {Delegate} delegate - * @return {Number} Productivity, with 2 decimals - */ -function calculateProductivity(delegate) { - const missedBlocks = +delegate.missedBlocks; - const producedBlocks = +delegate.producedBlocks; - - if (!missedBlocks && !producedBlocks) { - return +(0).toFixed(2); - } - - return +(100 - missedBlocks / ((producedBlocks + missedBlocks) / 100)).toFixed(2); -} - /** * Calculate the forged total of the given delegate. * @param {Delegate} delegate @@ -57,4 +41,4 @@ function calculateForgedTotal(delegate) { return +forgedFees.plus(forgedRewards).toFixed(); } -export { calculateApproval, calculateProductivity, calculateForgedTotal }; +export { calculateApproval, calculateForgedTotal }; diff --git a/packages/core-utils/src/index.ts b/packages/core-utils/src/index.ts index cbfec40ac7..7f6ee374d8 100644 --- a/packages/core-utils/src/index.ts +++ b/packages/core-utils/src/index.ts @@ -1,6 +1,6 @@ import { bignumify } from "./bignumify"; import { CappedSet } from "./capped-set"; -import { calculateApproval, calculateForgedTotal, calculateProductivity } from "./delegate-calculator"; +import { calculateApproval, calculateForgedTotal } from "./delegate-calculator"; import { formatTimestamp } from "./format-timestamp"; import { hasSomeProperty } from "./has-some-property"; import { httpie } from "./httpie"; @@ -8,7 +8,7 @@ import { NSect } from "./nsect"; import { calculateRound, isNewRound } from "./round-calculator"; import { calculate } from "./supply-calculator"; -const delegateCalculator = { calculateApproval, calculateProductivity, calculateForgedTotal }; +const delegateCalculator = { calculateApproval, calculateForgedTotal }; const roundCalculator = { calculateRound, isNewRound }; const supplyCalculator = { calculate };