aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/bench_test.go2
-rw-r--r--core/block_processor.go10
-rw-r--r--core/block_processor_test.go6
-rw-r--r--core/blockchain.go (renamed from core/chain_manager.go)114
-rw-r--r--core/blockchain_test.go (renamed from core/chain_manager_test.go)40
-rw-r--r--core/chain_makers.go4
-rw-r--r--core/chain_makers_test.go2
-rw-r--r--core/helper_test.go6
-rw-r--r--core/manager.go2
-rw-r--r--core/vm/common.go4
-rw-r--r--core/vm/contract.go4
-rw-r--r--core/vm/doc.go8
-rw-r--r--core/vm/environment.go4
-rw-r--r--core/vm/memory.go2
-rw-r--r--core/vm_env.go4
15 files changed, 86 insertions, 126 deletions
diff --git a/core/bench_test.go b/core/bench_test.go
index def4f0d2a..27f3e3158 100644
--- a/core/bench_test.go
+++ b/core/bench_test.go
@@ -168,7 +168,7 @@ func benchInsertChain(b *testing.B, disk bool, gen func(int, *BlockGen)) {
// Time the insertion of the new chain.
// State and blocks are stored in the same DB.
evmux := new(event.TypeMux)
- chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman, _ := NewBlockChain(db, FakePow{}, evmux)
chainman.SetProcessor(NewBlockProcessor(db, FakePow{}, chainman, evmux))
defer chainman.Stop()
b.ReportAllocs()
diff --git a/core/block_processor.go b/core/block_processor.go
index 40e3931ba..783e15687 100644
--- a/core/block_processor.go
+++ b/core/block_processor.go
@@ -47,7 +47,7 @@ type BlockProcessor struct {
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex sync.Mutex
// Canonical block chain
- bc *ChainManager
+ bc *BlockChain
// non-persistent key/value memory storage
mem map[string]*big.Int
// Proof of work used for validating
@@ -70,12 +70,12 @@ type GasPool interface {
SubGas(gas, price *big.Int) error
}
-func NewBlockProcessor(db ethdb.Database, pow pow.PoW, chainManager *ChainManager, eventMux *event.TypeMux) *BlockProcessor {
+func NewBlockProcessor(db ethdb.Database, pow pow.PoW, blockchain *BlockChain, eventMux *event.TypeMux) *BlockProcessor {
sm := &BlockProcessor{
chainDb: db,
mem: make(map[string]*big.Int),
Pow: pow,
- bc: chainManager,
+ bc: blockchain,
eventMux: eventMux,
}
return sm
@@ -124,7 +124,7 @@ func (self *BlockProcessor) ApplyTransaction(gp GasPool, statedb *state.StateDB,
return receipt, gas, err
}
-func (self *BlockProcessor) ChainManager() *ChainManager {
+func (self *BlockProcessor) BlockChain() *BlockChain {
return self.bc
}
@@ -347,7 +347,7 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty
// GetBlockReceipts returns the receipts beloniging to the block hash
func (sm *BlockProcessor) GetBlockReceipts(bhash common.Hash) types.Receipts {
- if block := sm.ChainManager().GetBlock(bhash); block != nil {
+ if block := sm.BlockChain().GetBlock(bhash); block != nil {
return GetBlockReceipts(sm.chainDb, block.Hash())
}
diff --git a/core/block_processor_test.go b/core/block_processor_test.go
index 5735b8d0a..ba8bd7bcd 100644
--- a/core/block_processor_test.go
+++ b/core/block_processor_test.go
@@ -30,16 +30,16 @@ import (
"github.com/ethereum/go-ethereum/pow/ezp"
)
-func proc() (*BlockProcessor, *ChainManager) {
+func proc() (*BlockProcessor, *BlockChain) {
db, _ := ethdb.NewMemDatabase()
var mux event.TypeMux
WriteTestNetGenesisBlock(db, 0)
- chainMan, err := NewChainManager(db, thePow(), &mux)
+ blockchain, err := NewBlockChain(db, thePow(), &mux)
if err != nil {
fmt.Println(err)
}
- return NewBlockProcessor(db, ezp.New(), chainMan, &mux), chainMan
+ return NewBlockProcessor(db, ezp.New(), blockchain, &mux), blockchain
}
func TestNumber(t *testing.T) {
diff --git a/core/chain_manager.go b/core/blockchain.go
index 49f831a59..e8209f8e3 100644
--- a/core/chain_manager.go
+++ b/core/blockchain.go
@@ -55,11 +55,9 @@ const (
blockCacheLimit = 256
maxFutureBlocks = 256
maxTimeFutureBlocks = 30
- checkpointLimit = 200
)
-type ChainManager struct {
- //eth EthManager
+type BlockChain struct {
chainDb ethdb.Database
processor types.BlockProcessor
eventMux *event.TypeMux
@@ -69,7 +67,6 @@ type ChainManager struct {
chainmu sync.RWMutex
tsmu sync.RWMutex
- checkpoint int // checkpoint counts towards the new checkpoint
td *big.Int
currentBlock *types.Block
currentGasLimit *big.Int
@@ -90,7 +87,7 @@ type ChainManager struct {
pow pow.PoW
}
-func NewChainManager(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) {
+func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*BlockChain, error) {
headerCache, _ := lru.New(headerCacheLimit)
bodyCache, _ := lru.New(bodyCacheLimit)
bodyRLPCache, _ := lru.New(bodyCacheLimit)
@@ -98,7 +95,7 @@ func NewChainManager(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*
blockCache, _ := lru.New(blockCacheLimit)
futureBlocks, _ := lru.New(maxFutureBlocks)
- bc := &ChainManager{
+ bc := &BlockChain{
chainDb: chainDb,
eventMux: mux,
quit: make(chan struct{}),
@@ -144,7 +141,7 @@ func NewChainManager(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*
return bc, nil
}
-func (bc *ChainManager) SetHead(head *types.Block) {
+func (bc *BlockChain) SetHead(head *types.Block) {
bc.mu.Lock()
defer bc.mu.Unlock()
@@ -163,80 +160,55 @@ func (bc *ChainManager) SetHead(head *types.Block) {
bc.setLastState()
}
-func (self *ChainManager) Td() *big.Int {
+func (self *BlockChain) Td() *big.Int {
self.mu.RLock()
defer self.mu.RUnlock()
return new(big.Int).Set(self.td)
}
-func (self *ChainManager) GasLimit() *big.Int {
+func (self *BlockChain) GasLimit() *big.Int {
self.mu.RLock()
defer self.mu.RUnlock()
return self.currentBlock.GasLimit()
}
-func (self *ChainManager) LastBlockHash() common.Hash {
+func (self *BlockChain) LastBlockHash() common.Hash {
self.mu.RLock()
defer self.mu.RUnlock()
return self.currentBlock.Hash()
}
-func (self *ChainManager) CurrentBlock() *types.Block {
+func (self *BlockChain) CurrentBlock() *types.Block {
self.mu.RLock()
defer self.mu.RUnlock()
return self.currentBlock
}
-func (self *ChainManager) Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash) {
+func (self *BlockChain) Status() (td *big.Int, currentBlock common.Hash, genesisBlock common.Hash) {
self.mu.RLock()
defer self.mu.RUnlock()
return new(big.Int).Set(self.td), self.currentBlock.Hash(), self.genesisBlock.Hash()
}
-func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
+func (self *BlockChain) SetProcessor(proc types.BlockProcessor) {
self.processor = proc
}
-func (self *ChainManager) State() *state.StateDB {
+func (self *BlockChain) State() *state.StateDB {
return state.New(self.CurrentBlock().Root(), self.chainDb)
}
-func (bc *ChainManager) recover() bool {
- data, _ := bc.chainDb.Get([]byte("checkpoint"))
- if len(data) != 0 {
- block := bc.GetBlock(common.BytesToHash(data))
- if block != nil {
- if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil {
- glog.Fatalf("failed to write database head number: %v", err)
- }
- if err := WriteHeadBlockHash(bc.chainDb, block.Hash()); err != nil {
- glog.Fatalf("failed to write database head hash: %v", err)
- }
- bc.currentBlock = block
- return true
- }
- }
- return false
-}
-
-func (bc *ChainManager) setLastState() error {
+func (bc *BlockChain) setLastState() error {
head := GetHeadBlockHash(bc.chainDb)
if head != (common.Hash{}) {
block := bc.GetBlock(head)
if block != nil {
bc.currentBlock = block
- } else {
- glog.Infof("LastBlock (%x) not found. Recovering...\n", head)
- if bc.recover() {
- glog.Infof("Recover successful")
- } else {
- glog.Fatalf("Recover failed. Please report")
- }
}
} else {
bc.Reset()
@@ -252,13 +224,13 @@ func (bc *ChainManager) setLastState() error {
}
// Reset purges the entire blockchain, restoring it to its genesis state.
-func (bc *ChainManager) Reset() {
+func (bc *BlockChain) Reset() {
bc.ResetWithGenesisBlock(bc.genesisBlock)
}
// ResetWithGenesisBlock purges the entire blockchain, restoring it to the
// specified genesis state.
-func (bc *ChainManager) ResetWithGenesisBlock(genesis *types.Block) {
+func (bc *BlockChain) ResetWithGenesisBlock(genesis *types.Block) {
bc.mu.Lock()
defer bc.mu.Unlock()
@@ -286,7 +258,7 @@ func (bc *ChainManager) ResetWithGenesisBlock(genesis *types.Block) {
}
// Export writes the active chain to the given writer.
-func (self *ChainManager) Export(w io.Writer) error {
+func (self *BlockChain) Export(w io.Writer) error {
if err := self.ExportN(w, uint64(0), self.currentBlock.NumberU64()); err != nil {
return err
}
@@ -294,7 +266,7 @@ func (self *ChainManager) Export(w io.Writer) error {
}
// ExportN writes a subset of the active chain to the given writer.
-func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error {
+func (self *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
self.mu.RLock()
defer self.mu.RUnlock()
@@ -320,40 +292,28 @@ func (self *ChainManager) ExportN(w io.Writer, first uint64, last uint64) error
// insert injects a block into the current chain block chain. Note, this function
// assumes that the `mu` mutex is held!
-func (bc *ChainManager) insert(block *types.Block) {
+func (bc *BlockChain) insert(block *types.Block) {
// Add the block to the canonical chain number scheme and mark as the head
if err := WriteCanonicalHash(bc.chainDb, block.Hash(), block.NumberU64()); err != nil {
glog.Fatalf("failed to insert block number: %v", err)
}
- if err := WriteHeadBlockHash(bc.chainDb, block.Hash()); err != nil {
- glog.Fatalf("failed to insert block number: %v", err)
- }
- // Add a new restore point if we reached some limit
- bc.checkpoint++
- if bc.checkpoint > checkpointLimit {
- if err := bc.chainDb.Put([]byte("checkpoint"), block.Hash().Bytes()); err != nil {
- glog.Fatalf("failed to create checkpoint: %v", err)
- }
- bc.checkpoint = 0
- }
- // Update the internal internal state with the head block
bc.currentBlock = block
}
// Accessors
-func (bc *ChainManager) Genesis() *types.Block {
+func (bc *BlockChain) Genesis() *types.Block {
return bc.genesisBlock
}
// HasHeader checks if a block header is present in the database or not, caching
// it if present.
-func (bc *ChainManager) HasHeader(hash common.Hash) bool {
+func (bc *BlockChain) HasHeader(hash common.Hash) bool {
return bc.GetHeader(hash) != nil
}
// GetHeader retrieves a block header from the database by hash, caching it if
// found.
-func (self *ChainManager) GetHeader(hash common.Hash) *types.Header {
+func (self *BlockChain) GetHeader(hash common.Hash) *types.Header {
// Short circuit if the header's already in the cache, retrieve otherwise
if header, ok := self.headerCache.Get(hash); ok {
return header.(*types.Header)
@@ -369,7 +329,7 @@ func (self *ChainManager) GetHeader(hash common.Hash) *types.Header {
// GetHeaderByNumber retrieves a block header from the database by number,
// caching it (associated with its hash) if found.
-func (self *ChainManager) GetHeaderByNumber(number uint64) *types.Header {
+func (self *BlockChain) GetHeaderByNumber(number uint64) *types.Header {
hash := GetCanonicalHash(self.chainDb, number)
if hash == (common.Hash{}) {
return nil
@@ -379,7 +339,7 @@ func (self *ChainManager) GetHeaderByNumber(number uint64) *types.Header {
// GetBody retrieves a block body (transactions and uncles) from the database by
// hash, caching it if found.
-func (self *ChainManager) GetBody(hash common.Hash) *types.Body {
+func (self *BlockChain) GetBody(hash common.Hash) *types.Body {
// Short circuit if the body's already in the cache, retrieve otherwise
if cached, ok := self.bodyCache.Get(hash); ok {
body := cached.(*types.Body)
@@ -396,7 +356,7 @@ func (self *ChainManager) GetBody(hash common.Hash) *types.Body {
// GetBodyRLP retrieves a block body in RLP encoding from the database by hash,
// caching it if found.
-func (self *ChainManager) GetBodyRLP(hash common.Hash) rlp.RawValue {
+func (self *BlockChain) GetBodyRLP(hash common.Hash) rlp.RawValue {
// Short circuit if the body's already in the cache, retrieve otherwise
if cached, ok := self.bodyRLPCache.Get(hash); ok {
return cached.(rlp.RawValue)
@@ -412,7 +372,7 @@ func (self *ChainManager) GetBodyRLP(hash common.Hash) rlp.RawValue {
// GetTd retrieves a block's total difficulty in the canonical chain from the
// database by hash, caching it if found.
-func (self *ChainManager) GetTd(hash common.Hash) *big.Int {
+func (self *BlockChain) GetTd(hash common.Hash) *big.Int {
// Short circuit if the td's already in the cache, retrieve otherwise
if cached, ok := self.tdCache.Get(hash); ok {
return cached.(*big.Int)
@@ -428,12 +388,12 @@ func (self *ChainManager) GetTd(hash common.Hash) *big.Int {
// HasBlock checks if a block is fully present in the database or not, caching
// it if present.
-func (bc *ChainManager) HasBlock(hash common.Hash) bool {
+func (bc *BlockChain) HasBlock(hash common.Hash) bool {
return bc.GetBlock(hash) != nil
}
// GetBlock retrieves a block from the database by hash, caching it if found.
-func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
+func (self *BlockChain) GetBlock(hash common.Hash) *types.Block {
// Short circuit if the block's already in the cache, retrieve otherwise
if block, ok := self.blockCache.Get(hash); ok {
return block.(*types.Block)
@@ -449,7 +409,7 @@ func (self *ChainManager) GetBlock(hash common.Hash) *types.Block {
// GetBlockByNumber retrieves a block from the database by number, caching it
// (associated with its hash) if found.
-func (self *ChainManager) GetBlockByNumber(number uint64) *types.Block {
+func (self *BlockChain) GetBlockByNumber(number uint64) *types.Block {
hash := GetCanonicalHash(self.chainDb, number)
if hash == (common.Hash{}) {
return nil
@@ -459,7 +419,7 @@ func (self *ChainManager) GetBlockByNumber(number uint64) *types.Block {
// GetBlockHashesFromHash retrieves a number of block hashes starting at a given
// hash, fetching towards the genesis block.
-func (self *ChainManager) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash {
+func (self *BlockChain) GetBlockHashesFromHash(hash common.Hash, max uint64) []common.Hash {
// Get the origin header from which to fetch
header := self.GetHeader(hash)
if header == nil {
@@ -481,7 +441,7 @@ func (self *ChainManager) GetBlockHashesFromHash(hash common.Hash, max uint64) [
// [deprecated by eth/62]
// GetBlocksFromHash returns the block corresponding to hash and up to n-1 ancestors.
-func (self *ChainManager) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.Block) {
+func (self *BlockChain) GetBlocksFromHash(hash common.Hash, n int) (blocks []*types.Block) {
for i := 0; i < n; i++ {
block := self.GetBlock(hash)
if block == nil {
@@ -493,7 +453,7 @@ func (self *ChainManager) GetBlocksFromHash(hash common.Hash, n int) (blocks []*
return
}
-func (self *ChainManager) GetUnclesInChain(block *types.Block, length int) (uncles []*types.Header) {
+func (self *BlockChain) 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())
@@ -504,11 +464,11 @@ func (self *ChainManager) GetUnclesInChain(block *types.Block, length int) (uncl
// setTotalDifficulty updates the TD of the chain manager. Note, this function
// assumes that the `mu` mutex is held!
-func (bc *ChainManager) setTotalDifficulty(td *big.Int) {
+func (bc *BlockChain) setTotalDifficulty(td *big.Int) {
bc.td = new(big.Int).Set(td)
}
-func (bc *ChainManager) Stop() {
+func (bc *BlockChain) Stop() {
if !atomic.CompareAndSwapInt32(&bc.running, 0, 1) {
return
}
@@ -527,7 +487,7 @@ type queueEvent struct {
splitCount int
}
-func (self *ChainManager) procFutureBlocks() {
+func (self *BlockChain) procFutureBlocks() {
blocks := make([]*types.Block, self.futureBlocks.Len())
for i, hash := range self.futureBlocks.Keys() {
block, _ := self.futureBlocks.Get(hash)
@@ -549,7 +509,7 @@ const (
)
// WriteBlock writes the block to the chain.
-func (self *ChainManager) WriteBlock(block *types.Block) (status writeStatus, err error) {
+func (self *BlockChain) WriteBlock(block *types.Block) (status writeStatus, err error) {
self.wg.Add(1)
defer self.wg.Done()
@@ -599,7 +559,7 @@ func (self *ChainManager) WriteBlock(block *types.Block) (status writeStatus, er
// InsertChain will attempt to insert the given chain in to the canonical chain or, otherwise, create a fork. It an error is returned
// it will return the index number of the failing block as well an error describing what went wrong (for possible errors see core/errors.go).
-func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
+func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) {
self.wg.Add(1)
defer self.wg.Done()
@@ -730,7 +690,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) (int, error) {
// reorgs takes two blocks, an old chain and a new chain and will reconstruct the blocks and inserts them
// to be part of the new canonical chain and accumulates potential missing transactions and post an
// event about them
-func (self *ChainManager) reorg(oldBlock, newBlock *types.Block) error {
+func (self *BlockChain) reorg(oldBlock, newBlock *types.Block) error {
self.mu.Lock()
defer self.mu.Unlock()
@@ -811,7 +771,7 @@ func (self *ChainManager) reorg(oldBlock, newBlock *types.Block) error {
return nil
}
-func (self *ChainManager) update() {
+func (self *BlockChain) update() {
events := self.eventMux.Subscribe(queueEvent{})
futureTimer := time.Tick(5 * time.Second)
out:
diff --git a/core/chain_manager_test.go b/core/blockchain_test.go
index 40286190b..e034417ce 100644
--- a/core/chain_manager_test.go
+++ b/core/blockchain_test.go
@@ -48,19 +48,19 @@ func thePow() pow.PoW {
return pow
}
-func theChainManager(db ethdb.Database, t *testing.T) *ChainManager {
+func theBlockChain(db ethdb.Database, t *testing.T) *BlockChain {
var eventMux event.TypeMux
WriteTestNetGenesisBlock(db, 0)
- chainMan, err := NewChainManager(db, thePow(), &eventMux)
+ blockchain, err := NewBlockChain(db, thePow(), &eventMux)
if err != nil {
t.Error("failed creating chainmanager:", err)
t.FailNow()
return nil
}
- blockMan := NewBlockProcessor(db, nil, chainMan, &eventMux)
- chainMan.SetProcessor(blockMan)
+ blockMan := NewBlockProcessor(db, nil, blockchain, &eventMux)
+ blockchain.SetProcessor(blockMan)
- return chainMan
+ return blockchain
}
// Test fork of length N starting from block i
@@ -104,7 +104,7 @@ func testFork(t *testing.T, bman *BlockProcessor, i, N int, f func(td1, td2 *big
// Loop over parents making sure reconstruction is done properly
}
-func printChain(bc *ChainManager) {
+func printChain(bc *BlockChain) {
for i := bc.CurrentBlock().Number().Uint64(); i > 0; i-- {
b := bc.GetBlockByNumber(uint64(i))
fmt.Printf("\t%x %v\n", b.Hash(), b.Difficulty())
@@ -144,8 +144,8 @@ func loadChain(fn string, t *testing.T) (types.Blocks, error) {
return chain, nil
}
-func insertChain(done chan bool, chainMan *ChainManager, chain types.Blocks, t *testing.T) {
- _, err := chainMan.InsertChain(chain)
+func insertChain(done chan bool, blockchain *BlockChain, chain types.Blocks, t *testing.T) {
+ _, err := blockchain.InsertChain(chain)
if err != nil {
fmt.Println(err)
t.FailNow()
@@ -294,23 +294,23 @@ func TestChainInsertions(t *testing.T) {
t.FailNow()
}
- chainMan := theChainManager(db, t)
+ blockchain := theBlockChain(db, t)
const max = 2
done := make(chan bool, max)
- go insertChain(done, chainMan, chain1, t)
- go insertChain(done, chainMan, chain2, t)
+ go insertChain(done, blockchain, chain1, t)
+ go insertChain(done, blockchain, chain2, t)
for i := 0; i < max; i++ {
<-done
}
- if chain2[len(chain2)-1].Hash() != chainMan.CurrentBlock().Hash() {
+ if chain2[len(chain2)-1].Hash() != blockchain.CurrentBlock().Hash() {
t.Error("chain2 is canonical and shouldn't be")
}
- if chain1[len(chain1)-1].Hash() != chainMan.CurrentBlock().Hash() {
+ if chain1[len(chain1)-1].Hash() != blockchain.CurrentBlock().Hash() {
t.Error("chain1 isn't canonical and should be")
}
}
@@ -337,7 +337,7 @@ func TestChainMultipleInsertions(t *testing.T) {
}
}
- chainMan := theChainManager(db, t)
+ blockchain := theBlockChain(db, t)
done := make(chan bool, max)
for i, chain := range chains {
@@ -345,7 +345,7 @@ func TestChainMultipleInsertions(t *testing.T) {
i := i
chain := chain
go func() {
- insertChain(done, chainMan, chain, t)
+ insertChain(done, blockchain, chain, t)
fmt.Println(i, "done")
}()
}
@@ -354,7 +354,7 @@ func TestChainMultipleInsertions(t *testing.T) {
<-done
}
- if chains[longest][len(chains[longest])-1].Hash() != chainMan.CurrentBlock().Hash() {
+ if chains[longest][len(chains[longest])-1].Hash() != blockchain.CurrentBlock().Hash() {
t.Error("Invalid canonical chain")
}
}
@@ -382,9 +382,9 @@ func makeChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Block
return chain
}
-func chm(genesis *types.Block, db ethdb.Database) *ChainManager {
+func chm(genesis *types.Block, db ethdb.Database) *BlockChain {
var eventMux event.TypeMux
- bc := &ChainManager{chainDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
+ bc := &BlockChain{chainDb: db, genesisBlock: genesis, eventMux: &eventMux, pow: FakePow{}}
bc.headerCache, _ = lru.New(100)
bc.bodyCache, _ = lru.New(100)
bc.bodyRLPCache, _ = lru.New(100)
@@ -459,7 +459,7 @@ func TestReorgBadHashes(t *testing.T) {
BadHashes[chain[3].Header().Hash()] = true
var eventMux event.TypeMux
- ncm, err := NewChainManager(db, FakePow{}, &eventMux)
+ ncm, err := NewBlockChain(db, FakePow{}, &eventMux)
if err != nil {
t.Errorf("NewChainManager err: %s", err)
}
@@ -593,7 +593,7 @@ func TestChainTxReorgs(t *testing.T) {
})
// Import the chain. This runs all block validation rules.
evmux := &event.TypeMux{}
- chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman, _ := NewBlockChain(db, FakePow{}, evmux)
chainman.SetProcessor(NewBlockProcessor(db, FakePow{}, chainman, evmux))
if i, err := chainman.InsertChain(chain); err != nil {
t.Fatalf("failed to insert original chain[%d]: %v", i, err)
diff --git a/core/chain_makers.go b/core/chain_makers.go
index 3af9b0b89..ba09b3029 100644
--- a/core/chain_makers.go
+++ b/core/chain_makers.go
@@ -153,7 +153,7 @@ func (b *BlockGen) OffsetTime(seconds int64) {
// and their coinbase will be the zero address.
//
// Blocks created by GenerateChain do not contain valid proof of work
-// values. Inserting them into ChainManager requires use of FakePow or
+// values. Inserting them into BlockChain requires use of FakePow or
// a similar non-validating proof of work implementation.
func GenerateChain(parent *types.Block, db ethdb.Database, n int, gen func(int, *BlockGen)) []*types.Block {
statedb := state.New(parent.Root(), db)
@@ -205,7 +205,7 @@ func newCanonical(n int, db ethdb.Database) (*BlockProcessor, error) {
evmux := &event.TypeMux{}
WriteTestNetGenesisBlock(db, 0)
- chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman, _ := NewBlockChain(db, FakePow{}, evmux)
bman := NewBlockProcessor(db, FakePow{}, chainman, evmux)
bman.bc.SetProcessor(bman)
parent := bman.bc.CurrentBlock()
diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go
index ac18e5e0b..b33af8d87 100644
--- a/core/chain_makers_test.go
+++ b/core/chain_makers_test.go
@@ -77,7 +77,7 @@ func ExampleGenerateChain() {
// Import the chain. This runs all block validation rules.
evmux := &event.TypeMux{}
- chainman, _ := NewChainManager(db, FakePow{}, evmux)
+ chainman, _ := NewBlockChain(db, FakePow{}, evmux)
chainman.SetProcessor(NewBlockProcessor(db, FakePow{}, chainman, evmux))
if i, err := chainman.InsertChain(chain); err != nil {
fmt.Printf("insert error (block %d): %v\n", i, err)
diff --git a/core/helper_test.go b/core/helper_test.go
index 81ea6fc22..fd6a5491c 100644
--- a/core/helper_test.go
+++ b/core/helper_test.go
@@ -34,7 +34,7 @@ type TestManager struct {
db ethdb.Database
txPool *TxPool
- blockChain *ChainManager
+ blockChain *BlockChain
Blocks []*types.Block
}
@@ -54,7 +54,7 @@ func (s *TestManager) Peers() *list.List {
return list.New()
}
-func (s *TestManager) ChainManager() *ChainManager {
+func (s *TestManager) BlockChain() *BlockChain {
return s.blockChain
}
@@ -89,7 +89,7 @@ func NewTestManager() *TestManager {
testManager.eventMux = new(event.TypeMux)
testManager.db = db
// testManager.txPool = NewTxPool(testManager)
- // testManager.blockChain = NewChainManager(testManager)
+ // testManager.blockChain = NewBlockChain(testManager)
// testManager.stateManager = NewStateManager(testManager)
return testManager
diff --git a/core/manager.go b/core/manager.go
index 0f108a6de..289c87c11 100644
--- a/core/manager.go
+++ b/core/manager.go
@@ -26,7 +26,7 @@ import (
type Backend interface {
AccountManager() *accounts.Manager
BlockProcessor() *BlockProcessor
- ChainManager() *ChainManager
+ BlockChain() *BlockChain
TxPool() *TxPool
ChainDb() ethdb.Database
DappDb() ethdb.Database
diff --git a/core/vm/common.go b/core/vm/common.go
index b52b598ba..2d1aa9332 100644
--- a/core/vm/common.go
+++ b/core/vm/common.go
@@ -38,7 +38,7 @@ const (
)
var (
- Pow256 = common.BigPow(2, 256) // Pew256 is 2**256
+ Pow256 = common.BigPow(2, 256) // Pow256 is 2**256
U256 = common.U256 // Shortcut to common.U256
S256 = common.S256 // Shortcut to common.S256
@@ -46,7 +46,7 @@ var (
Zero = common.Big0 // Shortcut to common.Big0
One = common.Big1 // Shortcut to common.Big1
- max = big.NewInt(math.MaxInt64) // Maximum 256 bit integer
+ max = big.NewInt(math.MaxInt64) // Maximum 64 bit integer
)
// NewVm returns a new VM based on the Environment
diff --git a/core/vm/contract.go b/core/vm/contract.go
index 8460cc47b..95417e747 100644
--- a/core/vm/contract.go
+++ b/core/vm/contract.go
@@ -118,8 +118,8 @@ func (self *Contract) SetCode(code []byte) {
self.Code = code
}
-// SetCallCode sets the address of the code address and sets the code
-// of the contract according to the backing database.
+// SetCallCode sets the code of the contract and address of the backing data
+// object
func (self *Contract) SetCallCode(addr *common.Address, code []byte) {
self.Code = code
self.CodeAddr = addr
diff --git a/core/vm/doc.go b/core/vm/doc.go
index 4deb7761d..ab87bf934 100644
--- a/core/vm/doc.go
+++ b/core/vm/doc.go
@@ -18,15 +18,15 @@
Package vm implements the Ethereum Virtual Machine.
The vm package implements two EVMs, a byte code VM and a JIT VM. The BC
-(Byte Code) VM loops over a set of bytes and executes them according to a set
-of rules defined in the Ethereum yellow paper. When the BC VM is invokes it
+(Byte Code) VM loops over a set of bytes and executes them according to the set
+of rules defined in the Ethereum yellow paper. When the BC VM is invoked it
invokes the JIT VM in a seperate goroutine and compiles the byte code in JIT
instructions.
The JIT VM, when invoked, loops around a set of pre-defined instructions until
-it either runs of gas, causes an internel error, returns or stops. At a later
+it either runs of gas, causes an internal error, returns or stops. At a later
stage the JIT VM will see some additional features that will cause sets of
instructions to be compiled down to segments. Segments are sets of instructions
-that can be ran in one go saving precious time during execution.
+that can be run in one go saving precious time during execution.
*/
package vm
diff --git a/core/vm/environment.go b/core/vm/environment.go
index 606518fd4..f8e19baea 100644
--- a/core/vm/environment.go
+++ b/core/vm/environment.go
@@ -26,7 +26,7 @@ import (
// it's own isolated environment.
// Environment is an EVM requirement and helper which allows access to outside
-// information such like states.
+// information such as states.
type Environment interface {
// The state database
Db() Database
@@ -50,7 +50,7 @@ type Environment interface {
GasLimit() *big.Int
// Determines whether it's possible to transact
CanTransfer(from common.Address, balance *big.Int) bool
- // Transfer from to to with amount set
+ // Transfers amount from one account to the other
Transfer(from, to Account, amount *big.Int) error
// Adds a LOG to the state
AddLog(*Log)
diff --git a/core/vm/memory.go b/core/vm/memory.go
index 101ec75cb..d01188417 100644
--- a/core/vm/memory.go
+++ b/core/vm/memory.go
@@ -18,7 +18,7 @@ package vm
import "fmt"
-// Memory implements ethereum RAM backed by a simple byte slice
+// Memory implements a simple memory model for the ethereum virtual machine.
type Memory struct {
store []byte
}
diff --git a/core/vm_env.go b/core/vm_env.go
index dea280746..467e34c6b 100644
--- a/core/vm_env.go
+++ b/core/vm_env.go
@@ -30,13 +30,13 @@ type VMEnv struct {
header *types.Header
msg Message
depth int
- chain *ChainManager
+ chain *BlockChain
typ vm.Type
// structured logging
logs []vm.StructLog
}
-func NewEnv(state *state.StateDB, chain *ChainManager, msg Message, header *types.Header) *VMEnv {
+func NewEnv(state *state.StateDB, chain *BlockChain, msg Message, header *types.Header) *VMEnv {
return &VMEnv{
chain: chain,
state: state,