-
Notifications
You must be signed in to change notification settings - Fork 455
Initial documentation for blocks module - Closes #542 #553
Conversation
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.
Grammatical changes/spelling changes. The rest looks great :)
modules/blocks.js
Outdated
@@ -252,14 +329,17 @@ __private.getIdSequence = function (height, cb) { | |||
} | |||
} | |||
|
|||
// Add last block at the beginning if set not cointains it already |
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.
// Add last block at the beginning if set not cointains it already
Add last block at the beginning if the set does not contain it already
modules/blocks.js
Outdated
library.db.query(sql.getIdSequence(), {height: height, limit: 5, delegates: constants.activeDelegates}).then(function (rows) { | ||
if (rows.length === 0) { | ||
return setImmediate(cb, 'Failed to get id sequence for height: ' + height); | ||
} | ||
|
||
var ids = []; | ||
|
||
// Add genesis block at the end if set not cointains it already |
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.
Add genesis block at the end if the set does not contain it already
modules/blocks.js
Outdated
__private.saveGenesisBlock = function (cb) { | ||
// Check if there is already block with genesis block ID in database |
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.
Check if genesis block ID already exists in the database
transaction.blockId = block.id; | ||
// Create bytea fileds (buffers), and returns pseudo-row promise-like object |
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.
Fields
Blocks.prototype.getLastBlock = function () { | ||
if (__private.lastBlock) { | ||
var epoch = constants.epochTime / 1000; | ||
var lastBlockTime = epoch + __private.lastBlock.timestamp; | ||
var currentTime = new Date().getTime() / 1000; | ||
|
||
//FIXME: That function modify global last block object - not good, for what we need those properties? |
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.
This function modifies global last block object.
We should find a different way, as this can produce inconsistencies.
modules/blocks.js
Outdated
blocks = __private.readDbRows(rows); | ||
} | ||
|
||
return setImmediate(cb, err, blocks); | ||
}); | ||
}; | ||
|
||
/** | ||
* Loads full blocks from database, used when rebuilding blockchain, snapshoting |
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.
snapshotting
modules/blocks.js
Outdated
* @method loadBlocksOffset | ||
* @param {number} limit Limit amount of blocks | ||
* @param {number} offset Offset to start at | ||
* @param {boolean} verify Indicator that block need to be verified |
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.
needs
modules/blocks.js
Outdated
library.dbSequence.add(function (cb) { | ||
// Loads full blocks from database | ||
// FIXME: Weird logic in that SQL query, also ordering used can be performance bootleneck - to rewrite |
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.
bottleneck
modules/blocks.js
Outdated
return setImmediate(cb, check.errors[0]); | ||
} | ||
} | ||
if (block.id === genesisblock.block.id) { | ||
__private.applyGenesisBlock(block, cb); | ||
} else { | ||
// Apply block - broadcast: false, saveBlock: false | ||
// FIXME: Looks like we missing some validations here, because applyBlock is different than processBlock used elesewhere |
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.
we are missing
modules/blocks.js
Outdated
return setImmediate(cb, check.errors[0]); | ||
} | ||
} | ||
if (block.id === genesisblock.block.id) { | ||
__private.applyGenesisBlock(block, cb); | ||
} else { | ||
// Apply block - broadcast: false, saveBlock: false | ||
// FIXME: Looks like we missing some validations here, because applyBlock is different than processBlock used elesewhere | ||
// - that need to be checked and adjusted to be consistent |
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.
Consistency should be verified and fixed
* @param {Function} cb Callback function | ||
* @return {Function} cb Callback function from params (through setImmediate) | ||
* @return {Object} cb.err Error if occurred | ||
*/ |
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.
Also this method returns a call to afterSave
. It should be something like returns {Error|afterSave} if SQL transaction is ok, returns safterSave execution, if not returns error
modules/blocks.js
Outdated
* @param {Object} block Full normalized block | ||
* @param {Object} blockPromises Not used | ||
* @return {Object} t SQL connection object filled with inserts | ||
*/ |
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.
@throws Will throw 'Invalid promise' when no promise, promise.values or promise.table
* @param {boolean} saveBlock Indicator that block needs to be saved to database | ||
* @return {Function} cb Callback function from params (through setImmediate) | ||
* @return {Object} cb.err Error if occurred | ||
*/ |
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.
Add @emits SIGTERM
modules/blocks.js
Outdated
* @method sandboxApi | ||
* @param {string} call Name of the function to be called | ||
* @param {Object} args Arguments | ||
* @return {Function} cb Callback function |
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.
replace last comment @return
with @param
modules/blocks.js
Outdated
* @method onReceiveBlock | ||
* @listens module:transport~event:receiveBlock | ||
* @param {block} block New block | ||
*/ |
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.
missed return parameters
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.
Because that function doesn't return.
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.
Returns empty when client not ready to receive block
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.
So it should be @return {undefined}
? When I ommit @return
tag compiler should assume that the function returns undefined
.
Fixed issues from review, thanks. |
Addresses
modules/blocks.js
in #542.