aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-01-10 00:38:35 +0800
committerobscuren <geffobscura@gmail.com>2015-01-10 00:38:35 +0800
commit905b8cc82f3dc29131f45ccf29bd1d6c967fe132 (patch)
tree61f251d788868263cdd93aeb7c19b8ea3f3e0be4 /core
parent35f4bb96f313f4f04e70d1cf135be3a4759a8179 (diff)
downloadgo-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar.gz
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar.bz2
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar.lz
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar.xz
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.tar.zst
go-tangerine-905b8cc82f3dc29131f45ccf29bd1d6c967fe132.zip
mem fixes for vm. Changed uncle inclusion tests
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go34
-rw-r--r--core/chain_manager.go22
2 files changed, 42 insertions, 14 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 87e823362..3ccf2d03c 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -294,32 +294,38 @@ func (sm *BlockProcessor) ValidateBlock(block, parent *types.Block) error {
func (sm *BlockProcessor) AccumelateRewards(statedb *state.StateDB, block, parent *types.Block) error {
reward := new(big.Int).Set(BlockReward)
- knownUncles := set.New()
- for _, uncle := range parent.Uncles() {
- knownUncles.Add(string(uncle.Hash()))
+ ancestors := set.New()
+ for _, ancestor := range sm.bc.GetAncestors(block, 6) {
+ ancestors.Add(string(ancestor.Hash()))
}
- nonces := ethutil.NewSet(block.Header().Nonce)
+ uncles := set.New()
+ uncles.Add(string(block.Hash()))
for _, uncle := range block.Uncles() {
- if nonces.Include(uncle.Nonce) {
+ if uncles.Has(string(uncle.Hash())) {
// Error not unique
return UncleError("Uncle not unique")
}
+ uncles.Add(string(uncle.Hash()))
- uncleParent := sm.bc.GetBlock(uncle.ParentHash)
- if uncleParent == nil {
+ if !ancestors.Has(uncle.ParentHash) {
return UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4]))
}
- if uncleParent.Header().Number.Cmp(new(big.Int).Sub(parent.Header().Number, big.NewInt(6))) < 0 {
- return UncleError("Uncle too old")
- }
+ /*
+ uncleParent := sm.bc.GetBlock(uncle.ParentHash)
+ if uncleParent == nil {
+ return UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4]))
+ }
- if knownUncles.Has(string(uncle.Hash())) {
- return UncleError("Uncle in chain")
- }
+ if uncleParent.Number().Cmp(new(big.Int).Sub(parent.Number(), big.NewInt(6))) < 0 {
+ return UncleError("Uncle too old")
+ }
- nonces.Insert(uncle.Nonce)
+ if knownUncles.Has(string(uncle.Hash())) {
+ return UncleError("Uncle in chain")
+ }
+ */
r := new(big.Int)
r.Mul(BlockReward, big.NewInt(15)).Div(r, big.NewInt(16))
diff --git a/core/chain_manager.go b/core/chain_manager.go
index 3e0a3fb23..90b5692ac 100644
--- a/core/chain_manager.go
+++ b/core/chain_manager.go
@@ -262,6 +262,28 @@ func (self *ChainManager) GetBlock(hash []byte) *types.Block {
return &block
}
+func (self *ChainManager) GetUnclesInChain(block *types.Block, length int) (uncles []*types.Header) {
+ for i := 0; block != nil && i < length; i++ {
+ uncles = append(uncles, block.Uncles()...)
+ block = self.GetBlock(block.ParentHash())
+ }
+
+ return
+}
+
+func (self *ChainManager) GetAncestors(block *types.Block, length int) (blocks []*types.Block) {
+ for i := 0; i < length; i++ {
+ block = self.GetBlock(block.ParentHash())
+ if block == nil {
+ break
+ }
+
+ blocks = append(blocks, block)
+ }
+
+ return
+}
+
func (self *ChainManager) GetBlockByNumber(num uint64) *types.Block {
self.mu.RLock()
defer self.mu.RUnlock()