LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 456 forks source link

Remove block dependency from blocks/utils #4012

Closed nazarhussain closed 5 years ago

nazarhussain commented 5 years ago

Expected behavior

Blocks/Utils must be pure utility functions without have any dependency on any other module.

Actual behavior

Currently the block/utils.js is requiring block.js which is requiring the block_v1.js and block_v2.js. It violates the concepts of utility functions. Also in case we need to use some utility function inside block_v1.js or block_v2.js, it creates a circular dependency and failed.

https://github.com/LiskHQ/lisk-sdk/blob/8920e9dd4bd1be8aa578d294395fe46d50b0f970/framework/src/modules/chain/blocks/utils.js#L20

Which version(s) does this affect? (Environment, OS, etc...)

2.3.0

nazarhussain commented 5 years ago

One who work own this, must use the shared logic of sort functions

https://github.com/LiskHQ/lisk-sdk/blob/b36afadc835f6e627c6a1859992106b2eb3c61eb/framework/src/modules/chain/blocks/utils.js#L559

on these two places

https://github.com/LiskHQ/lisk-sdk/blob/b36afadc835f6e627c6a1859992106b2eb3c61eb/framework/src/modules/chain/blocks/block_v1.js#L173

https://github.com/LiskHQ/lisk-sdk/blob/b36afadc835f6e627c6a1859992106b2eb3c61eb/framework/src/modules/chain/blocks/block_v2.js#L192

michielmulders commented 5 years ago

blocksLogic.storageRead(block); I think this function can use blocks functionality to read blocks and a pure function in blocksLogic that only processes this.

michielmulders commented 5 years ago

Same for const block = blocksLogic.dbRead(rows[i]); @nazarhussain

nazarhussain commented 5 years ago

All dependepdecies to block/utils.js must be passed as arguments.