aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/block_processor.go54
-rw-r--r--core/execution.go6
-rw-r--r--core/vm/memory.go12
-rw-r--r--core/vm/vm.go2
4 files changed, 49 insertions, 25 deletions
diff --git a/core/block_processor.go b/core/block_processor.go
index 20e6722a4..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 (
@@ -23,6 +24,8 @@ const (
BlockChainVersion = 2
)
+var receiptsPre = []byte("receipts-")
+
type BlockProcessor struct {
db common.Database
extraDb common.Database
@@ -262,9 +265,23 @@ func (sm *BlockProcessor) processWithParent(block, parent *types.Block) (logs st
putTx(sm.extraDb, tx, block, uint64(i))
}
+ receiptsRlp := block.Receipts().RlpEncode()
+ sm.extraDb.Put(append(receiptsPre, block.Hash().Bytes()...), receiptsRlp)
+
return state.Logs(), nil
}
+func (self *BlockProcessor) GetBlockReceipts(bhash common.Hash) (receipts types.Receipts, err error) {
+ var rdata []byte
+ rdata, err = self.extraDb.Get(append(receiptsPre, bhash[:]...))
+
+ if err == nil {
+ err = rlp.DecodeBytes(rdata, &receipts)
+ }
+ return
+
+}
+
// 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)
@@ -330,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])
}
diff --git a/core/execution.go b/core/execution.go
index 9adf98032..522c90449 100644
--- a/core/execution.go
+++ b/core/execution.go
@@ -38,6 +38,12 @@ func (self *Execution) Create(caller vm.ContextRef) (ret []byte, err error, acco
code := self.input
self.input = nil
ret, err = self.exec(nil, code, caller)
+ // Here we get an error if we run into maximum stack depth,
+ // See: https://github.com/ethereum/yellowpaper/pull/131
+ // and YP definitions for CREATE instruction
+ if err != nil {
+ return nil, err, nil
+ }
account = self.env.State().GetStateObject(*self.address)
return
}
diff --git a/core/vm/memory.go b/core/vm/memory.go
index b77d486eb..d20aa9591 100644
--- a/core/vm/memory.go
+++ b/core/vm/memory.go
@@ -49,6 +49,18 @@ func (self *Memory) Get(offset, size int64) (cpy []byte) {
return
}
+func (self *Memory) GetPtr(offset, size int64) []byte {
+ if size == 0 {
+ return nil
+ }
+
+ if len(self.store) > int(offset) {
+ return self.store[offset : offset+size]
+ }
+
+ return nil
+}
+
func (m *Memory) Len() int {
return len(m.store)
}
diff --git a/core/vm/vm.go b/core/vm/vm.go
index 927b67293..35fa19d03 100644
--- a/core/vm/vm.go
+++ b/core/vm/vm.go
@@ -695,7 +695,7 @@ func (self *Vm) Run(context *Context, callData []byte) (ret []byte, err error) {
self.Printf("resume %x (%v)", context.Address(), context.Gas)
case RETURN:
offset, size := stack.pop(), stack.pop()
- ret := mem.Get(offset.Int64(), size.Int64())
+ ret := mem.GetPtr(offset.Int64(), size.Int64())
self.Printf(" => [%v, %v] (%d) 0x%x", offset, size, len(ret), ret).Endl()