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

remove error log when block already exist blockchain #341

Merged
merged 11 commits into from
Dec 7, 2018
Merged

remove error log when block already exist blockchain #341

merged 11 commits into from
Dec 7, 2018

Conversation

FishMeat
Copy link
Contributor

@FishMeat FishMeat requested a review from a team as a code owner November 22, 2018 03:19
Copy link
Contributor

@zjshen14 zjshen14 left a comment

Choose a reason for hiding this comment

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

BTW, are you using golang 1.11? 1.11 and 1.10 have incompatible fmt rules, so that you will create some unnecessary code diff

@@ -678,6 +681,9 @@ func (bc *blockchain) MintNewSecretBlock(
func (bc *blockchain) CommitBlock(blk *Block) error {
bc.mu.Lock()
defer bc.mu.Unlock()
if b, _ := bc.GetBlockByHash(blk.HashBlock()); b != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

This may not work perfectly. Between L686 and L687, if there's a context switch, the db will still throw error. I don't think we need to define another error. Instead, if we see the cause of the error is db.ErrAlreadyExist, we should just ignore it, and not print error message.

@@ -8,6 +8,7 @@ package consensus

import (
"context"
"github.com/iotexproject/iotex-core/db"

Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

@@ -7,6 +7,7 @@
package blocksync

import (
"github.com/iotexproject/iotex-core/db"

Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

@@ -10,6 +10,7 @@ import (
"bytes"
"context"
"encoding/hex"
"github.com/iotexproject/iotex-core/db"

Choose a reason for hiding this comment

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

File is not goimports-ed (from goimports)

@codecov
Copy link

codecov bot commented Dec 3, 2018

Codecov Report

Merging #341 into master will decrease coverage by 0.08%.
The diff coverage is 9.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #341      +/-   ##
==========================================
- Coverage   60.77%   60.69%   -0.09%     
==========================================
  Files         118      118              
  Lines       11509    11512       +3     
==========================================
- Hits         6995     6987       -8     
- Misses       3532     3542      +10     
- Partials      982      983       +1
Impacted Files Coverage Δ
consensus/scheme/rolldpos/fsm.go 75.14% <0%> (+1.13%) ⬆️
blocksync/buffer.go 84.61% <25%> (-4.62%) ⬇️
network/pinger.go 12.5% <0%> (-37.5%) ⬇️
network/healthchecker.go 50% <0%> (-16.67%) ⬇️
db/trie/branchnode.go 64.4% <0%> (-1.7%) ⬇️

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 a7cbf75...383f6c8. Read the comment docs.

@codecov
Copy link

codecov bot commented Dec 3, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@0a08e71). Click here to learn what that means.
The diff coverage is 50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #341   +/-   ##
=========================================
  Coverage          ?   62.72%           
=========================================
  Files             ?      110           
  Lines             ?    11069           
  Branches          ?        0           
=========================================
  Hits              ?     6943           
  Misses            ?     3158           
  Partials          ?      968
Impacted Files Coverage Δ
consensus/scheme/rolldpos/fsm.go 74% <0%> (ø)
blocksync/buffer.go 89.23% <100%> (ø)

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 0a08e71...8ba54f3. Read the comment docs.

@FishMeat
Copy link
Contributor Author

FishMeat commented Dec 3, 2018

make some changes

@@ -65,7 +66,7 @@ func (b *blockBuffer) Flush(blk *blockchain.Block) (bool, bCheckinResult) {
break
}
delete(b.blocks, heightToSync)
if err := commitBlock(b.bc, b.ap, blk); err != nil {
if err := commitBlock(b.bc, b.ap, blk); err != nil && err != db.ErrAlreadyExist {
Copy link
Contributor

Choose a reason for hiding this comment

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

if err == db.ErrAlreadyExist, we should also not say "Successfully committed block". Maybe ether skip the log or say "Already exists"

@FishMeat
Copy link
Contributor Author

FishMeat commented Dec 4, 2018

If block already exists, ignore the err and log info msg.

zjshen14 and others added 2 commits December 7, 2018 10:19
Co-Authored-By: FishMeat <330771743@qq.com>
Uint64("block", pendingBlock.Height()).
Msg("error when committing a block")
if err == db.ErrAlreadyExist {
err = nil

Choose a reason for hiding this comment

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

ineffectual assignment to err (from ineffassign)

@@ -66,6 +67,11 @@ func (b *blockBuffer) Flush(blk *blockchain.Block) (bool, bCheckinResult) {
}
delete(b.blocks, heightToSync)
if err := commitBlock(b.bc, b.ap, blk); err != nil {
if err == db.ErrAlreadyExist {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I just double check , and i think the right logic here is

Suggested change
if err == db.ErrAlreadyExist {
if err == db.ErrAlreadyExist {
l.Info().Uint64("syncHeight", heightToSync).Msg("Block already exists.")
} else {
l.Error().Err(err).Uint64("syncHeight", heightToSync).Msg("Failed to commit the block.")
break
}

And then, we don't need L75-L81

@zjshen14 zjshen14 merged commit ee0510f into iotexproject:master Dec 7, 2018
@FishMeat FishMeat deleted the issue251 branch December 8, 2018 04: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.

None yet

3 participants