This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 458
Implement genesis block creation and validation function in lisk-genesis - Closes #5277, #5386 #5421
Merged
Merged
Implement genesis block creation and validation function in lisk-genesis - Closes #5277, #5386 #5421
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fb881e5
Update lisk-chain to export schema objects
nazarhussain 46b26e8
Update lisk-genesis to use lisk-chain and lisk-validator
nazarhussain 92293ed
Define types and constants for lisk-genesis
nazarhussain 2eb802c
Add createGenesisBlock to lisk-genesis
nazarhussain 7fb97ef
Add utility functions to be used in lisk-genesis
nazarhussain 10be84a
Update validation for lisk genesis block
nazarhussain 332d9f5
Add lisk-cryptography and lisk-codec as dependency for lisk-genesis
nazarhussain 920d382
Update createGenesisBlock to generate actual block id
nazarhussain ea372c2
Merge branch 'development' into 5277-create-genesis-block
nazarhussain d304c16
Update create genesis to use constant values
nazarhussain e7a4d7d
Add default account asset schema for genesis
nazarhussain d803148
Update create and validate function to use default account asset schema
nazarhussain 75dd063
Add test case for valid input of genesis block to match snapshot
nazarhussain abddaa2
Merge branch 'development' into 5277-create-genesis-block
nazarhussain 2e8c130
Add test skeleton for genesis block creation and validation
nazarhussain 67095b6
Add validation tests for genesis block
nazarhussain 46a1fb1
Add account keys validation for genesis block
nazarhussain 5ff76ef
Add validtion for initDelegates of genesis block
nazarhussain 8fd6ebf
Add unit tests for genesis block creation
nazarhussain 1056c30
Remove a left over console statement
nazarhussain ddd3f1e
Merge branch 'development' into 5277-create-genesis-block
nazarhussain 1a11968
Update some spec comments
nazarhussain 6078f57
Update code with provided feedback
nazarhussain d06e52e
Merge branch 'development' into 5277-create-genesis-block
nazarhussain 2ca9b85
Remove unncessary file from branch
nazarhussain c976906
Add test comments
nazarhussain a7532e4
Update genesis block type to use generic Block type
nazarhussain f37b818
Merge branch 'development' into 5277-create-genesis-block
nazarhussain aff7e4e
Revert "Update genesis block type to use generic Block type"
nazarhussain b81809b
Update validation for buffer values
nazarhussain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright © 2020 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
import { hash } from '@liskhq/lisk-cryptography'; | ||
|
||
export const EMPTY_BUFFER = Buffer.alloc(0); | ||
export const EMPTY_HASH = hash(EMPTY_BUFFER); | ||
|
||
export const GENESIS_BLOCK_VERSION = 0; | ||
export const GENESIS_BLOCK_GENERATOR_PUBLIC_KEY = EMPTY_BUFFER; | ||
export const GENESIS_BLOCK_REWARD = BigInt(0); | ||
export const GENESIS_BLOCK_PAYLOAD: Buffer[] = []; | ||
export const GENESIS_BLOCK_SIGNATURE = EMPTY_BUFFER; | ||
export const GENESIS_BLOCK_TRANSACTION_ROOT = EMPTY_HASH; | ||
export const GENESIS_BLOCK_MAX_BALANCE = BigInt(2) ** BigInt(63) - BigInt(1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
/* | ||
* Copyright © 2020 Lisk Foundation | ||
* | ||
* See the LICENSE file at the top-level directory of this distribution | ||
* for licensing information. | ||
* | ||
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, | ||
* no part of this software, including this file, may be copied, modified, | ||
* propagated, or distributed except according to the terms contained in the | ||
* LICENSE file. | ||
* | ||
* Removal or modification of this copyright notice is prohibited. | ||
*/ | ||
|
||
import { Schema } from '@liskhq/lisk-codec'; | ||
|
||
import { | ||
blockSchema, | ||
baseAccountSchema, | ||
blockHeaderSchema, | ||
} from '@liskhq/lisk-chain'; | ||
import { mergeDeep } from './utils'; | ||
|
||
export const genesisAccountSchema = mergeDeep({}, baseAccountSchema) as Schema; | ||
export const genesisBlockSchema = mergeDeep({}, blockSchema, { | ||
properties: { | ||
payload: { | ||
const: [], | ||
}, | ||
}, | ||
}) as Schema; | ||
|
||
export const defaultAccountAssetSchema = { | ||
$id: '/genesis_block/account/default', | ||
type: 'object', | ||
properties: { | ||
delegate: { | ||
type: 'object', | ||
fieldNumber: 1, | ||
properties: { | ||
username: { dataType: 'string', fieldNumber: 1 }, | ||
pomHeights: { | ||
type: 'array', | ||
items: { dataType: 'uint32' }, | ||
fieldNumber: 2, | ||
}, | ||
consecutiveMissedBlocks: { dataType: 'uint32', fieldNumber: 3 }, | ||
lastForgedHeight: { dataType: 'uint32', fieldNumber: 4 }, | ||
isBanned: { dataType: 'boolean', fieldNumber: 5 }, | ||
totalVotesReceived: { dataType: 'uint64', fieldNumber: 6 }, | ||
}, | ||
required: [ | ||
'username', | ||
'pomHeights', | ||
'consecutiveMissedBlocks', | ||
'lastForgedHeight', | ||
'isBanned', | ||
'totalVotesReceived', | ||
], | ||
}, | ||
sentVotes: { | ||
type: 'array', | ||
fieldNumber: 2, | ||
items: { | ||
type: 'object', | ||
properties: { | ||
delegateAddress: { | ||
dataType: 'bytes', | ||
fieldNumber: 1, | ||
}, | ||
amount: { | ||
dataType: 'uint64', | ||
fieldNumber: 2, | ||
}, | ||
}, | ||
required: ['delegateAddress', 'amount'], | ||
}, | ||
}, | ||
unlocking: { | ||
type: 'array', | ||
fieldNumber: 3, | ||
items: { | ||
type: 'object', | ||
properties: { | ||
delegateAddress: { | ||
dataType: 'bytes', | ||
fieldNumber: 1, | ||
}, | ||
amount: { | ||
dataType: 'uint64', | ||
fieldNumber: 2, | ||
}, | ||
unvoteHeight: { | ||
dataType: 'uint32', | ||
fieldNumber: 3, | ||
}, | ||
}, | ||
required: ['delegateAddress', 'amount', 'unvoteHeight'], | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export const genesisBlockHeaderSchema = mergeDeep({}, blockHeaderSchema, { | ||
properties: { | ||
version: { | ||
const: 0, | ||
}, | ||
}, | ||
}) as Schema; | ||
|
||
export const genesisBlockHeaderAssetSchema = { | ||
$id: '/genesis_block/header/asset', | ||
type: 'object', | ||
required: ['accounts', 'initDelegates', 'initRounds'], | ||
properties: { | ||
accounts: { | ||
type: 'array', | ||
items: { | ||
...genesisAccountSchema, | ||
nazarhussain marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
fieldNumber: 1, | ||
}, | ||
initDelegates: { | ||
type: 'array', | ||
items: { | ||
dataType: 'bytes', | ||
}, | ||
fieldNumber: 2, | ||
minItems: 1, | ||
}, | ||
initRounds: { | ||
dataType: 'uint32', | ||
fieldNumber: 3, | ||
minimum: 3, | ||
}, | ||
}, | ||
} as Schema; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to change this to instance here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, we have to specify full account type and also duplicate code to convert the partial account to a full account attributes. Then we have to add another dependency of
lisk-transactions