aboutsummaryrefslogtreecommitdiffstats
path: root/core/block_processor.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-21 17:36:39 +0800
committerobscuren <geffobscura@gmail.com>2015-05-21 17:36:39 +0800
commitef8744d9fcc363ae1dfd4784902a8c8824fffda1 (patch)
treea42ab115e71b3c9d6e46161f1a6a14406b04d9b3 /core/block_processor.go
parentff1630834cddb768826cec0e555a645e13c7bc9c (diff)
downloadgo-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar.gz
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar.bz2
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar.lz
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar.xz
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.tar.zst
go-tangerine-ef8744d9fcc363ae1dfd4784902a8c8824fffda1.zip
core: switched back to `set.Set` for uncle verification
Diffstat (limited to 'core/block_processor.go')
-rw-r--r--core/block_processor.go38
1 files changed, 14 insertions, 24 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 3a224059b..3f10e5efd 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp"
+ "gopkg.in/fatih/set.v0"
)
const (
@@ -346,50 +347,39 @@ func AccumulateRewards(statedb *state.StateDB, block *types.Block) {
}
func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *types.Block) error {
- //ancestors := set.New()
- //uncles := set.New()
- ancestors := make(map[common.Hash]struct{})
- uncles := make(map[common.Hash]struct{})
+ ancestors := set.New()
+ uncles := set.New()
ancestorHeaders := make(map[common.Hash]*types.Header)
for _, ancestor := range sm.bc.GetAncestors(block, 7) {
ancestorHeaders[ancestor.Hash()] = ancestor.Header()
- //ancestors.Add(ancestor.Hash())
- ancestors[ancestor.Hash()] = struct{}{}
+ ancestors.Add(ancestor.Hash())
// Include ancestors uncles in the uncle set. Uncles must be unique.
for _, uncle := range ancestor.Uncles() {
- //uncles.Add(uncle.Hash())
- uncles[uncle.Hash()] = struct{}{}
+ uncles.Add(uncle.Hash())
}
}
- //uncles.Add(block.Hash())
- uncles[block.Hash()] = struct{}{}
+ uncles.Add(block.Hash())
for i, uncle := range block.Uncles() {
hash := uncle.Hash()
- //if uncles.Has(hash) {
- if _, has := uncles[hash]; has {
+ if uncles.Has(hash) {
// Error not unique
return UncleError("uncle[%d](%x) not unique", i, hash[:4])
}
- uncles[hash] = struct{}{}
+ uncles.Add(hash)
- //if ancestors.Has(hash) {
- if _, has := ancestors[hash]; has {
- var branch string
- //ancestors.Each(func(item interface{}) bool {
- for hash := range ancestors {
+ if ancestors.Has(hash) {
+ branch := fmt.Sprintf(" O - %x\n |\n", block.Hash())
+ ancestors.Each(func(item interface{}) bool {
branch += fmt.Sprintf(" O - %x\n |\n", hash)
- //return true
- }
- //})
- branch += fmt.Sprintf(" O - %x\n |\n", block.Hash())
+ return true
+ })
glog.Infoln(branch)
return UncleError("uncle[%d](%x) is ancestor", i, hash[:4])
}
- //if !ancestors.Has(uncle.ParentHash) {
- if _, has := ancestors[uncle.ParentHash]; !has {
+ if !ancestors.Has(uncle.ParentHash) {
return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4])
}