mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
fix error double validation
This commit is contained in:
parent
03c07f37b4
commit
53e39d77ac
2 changed files with 14 additions and 21 deletions
|
|
@ -34,4 +34,6 @@ var (
|
|||
// ErrInvalidNumber is returned if a block's number doesn't equal it's parent's
|
||||
// plus one.
|
||||
ErrInvalidNumber = errors.New("invalid block number")
|
||||
|
||||
ErrMissingValidatorSignature = errors.New("missing validator in header")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -142,7 +142,6 @@ type Fetcher struct {
|
|||
queueChangeHook func(common.Hash, bool) // Method to call upon adding or deleting a block from the import queue
|
||||
fetchingHook func([]common.Hash) // Method to call upon starting a block (eth/61) or header (eth/62) fetch
|
||||
completingHook func([]common.Hash) // Method to call upon starting a block body fetch (eth/62)
|
||||
doubleValidateHook func(*types.Block) error
|
||||
signHook func(*types.Block) error
|
||||
appendM2HeaderHook func(*types.Block) (*types.Block, error)
|
||||
}
|
||||
|
|
@ -654,33 +653,30 @@ func (f *Fetcher) insert(peer string, block *types.Block) {
|
|||
// Quickly validate the header and propagate the block if it passes
|
||||
switch err := f.verifyHeader(block.Header()); err {
|
||||
case nil:
|
||||
// All ok, quickly propagate to our peers
|
||||
propBroadcastOutTimer.UpdateSince(block.ReceivedAt)
|
||||
go f.broadcastBlock(block, true)
|
||||
case consensus.ErrFutureBlock:
|
||||
case consensus.ErrMissingValidatorSignature:
|
||||
newBlock := block
|
||||
if f.appendM2HeaderHook != nil {
|
||||
if block, err = f.appendM2HeaderHook(block); err != nil {
|
||||
if newBlock, err = f.appendM2HeaderHook(block); err != nil {
|
||||
log.Error("Append m2 to block header fail", "err", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// All ok, quickly propagate to our peers
|
||||
propBroadcastOutTimer.UpdateSince(block.ReceivedAt)
|
||||
go f.broadcastBlock(block, true)
|
||||
|
||||
case consensus.ErrFutureBlock:
|
||||
// Weird future block, don't fail, but neither propagate
|
||||
|
||||
if newBlock.Hash() == block.Hash() {
|
||||
return
|
||||
}
|
||||
block = newBlock
|
||||
propBroadcastOutTimer.UpdateSince(block.ReceivedAt)
|
||||
default:
|
||||
// Something went very wrong, drop the peer
|
||||
log.Debug("Propagated block verification failed", "peer", peer, "number", block.Number(), "hash", hash, "err", err)
|
||||
f.dropPeer(peer)
|
||||
return
|
||||
}
|
||||
// Invoke the dv hook to run double validation layer
|
||||
if f.doubleValidateHook != nil {
|
||||
if err := f.doubleValidateHook(block); err != nil {
|
||||
log.Error("Double validation failed", "err", err, "Discard this block!")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Run the actual import and log any issues
|
||||
if _, err := f.insertChain(types.Blocks{block}); err != nil {
|
||||
|
|
@ -756,11 +752,6 @@ func (f *Fetcher) forgetBlock(hash common.Hash) {
|
|||
}
|
||||
}
|
||||
|
||||
// Bind double validate hook before block imported into chain.
|
||||
func (f *Fetcher) SetDoubleValidateHook(doubleValidateHook func(*types.Block) error) {
|
||||
f.doubleValidateHook = doubleValidateHook
|
||||
}
|
||||
|
||||
// Bind double validate hook before block imported into chain.
|
||||
func (f *Fetcher) SetSignHook(signHook func(*types.Block) error) {
|
||||
f.signHook = signHook
|
||||
|
|
|
|||
Loading…
Reference in a new issue