aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-11-04 17:57:02 +0800
committerobscuren <geffobscura@gmail.com>2014-11-04 17:57:02 +0800
commitf59a3b67f69b26f969084e0de165435e80bd8e12 (patch)
treef92098fa0252484fcdccdaf6075c2842713a2fc9
parent1025d097fd4e5171dadb2c1a8eeb43b7730b13b6 (diff)
downloadgo-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar.gz
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar.bz2
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar.lz
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar.xz
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.tar.zst
go-tangerine-f59a3b67f69b26f969084e0de165435e80bd8e12.zip
StateManager => BlockManager
-rw-r--r--block_pool.go2
-rw-r--r--chain/block_manager.go (renamed from chain/state_manager.go)52
-rw-r--r--chain/bloom9_test.go6
-rw-r--r--chain/filter.go2
-rw-r--r--chain/transaction_pool.go4
-rw-r--r--cmd/mist/bindings.go2
-rw-r--r--cmd/mist/debugger.go4
-rw-r--r--cmd/mist/gui.go4
-rw-r--r--cmd/mist/ui_lib.go2
-rw-r--r--cmd/utils/cmd.go2
-rw-r--r--ethereum.go12
-rw-r--r--javascript/javascript_runtime.go2
-rw-r--r--miner/miner.go10
-rw-r--r--xeth/hexface.go4
-rw-r--r--xeth/pipe.go8
-rw-r--r--xeth/world.go2
16 files changed, 51 insertions, 67 deletions
diff --git a/block_pool.go b/block_pool.go
index 0e182623f..9003256fd 100644
--- a/block_pool.go
+++ b/block_pool.go
@@ -315,7 +315,7 @@ out:
// otherwise process and don't emit anything
var err error
for i, block := range blocks {
- err = self.eth.StateManager().Process(block)
+ err = self.eth.BlockManager().Process(block)
if err != nil {
poollogger.Infoln(err)
poollogger.Debugf("Block #%v failed (%x...)\n", block.Number, block.Hash()[0:4])
diff --git a/chain/state_manager.go b/chain/block_manager.go
index 31b77c574..998b1705d 100644
--- a/chain/state_manager.go
+++ b/chain/block_manager.go
@@ -32,7 +32,7 @@ type Peer interface {
}
type EthManager interface {
- StateManager() *StateManager
+ BlockManager() *BlockManager
ChainManager() *ChainManager
TxPool() *TxPool
Broadcast(msgType wire.MsgType, data []interface{})
@@ -46,7 +46,7 @@ type EthManager interface {
EventMux() *event.TypeMux
}
-type StateManager struct {
+type BlockManager struct {
// Mutex for locking the block processor. Blocks can only be handled one at a time
mutex sync.Mutex
// Canonical block chain
@@ -74,8 +74,8 @@ type StateManager struct {
events event.Subscription
}
-func NewStateManager(ethereum EthManager) *StateManager {
- sm := &StateManager{
+func NewBlockManager(ethereum EthManager) *BlockManager {
+ sm := &BlockManager{
mem: make(map[string]*big.Int),
Pow: &EasyPow{},
eth: ethereum,
@@ -87,18 +87,18 @@ func NewStateManager(ethereum EthManager) *StateManager {
return sm
}
-func (self *StateManager) Start() {
+func (self *BlockManager) Start() {
statelogger.Debugln("Starting state manager")
self.events = self.eth.EventMux().Subscribe(Blocks(nil))
go self.updateThread()
}
-func (self *StateManager) Stop() {
+func (self *BlockManager) Stop() {
statelogger.Debugln("Stopping state manager")
self.events.Unsubscribe()
}
-func (self *StateManager) updateThread() {
+func (self *BlockManager) updateThread() {
for ev := range self.events.Chan() {
for _, block := range ev.(Blocks) {
err := self.Process(block)
@@ -112,29 +112,29 @@ func (self *StateManager) updateThread() {
}
}
-func (sm *StateManager) CurrentState() *state.State {
+func (sm *BlockManager) CurrentState() *state.State {
return sm.eth.ChainManager().CurrentBlock.State()
}
-func (sm *StateManager) TransState() *state.State {
+func (sm *BlockManager) TransState() *state.State {
return sm.transState
}
-func (sm *StateManager) MiningState() *state.State {
+func (sm *BlockManager) MiningState() *state.State {
return sm.miningState
}
-func (sm *StateManager) NewMiningState() *state.State {
+func (sm *BlockManager) NewMiningState() *state.State {
sm.miningState = sm.eth.ChainManager().CurrentBlock.State().Copy()
return sm.miningState
}
-func (sm *StateManager) ChainManager() *ChainManager {
+func (sm *BlockManager) ChainManager() *ChainManager {
return sm.bc
}
-func (self *StateManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) {
+func (self *BlockManager) ProcessTransactions(coinbase *state.StateObject, state *state.State, block, parent *Block, txs Transactions) (Receipts, Transactions, Transactions, Transactions, error) {
var (
receipts Receipts
handled, unhandled Transactions
@@ -209,7 +209,7 @@ done:
return receipts, handled, unhandled, erroneous, err
}
-func (sm *StateManager) Process(block *Block) (err error) {
+func (sm *BlockManager) Process(block *Block) (err error) {
// Processing a blocks may never happen simultaneously
sm.mutex.Lock()
defer sm.mutex.Unlock()
@@ -298,7 +298,7 @@ func (sm *StateManager) Process(block *Block) (err error) {
return nil
}
-func (sm *StateManager) ApplyDiff(state *state.State, parent, block *Block) (receipts Receipts, err error) {
+func (sm *BlockManager) ApplyDiff(state *state.State, parent, block *Block) (receipts Receipts, err error) {
coinbase := state.GetOrNewStateObject(block.Coinbase)
coinbase.SetGasPool(block.CalcGasLimit(parent))
@@ -311,7 +311,7 @@ func (sm *StateManager) ApplyDiff(state *state.State, parent, block *Block) (rec
return receipts, nil
}
-func (sm *StateManager) CalculateTD(block *Block) bool {
+func (sm *BlockManager) CalculateTD(block *Block) bool {
uncleDiff := new(big.Int)
for _, uncle := range block.Uncles {
uncleDiff = uncleDiff.Add(uncleDiff, uncle.Difficulty)
@@ -337,7 +337,7 @@ func (sm *StateManager) CalculateTD(block *Block) bool {
// 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)
-func (sm *StateManager) ValidateBlock(block *Block) error {
+func (sm *BlockManager) ValidateBlock(block *Block) error {
// Check each uncle's previous hash. In order for it to be valid
// is if it has the same block hash as the current
parent := sm.bc.GetBlock(block.PrevHash)
@@ -374,7 +374,7 @@ func (sm *StateManager) ValidateBlock(block *Block) error {
return nil
}
-func (sm *StateManager) AccumelateRewards(state *state.State, block, parent *Block) error {
+func (sm *BlockManager) AccumelateRewards(state *state.State, block, parent *Block) error {
reward := new(big.Int).Set(BlockReward)
knownUncles := ethutil.Set(parent.Uncles)
@@ -417,21 +417,7 @@ func (sm *StateManager) AccumelateRewards(state *state.State, block, parent *Blo
return nil
}
-// Manifest will handle both creating notifications and generating bloom bin data
-func (sm *StateManager) createBloomFilter(state *state.State) *BloomFilter {
- bloomf := NewBloomFilter(nil)
-
- for _, msg := range state.Manifest().Messages {
- bloomf.Set(msg.To)
- bloomf.Set(msg.From)
- }
-
- sm.eth.EventMux().Post(state.Manifest().Messages)
-
- return bloomf
-}
-
-func (sm *StateManager) GetMessages(block *Block) (messages []*state.Message, err error) {
+func (sm *BlockManager) GetMessages(block *Block) (messages []*state.Message, err error) {
if !sm.bc.HasBlock(block.PrevHash) {
return nil, ParentError(block.PrevHash)
}
diff --git a/chain/bloom9_test.go b/chain/bloom9_test.go
index 8d8822030..8b1b962cb 100644
--- a/chain/bloom9_test.go
+++ b/chain/bloom9_test.go
@@ -1,12 +1,8 @@
package chain
import (
- "fmt"
"testing"
-
- "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/state"
- "github.com/ethgo.old/ethutil"
)
func TestBloom9(t *testing.T) {
@@ -21,6 +17,7 @@ func TestBloom9(t *testing.T) {
}
}
+/*
func TestAddress(t *testing.T) {
block := &Block{}
block.Coinbase = ethutil.Hex2Bytes("22341ae42d6dd7384bc8584e50419ea3ac75b83f")
@@ -29,3 +26,4 @@ func TestAddress(t *testing.T) {
bin := CreateBloom(block)
fmt.Printf("bin = %x\n", ethutil.LeftPadBytes(bin, 64))
}
+*/
diff --git a/chain/filter.go b/chain/filter.go
index 0265a60fa..3494e4dcc 100644
--- a/chain/filter.go
+++ b/chain/filter.go
@@ -100,7 +100,7 @@ func (self *Filter) Find() []*state.Message {
// current parameters
if self.bloomFilter(block) {
// Get the messages of the block
- msgs, err := self.eth.StateManager().GetMessages(block)
+ msgs, err := self.eth.BlockManager().GetMessages(block)
if err != nil {
chainlogger.Warnln("err: filter get messages ", err)
diff --git a/chain/transaction_pool.go b/chain/transaction_pool.go
index a7c85e802..ff75089d6 100644
--- a/chain/transaction_pool.go
+++ b/chain/transaction_pool.go
@@ -114,8 +114,8 @@ func (pool *TxPool) ValidateTransaction(tx *Transaction) error {
}
// Get the sender
- //sender := pool.Ethereum.StateManager().procState.GetAccount(tx.Sender())
- sender := pool.Ethereum.StateManager().CurrentState().GetAccount(tx.Sender())
+ //sender := pool.Ethereum.BlockManager().procState.GetAccount(tx.Sender())
+ sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value)
// Make sure there's enough in the sender's account. Having insufficient
diff --git a/cmd/mist/bindings.go b/cmd/mist/bindings.go
index 196fd38a1..ebdd8ec73 100644
--- a/cmd/mist/bindings.go
+++ b/cmd/mist/bindings.go
@@ -108,7 +108,7 @@ func (self *Gui) DumpState(hash, path string) {
var stateDump []byte
if len(hash) == 0 {
- stateDump = self.eth.StateManager().CurrentState().Dump()
+ stateDump = self.eth.BlockManager().CurrentState().Dump()
} else {
var block *chain.Block
if hash[0] == '#' {
diff --git a/cmd/mist/debugger.go b/cmd/mist/debugger.go
index 3fd48eec6..a2aae6f0b 100644
--- a/cmd/mist/debugger.go
+++ b/cmd/mist/debugger.go
@@ -141,8 +141,8 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
keyPair = self.lib.eth.KeyManager().KeyPair()
)
- statedb := self.lib.eth.StateManager().TransState()
- account := self.lib.eth.StateManager().TransState().GetAccount(keyPair.Address())
+ statedb := self.lib.eth.BlockManager().TransState()
+ account := self.lib.eth.BlockManager().TransState().GetAccount(keyPair.Address())
contract := statedb.NewStateObject([]byte{0})
contract.SetBalance(value)
diff --git a/cmd/mist/gui.go b/cmd/mist/gui.go
index 8fa068c14..5af1b5c7b 100644
--- a/cmd/mist/gui.go
+++ b/cmd/mist/gui.go
@@ -396,7 +396,7 @@ func (gui *Gui) update() {
generalUpdateTicker := time.NewTicker(500 * time.Millisecond)
statsUpdateTicker := time.NewTicker(5 * time.Second)
- state := gui.eth.StateManager().TransState()
+ state := gui.eth.BlockManager().TransState()
unconfirmedFunds := new(big.Int)
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance())))
@@ -428,7 +428,7 @@ func (gui *Gui) update() {
case chain.NewBlockEvent:
gui.processBlock(ev.Block, false)
if bytes.Compare(ev.Block.Coinbase, gui.address()) == 0 {
- gui.setWalletValue(gui.eth.StateManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
+ gui.setWalletValue(gui.eth.BlockManager().CurrentState().GetAccount(gui.address()).Balance(), nil)
}
case chain.TxPreEvent:
diff --git a/cmd/mist/ui_lib.go b/cmd/mist/ui_lib.go
index db299f18d..bb978707d 100644
--- a/cmd/mist/ui_lib.go
+++ b/cmd/mist/ui_lib.go
@@ -190,7 +190,7 @@ func (ui *UiLib) AssetPath(p string) string {
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
dbWindow := NewDebuggerWindow(self)
- object := self.eth.StateManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
+ object := self.eth.BlockManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash))
if len(object.Code) > 0 {
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code))
}
diff --git a/cmd/utils/cmd.go b/cmd/utils/cmd.go
index ef2ce8b47..e39655403 100644
--- a/cmd/utils/cmd.go
+++ b/cmd/utils/cmd.go
@@ -317,7 +317,7 @@ func BlockDo(ethereum *eth.Ethereum, hash []byte) error {
parent := ethereum.ChainManager().GetBlock(block.PrevHash)
- _, err := ethereum.StateManager().ApplyDiff(parent.State(), parent, block)
+ _, err := ethereum.BlockManager().ApplyDiff(parent.State(), parent, block)
if err != nil {
return err
}
diff --git a/ethereum.go b/ethereum.go
index d4abeed26..54949d195 100644
--- a/ethereum.go
+++ b/ethereum.go
@@ -50,7 +50,7 @@ type Ethereum struct {
// DB interface
db ethutil.Database
// State manager for processing new blocks and managing the over all states
- stateManager *chain.StateManager
+ blockManager *chain.BlockManager
// The transaction pool. Transaction can be pushed on this pool
// for later including in the blocks
txPool *chain.TxPool
@@ -130,7 +130,7 @@ func New(db ethutil.Database, clientIdentity wire.ClientIdentity, keyManager *cr
ethereum.blockPool = NewBlockPool(ethereum)
ethereum.txPool = chain.NewTxPool(ethereum)
ethereum.blockChain = chain.NewChainManager(ethereum)
- ethereum.stateManager = chain.NewStateManager(ethereum)
+ ethereum.blockManager = chain.NewBlockManager(ethereum)
// Start the tx pool
ethereum.txPool.Start()
@@ -150,8 +150,8 @@ func (s *Ethereum) ChainManager() *chain.ChainManager {
return s.blockChain
}
-func (s *Ethereum) StateManager() *chain.StateManager {
- return s.stateManager
+func (s *Ethereum) BlockManager() *chain.BlockManager {
+ return s.blockManager
}
func (s *Ethereum) TxPool() *chain.TxPool {
@@ -392,7 +392,7 @@ func (s *Ethereum) reapDeadPeerHandler() {
// Start the ethereum
func (s *Ethereum) Start(seed bool) {
s.blockPool.Start()
- s.stateManager.Start()
+ s.blockManager.Start()
// Bind to addr and port
ln, err := net.Listen("tcp", ":"+s.Port)
@@ -516,7 +516,7 @@ func (s *Ethereum) Stop() {
s.RpcServer.Stop()
}
s.txPool.Stop()
- s.stateManager.Stop()
+ s.blockManager.Stop()
s.blockPool.Stop()
loggerger.Infoln("Server stopped")
diff --git a/javascript/javascript_runtime.go b/javascript/javascript_runtime.go
index ea3cb6071..86a376fbf 100644
--- a/javascript/javascript_runtime.go
+++ b/javascript/javascript_runtime.go
@@ -149,7 +149,7 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
state = block.State()
} else {
- state = self.ethereum.StateManager().CurrentState()
+ state = self.ethereum.BlockManager().CurrentState()
}
v, _ := self.Vm.ToValue(state.Dump())
diff --git a/miner/miner.go b/miner/miner.go
index b11bd9532..fd74da4d1 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -67,7 +67,7 @@ func (miner *Miner) Start() {
miner.events = mux.Subscribe(chain.NewBlockEvent{}, chain.TxPreEvent{})
// Prepare inital block
- //miner.ethereum.StateManager().Prepare(miner.block.State(), miner.block.State())
+ //miner.ethereum.BlockManager().Prepare(miner.block.State(), miner.block.State())
go miner.listener()
minerlogger.Infoln("Started")
@@ -161,7 +161,7 @@ func (miner *Miner) stopMining() {
}
func (self *Miner) mineNewBlock() {
- stateManager := self.ethereum.StateManager()
+ blockManager := self.ethereum.BlockManager()
self.block = self.ethereum.ChainManager().NewBlock(self.coinbase)
@@ -178,7 +178,7 @@ func (self *Miner) mineNewBlock() {
parent := self.ethereum.ChainManager().GetBlock(self.block.PrevHash)
coinbase := self.block.State().GetOrNewStateObject(self.block.Coinbase)
coinbase.SetGasPool(self.block.CalcGasLimit(parent))
- receipts, txs, unhandledTxs, erroneous, err := stateManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
+ receipts, txs, unhandledTxs, erroneous, err := blockManager.ProcessTransactions(coinbase, self.block.State(), self.block, self.block, self.txs)
if err != nil {
minerlogger.Debugln(err)
}
@@ -189,7 +189,7 @@ func (self *Miner) mineNewBlock() {
self.block.SetReceipts(receipts)
// Accumulate the rewards included for this block
- stateManager.AccumelateRewards(self.block.State(), self.block, parent)
+ blockManager.AccumelateRewards(self.block.State(), self.block, parent)
self.block.State().Update()
@@ -199,7 +199,7 @@ func (self *Miner) mineNewBlock() {
nonce := self.pow.Search(self.block, self.powQuitChan)
if nonce != nil {
self.block.Nonce = nonce
- err := self.ethereum.StateManager().Process(self.block)
+ err := self.ethereum.BlockManager().Process(self.block)
if err != nil {
minerlogger.Infoln(err)
} else {
diff --git a/xeth/hexface.go b/xeth/hexface.go
index 5c8e7a3c7..21e82e37d 100644
--- a/xeth/hexface.go
+++ b/xeth/hexface.go
@@ -224,10 +224,10 @@ func (self *JSXEth) Transact(key, toStr, valueStr, gasStr, gasPriceStr, codeStr
tx = chain.NewTransactionMessage(hash, value, gas, gasPrice, data)
}
- acc := self.obj.StateManager().TransState().GetOrNewStateObject(keyPair.Address())
+ acc := self.obj.BlockManager().TransState().GetOrNewStateObject(keyPair.Address())
tx.Nonce = acc.Nonce
acc.Nonce += 1
- self.obj.StateManager().TransState().UpdateStateObject(acc)
+ self.obj.BlockManager().TransState().UpdateStateObject(acc)
tx.Sign(keyPair.PrivateKey)
self.obj.TxPool().QueueTransaction(tx)
diff --git a/xeth/pipe.go b/xeth/pipe.go
index 25a69137d..abed8ef9a 100644
--- a/xeth/pipe.go
+++ b/xeth/pipe.go
@@ -24,7 +24,7 @@ type VmVars struct {
type XEth struct {
obj chain.EthManager
- stateManager *chain.StateManager
+ blockManager *chain.BlockManager
blockChain *chain.ChainManager
world *World
@@ -34,7 +34,7 @@ type XEth struct {
func New(obj chain.EthManager) *XEth {
pipe := &XEth{
obj: obj,
- stateManager: obj.StateManager(),
+ blockManager: obj.BlockManager(),
blockChain: obj.ChainManager(),
}
pipe.world = NewWorld(pipe)
@@ -137,10 +137,10 @@ func (self *XEth) Transact(key *crypto.KeyPair, rec []byte, value, gas, price *e
tx = chain.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data)
}
- acc := self.stateManager.TransState().GetOrNewStateObject(key.Address())
+ acc := self.blockManager.TransState().GetOrNewStateObject(key.Address())
tx.Nonce = acc.Nonce
acc.Nonce += 1
- self.stateManager.TransState().UpdateStateObject(acc)
+ self.blockManager.TransState().UpdateStateObject(acc)
tx.Sign(key.PrivateKey)
self.obj.TxPool().QueueTransaction(tx)
diff --git a/xeth/world.go b/xeth/world.go
index dda2df274..6fb757d67 100644
--- a/xeth/world.go
+++ b/xeth/world.go
@@ -23,7 +23,7 @@ func (self *XEth) World() *World {
}
func (self *World) State() *state.State {
- return self.pipe.stateManager.CurrentState()
+ return self.pipe.blockManager.CurrentState()
}
func (self *World) Get(addr []byte) *Object {