-
Notifications
You must be signed in to change notification settings - Fork 20.1k
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
core,eth,internal: Added debug_getBadBlocks()
method
#3654
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,7 @@ const ( | |
// must be bumped when consensus algorithm is changed, this forces the upgradedb | ||
// command to be run (forces the blocks to be imported again using the new algorithm) | ||
BlockChainVersion = 3 | ||
badBlockLimit = 10 | ||
) | ||
|
||
// BlockChain represents the canonical chain given a database with a genesis | ||
|
@@ -108,6 +109,8 @@ type BlockChain struct { | |
processor Processor // block processor interface | ||
validator Validator // block and state validator interface | ||
vmConfig vm.Config | ||
|
||
badBlocks *lru.Cache // Bad block cache | ||
} | ||
|
||
// NewBlockChain returns a fully initialised block chain using information | ||
|
@@ -118,6 +121,7 @@ func NewBlockChain(chainDb ethdb.Database, config *params.ChainConfig, pow pow.P | |
bodyRLPCache, _ := lru.New(bodyCacheLimit) | ||
blockCache, _ := lru.New(blockCacheLimit) | ||
futureBlocks, _ := lru.New(maxFutureBlocks) | ||
badBlocks, _ := lru.New(badBlockLimit) | ||
|
||
bc := &BlockChain{ | ||
config: config, | ||
|
@@ -130,6 +134,7 @@ func NewBlockChain(chainDb ethdb.Database, config *params.ChainConfig, pow pow.P | |
futureBlocks: futureBlocks, | ||
pow: pow, | ||
vmConfig: vmConfig, | ||
badBlocks: badBlocks, | ||
} | ||
bc.SetValidator(NewBlockValidator(config, bc, pow)) | ||
bc.SetProcessor(NewStateProcessor(config, bc)) | ||
|
@@ -893,7 +898,6 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { | |
glog.V(logger.Debug).Infoln("Premature abort during block chain processing") | ||
break | ||
} | ||
|
||
bstart := time.Now() | ||
// Wait for block i's nonce to be verified before processing | ||
// its state transition. | ||
|
@@ -1242,8 +1246,30 @@ func (self *BlockChain) update() { | |
} | ||
} | ||
|
||
// BadBlockArgs represents the entries in the list returned when bad blocks are queried. | ||
type BadBlockArgs struct { | ||
Hash common.Hash `json:"hash"` | ||
Header *types.Header `json:"header"` | ||
} | ||
|
||
// BadBlocks returns a list of the last 'bad blocks' that the client has seen on the network | ||
func (bc *BlockChain) BadBlocks() ([]BadBlockArgs, error) { | ||
headers := make([]BadBlockArgs, 0, bc.badBlocks.Len()) | ||
for _, hash := range bc.badBlocks.Keys() { | ||
if hdr, exist := bc.badBlocks.Peek(hash); exist { | ||
headers = append(headers, BadBlockArgs{hdr.(*types.Header).Hash(), hdr.(*types.Header)}) | ||
} | ||
} | ||
return headers, nil | ||
} | ||
// Adds a 'bad lock' to the LRU | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please change comment to |
||
func (bc *BlockChain) addBadBlock(block *types.Block) { | ||
bc.badBlocks.Add(block.Header().Hash(), block.Header()) | ||
} | ||
|
||
// reportBlock logs a bad block error. | ||
func (bc *BlockChain) reportBlock(block *types.Block, receipts types.Receipts, err error) { | ||
bc.addBadBlock(block) | ||
if glog.V(logger.Error) { | ||
var receiptString string | ||
for _, receipt := range receipts { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe assign
hdr.(*types.Header)
first so you don't need to type assert twice.