10000 Refactoring BadBlock by hqjang-pepper · Pull Request #1371 · klaytn/klaytn · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Aug 19, 2024. It is now read-only.

Refactoring BadBlock #1371

Merged
merged 22 commits into from
Jul 5, 2022
Merged

Refactoring BadBlock #1371

merged 22 commits into from
Jul 5, 2022

Conversation

hqjang-pepper
Copy link
Contributor
@hqjang-pepper hqjang-pepper commented May 12, 2022

Proposed changes

  • fix BadBlock log print from multi-line into single line.
  • Change BadBlock storing location from Cache to DB.

Types of changes

Please put an x in the boxes related to your change.

  • Bugfix
  • New feature or enhancement
  • Others

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I have read the CONTRIBUTING GUIDELINES doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes ($ make test)
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Related issues

  • Please leave the issue numbers or links related to this PR here.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

@hqjang-pepper hqjang-pepper self-assigned this May 13, 2022
@hqjang-pepper hqjang-pepper added this to the v1.9.0 milestone May 13, 2022
@hqjang-pepper
Copy link
Contributor Author

Adding testcode. This code is draft.

@hqjang-pepper hqjang-pepper added the draft More implementation is needed label May 13, 2022
@hqjang-pepper
Copy link
Contributor Author

Test code is updated.

@hqjang-pepper hqjang-pepper removed the draft More implementation is needed label May 13, 2022
Comment on lines +1495 to +1503
var badBlocks badBlockList
db := dbm.getDatabase(MiscDB)
blob, err := db.Get(badBlockKey)
if err != nil {
return nil, err
}
if err := rlp.DecodeBytes(blob, &badBlocks); err != nil {
return nil, err
}

Choose a reason for hiding this comment

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

Seems like reading bad blocks from DB is all the same. Can we make an internal function for this? If we do that, we can do refactor code more easily if needed.

Choose a reason for hiding this comment

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

@hqjang-pepper Please share your thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because the return arguments of readbadbock and readallbadblock are 1 and 2 respectively,
Even if the logic is the same, it is difficult to tie these parts in common.
I think it'll be fine to leave as it is.

aidan-kwon
aidan-kwon previously approved these changes Jun 27, 2022
@aidan-kwon
Copy link
Member

@hqjang-pepper Could you fix test failures?

@aidan-kwon aidan-kwon added the need to merge Need to merge for the next time label Jun 29, 2022
aidan-kwon
aidan-kwon previously approved these changes Jun 30, 2022
@aidan-kwon aidan-kwon removed the need to merge Need to merge for the next time label Jun 30, 2022
@hqjang-pepper hqjang-pepper mentioned this pull request Jun 30, 2022
10 tasks
yoomee1313
yoomee1313 previously approved these changes Jun 30, 2022
Copy link
Contributor
@hyunsooda hyunsooda left a comment

Choose a reason for hiding this comment

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

How did you decide on the space constraint of bad blocks? If it can be possibly leveraged for debug purposes, my suggestion is n EDBE ot to make the constraint of storage space for badblocks.

logger.Warn("Failed to load old bad blocks", "error", err)
}
var badBlocks badBlockList
if len(blob) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unncessary of its length check. nope?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If len(blob) ==0, it means that badblocklist is empty, so we don't have to execute DecodeBytes logic. I think this is a shortcut for 'no badblock case'. Agree?


// WriteBadBlock serializes the bad block into the database. If the cumulated
// bad blocks exceed the capacity, the oldest will be dropped.
func (dbm *databaseManager) WriteBadBlock(block *types.Block) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems costly. If one bad block should be stored, the read operation for entirely stored badblocks and putting them again with added new badblock are followed. Did you consider the other structure to avoid costly write operation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason to read all badblocks is to store badblocks in order. I agree this operation itself is costly high, but since max length is 100, it's not a big deal.

@aidan-kwon aidan-kwon added the need to merge Need to merge for the next time label Jul 1, 2022
@hqjang-pepper hqjang-pepper dismissed stale reviews from yoomee1313 and aidan-kwon via ca1d1c2 July 4, 2022 01:54
@hqjang-pepper hqjang-pepper merged commit 1690300 into klaytn:dev Jul 5, 2022
@blukat29 blukat29 removed the need to merge Need to merge for the next time label Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants
0