Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
♻️ Fix lint and remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
shuse2 committed Jul 13, 2021
1 parent e0070cb commit 5c52046
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
6 changes: 2 additions & 4 deletions elements/lisk-chain/src/data_access/data_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
};
}
}
1 change: 1 addition & 0 deletions elements/lisk-chain/src/data_access/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
1 change: 0 additions & 1 deletion elements/lisk-chain/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,5 @@ export interface Validator {

export interface GenesisInfo {
height: number;
timestamp: number;
initRounds: number;
}
2 changes: 1 addition & 1 deletion framework/src/node/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion framework/src/node/transport/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class Transport {
return codec.encode(getBlocksFromIdResponseSchema, { blocks: encodedBlocks });
}

public async handleRPCGetHighestCommonBlock(data: unknown, peerId: string): Promise<Buffer> {
public async handleRPCGetHighestCommonBlockID(data: unknown, peerId: string): Promise<Buffer> {
this._addRateLimit('getHighestCommonBlock', peerId, DEFAULT_COMMON_BLOCK_RATE_LIMIT_FREQUENCY);
const blockIds = codec.decode<RPCHighestCommonBlockData>(
getHighestCommonBlockRequestSchema,
Expand Down
4 changes: 2 additions & 2 deletions framework/src/testing/app_env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ export class ApplicationEnv {
private _application!: Application;
private _dataPath!: string;
private _ipcClient!: APIClient;
private _genesisBlock: Record<string, unknown>;
private _genesisBlock!: Record<string, unknown>;

public constructor(appConfig: ApplicationEnvConfig) {
this._genesisBlock = appConfig.genesisBlockJSON as Record<string, unknown>;
this._initApplication(appConfig);
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions framework/test/unit/node/transport/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ describe('Transport', () => {
});
});

describe('handleRPCGetHighestCommonBlock', () => {
describe('handleRPCGetHighestCommonBlockID', () => {
const defaultPeerId = 'peer-id';

describe('when commonBlock has not been found', () => {
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5c52046

Please sign in to comment.