-
Notifications
You must be signed in to change notification settings - Fork 182
Conversation
Adding testcode. This code is draft. |
Test code is updated. |
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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@hqjang-pepper Could you fix test failures? |
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Proposed changes
Types of changes
Please put an x in the boxes related to your change.
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.
$ make test
)Related issues
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...