aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_processor.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-17 07:42:30 +0800
committerobscuren <geffobscura@gmail.com>2015-05-18 19:59:22 +0800
commitc67424ecc8a75d7c0bc942227a4c4e5c5628d7bc (patch)
treec234714a27c5bab93d56236601524cf7664df5e8 /core/block_processor.go
parent443d0248436f653bc2d56653dd52b8abbe408f60 (diff)
downloadgo-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar.gz
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar.bz2
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar.lz
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar.xz
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.tar.zst
go-tangerine-c67424ecc8a75d7c0bc942227a4c4e5c5628d7bc.zip
core: parallelise nonce checking when processing blocks
ChainManager now uses a parallel approach to block processing where all nonces are checked seperatly from the block processing process. This speeds up the process by about 3 times on my i7
Diffstat (limited to 'core/block_processor.go')
-rw-r--r--core/block_processor.go14
1 files changed, 8 insertions, 6 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index cae618b39..a021086c0 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -189,7 +189,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
state := state.New(parent.Root(), sm.db)
// Block validation
- if err = sm.ValidateHeader(block.Header(), parent.Header()); err != nil {
+ if err = sm.ValidateHeader(block.Header(), parent.Header(), false); err != nil {
return
}
@@ -269,7 +269,7 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
// Validates the current block. Returns an error if the block was invalid,
// an uncle or anything that isn't on the current block chain.
// Validation validates easy over difficult (dagger takes longer time = difficult)
-func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
+func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header, checkPow bool) error {
if big.NewInt(int64(len(block.Extra))).Cmp(params.MaximumExtraDataSize) == 1 {
return fmt.Errorf("Block extra data too long (%d)", len(block.Extra))
}
@@ -300,9 +300,11 @@ func (sm *BlockProcessor) ValidateHeader(block, parent *types.Header) error {
return BlockEqualTSErr //ValidationError("Block timestamp equal or less than previous block (%v - %v)", block.Time, parent.Time)
}
- // Verify the nonce of the block. Return an error if it's not valid
- if !sm.Pow.Verify(types.NewBlockWithHeader(block)) {
- return ValidationError("Block's nonce is invalid (= %x)", block.Nonce)
+ if checkPow {
+ // Verify the nonce of the block. Return an error if it's not valid
+ if !sm.Pow.Verify(types.NewBlockWithHeader(block)) {
+ return ValidationError("Block's nonce is invalid (= %x)", block.Nonce)
+ }
}
return nil
@@ -358,7 +360,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4])
}
- if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash]); err != nil {
+ if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash], true); err != nil {
return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, hash[:4], err))
}
}