Skip to content

Commit

Permalink
refactor: remove missed blocks and productivity (#2257)
Browse files Browse the repository at this point in the history
  • Loading branch information
faustbrian authored Mar 18, 2019
1 parent 7a1ccd6 commit 0288158
Show file tree
Hide file tree
Showing 22 changed files with 15 additions and 289 deletions.
1 change: 0 additions & 1 deletion __tests__/integration/core-api/__support__/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 0 additions & 2 deletions __tests__/integration/core-api/v1/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
93 changes: 0 additions & 93 deletions __tests__/integration/core-api/v2/handlers/delegates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const delegate = {
forgedRewards: 50,
forgedTotal: 100,
producedBlocks: 75,
missedBlocks: 25,
productivity: 75,
voteBalance: 100000,
};

Expand All @@ -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);
});
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 0 additions & 2 deletions __tests__/integration/core-api/v2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"rank": 1,
"blocks": {
"produced": 15605,
"missed": 709,
"last": {
"id": "9508080167740922063",
"timestamp": {
Expand All @@ -29,8 +28,7 @@
}
},
"production": {
"approval": 0.34,
"productivity": 95.65
"approval": 0.34
},
"forged": {
"fees": 74694705072,
Expand All @@ -46,7 +44,6 @@
"rank": 2,
"blocks": {
"produced": 15104,
"missed": 493,
"last": {
"id": "6408769526029163610",
"timestamp": {
Expand All @@ -57,8 +54,7 @@
}
},
"production": {
"approval": 0.06,
"productivity": 96.84
"approval": 0.06
},
"forged": {
"fees": 50980000000,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"rank": 4,
"blocks": {
"produced": 1551,
"missed": 180,
"last": {
"id": "3658545612136752676",
"timestamp": {
Expand All @@ -29,8 +28,7 @@
}
},
"production": {
"approval": 0.05,
"productivity": 89.6
"approval": 0.05
},
"forged": {
"fees": 5060000000,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@ describe("Delegate Repository", () => {
publicKey: "test",
voteBalance: new Bignum(10000 * constants.SATOSHI),
producedBlocks: 1000,
missedBlocks: 500,
};
const height = 1;

Expand Down
23 changes: 1 addition & 22 deletions __tests__/unit/core-utils/delegate-calculator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion deprecated/core-graphql/src/defs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down
2 changes: 0 additions & 2 deletions packages/core-api/src/versions/1/delegates/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
8 changes: 0 additions & 8 deletions packages/core-api/src/versions/2/delegates/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ export const index: object = {
producedBlocks: Joi.number()
.integer()
.min(0),
missedBlocks: Joi.number()
.integer()
.min(0),
},
},
};
Expand Down Expand Up @@ -107,9 +104,7 @@ export const search: object = {
forgedFees: schemaIntegerBetween,
forgedRewards: schemaIntegerBetween,
forgedTotal: schemaIntegerBetween,
missedBlocks: schemaIntegerBetween,
producedBlocks: schemaIntegerBetween,
productivity: schemaPercentage,
voteBalance: schemaIntegerBetween,
},
};
Expand Down Expand Up @@ -187,9 +182,6 @@ export const voters: object = {
producedBlocks: Joi.number()
.integer()
.min(0),
missedBlocks: Joi.number()
.integer()
.min(0),
},
},
};
Expand Down
2 changes: 0 additions & 2 deletions packages/core-api/src/versions/2/delegates/transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
6 changes: 0 additions & 6 deletions packages/core-api/src/versions/2/wallets/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ export const index: object = {
producedBlocks: Joi.number()
.integer()
.min(0),
missedBlocks: Joi.number()
.integer()
.min(0),
},
},
};
Expand Down Expand Up @@ -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(),
Expand Down
1 change: 0 additions & 1 deletion packages/core-database-postgres/src/integrity-verifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion packages/core-database-postgres/src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from "./block";
export * from "./migration";
export * from "./round";
export * from "./transaction";
export * from "./wallet";
Loading

0 comments on commit 0288158

Please sign in to comment.