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

Create BlockProcessorV0 which handles the genesis block - Closes #5278 #5457

Merged
merged 28 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8c7f4e7
Merge branch 'development' into feature/new-genesis-integration
nazarhussain Jun 22, 2020
6666524
Add encoding/decoding test case for genesis block
nazarhussain Jun 22, 2020
8b3bb7b
Update the condition for application state to include genesis block h…
nazarhussain Jun 22, 2020
d6c9f2b
Remove applyGenesis pipeline from base block processor
nazarhussain Jun 22, 2020
3e17cb7
Remove applyGenesis step from block processor v2
nazarhussain Jun 22, 2020
e78a081
Update the check for isGenesis block in lisk-dpos
nazarhussain Jun 22, 2020
46b5a57
Update lisk-chain to load genesis block by id not by height
nazarhussain Jun 22, 2020
ff0c03f
Add get/set for registered delegates to lisk-dpos
nazarhussain Jun 22, 2020
75782dc
Update the check for isGenesis in lisk-chain
nazarhussain Jun 22, 2020
fbd63b2
Remove unused functions for genesis block in lisk-chain
nazarhussain Jun 22, 2020
9e1dfd7
Add block processor for version 0
nazarhussain Jun 22, 2020
ce297e1
Update block processor to run block processor for version 0
nazarhussain Jun 22, 2020
88b52b8
Update the occurences of the genesis block version
nazarhussain Jun 22, 2020
f148180
Fix framework unit tests
nazarhussain Jun 22, 2020
de1de92
Merge branch 'feature/new-genesis-integration' into 5278-genesis-bloc…
nazarhussain Jun 23, 2020
756cf0d
Fix lisk-dpos unit tests
nazarhussain Jun 23, 2020
808525c
Fix lisk-chain unit tests
nazarhussain Jun 23, 2020
c295a16
Update the code as per feedback
nazarhussain Jun 23, 2020
630465f
Fix feedback from deepscan
nazarhussain Jun 23, 2020
6903233
Fix block_synchronization tests
ishantiw Jun 23, 2020
89f825c
Fix default value for finalized height stored in bft
nazarhussain Jun 23, 2020
257a3dc
Fix tests for lisk-chain
nazarhussain Jun 23, 2020
399bff9
Fix genesis block parsing in framework
nazarhussain Jun 23, 2020
43eacf3
Fix functional and integration tests for framework
nazarhussain Jun 23, 2020
2273e14
Merge branch '5278-genesis-block-processor' of github.com:LiskHQ/lisk…
nazarhussain Jun 23, 2020
b8d00bb
Fix block synchronization mechanism unit tets
nazarhussain Jun 23, 2020
94dc214
Fix fast chain switching mechanism unit tets
nazarhussain Jun 23, 2020
f34f9d8
Update block processor v0 to fetch the delegate usernames in one loop
nazarhussain Jun 24, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion elements/lisk-bft/src/bft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class BFT extends EventEmitter {

const finalizedHeightStored =
storedFinalizedHeightBuffer === undefined
? 1
? 0
: codec.decode<BFTPersistedValues>(
BFTFinalizedHeightCodecSchema,
storedFinalizedHeightBuffer,
Expand Down
20 changes: 6 additions & 14 deletions elements/lisk-chain/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { DataAccess } from './data_access';
import { Slots } from './slots';
import { StateStore } from './state_store';
import {
applyGenesisTransactions,
applyTransactions,
checkAllowedTransactions,
undoTransactions,
Expand Down Expand Up @@ -222,7 +221,9 @@ export class Chain {
// Check mem tables
let genesisBlock: BlockHeader;
try {
genesisBlock = await this.dataAccess.getBlockHeaderByHeight(1);
genesisBlock = await this.dataAccess.getBlockHeaderByID(
this.genesisBlock.header.id,
);
} catch (error) {
throw new Error('Failed to load genesis block');
}
Expand Down Expand Up @@ -253,7 +254,7 @@ export class Chain {

public async newStateStore(skipLastHeights = 0): Promise<StateStore> {
const fromHeight = Math.max(
1,
0,
this._lastBlock.header.height -
this.constants.stateBlockSize -
skipLastHeights,
Expand Down Expand Up @@ -363,15 +364,6 @@ export class Chain {
await applyFeeAndRewards(block, stateStore);
}

// eslint-disable-next-line class-methods-use-this
public async applyGenesis(
block: Block,
stateStore: StateStore,
): Promise<void> {
await applyGenesisTransactions(block.payload, stateStore);
await applyFeeAndRewards(block, stateStore);
}

public async save(
block: Block,
stateStore: StateStore,
Expand Down Expand Up @@ -416,7 +408,7 @@ export class Chain {
stateStore: StateStore,
{ saveTempBlock } = { saveTempBlock: false },
): Promise<void> {
if (block.header.height === 1) {
if (block.header.version === this.genesisBlock.header.version) {
throw new Error('Cannot delete genesis block');
}
let secondLastBlock: Block;
Expand Down Expand Up @@ -533,7 +525,7 @@ export class Chain {
// Cache the block headers (size=DEFAULT_MAX_BLOCK_HEADER_CACHE)
const fromHeight = Math.max(
storageLastBlock.header.height - DEFAULT_MAX_BLOCK_HEADER_CACHE,
1,
0,
);
const toHeight = storageLastBlock.header.height;

Expand Down
1 change: 0 additions & 1 deletion elements/lisk-chain/src/transactions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,4 @@ export {
applyTransactions,
checkAllowedTransactions,
undoTransactions,
applyGenesisTransactions,
} from './transactions_handlers';
23 changes: 1 addition & 22 deletions elements/lisk-chain/src/transactions/transactions_handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,13 @@ import {
} from '@liskhq/lisk-transactions';

import { StateStore } from '../state_store';
import {
Contexter,
MatcherTransaction,
WriteableTransactionResponse,
} from '../types';
import { Contexter, MatcherTransaction } from '../types';

export const validateTransactions = (
transactions: ReadonlyArray<BaseTransaction>,
): ReadonlyArray<TransactionResponse> =>
transactions.map(transaction => transaction.validate());

export const applyGenesisTransactions = async (
transactions: ReadonlyArray<BaseTransaction>,
stateStore: StateStore,
): Promise<TransactionResponse[]> => {
const transactionsResponses: TransactionResponse[] = [];
for (const transaction of transactions) {
const transactionResponse = await transaction.apply(stateStore);

// We are overriding the status of transaction because it's from genesis block
(transactionResponse as WriteableTransactionResponse).status =
TransactionStatus.OK;
transactionsResponses.push(transactionResponse);
}

return transactionsResponses;
};

export const applyTransactions = async (
transactions: ReadonlyArray<BaseTransaction>,
stateStore: StateStore,
Expand Down
7 changes: 2 additions & 5 deletions elements/lisk-chain/src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ export const validatePreviousBlockProperty = (
): void => {
const isGenesisBlock =
block.header.id.equals(genesisBlock.header.id) &&
block.header.previousBlockID.length === 0 &&
block.header.height === 1;
block.header.version === 0;
const propertyIsValid =
isGenesisBlock ||
(!block.header.id.equals(genesisBlock.header.id) &&
block.header.previousBlockID.length > 0 &&
block.header.height !== 1);
(block.header.previousBlockID.length > 0 && block.header.version !== 0);

if (!propertyIsValid) {
throw new Error('Invalid previous block');
Expand Down
Loading