aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-18 16:49:09 +0800
committerobscuren <geffobscura@gmail.com>2015-05-18 16:49:09 +0800
commit67d44519ce4344d5ee5f7cf37dd785ead70e8453 (patch)
tree13424e1c17374ce28602c5324df581f4a6ad6db1
parent54f0f82dd13f7faed68ab3a781df97a62b7d15d4 (diff)
downloaddexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar.gz
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar.bz2
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar.lz
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar.xz
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.tar.zst
dexon-67d44519ce4344d5ee5f7cf37dd785ead70e8453.zip
core: bugfix test 2. set => hash map
-rw-r--r--core/block_processor.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 97ac4ce24..0652d217f 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -15,7 +15,6 @@ 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 (
@@ -329,40 +328,50 @@ 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 := set.New()
+ //uncles := set.New()
+ ancestors := make(map[common.Hash]struct{})
+ uncles := make(map[common.Hash]struct{})
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.Add(ancestor.Hash())
+ ancestors[ancestor.Hash()] = struct{}{}
// Include ancestors uncles in the uncle set. Uncles must be unique.
for _, uncle := range ancestor.Uncles() {
- uncles.Add(uncle.Hash())
+ //uncles.Add(uncle.Hash())
+ uncles[uncle.Hash()] = struct{}{}
}
}
- uncles.Add(block.Hash())
+ //uncles.Add(block.Hash())
+ uncles[block.Hash()] = struct{}{}
for i, uncle := range block.Uncles() {
hash := uncle.Hash()
- if uncles.Has(hash) {
+ //if uncles.Has(hash) {
+ if _, has := uncles[hash]; has {
// Error not unique
return UncleError("uncle[%d](%x) not unique", i, hash[:4])
}
- uncles.Add(hash)
+ uncles[hash] = struct{}{}
- if ancestors.Has(hash) {
+ //if ancestors.Has(hash) {
+ if _, has := ancestors[hash]; has {
var branch string
- ancestors.Each(func(item interface{}) bool {
- branch += fmt.Sprintf(" O - %x\n |\n", item.(common.Hash))
- return true
- })
+ //ancestors.Each(func(item interface{}) bool {
+ for hash := range ancestors {
+ branch += fmt.Sprintf(" O - %x\n |\n", hash)
+ //return true
+ }
+ //})
branch += fmt.Sprintf(" O - %x\n |\n", block.Hash())
glog.Infoln(branch)
return UncleError("uncle[%d](%x) is ancestor", i, hash[:4])
}
- if !ancestors.Has(uncle.ParentHash) {
+ //if !ancestors.Has(uncle.ParentHash) {
+ if _, has := ancestors[uncle.ParentHash]; !has {
return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4])
}