Skip to content
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 and bugfix requestEpochStartInfo #3762

Merged
merged 8 commits into from
Feb 10, 2022

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Feb 7, 2022

Tests

  • Added tests for requestEpochStartInfo from shardBlock.go
  • Since nil pointer checks for shardBlock.go are done in baseProcesss.go( CheckProcessorNilParameters), I've moved all nil pointer check tests + created new ones from shardBlock.go -> baseProcesss.go

Bugfixes

  • Fixed a bug in NewShardProcessor where arguments.DataComponents.Blockchain().GetGenesisHeader() could have been a nil pointer.
  • Fixed a bug in requestEpochStartInfo: Before entering in the foor loop to request headers (L343), meta header is requested once sp.requestHandler.RequestMetaHeader(header.GetEpochStartMetaHash()) (L340).
    While inside the loop, if header is not found in pool (headersPool.GetHeaderByHash, from various reasons we did not have a response to our query) => error is returned, but we do not make any more requests for it . One line code on L354 would fix it:
	if err != nil {
			go sp.requestHandler.RequestMetaHeader(header.GetEpochStartMetaHash()) // THIS LINE
			continue
		}

@mariusmihaic mariusmihaic self-assigned this Feb 7, 2022
@codecov
Copy link

codecov bot commented Feb 7, 2022

Codecov Report

Merging #3762 (4e45bd3) into development (9ca95a6) will increase coverage by 0.07%.
The diff coverage is 100.00%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #3762      +/-   ##
===============================================
+ Coverage        74.29%   74.37%   +0.07%     
===============================================
  Files              603      603              
  Lines            79463    79466       +3     
===============================================
+ Hits             59039    59102      +63     
+ Misses           15864    15823      -41     
+ Partials          4560     4541      -19     
Impacted Files Coverage Δ
process/block/shardblock.go 65.72% <100.00%> (+1.45%) ⬆️
ntp/syncTime.go 87.23% <0.00%> (+2.12%) ⬆️
process/block/baseProcess.go 72.04% <0.00%> (+3.90%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1dfcfa8...4e45bd3. Read the comment docs.

@mariusmihaic mariusmihaic changed the title FEAT: Add first tests for RequestEpochStartInfo Unit tests shardBlock Feb 8, 2022
@mariusmihaic mariusmihaic changed the title Unit tests shardBlock Unit tests requestEpochStartInfo Feb 9, 2022
@mariusmihaic mariusmihaic changed the title Unit tests requestEpochStartInfo Unit tests and bugfix requestEpochStartInfo Feb 9, 2022
@ssd04 ssd04 self-requested a review February 9, 2022 13:23
sasurobert
sasurobert previously approved these changes Feb 9, 2022
Copy link
Contributor

@iulianpascalau iulianpascalau left a comment

Choose a reason for hiding this comment

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

GJ! 👍


coreComponents, dataComponents, bootstrapComponents, statusComponents := createComponentHolderMocks()

tests := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

... or could have used the t.Run pattern as those kind of tests are easier to debug
Can be left as it is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, that's right. I don't think it's worth a refactor for these nil pointer checks, will leave it as it is then

genesisHdr := arguments.DataComponents.Blockchain().GetGenesisHeader()
if check.IfNil(genesisHdr) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a good check, but the project is swarming with blockchain Get operations without nil checks. The blockchain was thought to be a struct that shouldn't contain nil values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This might've been the reason why this nil check was missed. Discovered it while setting up mocks for the tests

@@ -349,6 +352,7 @@ func (sp *shardProcessor) requestEpochStartInfo(header data.ShardHeaderHandler,

epochStartMetaHdr, err := headersPool.GetHeaderByHash(header.GetEpochStartMetaHash())
if err != nil {
go sp.requestHandler.RequestMetaHeader(header.GetEpochStartMetaHash())
Copy link
Contributor

Choose a reason for hiding this comment

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

this will trigger ~10 requests / second. This is a little too much as it will flood the network with messages. Suggestion to add a counter here and only when that counter reaches a predefined value, say 10, it will launch the request go routine

Copy link
Contributor

Choose a reason for hiding this comment

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

Will remain as it is. As discussed, L361 does not have a throttle. The final throttler (output antiflooder) will kick in, if required.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think they are worthless as the requestHandler has a protection mechanism which not allows more than one request with the same hash in less than one second from the previous one, through testIfRequestIsNeeded method in it's first line

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great info, will keep it as it is then

expectedErr: process.ErrNilDataComponentsHolder,
},
{
args: func() blproc.ArgShardProcessor {
Copy link
Contributor

Choose a reason for hiding this comment

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

almost the same number of lines of code as t.Run :D
Can be left as it is

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will leave it like this then

process/block/shardblock_test.go Show resolved Hide resolved
process/block/shardblock_test.go Show resolved Hide resolved
@mariusmihaic mariusmihaic marked this pull request as ready for review February 9, 2022 14:31
Copy link
Collaborator

@gabi-vuls gabi-vuls left a comment

Choose a reason for hiding this comment

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

System test passed.

@gabi-vuls gabi-vuls merged commit 611b533 into development Feb 10, 2022
@gabi-vuls gabi-vuls deleted the unit-tests-shardBlock-EN-11619 branch February 10, 2022 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants