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

Commit

Permalink
Merge pull request #6578 from LiskHQ/6573-fix_p2p_block_response
Browse files Browse the repository at this point in the history
Update p2p block response not to use the decoding data access -  Closes #6573
  • Loading branch information
shuse2 authored Jul 13, 2021
2 parents 784ceb7 + 88ef575 commit 4cf62f9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 4 additions & 0 deletions elements/lisk-chain/src/data_access/data_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ export class DataAccess {
return this._blockHeaderAdapter.decode(blockHeaderBuffer);
}

public async getRawBlockHeaderByID(id: Buffer): Promise<BlockHeader> {
return this._getRawBlockHeaderByID(id);
}

public async blockHeaderExists(id: Buffer): Promise<boolean> {
const cachedBlock = this._blocksCache.getByID(id);
if (cachedBlock) {
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 @@ -180,7 +180,7 @@ export class Transport {
const { blockId } = decodedData as RPCBlocksByIdData;

// Get height of block with supplied ID
const lastBlock = await this._chainModule.dataAccess.getBlockHeaderByID(blockId);
const lastBlock = await this._chainModule.dataAccess.getRawBlockHeaderByID(blockId);

const lastBlockHeight = lastBlock.height;

Expand Down
1 change: 1 addition & 0 deletions framework/test/unit/node/transport/transport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ describe('Transport', () => {
getTransactionsByIDs: jest.fn(),
getHighestCommonBlockID: jest.fn(),
getBlockHeaderByID: jest.fn().mockReturnValue({ height: 123 }),
getRawBlockHeaderByID: jest.fn().mockReturnValue({ height: 123 }),
getBlocksByHeightBetween: jest.fn().mockReturnValue([{ height: 123 }]),
decodeTransaction: jest.fn(),
encodeBlockHeader: jest.fn().mockReturnValue(encodedBlock),
Expand Down
5 changes: 3 additions & 2 deletions framework/test/unit/node/transport/transport_private.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ describe('transport', () => {
lastBlock: jest.fn().mockReturnValue({ height: 1, version: 1, timestamp: 1 }) as any,
dataAccess: {
getBlockHeaderByID: jest.fn().mockReturnValue({ height: 2, version: 1, timestamp: 1 }),
getRawBlockHeaderByID: jest.fn().mockReturnValue({ height: 2, version: 1, timestamp: 1 }),
getBlocksByHeightBetween: jest.fn().mockReturnValue([
{ height: 3, version: 1, timestamp: 1 },
{ height: 37, version: 1, timestamp: 1 },
Expand Down Expand Up @@ -515,7 +516,7 @@ describe('transport', () => {

await transportModule.handleRPCGetBlocksFromId(blockIds);
expect(
transportModule['_chainModule'].dataAccess.getBlockHeaderByID,
transportModule['_chainModule'].dataAccess.getRawBlockHeaderByID,
).toHaveBeenCalledWith(Buffer.from('6258354802676165798'));
return expect(
transportModule['_chainModule'].dataAccess.getBlocksByHeightBetween,
Expand All @@ -532,7 +533,7 @@ describe('transport', () => {
const errorMessage = 'Failed to load blocks...';
const loadBlockFailed = new Error(errorMessage);

transportModule['_chainModule'].dataAccess.getBlockHeaderByID.mockResolvedValue(
transportModule['_chainModule'].dataAccess.getRawBlockHeaderByID.mockResolvedValue(
Promise.reject(loadBlockFailed),
);

Expand Down

0 comments on commit 4cf62f9

Please sign in to comment.