aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/block_manager_test.go36
-rw-r--r--ethchain/chain_manager.go (renamed from ethchain/block_chain.go)44
-rw-r--r--ethchain/chain_manager_test.go (renamed from ethchain/block_chain_test.go)0
-rw-r--r--ethchain/filter.go8
-rw-r--r--ethchain/state_manager.go16
-rw-r--r--ethchain/transaction_pool.go2
6 files changed, 35 insertions, 71 deletions
diff --git a/ethchain/block_manager_test.go b/ethchain/block_manager_test.go
deleted file mode 100644
index 3a1e5f510..000000000
--- a/ethchain/block_manager_test.go
+++ /dev/null
@@ -1,36 +0,0 @@
-package ethchain
-
-/*
-import (
- _ "fmt"
- "github.com/ethereum/eth-go/ethdb"
- "github.com/ethereum/eth-go/ethutil"
- "math/big"
- "testing"
-)
-
-func TestVm(t *testing.T) {
- InitFees()
- ethutil.ReadConfig("")
-
- db, _ := ethdb.NewMemDatabase()
- ethutil.Config.Db = db
- bm := NewStateManager(nil)
-
- block := bm.bc.genesisBlock
- bm.Prepare(block.State(), block.State())
- script := Compile([]string{
- "PUSH",
- "1",
- "PUSH",
- "2",
- })
- tx := NewTransaction(ContractAddr, big.NewInt(200000000), script)
- addr := tx.Hash()[12:]
- bm.ApplyTransactions(block, []*Transaction{tx})
-
- tx2 := NewTransaction(addr, big.NewInt(1e17), nil)
- tx2.Sign([]byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
- bm.ApplyTransactions(block, []*Transaction{tx2})
-}
-*/
diff --git a/ethchain/block_chain.go b/ethchain/chain_manager.go
index a5dcec438..227b02c0a 100644
--- a/ethchain/block_chain.go
+++ b/ethchain/chain_manager.go
@@ -11,7 +11,7 @@ import (
var chainlogger = ethlog.NewLogger("CHAIN")
-type BlockChain struct {
+type ChainManager struct {
Ethereum EthManager
// The famous, the fabulous Mister GENESIIIIIIS (block)
genesisBlock *Block
@@ -24,8 +24,8 @@ type BlockChain struct {
LastBlockHash []byte
}
-func NewBlockChain(ethereum EthManager) *BlockChain {
- bc := &BlockChain{}
+func NewChainManager(ethereum EthManager) *ChainManager {
+ bc := &ChainManager{}
bc.genesisBlock = NewBlockFromBytes(ethutil.Encode(Genesis))
bc.Ethereum = ethereum
@@ -34,11 +34,11 @@ func NewBlockChain(ethereum EthManager) *BlockChain {
return bc
}
-func (bc *BlockChain) Genesis() *Block {
+func (bc *ChainManager) Genesis() *Block {
return bc.genesisBlock
}
-func (bc *BlockChain) NewBlock(coinbase []byte) *Block {
+func (bc *ChainManager) NewBlock(coinbase []byte) *Block {
var root interface{}
hash := ZeroHash256
@@ -81,7 +81,7 @@ func CalcDifficulty(block, parent *Block) *big.Int {
return diff
}
-func (bc *BlockChain) Reset() {
+func (bc *ChainManager) Reset() {
AddTestNetFunds(bc.genesisBlock)
bc.genesisBlock.state.Trie.Sync()
@@ -97,13 +97,13 @@ func (bc *BlockChain) Reset() {
bc.TD = ethutil.BigD(ethutil.Config.Db.LastKnownTD())
}
-func (bc *BlockChain) HasBlock(hash []byte) bool {
+func (bc *ChainManager) HasBlock(hash []byte) bool {
data, _ := ethutil.Config.Db.Get(hash)
return len(data) != 0
}
// TODO: At one point we might want to save a block by prevHash in the db to optimise this...
-func (bc *BlockChain) HasBlockWithPrevHash(hash []byte) bool {
+func (bc *ChainManager) HasBlockWithPrevHash(hash []byte) bool {
block := bc.CurrentBlock
for ; block != nil; block = bc.GetBlock(block.PrevHash) {
@@ -114,7 +114,7 @@ func (bc *BlockChain) HasBlockWithPrevHash(hash []byte) bool {
return false
}
-func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int {
+func (bc *ChainManager) CalculateBlockTD(block *Block) *big.Int {
blockDiff := new(big.Int)
for _, uncle := range block.Uncles {
@@ -125,11 +125,11 @@ func (bc *BlockChain) CalculateBlockTD(block *Block) *big.Int {
return blockDiff
}
-func (bc *BlockChain) GenesisBlock() *Block {
+func (bc *ChainManager) GenesisBlock() *Block {
return bc.genesisBlock
}
-func (self *BlockChain) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) {
+func (self *ChainManager) GetChainHashesFromHash(hash []byte, max uint64) (chain [][]byte) {
block := self.GetBlock(hash)
if block == nil {
return
@@ -167,7 +167,7 @@ func AddTestNetFunds(block *Block) {
}
}
-func (bc *BlockChain) setLastBlock() {
+func (bc *ChainManager) setLastBlock() {
data, _ := ethutil.Config.Db.Get([]byte("LastBlock"))
if len(data) != 0 {
// Prep genesis
@@ -187,13 +187,13 @@ func (bc *BlockChain) setLastBlock() {
chainlogger.Infof("Last block (#%d) %x\n", bc.LastBlockNumber, bc.CurrentBlock.Hash())
}
-func (bc *BlockChain) SetTotalDifficulty(td *big.Int) {
+func (bc *ChainManager) SetTotalDifficulty(td *big.Int) {
ethutil.Config.Db.Put([]byte("LTD"), td.Bytes())
bc.TD = td
}
// Add a block to the chain and record addition information
-func (bc *BlockChain) Add(block *Block) {
+func (bc *ChainManager) Add(block *Block) {
bc.writeBlockInfo(block)
// Prepare the genesis block
@@ -205,7 +205,7 @@ func (bc *BlockChain) Add(block *Block) {
ethutil.Config.Db.Put([]byte("LastBlock"), encodedBlock)
}
-func (self *BlockChain) CalcTotalDiff(block *Block) (*big.Int, error) {
+func (self *ChainManager) CalcTotalDiff(block *Block) (*big.Int, error) {
parent := self.GetBlock(block.PrevHash)
if parent == nil {
return nil, fmt.Errorf("Unable to calculate total diff without known parent %x", block.PrevHash)
@@ -225,7 +225,7 @@ func (self *BlockChain) CalcTotalDiff(block *Block) (*big.Int, error) {
return td, nil
}
-func (bc *BlockChain) GetBlock(hash []byte) *Block {
+func (bc *ChainManager) GetBlock(hash []byte) *Block {
data, _ := ethutil.Config.Db.Get(hash)
if len(data) == 0 {
return nil
@@ -234,7 +234,7 @@ func (bc *BlockChain) GetBlock(hash []byte) *Block {
return NewBlockFromBytes(data)
}
-func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
+func (self *ChainManager) GetBlockByNumber(num uint64) *Block {
block := self.CurrentBlock
for ; block != nil; block = self.GetBlock(block.PrevHash) {
if block.Number.Uint64() == num {
@@ -249,7 +249,7 @@ func (self *BlockChain) GetBlockByNumber(num uint64) *Block {
return block
}
-func (self *BlockChain) GetBlockBack(num uint64) *Block {
+func (self *ChainManager) GetBlockBack(num uint64) *Block {
block := self.CurrentBlock
for ; num != 0 && block != nil; num-- {
@@ -259,7 +259,7 @@ func (self *BlockChain) GetBlockBack(num uint64) *Block {
return block
}
-func (bc *BlockChain) BlockInfoByHash(hash []byte) BlockInfo {
+func (bc *ChainManager) BlockInfoByHash(hash []byte) BlockInfo {
bi := BlockInfo{}
data, _ := ethutil.Config.Db.Get(append(hash, []byte("Info")...))
bi.RlpDecode(data)
@@ -267,7 +267,7 @@ func (bc *BlockChain) BlockInfoByHash(hash []byte) BlockInfo {
return bi
}
-func (bc *BlockChain) BlockInfo(block *Block) BlockInfo {
+func (bc *ChainManager) BlockInfo(block *Block) BlockInfo {
bi := BlockInfo{}
data, _ := ethutil.Config.Db.Get(append(block.Hash(), []byte("Info")...))
bi.RlpDecode(data)
@@ -276,7 +276,7 @@ func (bc *BlockChain) BlockInfo(block *Block) BlockInfo {
}
// Unexported method for writing extra non-essential block info to the db
-func (bc *BlockChain) writeBlockInfo(block *Block) {
+func (bc *ChainManager) writeBlockInfo(block *Block) {
bc.LastBlockNumber++
bi := BlockInfo{Number: bc.LastBlockNumber, Hash: block.Hash(), Parent: block.PrevHash, TD: bc.TD}
@@ -284,7 +284,7 @@ func (bc *BlockChain) writeBlockInfo(block *Block) {
ethutil.Config.Db.Put(append(block.Hash(), []byte("Info")...), bi.RlpEncode())
}
-func (bc *BlockChain) Stop() {
+func (bc *ChainManager) Stop() {
if bc.CurrentBlock != nil {
chainlogger.Infoln("Stopped")
}
diff --git a/ethchain/block_chain_test.go b/ethchain/chain_manager_test.go
index 3603fd8a7..3603fd8a7 100644
--- a/ethchain/block_chain_test.go
+++ b/ethchain/chain_manager_test.go
diff --git a/ethchain/filter.go b/ethchain/filter.go
index 90f2512ab..4e8df7d5f 100644
--- a/ethchain/filter.go
+++ b/ethchain/filter.go
@@ -76,16 +76,16 @@ func (self *Filter) SetSkip(skip int) {
func (self *Filter) Find() []*ethstate.Message {
var earliestBlockNo uint64 = uint64(self.earliest)
if self.earliest == -1 {
- earliestBlockNo = self.eth.BlockChain().CurrentBlock.Number.Uint64()
+ earliestBlockNo = self.eth.ChainManager().CurrentBlock.Number.Uint64()
}
var latestBlockNo uint64 = uint64(self.latest)
if self.latest == -1 {
- latestBlockNo = self.eth.BlockChain().CurrentBlock.Number.Uint64()
+ latestBlockNo = self.eth.ChainManager().CurrentBlock.Number.Uint64()
}
var (
messages []*ethstate.Message
- block = self.eth.BlockChain().GetBlockByNumber(latestBlockNo)
+ block = self.eth.ChainManager().GetBlockByNumber(latestBlockNo)
quit bool
)
for i := 0; !quit && block != nil; i++ {
@@ -111,7 +111,7 @@ func (self *Filter) Find() []*ethstate.Message {
messages = append(messages, self.FilterMessages(msgs)...)
}
- block = self.eth.BlockChain().GetBlock(block.PrevHash)
+ block = self.eth.ChainManager().GetBlock(block.PrevHash)
}
skip := int(math.Min(float64(len(messages)), float64(self.skip)))
diff --git a/ethchain/state_manager.go b/ethchain/state_manager.go
index b71cbe8a1..ed513c9dc 100644
--- a/ethchain/state_manager.go
+++ b/ethchain/state_manager.go
@@ -33,7 +33,7 @@ type Peer interface {
type EthManager interface {
StateManager() *StateManager
- BlockChain() *BlockChain
+ ChainManager() *ChainManager
TxPool() *TxPool
Broadcast(msgType ethwire.MsgType, data []interface{})
PeerCount() int
@@ -50,7 +50,7 @@ type StateManager struct {
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex sync.Mutex
// Canonical block chain
- bc *BlockChain
+ bc *ChainManager
// non-persistent key/value memory storage
mem map[string]*big.Int
// Proof of work used for validating
@@ -79,10 +79,10 @@ func NewStateManager(ethereum EthManager) *StateManager {
mem: make(map[string]*big.Int),
Pow: &EasyPow{},
eth: ethereum,
- bc: ethereum.BlockChain(),
+ bc: ethereum.ChainManager(),
}
- sm.transState = ethereum.BlockChain().CurrentBlock.State().Copy()
- sm.miningState = ethereum.BlockChain().CurrentBlock.State().Copy()
+ sm.transState = ethereum.ChainManager().CurrentBlock.State().Copy()
+ sm.miningState = ethereum.ChainManager().CurrentBlock.State().Copy()
return sm
}
@@ -113,7 +113,7 @@ func (self *StateManager) updateThread() {
}
func (sm *StateManager) CurrentState() *ethstate.State {
- return sm.eth.BlockChain().CurrentBlock.State()
+ return sm.eth.ChainManager().CurrentBlock.State()
}
func (sm *StateManager) TransState() *ethstate.State {
@@ -125,12 +125,12 @@ func (sm *StateManager) MiningState() *ethstate.State {
}
func (sm *StateManager) NewMiningState() *ethstate.State {
- sm.miningState = sm.eth.BlockChain().CurrentBlock.State().Copy()
+ sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
return sm.miningState
}
-func (sm *StateManager) BlockChain() *BlockChain {
+func (sm *StateManager) ChainManager() *ChainManager {
return sm.bc
}
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index 0676af3a3..ff3184582 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -96,7 +96,7 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
// Get the last block so we can retrieve the sender and receiver from
// the merkle trie
- block := pool.Ethereum.BlockChain().CurrentBlock
+ block := pool.Ethereum.ChainManager().CurrentBlock
// Something has gone horribly wrong if this happens
if block == nil {
return fmt.Errorf("[TXPL] No last block on the block chain")