New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement unit tests for Block Synchronization Mechanism - Closes #4375 #4476
Conversation
49721e1
to
c77a977
Compare
d08f368
to
931e4fa
Compare
ac3ff3e
to
61adee1
Compare
442e6df
to
53059c6
Compare
…idnt return any common block and continue trying
…omply with LIP updates
53059c6
to
490ba93
Compare
c99feff
to
ec29c3a
Compare
async _handleBlockProcessingError(lastCommonBlock, peerId) { | ||
// If the list of blocks has not been fully applied | ||
this.logger.debug('Failed to apply obtained blocks from peer'); | ||
const [tipBeforeApplying] = await this.storage.entities.TempBlock.get( |
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.
tipBeforeApplying can be undefined
?
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.
True, in that case I guess we should restart mechanism only? and cleanup temp table just in case?
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.
I think if it fails to get
then it's already cleaned up?
but in that case, i think we can just restart
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.
Maybe temp table is full and there is an error accessing database, hmmm
...ain/synchronizer/block_synchronization_mechanism/block_synchronization_mechanism.spec.bak.js
Outdated
Show resolved
Hide resolved
...ain/synchronizer/block_synchronization_mechanism/block_synchronization_mechanism.spec.bak.js
Outdated
Show resolved
Hide resolved
ec29c3a
to
b79eed1
Compare
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 missing test for isValidFor
- Implement the following missing behaviour
async _requestAndValidateLastBlock(peerId) {
this.logger.debug({ peerId }, 'Requesting tip of the chain from peer');
const { data } = await this.channel.invoke('network:requestFromPeer', {
procedure: 'getLastBlock',
peerId,
});
- Mock peer to return empty data and handle the scenario
- Update the title
should give up requesting the last common block after 3 tries, and then ban the peer and restart the mechanism
tipBeforeApplyingInstance, // Previous tip of the chain | ||
); | ||
|
||
const newTipHasPreference = forkStatus === FORK_STATUS_DIFFERENT_CHAIN; |
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.
any reason not to use directly in if condition?
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.
Yes, it is easier to read and to understand what the condition means, especially because the FORK_STATUS_DIFFERENT_CHAIN is not the best name to represent that behavior and I didn't want to change it in this PR
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 delete last block called with
backUP
true when deleting from common block - Clone deep the requested block to test truncate
...s/chain/synchronizer/block_synchronization_mechanism/block_synchronization_mechanism.spec.js
Outdated
Show resolved
Hide resolved
f3f303f
to
cccbf02
Compare
ebee456
to
92956f6
Compare
What was the problem?
There were no unit tests for Block Synchronization Mechanism
How did I solve it?
By adding tests
How to manually test it?
Run
block_synchronization_mechanism.spec.js
with JestReview checklist