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

Consensus rules cannot be broken in finishOperation #563

Closed
wants to merge 1 commit into from
Closed

Consensus rules cannot be broken in finishOperation #563

wants to merge 1 commit into from

Conversation

Geod24
Copy link
Contributor

@Geod24 Geod24 commented Oct 18, 2018

The consensus rules are checked in checker_ballot_transaction's ValidateOp.
So if this error happens, it means there's an important bug in sebak,
and that the consensus rules were bypassed.
As a result, we remove the checks which are not necessary,
and panic on operations that shouldn't return an error.

@codecov-io
Copy link

codecov-io commented Oct 18, 2018

Codecov Report

Merging #563 into master will increase coverage by 3.84%.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #563      +/-   ##
==========================================
+ Coverage   61.01%   64.85%   +3.84%     
==========================================
  Files         159      114      -45     
  Lines       11239     6911    -4328     
==========================================
- Hits         6857     4482    -2375     
+ Misses       3575     1899    -1676     
+ Partials      807      530     -277
Flag Coverage Δ
#integration_tests_long_term ?
#integration_tests_node 43.14% <50%> (+2.07%) ⬆️
#integration_tests_retry ?
#unittests 54.18% <50%> (+6.77%) ⬆️
Impacted Files Coverage Δ
lib/node/runner/checker.go 64.32% <50%> (-9.3%) ⬇️
lib/consensus/isaac_state.go 66.66% <0%> (-33.34%) ⬇️
lib/block/header.go 53.84% <0%> (-24.73%) ⬇️
lib/block/test.go 56.25% <0%> (-19.43%) ⬇️
lib/consensus/round_vote.go 75.38% <0%> (-13.68%) ⬇️
lib/transaction/operation/collect_tx_fee.go 47.05% <0%> (-13.66%) ⬇️
lib/transaction/operation/test.go 86.36% <0%> (-13.64%) ⬇️
lib/network/http2_client.go 53.39% <0%> (-13.62%) ⬇️
lib/storage/options.go 21.15% <0%> (-13.23%) ⬇️
lib/consensus/isaac.go 72.03% <0%> (-10.66%) ⬇️
... and 149 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 e26154a...96f1c2c. Read the comment docs.

Copy link
Contributor

@spikeekips spikeekips left a comment

Choose a reason for hiding this comment

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

At this time, when error occurred in finish~ process the panic will be reasonable. @Charleslee522 If possible, when error or problem found in finish~ process, how about go to Syncing?

if err = baTarget.Save(st); err != nil {
return
if err := baTarget.Save(st); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

Like finishPayment, this also just can make panic, is there any reason to return error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it writes to LevelDB, there are much more potential for failure, that's why it's treated differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agreed.
finishXXX should not return an error.
How about using MustXXX pattern?

Copy link
Contributor

@spikeekips spikeekips left a comment

Choose a reason for hiding this comment

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

Instead of panicking, we already use leveldb’s transaction, so

  1. Discard when error
  2. Sync process

How about this scenario?

@Geod24
Copy link
Contributor Author

Geod24 commented Oct 18, 2018

@spikeekips : Those are different kind of errors. At the moment, this panic should never happen. If it happens, there's a bug in Sebak, and it's much better if we know about it than trying to hide it.
Here, panic is just an assert.

I'm usually fine with recovering from programming errors, but with our development process and the amount of work being done on Sebak, it's not realistic to do it at the moment.

@spikeekips
Copy link
Contributor

spikeekips commented Oct 18, 2018

@Geod24 Hmm. Most error cases can be from SEBAK itself, but there are plenty cases, error occurr like,

  • disk full
  • db file corruption by other process
  • leveldb’s own bug
  • etc

Db fail -> process end, it seems unnatural. In most if failed cases, panic can be good, but disk full sebak should ensure, I think. Logging critic message will be enough.

@anarcher
Copy link
Contributor

anarcher commented Oct 18, 2018

I never ever use panic unless it's really unrecoverable error that the layer above should not be handling. It's an "abort the entire program" kind of error which you don't encounter that often. And A panic cannot be recovered by a different goroutine.

My general rule: avoid as much as possible.

@Geod24
Copy link
Contributor Author

Geod24 commented Oct 18, 2018

but disk full sebak should ensure, I think

Yeah, that's why I only panic on read, not on write.

The consensus rules are checked in checker_ballot_transaction's `ValidateOp`.
So if this error happens, it means there's an important bug in sebak,
and that the consensus rules were bypassed.
As a result, we remove the checks which are not necessary,
and panic on operations that shouldn't return an error.
@Geod24 Geod24 closed this Feb 21, 2019
@Geod24 Geod24 deleted the panic-is-useful branch February 21, 2019 07:48
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.

5 participants