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

Improve block propagation - Closes #541 #623

Merged
merged 40 commits into from
Aug 8, 2017
Merged

Conversation

LucasIsasmendi
Copy link
Contributor

@LucasIsasmendi LucasIsasmendi commented Jun 21, 2017

Closes #541

Copy link
Contributor

@4miners 4miners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, added some comments. 👍

We can go one step ahead with block minify. Beacause we already need to calculate some properties during verify and then check against them - we can skip them entirely and then instead validate signature.

* @param {Object} block Block object completed
* @return {Object} Block object reduced
*/
__private.deleteBlockProperties = function (block) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalAmount, totalFee, payloadLength can also be skipped if 0

}

result.verified = result.errors.length === 0;
return result;
if (getBlockId !== block.id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We change behavior here, previous was:

  • overwrite block.id
  • validate signature

Now we have:

  • validate signature
  • validate block.id

Maybe validation is not needed so we can also skip block.id during broadcast?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, in this way verifyBlock will validate parameters and at the end generate and add block.id

@@ -231,6 +268,18 @@ Verify.prototype.processBlock = function (block, broadcast, cb, saveBlock) {
}

async.series({
addBlockProperties: function (seriesCb) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should be performed inside objectNormalize

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block.prototype.create calls to objectNormalize, there are no missed properties, therefore no need to perform addBlockProperties logic. Same for loadBlocksOffset, with data from DB.
receiveBlock will need it, so we can add it to public logic.block and call it from transport and verify to avoid one function with two logics.

function createBlock (blocksModule, blockLogic, secret, timestamp, transactions, previousBlock) {
var keypair = blockLogic.scope.ed.makeKeypair(crypto.createHash('sha256').update(secret, 'utf8').digest());
blocksModule.lastBlock.set(previousBlock);
var newBLock = blockLogic.create({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo newBLock

}
blockLogic = __blockLogic;

modulesLoader.initModules([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's why I don't like #555 :D

done();
});

it('previous block should fail', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why it should fail?

done();
});

it('block timestamp should fail', function (done) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is should fail? Mean what's wrong with used timestamp.

it('should generate valid block2', function (done) {
var secret = 'flip relief play educate address plastic doctor fix must frown oppose segment';
validBlock2 = createBlock(blocks, blockLogic, secret, 33772862, transactionsValidBlock2, validBlock1);
expect(validBlock2.version).to.equal(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same - check all properties.

});

it('normalizeBlock should fail (transaction schema: type)', function (done) {
invalidBlock2.transactions = JSON.parse(JSON.stringify(validBlock2.transactions));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use fresh copy instead of restoring previously deleted properties.


blocksVerify.processBlock(invalidBlock2, false, function (err, result) {
if (err) {
expect(err).equal('Failed to validate block schema: Object didn\'t pass validation for format publicKey: invalid-public-key');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's really a check for fork 3?

@Isabello
Copy link
Contributor

Isabello commented Aug 7, 2017

The commit with JSDoc was passing, unfortunately the new jenkins implementation is already talking back to github and messed up your test results. I fixed your test results.

4miners
4miners previously approved these changes Aug 7, 2017
Isabello
Isabello previously approved these changes Aug 7, 2017
@4miners 4miners dismissed stale reviews from Isabello and themself via 360949f August 8, 2017 09:12
4miners
4miners previously approved these changes Aug 8, 2017
done();
}, false);
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

delete block.payloadLength;
}
delete block.id;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return not used, please remove

version:0,
};
var block1;
var transactionsBlock1 = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formatting

Copy link
Contributor

@MaciejBaj MaciejBaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove try catch block in Chain.prototype.broadcastReducedBlock function, minor format issues, redundant return in tests

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants