-
Notifications
You must be signed in to change notification settings - Fork 114
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
Unit tests for the Blockstore #1129
Changes from all commits
ed4d0db
bd38035
e11b29b
5fb5e03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -558,9 +558,10 @@ boolean isBlockStored(byte[] hash, long number) { | |
} | ||
|
||
/** | ||
* Retrieve block with unity protocol info | ||
* @param hash given hash of the block | ||
* @return the block data has matched hash with unity protocol info | ||
* Retrieve a block with unity protocol info. | ||
* | ||
* @param hash the hash of the requested block | ||
* @return the block data for the given hash with unity protocol info | ||
*/ | ||
public Block getBlockByHashWithInfo(byte[] hash) { | ||
if (hash == null) { | ||
|
@@ -1391,18 +1392,21 @@ void redoIndexWithoutSideChains(Block block) { | |
} | ||
|
||
/** | ||
* Retrieve three generation blocks with unity protocol info with one lock. | ||
* @param hash given hash of the block | ||
* @return the 3 generation block data have matched hash with unity protocol info. Block[0] is the parent block, | ||
* Block[1] is the grandParent block, and Block[2] is the greatParentBlock. The return might only contain the parent | ||
* block and still return the 3-elements array. | ||
* Retrieves three generation blocks with unity protocol info. | ||
* <p> | ||
* Always returns a 3-element array. If the blocks cannot be retrieved the array will contain null values. | ||
* Block[0] is the parent block and has the given hash. Block[1] is the grandparent block. | ||
* Block[2] is the great grandparent block. | ||
* | ||
* @param hash the hash of the parent block | ||
* @return the retrieved three generation blocks with unity protocol info | ||
*/ | ||
public final Block[] getThreeGenerationBlocksByHashWithInfo(byte[] hash) { | ||
Block[] blockFamily = new Block[] { null, null, null}; | ||
if (hash == null) { | ||
return null; | ||
return blockFamily; | ||
} | ||
|
||
Block[] blockFamily = new Block[] { null, null, null}; | ||
lock.lock(); | ||
|
||
try { | ||
|
@@ -1428,18 +1432,19 @@ public final Block[] getThreeGenerationBlocksByHashWithInfo(byte[] hash) { | |
} | ||
|
||
/** | ||
* Retrieve two generation blocks with unity protocol info with one lock. | ||
* Retrieves two generation blocks with unity protocol info. | ||
* <p> | ||
* Always returns a 2-element array. If the blocks cannot be retrieved the array will contain null values. | ||
* Block[0] is the parent block and has the given hash. Block[1] is the grandparent block. | ||
* | ||
* @param hash given hash of the block | ||
* @return the 2 generation block data have matched hash with unity protocol info. Block[0] is | ||
* the parent block, Block[1] is the grandParent block. The return might only contain the | ||
* parent block and still return the 2-elements array. | ||
* @param hash the hash of the parent block | ||
* @return the retrieved two generation blocks with unity protocol info | ||
*/ | ||
public final Block[] getTwoGenerationBlocksByHashWithInfo(byte[] hash) { | ||
Block[] blockFamily = new Block[] { null, null}; | ||
if (hash == null) { | ||
return null; | ||
return blockFamily; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will let AionBlockChainImpl.createNewMiningBlockInternal() throw NPE There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would already throw an NPE because the blockFamily is accessed without a null check. The reason for the NPE differs but it will be thown in either case. If that happens I think we should allows the failure and fix the cause when we find one. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So We should just throw NPE if the input hash equal to null. instead of return values (or return null) Same as the other method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok. I made the update. |
||
} | ||
Block[] blockFamily = new Block[] { null, null}; | ||
|
||
lock.lock(); | ||
|
||
|
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 this change will let AionBlockChainImpl.isValid() throw null exception. Please have a check.
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 updated the
null
check inAionBlockchainImpl.isValid
to exit if the parent block is null.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.
Cool.