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

[storage] Protect against nil Helper and/or Handler in BalanceStorage #273

Merged
merged 2 commits into from
Dec 9, 2020

Conversation

patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Dec 9, 2020

Someone was able to force a panic in rosetta-cli because of an unpopulated BalanceStorage helper and handler. This PR causes BalanceStorage to raise an error in these cases instead of panicking.

Changes

  • Add new error
  • Check for nil helper or handler
  • Add new tests

@coveralls
Copy link

coveralls commented Dec 9, 2020

Pull Request Test Coverage Report for Build 13586

  • 11 of 21 (52.38%) changed or added relevant lines in 1 file are covered.
  • 400 unchanged lines in 6 files lost coverage.
  • Overall coverage decreased (-0.05%) to 78.038%

Changes Missing Coverage Covered Lines Changed/Added Lines %
storage/modules/balance_storage.go 11 21 52.38%
Files with Coverage Reduction New Missed Lines %
storage/modules/coin_storage.go 15 80.0%
asserter/network.go 21 86.22%
storage/modules/counter_storage.go 21 46.32%
storage/modules/broadcast_storage.go 63 70.72%
storage/modules/balance_storage.go 139 78.54%
storage/modules/block_storage.go 141 76.37%
Totals Coverage Status
Change from base Build 13567: -0.05%
Covered Lines: 8084
Relevant Lines: 10359

💛 - Coveralls

@@ -187,6 +187,10 @@ func (b *BalanceStorage) AddingBlock(
block *types.Block,
transaction database.Transaction,
) (database.CommitWorker, error) {
if b.handler == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we force the handler to be present in the methods used to create a new BalanceStorage instance?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wish! There is a somewhat complex dependency process where we can't add the handler or helper during initialization.

Copy link
Contributor Author

@patrick-ogrady patrick-ogrady Dec 9, 2020

Choose a reason for hiding this comment

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

We need a reference to BalanceStorage to create some useful helpers (we should probably clean this up after this release but it will be a pretty big refactor 😢 ): https://github.com/coinbase/rosetta-cli/blob/972a1690001f7f7d22fafa0a580512eac8517add/pkg/tester/data.go#L284-L305

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we should def clean it up!

@@ -187,6 +187,10 @@ func (b *BalanceStorage) AddingBlock(
block *types.Block,
transaction database.Transaction,
) (database.CommitWorker, error) {
if b.handler == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, we should def clean it up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants