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

clean up blockdao #4164

Merged
merged 4 commits into from
Mar 11, 2024
Merged

clean up blockdao #4164

merged 4 commits into from
Mar 11, 2024

Conversation

CoderZhi
Copy link
Collaborator

@CoderZhi CoderZhi commented Mar 5, 2024

struct blockDAO is a wrapper of a BlockDAO with attached indexers and cache. This PR tries to clean up the blockdao related code and clarify the concept:

  1. Delete unnecessary functions defined in BlockDAO, including:
    • GetActionByActionHash(hash.Hash256, uint64) and GetReceiptByActionHash(hash.Hash256, uint64), which are not core functions of the interface
    • DeleteBlockToTarget(uint64) is not usable, because not all indexers could be reverted
  2. Unify blockDAO constructor function
  3. Add a few TODOs

Fixes #(issue)

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

Copy link

codecov bot commented Mar 5, 2024

Codecov Report

Attention: Patch coverage is 19.23077% with 42 lines in your changes are missing coverage. Please review.

Project coverage is 76.03%. Comparing base (e1f0636) to head (f142eb6).
Report is 194 commits behind head on master.

Files Patch % Lines
blockchain/blockdao/blockdao.go 0.00% 20 Missing ⚠️
api/coreservice.go 41.66% 13 Missing and 1 partial ⚠️
blockchain/block/block.go 0.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4164      +/-   ##
==========================================
+ Coverage   75.38%   76.03%   +0.64%     
==========================================
  Files         303      340      +37     
  Lines       25923    28979    +3056     
==========================================
+ Hits        19541    22033    +2492     
- Misses       5360     5851     +491     
- Partials     1022     1095      +73     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -436,21 +446,17 @@ func TestBlockDAO(t *testing.T) {
}
}

func createTestBlockDAO(inMemory, legacy bool, compressBlock string, cfg db.Config) (BlockDAO, error) {
func createFileDAO(inMemory, legacy bool, compressBlock string, cfg db.Config) (filedao.FileDAO, error) {
Copy link
Member

Choose a reason for hiding this comment

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

createTestFileDAO? this is code for testing use

log.L().Fatal(err.Error(), zap.Any("cfg", cfg))
// NewBlockDAOWithIndexersAndCache returns a BlockDAO with indexers which will consume blocks appended, and
// caches which will speed up reading
func NewBlockDAOWithIndexersAndCache(blkStore BlockDAO, indexers []BlockIndexer, cacheSize int) BlockDAO {
Copy link
Member

Choose a reason for hiding this comment

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

may just change func name to NewBlockDAOWithIndexersAndCache, keep input param list the same
so we don't need to call explicitly fileDAO, err := filedao.NewFileDAO(cfg, deser) upfront, then pass fileDAO and call this.

return dao.blockStore.DeleteTipBlock()
}

func (dao *blockDAO) DeleteBlockToTarget(targetHeight uint64) error {
Copy link
Member

Choose a reason for hiding this comment

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

yes, these 2 need to be removed. there's an earlier PR but did not get merged

@@ -2395,4 +2431,17 @@ func classifyActions(actions []*action.SealedEnvelope) ([]*action.Transfer, []*a
return tsfs, exes
}

func ReceiptByActionHash(dao blockdao.BlockDAO, height uint64, h hash.Hash256) (*action.Receipt, error) {
Copy link
Member

Choose a reason for hiding this comment

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

receiptByActionHash can work?

if err != nil {
return nil, err
}
func receiptByActionHash(receipts []*action.Receipt, h hash.Hash256) (*action.Receipt, error) {
Copy link
Member

Choose a reason for hiding this comment

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

can move this to _test.go? seems only used in test

@Liuhaai
Copy link
Member

Liuhaai commented Mar 6, 2024

In the future, we might create blockreader and blockwriter separately from blockdao module since indexer isn't used except from PutBlock

Copy link

sonarcloud bot commented Mar 11, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
16.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@CoderZhi CoderZhi merged commit e7c3787 into master Mar 11, 2024
2 of 5 checks passed
@CoderZhi CoderZhi deleted the cleanup_blockdao branch March 11, 2024 16:55
@envestcc envestcc mentioned this pull request Mar 14, 2024
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.

4 participants