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

EN-10574 Get block by round #3430

Merged
merged 23 commits into from
Oct 8, 2021
Merged

Conversation

mariusmihaic
Copy link
Contributor

@mariusmihaic mariusmihaic commented Sep 9, 2021

  • Added /by-round/:round route to get block by round with optional withTxs query param
  • Created a new static storer which stores: key = round; value = nonce, also see function putRoundByNonce in (hr *historyRepository) RecordBlock
  • When asked to retrieve block data (withTxs) from key = round, we get its corresponding value = nonce and call existing function GetBlockByNonce(nonce, withTxs)
  • Added tests everrywhere, except in two places where there was no test file created and the functionality was pretty trivial.

@mariusmihaic mariusmihaic reopened this Sep 9, 2021
@mariusmihaic mariusmihaic reopened this Sep 9, 2021
@mariusmihaic mariusmihaic changed the title FEAT: Add initial version EN-10574 Get block by round Sep 9, 2021
@mariusmihaic mariusmihaic deleted the EN-10574-Get_block_by_round branch September 9, 2021 14:32
@mariusmihaic mariusmihaic restored the EN-10574-Get_block_by_round branch September 9, 2021 14:32
@mariusmihaic mariusmihaic reopened this Sep 9, 2021
@codecov
Copy link

codecov bot commented Sep 10, 2021

Codecov Report

Merging #3430 (968815e) into development (b573b38) will increase coverage by 0.04%.
The diff coverage is 79.64%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #3430      +/-   ##
===============================================
+ Coverage        73.85%   73.89%   +0.04%     
===============================================
  Files              581      581              
  Lines            73907    74278     +371     
===============================================
+ Hits             54583    54888     +305     
- Misses           14945    15003      +58     
- Partials          4379     4387       +8     
Impacted Files Coverage Δ
dataRetriever/interface.go 0.00% <ø> (ø)
node/nodeRunner.go 0.00% <0.00%> (ø)
process/economics/testEconomicsData.go 0.00% <0.00%> (ø)
storage/factory/pruningStorerFactory.go 0.00% <0.00%> (ø)
genesis/process/shardGenesisBlockCreator.go 43.09% <66.66%> (+0.15%) ⬆️
process/economics/economicsData.go 71.17% <69.29%> (-3.91%) ⬇️
process/block/preprocess/smartContractResults.go 69.75% <70.00%> (+1.00%) ⬆️
process/coordinator/process.go 75.06% <74.46%> (-0.07%) ⬇️
process/block/preprocess/transactions.go 55.69% <76.00%> (+2.55%) ⬆️
node/blockAPI/baseBlock.go 72.41% <77.77%> (+0.61%) ⬆️
... and 22 more

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 1229c24...968815e. Read the comment docs.

@bogdan-rosianu bogdan-rosianu marked this pull request as draft September 13, 2021 08:05
@mariusmihaic mariusmihaic self-assigned this Sep 15, 2021
@mariusmihaic mariusmihaic marked this pull request as ready for review September 16, 2021 12:44
@@ -9,6 +9,8 @@ import (
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/dblookupext/factory"
"github.com/ElrondNetwork/elrond-go/process"
mock2 "github.com/ElrondNetwork/elrond-go/process/mock"
Copy link
Contributor

Choose a reason for hiding this comment

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

mock2 ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing mock2 with processorMock alias

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to processMock

@@ -65,6 +65,21 @@ func (mbp *metaAPIBlockProcessor) GetBlockByHash(hash []byte, withTxs bool) (*ap
return mbp.computeStatusAndPutInBlock(blockAPI, dataRetriever.MetaHdrNonceHashDataUnit)
}

// GetBlockByRound will return a shard APIBlock by round
Copy link
Contributor

Choose a reason for hiding this comment

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

// GetBlockByRound will return a meta APIBlock by round

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, fixed it here and for GetBlockByHash as well

api/block/routes.go Outdated Show resolved Hide resolved
@@ -9,6 +9,8 @@ import (
"github.com/ElrondNetwork/elrond-go/config"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/dblookupext/factory"
"github.com/ElrondNetwork/elrond-go/process"
mock2 "github.com/ElrondNetwork/elrond-go/process/mock"
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing mock2 with processorMock alias

dblookupext/historyRepository.go Outdated Show resolved Hide resolved
dblookupext/historyRepository_test.go Outdated Show resolved Hide resolved
node/blockAPI/shardBlock.go Show resolved Hide resolved
@@ -35,6 +35,15 @@ func (n *Node) GetBlockByNonce(nonce uint64, withTxs bool) (*api.Block, error) {
return apiBlockProcessor.GetBlockByNonce(nonce, withTxs)
}

func (n *Node) GetBlockByRound(round uint64, withTxs bool) (*api.Block, error) {
apiBlockProcessor, err := n.createAPIBlockProcessor()
Copy link
Contributor

Choose a reason for hiding this comment

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

@miiu96 please check this. Why do we need to create an apiBlockProcessor for each request? We should definitely change this.

# Conflicts:
#	api/groups/blockGroup.go
#	api/groups/blockGroup_test.go
#	api/mock/facade.go
#	facade/disabled/disabledNodeFacade_test.go
// MetaHdrRoundHashDataUnit is the meta header round-hash storage data pair unit identifier
MetaHdrRoundHashDataUnit UnitType = 49
// ShardHdrRoundHashDataUnit is the shard round-hash storage data unit identifier
ShardHdrRoundHashDataUnit UnitType = 50
Copy link
Contributor

Choose a reason for hiding this comment

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

let's put this on the 200 value (or even better ~400 as to allow the creation of 256 shards) and place it after the ShardHdrNonceHashDataUnit definition. MetaHdrRoundHashDataUnit can be 19. Adjust the comment below to include the ShardHdrNonceHashDataUnit.

@@ -94,12 +94,12 @@ func TestNewHistoryRepository(t *testing.T) {
require.NotNil(t, repo)
}

func TestHistoryRepository_RecordBlock_InvalidBlockRoundByNonceStorer_ExpectError(t *testing.T) {
func TestHistoryRepository_RecordBlock_InvalidBlockRoundByHashStorer_ExpectError(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

too many _ in name. To align with the rest of the project, please rename this to:

TestHistoryRepository_RecordBlockInvalidBlockRoundByHashStorerExpectError

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed it to be consistent with the rest of the tests

createdStorers = append(createdStorers, blockRoundByNonceUnit)
chainStorer.AddStorer(dataRetriever.RoundNonceUnit, blockRoundByNonceUnit)
createdStorers = append(createdStorers, blockHashByRoundUnit)
chainStorer.AddStorer(hashByRoundUnitData, blockHashByRoundUnit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, one question here: why do we need a different value for blockHashByRoundUnit (according to the shard in which the node is operating) but we always open the same storer from the same path? This can be simplified by stating a hardcoded value in dataretrieve/interface.go for this unit type (not added to the shard ID value), something like 19 or 20 or something.

Copy link
Contributor

@LucianMincu LucianMincu left a comment

Choose a reason for hiding this comment

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

System tests passed.

@LucianMincu LucianMincu merged commit cc555fb into development Oct 8, 2021
@LucianMincu LucianMincu deleted the EN-10574-Get_block_by_round branch October 8, 2021 10:58
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

4 participants