core: switched back to `set.Set` for uncle verification

pull/1059/head
obscuren 10 years ago
parent ff1630834c
commit ef8744d9fc
  1. 38
      core/block_processor.go

@ -15,6 +15,7 @@ import (
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow"
"github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rlp"
"gopkg.in/fatih/set.v0"
) )
const ( 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 { func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *types.Block) error {
//ancestors := set.New() ancestors := set.New()
//uncles := set.New() uncles := set.New()
ancestors := make(map[common.Hash]struct{})
uncles := make(map[common.Hash]struct{})
ancestorHeaders := make(map[common.Hash]*types.Header) ancestorHeaders := make(map[common.Hash]*types.Header)
for _, ancestor := range sm.bc.GetAncestors(block, 7) { for _, ancestor := range sm.bc.GetAncestors(block, 7) {
ancestorHeaders[ancestor.Hash()] = ancestor.Header() 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. // Include ancestors uncles in the uncle set. Uncles must be unique.
for _, uncle := range ancestor.Uncles() { 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() { for i, uncle := range block.Uncles() {
hash := uncle.Hash() hash := uncle.Hash()
//if uncles.Has(hash) { if uncles.Has(hash) {
if _, has := uncles[hash]; has {
// Error not unique // Error not unique
return UncleError("uncle[%d](%x) not unique", i, hash[:4]) return UncleError("uncle[%d](%x) not unique", i, hash[:4])
} }
uncles[hash] = struct{}{} uncles.Add(hash)
//if ancestors.Has(hash) { if ancestors.Has(hash) {
if _, has := ancestors[hash]; has { branch := fmt.Sprintf(" O - %x\n |\n", block.Hash())
var branch string ancestors.Each(func(item interface{}) bool {
//ancestors.Each(func(item interface{}) bool {
for hash := range ancestors {
branch += fmt.Sprintf(" O - %x\n |\n", hash) branch += fmt.Sprintf(" O - %x\n |\n", hash)
//return true return true
} })
//})
branch += fmt.Sprintf(" O - %x\n |\n", block.Hash())
glog.Infoln(branch) glog.Infoln(branch)
return UncleError("uncle[%d](%x) is ancestor", i, hash[:4]) 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]) return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4])
} }

Loading…
Cancel
Save