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

chore(lib/trie): refactor lib/trie/database.go #2108

Merged
merged 5 commits into from
Jan 5, 2022

Conversation

qdm12
Copy link
Contributor

@qdm12 qdm12 commented Dec 10, 2021

Changes

This is a simple 'linear' refactor in order to see diffs in a clearer way.

  • Explicit variable names
  • Less indentation (avoid type switches)
  • More return early
  • Add named returns
  • Clarify comments
  • Wrap errors

Tests

go test github.com/ChainSafe/gossamer/lib/trie/... github.com/ChainSafe/gossamer/internal/trie/...

Issues

Primary Reviewer

@codecov
Copy link

codecov bot commented Dec 10, 2021

Codecov Report

Merging #2108 (7dfb20c) into development (de6e7c9) will increase coverage by 0.13%.
The diff coverage is 86.38%.

Impacted file tree graph

@@               Coverage Diff               @@
##           development    #2108      +/-   ##
===============================================
+ Coverage        61.37%   61.51%   +0.13%     
===============================================
  Files              202      213      +11     
  Lines            27362    27429      +67     
===============================================
+ Hits             16794    16873      +79     
+ Misses            8692     8688       -4     
+ Partials          1876     1868       -8     
Flag Coverage Δ
unit-tests 61.51% <86.38%> (+0.13%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
dot/state/offline_pruner.go 0.00% <0.00%> (ø)
lib/trie/database.go 51.72% <57.75%> (+2.31%) ⬆️
lib/trie/print.go 80.00% <71.42%> (-4.32%) ⬇️
internal/trie/node/leaf_encode.go 80.26% <80.26%> (ø)
lib/trie/proof.go 68.75% <83.33%> (-0.64%) ⬇️
internal/trie/node/branch_encode.go 84.84% <84.84%> (ø)
internal/trie/node/hash.go 85.71% <85.71%> (ø)
lib/trie/lookup.go 73.91% <88.88%> (ø)
lib/trie/trie.go 91.62% <95.87%> (-0.61%) ⬇️
internal/trie/codec/nibbles.go 100.00% <100.00%> (ø)
... and 20 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 a3ae30b...7dfb20c. Read the comment docs.

lib/trie/database.go Outdated Show resolved Hide resolved
lib/trie/database.go Outdated Show resolved Hide resolved
lib/trie/database.go Show resolved Hide resolved
Base automatically changed from qdm12-trie-node-subpkg-base to development December 16, 2021 15:46
qdm12 and others added 2 commits December 16, 2021 16:24
- Explicit variable names
- Less indentation
- More return early
- Add named returns
- Clarify comments
- Wrap errors
Co-authored-by: Eclésio Junior <eclesiomelo.1@gmail.com>
@qdm12 qdm12 requested review from EclesioMeloJunior and removed request for arijitAD December 16, 2021 21:31
Copy link
Contributor

@kishansagathiya kishansagathiya left a comment

Choose a reason for hiding this comment

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

🎉
I like that we are checking !ok instead of ok
Looks good, only small comments!

lib/trie/database.go Outdated Show resolved Hide resolved
lib/trie/database.go Outdated Show resolved Hide resolved
lib/trie/database.go Show resolved Hide resolved
lib/trie/database.go Outdated Show resolved Hide resolved
lib/trie/database.go Show resolved Hide resolved
lib/trie/database.go Show resolved Hide resolved
lib/trie/database.go Show resolved Hide resolved
@qdm12
Copy link
Contributor Author

qdm12 commented Dec 18, 2021

@kishansagathiya

I like that we are checking !ok instead of ok

Where do you mean this? 🤔

@kishansagathiya
Copy link
Contributor

@qdm12

like that we are checking !ok instead of ok

Sometimes, we check for the expected condition (true) and run when true and don't do anything when false.

I think you would have checked for the unexpected condition first and run some code on that unexpected condition.

@qdm12
Copy link
Contributor Author

qdm12 commented Jan 5, 2022

@kishansagathiya I tend to have the smaller code part inside the if block checking ok to reduce code indentation and improve readability. Maybe do you have an example where this could be improved in this PR?

@qdm12 qdm12 merged commit 68da00d into development Jan 5, 2022
@qdm12 qdm12 deleted the qdm12-trie-database-1 branch January 5, 2022 15:13
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