From 5c5204608e242c1c7f522a1a95929d13555a87d3 Mon Sep 17 00:00:00 2001 From: Shusetsu Toda Date: Tue, 13 Jul 2021 09:25:10 +0200 Subject: [PATCH] :recycle: Fix lint and remove unnecessary code --- elements/lisk-chain/src/data_access/data_access.ts | 6 ++---- elements/lisk-chain/src/data_access/storage.ts | 1 + elements/lisk-chain/src/types.ts | 1 - framework/src/node/node.ts | 2 +- framework/src/node/transport/transport.ts | 2 +- framework/src/testing/app_env.ts | 4 ++-- framework/test/unit/node/transport/transport.spec.ts | 8 ++++---- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/elements/lisk-chain/src/data_access/data_access.ts b/elements/lisk-chain/src/data_access/data_access.ts index 202b23c3961..7714389e288 100644 --- a/elements/lisk-chain/src/data_access/data_access.ts +++ b/elements/lisk-chain/src/data_access/data_access.ts @@ -13,7 +13,6 @@ */ import { KVStore, NotFoundError } from '@liskhq/lisk-db'; import { codec, Schema } from '@liskhq/lisk-codec'; -import { hash } from '@liskhq/lisk-cryptography'; import { Transaction } from '../transaction'; import { BlockHeader, Block, RawBlock, Account, BlockHeaderAsset } from '../types'; @@ -114,7 +113,7 @@ export class DataAccess { return true; } try { - // if header does not exist, it will through not found error + // if header does not exist, it will throw not found error await this._storage.getBlockHeaderByID(id); return true; } catch (error) { @@ -472,11 +471,10 @@ export class DataAccess { return cachedBlock; } const blockHeaderBuffer = await this._storage.getBlockHeaderByID(id); - const blockID = hash(blockHeaderBuffer); return { ...codec.decode(blockHeaderSchema, blockHeaderBuffer), - id: blockID, + id, }; } } diff --git a/elements/lisk-chain/src/data_access/storage.ts b/elements/lisk-chain/src/data_access/storage.ts index 32d5f0a0cc8..a496eda0e46 100644 --- a/elements/lisk-chain/src/data_access/storage.ts +++ b/elements/lisk-chain/src/data_access/storage.ts @@ -292,6 +292,7 @@ export class Storage { } } + // TODO: Remove in next version // Warning: This function should never be used. This exist only for migration purpose. // Specifically, only to set genesis state between 5.1.2 => 5.1.3 public async setConsensusState(key: string, val: Buffer): Promise { diff --git a/elements/lisk-chain/src/types.ts b/elements/lisk-chain/src/types.ts index c4452687086..41e8caa63c3 100644 --- a/elements/lisk-chain/src/types.ts +++ b/elements/lisk-chain/src/types.ts @@ -110,6 +110,5 @@ export interface Validator { export interface GenesisInfo { height: number; - timestamp: number; initRounds: number; } diff --git a/framework/src/node/node.ts b/framework/src/node/node.ts index 4b53ccdb66c..8a52bc20e14 100644 --- a/framework/src/node/node.ts +++ b/framework/src/node/node.ts @@ -286,7 +286,7 @@ export class Node { this._transport.handleRPCGetBlocksFromId(data, peerId), ); this._networkModule.registerEndpoint('getHighestCommonBlock', async ({ data, peerId }) => - this._transport.handleRPCGetHighestCommonBlock(data, peerId), + this._transport.handleRPCGetHighestCommonBlockID(data, peerId), ); // Network needs to be initialized first to call events diff --git a/framework/src/node/transport/transport.ts b/framework/src/node/transport/transport.ts index 0948baad70e..4f6a2711cfb 100644 --- a/framework/src/node/transport/transport.ts +++ b/framework/src/node/transport/transport.ts @@ -197,7 +197,7 @@ export class Transport { return codec.encode(getBlocksFromIdResponseSchema, { blocks: encodedBlocks }); } - public async handleRPCGetHighestCommonBlock(data: unknown, peerId: string): Promise { + public async handleRPCGetHighestCommonBlockID(data: unknown, peerId: string): Promise { this._addRateLimit('getHighestCommonBlock', peerId, DEFAULT_COMMON_BLOCK_RATE_LIMIT_FREQUENCY); const blockIds = codec.decode( getHighestCommonBlockRequestSchema, diff --git a/framework/src/testing/app_env.ts b/framework/src/testing/app_env.ts index 2eba25a6c50..335c8f4558e 100644 --- a/framework/src/testing/app_env.ts +++ b/framework/src/testing/app_env.ts @@ -45,10 +45,9 @@ export class ApplicationEnv { private _application!: Application; private _dataPath!: string; private _ipcClient!: APIClient; - private _genesisBlock: Record; + private _genesisBlock!: Record; public constructor(appConfig: ApplicationEnvConfig) { - this._genesisBlock = appConfig.genesisBlockJSON as Record; this._initApplication(appConfig); } @@ -119,6 +118,7 @@ export class ApplicationEnv { // so we need to make sure existing schemas are already clear codec.clearCache(); const { genesisBlockJSON } = createGenesisBlock({ modules: appConfig.modules }); + this._genesisBlock = genesisBlockJSON; // In order for application to start forging, update force to true const config = objects.mergeDeep({}, defaultConfig, appConfig.config ?? {}); const { label } = config; diff --git a/framework/test/unit/node/transport/transport.spec.ts b/framework/test/unit/node/transport/transport.spec.ts index ecda2a0389f..589638dfe59 100644 --- a/framework/test/unit/node/transport/transport.spec.ts +++ b/framework/test/unit/node/transport/transport.spec.ts @@ -312,7 +312,7 @@ describe('Transport', () => { }); }); - describe('handleRPCGetHighestCommonBlock', () => { + describe('handleRPCGetHighestCommonBlockID', () => { const defaultPeerId = 'peer-id'; describe('when commonBlock has not been found', () => { @@ -326,7 +326,7 @@ describe('Transport', () => { const blockIds = codec.encode(getHighestCommonBlockRequestSchema, { ids }); // Act - const result = await transport.handleRPCGetHighestCommonBlock(blockIds, defaultPeerId); + const result = await transport.handleRPCGetHighestCommonBlockID(blockIds, defaultPeerId); // Assert expect(chainStub.dataAccess.getHighestCommonBlockID).toHaveBeenCalledWith(ids); @@ -348,7 +348,7 @@ describe('Transport', () => { const blockIds = codec.encode(getHighestCommonBlockRequestSchema, { ids }); // Act - const result = await transport.handleRPCGetHighestCommonBlock(blockIds, defaultPeerId); + const result = await transport.handleRPCGetHighestCommonBlockID(blockIds, defaultPeerId); // Assert expect(chainStub.dataAccess.getHighestCommonBlockID).toHaveBeenCalledWith(ids); @@ -809,7 +809,7 @@ describe('Transport', () => { it('should apply penalty when called ', async () => { // Arrange [...new Array(DEFAULT_COMMON_BLOCK_RATE_LIMIT_FREQUENCY + 1)].map(async () => - transport.handleRPCGetHighestCommonBlock(blockIds, defaultPeerId), + transport.handleRPCGetHighestCommonBlockID(blockIds, defaultPeerId), ); jest.advanceTimersByTime(defaultRateLimit);