aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-09-12 06:29:27 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-09-12 06:29:27 +0800
commit55ed8d108d72d12543ecdc6d8c9d9978392dabf0 (patch)
treed594ab985612289895355f07d3a21892e3058e98 /core
parentf1a4b330dd281a37454df873c97afc7c700b61f2 (diff)
parentb81a6e6ab8954689fa183fd19639cf0344c0de19 (diff)
downloadgo-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar.gz
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar.bz2
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar.lz
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar.xz
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.tar.zst
go-tangerine-55ed8d108d72d12543ecdc6d8c9d9978392dabf0.zip
Merge pull request #1789 from Gustav-Simonsson/core_remove_unused_functions
core, core/vm, core/state: remove unused functions
Diffstat (limited to 'core')
-rw-r--r--core/block_cache.go120
-rw-r--r--core/block_cache_test.go76
-rw-r--r--core/state/state_object.go43
-rw-r--r--core/state/statedb.go21
-rw-r--r--core/types/transaction.go4
-rw-r--r--core/vm/errors.go17
6 files changed, 0 insertions, 281 deletions
diff --git a/core/block_cache.go b/core/block_cache.go
deleted file mode 100644
index 0fd711448..000000000
--- a/core/block_cache.go
+++ /dev/null
@@ -1,120 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package core
-
-import (
- "sync"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core/types"
-)
-
-// BlockCache implements a caching mechanism specifically for blocks and uses FILO to pop
-type BlockCache struct {
- size int
-
- hashes []common.Hash
- blocks map[common.Hash]*types.Block
-
- mu sync.RWMutex
-}
-
-// Creates and returns a `BlockCache` with `size`. If `size` is smaller than 1 it will panic
-func NewBlockCache(size int) *BlockCache {
- if size < 1 {
- panic("block cache size not allowed to be smaller than 1")
- }
-
- bc := &BlockCache{size: size}
- bc.Clear()
- return bc
-}
-
-func (bc *BlockCache) Clear() {
- bc.blocks = make(map[common.Hash]*types.Block)
- bc.hashes = nil
-
-}
-
-func (bc *BlockCache) Push(block *types.Block) {
- bc.mu.Lock()
- defer bc.mu.Unlock()
-
- if len(bc.hashes) == bc.size {
- delete(bc.blocks, bc.hashes[0])
-
- // XXX There are a few other options on solving this
- // 1) use a poller / GC like mechanism to clean up untracked objects
- // 2) copy as below
- // re-use the slice and remove the reference to bc.hashes[0]
- // this will allow the element to be garbage collected.
- copy(bc.hashes, bc.hashes[1:])
- } else {
- bc.hashes = append(bc.hashes, common.Hash{})
- }
-
- hash := block.Hash()
- bc.blocks[hash] = block
- bc.hashes[len(bc.hashes)-1] = hash
-}
-
-func (bc *BlockCache) Delete(hash common.Hash) {
- bc.mu.Lock()
- defer bc.mu.Unlock()
-
- if _, ok := bc.blocks[hash]; ok {
- delete(bc.blocks, hash)
- for i, h := range bc.hashes {
- if hash == h {
- bc.hashes = bc.hashes[:i+copy(bc.hashes[i:], bc.hashes[i+1:])]
- // or ? => bc.hashes = append(bc.hashes[:i], bc.hashes[i+1]...)
-
- break
- }
- }
- }
-}
-
-func (bc *BlockCache) Get(hash common.Hash) *types.Block {
- bc.mu.RLock()
- defer bc.mu.RUnlock()
-
- if block, haz := bc.blocks[hash]; haz {
- return block
- }
-
- return nil
-}
-
-func (bc *BlockCache) Has(hash common.Hash) bool {
- bc.mu.RLock()
- defer bc.mu.RUnlock()
-
- _, ok := bc.blocks[hash]
- return ok
-}
-
-func (bc *BlockCache) Each(cb func(int, *types.Block)) {
- bc.mu.Lock()
- defer bc.mu.Unlock()
-
- i := 0
- for _, block := range bc.blocks {
- cb(i, block)
- i++
- }
-}
diff --git a/core/block_cache_test.go b/core/block_cache_test.go
deleted file mode 100644
index ef826d5bd..000000000
--- a/core/block_cache_test.go
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package core
-
-import (
- "math/big"
- "testing"
-
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core/types"
-)
-
-func newChain(size int) (chain []*types.Block) {
- var parentHash common.Hash
- for i := 0; i < size; i++ {
- head := &types.Header{ParentHash: parentHash, Number: big.NewInt(int64(i))}
- block := types.NewBlock(head, nil, nil, nil)
- chain = append(chain, block)
- parentHash = block.Hash()
- }
- return chain
-}
-
-func insertChainCache(cache *BlockCache, chain []*types.Block) {
- for _, block := range chain {
- cache.Push(block)
- }
-}
-
-func TestNewBlockCache(t *testing.T) {
- chain := newChain(3)
- cache := NewBlockCache(2)
- insertChainCache(cache, chain)
-
- if cache.hashes[0] != chain[1].Hash() {
- t.Error("oldest block incorrect")
- }
-}
-
-func TestInclusion(t *testing.T) {
- chain := newChain(3)
- cache := NewBlockCache(3)
- insertChainCache(cache, chain)
-
- for _, block := range chain {
- if b := cache.Get(block.Hash()); b == nil {
- t.Errorf("getting %x failed", block.Hash())
- }
- }
-}
-
-func TestDeletion(t *testing.T) {
- chain := newChain(3)
- cache := NewBlockCache(3)
- insertChainCache(cache, chain)
-
- cache.Delete(chain[1].Hash())
-
- if cache.Has(chain[1].Hash()) {
- t.Errorf("expected %x not to be included")
- }
-}
diff --git a/core/state/state_object.go b/core/state/state_object.go
index 0af0fbd5a..69c64ae40 100644
--- a/core/state/state_object.go
+++ b/core/state/state_object.go
@@ -87,10 +87,6 @@ type StateObject struct {
dirty bool
}
-func (self *StateObject) Reset() {
- self.storage = make(Storage)
-}
-
func NewStateObject(address common.Address, db common.Database) *StateObject {
object := &StateObject{db: db, address: address, balance: new(big.Int), gasPool: new(big.Int), dirty: true}
object.trie = trie.NewSecure((common.Hash{}).Bytes(), db)
@@ -184,14 +180,6 @@ func (self *StateObject) Update() {
}
}
-func (c *StateObject) GetInstr(pc *big.Int) *common.Value {
- if int64(len(c.code)-1) < pc.Int64() {
- return common.NewValue(0)
- }
-
- return common.NewValueFromBytes([]byte{c.code[pc.Int64()]})
-}
-
func (c *StateObject) AddBalance(amount *big.Int) {
c.SetBalance(new(big.Int).Add(c.balance, amount))
@@ -268,10 +256,6 @@ func (self *StateObject) Copy() *StateObject {
return stateObject
}
-func (self *StateObject) Set(stateObject *StateObject) {
- *self = *stateObject
-}
-
//
// Attribute accessors
//
@@ -280,20 +264,11 @@ func (self *StateObject) Balance() *big.Int {
return self.balance
}
-func (c *StateObject) N() *big.Int {
- return big.NewInt(int64(c.nonce))
-}
-
// Returns the address of the contract/account
func (c *StateObject) Address() common.Address {
return c.address
}
-// Returns the initialization Code
-func (c *StateObject) Init() Code {
- return c.initCode
-}
-
func (self *StateObject) Trie() *trie.SecureTrie {
return self.trie
}
@@ -311,11 +286,6 @@ func (self *StateObject) SetCode(code []byte) {
self.dirty = true
}
-func (self *StateObject) SetInitCode(code []byte) {
- self.initCode = code
- self.dirty = true
-}
-
func (self *StateObject) SetNonce(nonce uint64) {
self.nonce = nonce
self.dirty = true
@@ -354,19 +324,6 @@ func (c *StateObject) CodeHash() common.Bytes {
return crypto.Sha3(c.code)
}
-func (c *StateObject) RlpDecode(data []byte) {
- decoder := common.NewValueFromBytes(data)
- c.nonce = decoder.Get(0).Uint()
- c.balance = decoder.Get(1).BigInt()
- c.trie = trie.NewSecure(decoder.Get(2).Bytes(), c.db)
- c.storage = make(map[string]common.Hash)
- c.gasPool = new(big.Int)
-
- c.codeHash = decoder.Get(3).Bytes()
-
- c.code, _ = c.db.Get(c.codeHash)
-}
-
// Storage change object. Used by the manifest for notifying changes to
// the sub channels.
type StorageState struct {
diff --git a/core/state/statedb.go b/core/state/statedb.go
index 577f7162e..b754f0887 100644
--- a/core/state/statedb.go
+++ b/core/state/statedb.go
@@ -18,7 +18,6 @@
package state
import (
- "bytes"
"math/big"
"github.com/ethereum/go-ethereum/common"
@@ -276,10 +275,6 @@ func (self *StateDB) CreateAccount(addr common.Address) *StateObject {
// Setting, copying of the state methods
//
-func (s *StateDB) Cmp(other *StateDB) bool {
- return bytes.Equal(s.trie.Root(), other.trie.Root())
-}
-
func (self *StateDB) Copy() *StateDB {
state := New(common.Hash{}, self.db)
state.trie = self.trie
@@ -311,22 +306,6 @@ func (s *StateDB) Root() common.Hash {
return common.BytesToHash(s.trie.Root())
}
-func (s *StateDB) Trie() *trie.SecureTrie {
- return s.trie
-}
-
-// Resets the trie and all siblings
-func (s *StateDB) Reset() {
- s.trie.Reset()
-
- // Reset all nested states
- for _, stateObject := range s.stateObjects {
- stateObject.Reset()
- }
-
- s.Empty()
-}
-
// Syncs the trie and all siblings
func (s *StateDB) Sync() {
// Sync all nested states
diff --git a/core/types/transaction.go b/core/types/transaction.go
index 28a7e02b3..8260d7423 100644
--- a/core/types/transaction.go
+++ b/core/types/transaction.go
@@ -33,10 +33,6 @@ import (
var ErrInvalidSig = errors.New("invalid v, r, s values")
-func IsContractAddr(addr []byte) bool {
- return len(addr) == 0
-}
-
type Transaction struct {
data txdata
// caches
diff --git a/core/vm/errors.go b/core/vm/errors.go
index 24567e9a1..e2fc84065 100644
--- a/core/vm/errors.go
+++ b/core/vm/errors.go
@@ -25,20 +25,3 @@ import (
var OutOfGasError = errors.New("Out of gas")
var DepthError = fmt.Errorf("Max call depth exceeded (%d)", params.CallCreateDepth)
-
-type StackError struct {
- req, has int
-}
-
-func StackErr(req, has int) StackError {
- return StackError{req, has}
-}
-
-func (self StackError) Error() string {
- return fmt.Sprintf("stack error! require %v, have %v", self.req, self.has)
-}
-
-func IsStackErr(err error) bool {
- _, ok := err.(StackError)
- return ok
-}