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

Disabled storer on SaveInStorageEnabled false #4345

Merged
merged 5 commits into from
Aug 4, 2022

Conversation

sstanculeanu
Copy link
Contributor

Description of the reasoning behind the pull request (what feature was missing / how the problem was manifesting itself / what was the motive behind the refactoring)

  • when SaveInStorageEnabled was false, the TxLogsUnit storer was nil, leading to panic on different api calls

Proposed Changes

  • added disabled storer for this case

Testing procedure

  • system test, using /block/by-nonce/15?withTxs=true&withLogs=true should not panic no matter what block is asked for, with config values LogsAndEvents.SaveInStorageEnabled = false and DbLookupExtensions.Enabled = false

@iulianpascalau iulianpascalau self-requested a review August 3, 2022 15:12
@@ -61,3 +61,17 @@ func TestLogsRepository_GetLogsShouldErr(t *testing.T) {
require.ErrorIs(t, err, errCannotUnmarshalLog)
require.Nil(t, badLog)
}

func TestLogsRepository_GetLogsShouldUseDisabled(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍


type storer struct{}

// NewStorer returns a new instance of this disabled storer
Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, we didn't have an existing "generic" disabled storer, all the other ones were defined in their client packages. 👍 for adding it here.

andreibancioiu
andreibancioiu previously approved these changes Aug 3, 2022
@@ -17,6 +19,10 @@ type logsRepository struct {

func newLogsRepository(storageService dataRetriever.StorageService, marshaller marshal.Marshalizer) *logsRepository {
storer := storageService.GetStorer(dataRetriever.TxLogsUnit)
if check.IfNil(storer) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit debatable if we should have used a disabledLogsFacade at a higher level, instead, when logs saving is disabled. But it's all right this way, as well 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed Iulian's solution which fixes this

@@ -17,6 +19,10 @@ type logsRepository struct {

func newLogsRepository(storageService dataRetriever.StorageService, marshaller marshal.Marshalizer) *logsRepository {
storer := storageService.GetStorer(dataRetriever.TxLogsUnit)
if check.IfNil(storer) {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of this approach, I would make the storageService.GetStorer(dataRetriever.TxLogsUnit) call return always a not-nil pointer, on all conditions. So, in StorageServiceFactory.setupLogsAndEventsStorer function, on L556 I would add a disabled storer.
This will simplify all involved code and this new if branch will no longer be necessary.
For a next PR: we might return an error on the GetStorer function whenever we've provided a key that does not contain a valid storer as to align the code to the rest of the project.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

pushed

@codecov-commenter
Copy link

Codecov Report

Merging #4345 (edae89a) into rc/2022-july (11e589f) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

❗ Current head edae89a differs from pull request most recent head 47810e3. Consider uploading reports for the commit 47810e3 to get more accurate results

@@               Coverage Diff                @@
##           rc/2022-july    #4345      +/-   ##
================================================
- Coverage         73.74%   73.70%   -0.04%     
================================================
  Files               670      670              
  Lines             86388    86390       +2     
================================================
- Hits              63707    63677      -30     
- Misses            17908    17940      +32     
  Partials           4773     4773              
Impacted Files Coverage Δ
storage/factory/pruningStorerFactory.go 0.00% <0.00%> (ø)
p2p/libp2p/netMessenger.go 76.10% <0.00%> (-3.92%) ⬇️

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 11e589f...47810e3. Read the comment docs.

Copy link
Contributor

@popenta popenta left a comment

Choose a reason for hiding this comment

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

@@ Log scanner @@

fix_logs_repository

================================================================================

  • Known Warnings 14
  • New Warnings 3
  • Known Errors 0
  • New Errors 0
  • Panics 0
    ================================================================================

@sstanculeanu sstanculeanu merged commit ce0134b into rc/2022-july Aug 4, 2022
@sstanculeanu sstanculeanu deleted the fix_logs_repository branch August 4, 2022 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants