states moved to chain

This commit is contained in:
obscuren 2014-12-10 19:59:12 +01:00
parent af6afbaa56
commit 5553e5aaed
11 changed files with 31 additions and 28 deletions

View File

@ -103,7 +103,7 @@ func (self *Gui) DumpState(hash, path string) {
var stateDump []byte var stateDump []byte
if len(hash) == 0 { if len(hash) == 0 {
stateDump = self.eth.BlockManager().CurrentState().Dump() stateDump = self.eth.ChainManager().State().Dump()
} else { } else {
var block *types.Block var block *types.Block
if hash[0] == '#' { if hash[0] == '#' {

View File

@ -141,8 +141,8 @@ func (self *DebuggerWindow) Debug(valueStr, gasStr, gasPriceStr, scriptStr, data
keyPair = self.lib.eth.KeyManager().KeyPair() keyPair = self.lib.eth.KeyManager().KeyPair()
) )
statedb := self.lib.eth.BlockManager().TransState() statedb := self.lib.eth.ChainManager().TransState()
account := self.lib.eth.BlockManager().TransState().GetAccount(keyPair.Address()) account := self.lib.eth.ChainManager().TransState().GetAccount(keyPair.Address())
contract := statedb.NewStateObject([]byte{0}) contract := statedb.NewStateObject([]byte{0})
contract.SetCode(script) contract.SetCode(script)
contract.SetBalance(value) contract.SetBalance(value)

View File

@ -401,7 +401,7 @@ func (gui *Gui) update() {
generalUpdateTicker := time.NewTicker(500 * time.Millisecond) generalUpdateTicker := time.NewTicker(500 * time.Millisecond)
statsUpdateTicker := time.NewTicker(5 * time.Second) statsUpdateTicker := time.NewTicker(5 * time.Second)
state := gui.eth.BlockManager().TransState() state := gui.eth.ChainManager().TransState()
gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance()))) gui.win.Root().Call("setWalletValue", fmt.Sprintf("%v", ethutil.CurrencyToString(state.GetAccount(gui.address()).Balance())))
@ -428,14 +428,14 @@ func (gui *Gui) update() {
case core.NewBlockEvent: case core.NewBlockEvent:
gui.processBlock(ev.Block, false) gui.processBlock(ev.Block, false)
if bytes.Compare(ev.Block.Coinbase, gui.address()) == 0 { if bytes.Compare(ev.Block.Coinbase, gui.address()) == 0 {
gui.setWalletValue(gui.eth.BlockManager().CurrentState().GetAccount(gui.address()).Balance(), nil) gui.setWalletValue(gui.eth.ChainManager().State().GetBalance(gui.address()), nil)
} }
case core.TxPreEvent: case core.TxPreEvent:
tx := ev.Tx tx := ev.Tx
tstate := gui.eth.BlockManager().TransState() tstate := gui.eth.ChainManager().TransState()
cstate := gui.eth.BlockManager().CurrentState() cstate := gui.eth.ChainManager().State()
taccount := tstate.GetAccount(gui.address()) taccount := tstate.GetAccount(gui.address())
caccount := cstate.GetAccount(gui.address()) caccount := cstate.GetAccount(gui.address())

View File

@ -200,7 +200,7 @@ func (ui *UiLib) AssetPath(p string) string {
func (self *UiLib) StartDbWithContractAndData(contractHash, data string) { func (self *UiLib) StartDbWithContractAndData(contractHash, data string) {
dbWindow := NewDebuggerWindow(self) dbWindow := NewDebuggerWindow(self)
object := self.eth.BlockManager().CurrentState().GetStateObject(ethutil.Hex2Bytes(contractHash)) object := self.eth.ChainManager().State().GetStateObject(ethutil.Hex2Bytes(contractHash))
if len(object.Code) > 0 { if len(object.Code) > 0 {
dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code)) dbWindow.SetCode("0x" + ethutil.Bytes2Hex(object.Code))
} }

View File

@ -84,20 +84,10 @@ func NewBlockManager(ethereum EthManager) *BlockManager {
eth: ethereum, eth: ethereum,
bc: ethereum.ChainManager(), bc: ethereum.ChainManager(),
} }
sm.transState = ethereum.ChainManager().CurrentBlock.State().Copy()
sm.miningState = ethereum.ChainManager().CurrentBlock.State().Copy()
return sm return sm
} }
func (sm *BlockManager) CurrentState() *state.StateDB {
return sm.eth.ChainManager().CurrentBlock.State()
}
func (sm *BlockManager) TransState() *state.StateDB {
return sm.transState
}
func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *types.Block) (receipts types.Receipts, err error) { func (sm *BlockManager) TransitionState(statedb *state.StateDB, parent, block *types.Block) (receipts types.Receipts, err error) {
coinbase := statedb.GetOrNewStateObject(block.Coinbase) coinbase := statedb.GetOrNewStateObject(block.Coinbase)
coinbase.SetGasPool(block.CalcGasLimit(parent)) coinbase.SetGasPool(block.CalcGasLimit(parent))

View File

@ -8,6 +8,7 @@ import (
"github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/ethutil"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/state"
) )
var chainlogger = logger.NewLogger("CHAIN") var chainlogger = logger.NewLogger("CHAIN")
@ -55,6 +56,8 @@ type ChainManager struct {
CurrentBlock *types.Block CurrentBlock *types.Block
LastBlockHash []byte LastBlockHash []byte
transState *state.StateDB
} }
func NewChainManager(mux *event.TypeMux) *ChainManager { func NewChainManager(mux *event.TypeMux) *ChainManager {
@ -64,6 +67,8 @@ func NewChainManager(mux *event.TypeMux) *ChainManager {
bc.setLastBlock() bc.setLastBlock()
bc.transState = bc.State().Copy()
return bc return bc
} }
@ -71,6 +76,14 @@ func (self *ChainManager) SetProcessor(proc types.BlockProcessor) {
self.processor = proc self.processor = proc
} }
func (self *ChainManager) State() *state.StateDB {
return self.CurrentBlock.State()
}
func (self *ChainManager) TransState() *state.StateDB {
return self.transState
}
func (bc *ChainManager) setLastBlock() { func (bc *ChainManager) setLastBlock() {
data, _ := ethutil.Config.Db.Get([]byte("LastBlock")) data, _ := ethutil.Config.Db.Get([]byte("LastBlock"))
if len(data) != 0 { if len(data) != 0 {

View File

@ -116,7 +116,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
} }
// Get the sender // Get the sender
sender := pool.Ethereum.BlockManager().CurrentState().GetAccount(tx.Sender()) sender := pool.Ethereum.ChainManager().State().GetAccount(tx.Sender())
totAmount := new(big.Int).Set(tx.Value) totAmount := new(big.Int).Set(tx.Value)
// Make sure there's enough in the sender's account. Having insufficient // Make sure there's enough in the sender's account. Having insufficient

View File

@ -150,7 +150,7 @@ func (self *JSRE) dump(call otto.FunctionCall) otto.Value {
state = block.State() state = block.State()
} else { } else {
state = self.ethereum.BlockManager().CurrentState() state = self.ethereum.ChainManager().State()
} }
v, _ := self.Vm.ToValue(state.Dump()) v, _ := self.Vm.ToValue(state.Dump())

View File

@ -232,7 +232,7 @@ func (self *Miner) finiliseTxs() types.Transactions {
actualSize := len(self.localTxs) // See copy below actualSize := len(self.localTxs) // See copy below
txs := make(types.Transactions, actualSize+self.eth.TxPool().Size()) txs := make(types.Transactions, actualSize+self.eth.TxPool().Size())
state := self.eth.BlockManager().TransState() state := self.eth.ChainManager().TransState()
// XXX This has to change. Coinbase is, for new, same as key. // XXX This has to change. Coinbase is, for new, same as key.
key := self.eth.KeyManager() key := self.eth.KeyManager()
for i, ltx := range self.localTxs { for i, ltx := range self.localTxs {

View File

@ -22,7 +22,7 @@ type VmVars struct {
type XEth struct { type XEth struct {
obj core.EthManager obj core.EthManager
blockManager *core.BlockManager blockManager *core.BlockManager
blockChain *core.ChainManager chainManager *core.ChainManager
world *World world *World
Vm VmVars Vm VmVars
@ -32,7 +32,7 @@ func New(obj core.EthManager) *XEth {
pipe := &XEth{ pipe := &XEth{
obj: obj, obj: obj,
blockManager: obj.BlockManager(), blockManager: obj.BlockManager(),
blockChain: obj.ChainManager(), chainManager: obj.ChainManager(),
} }
pipe.world = NewWorld(pipe) pipe.world = NewWorld(pipe)
@ -51,7 +51,7 @@ func (self *XEth) Nonce(addr []byte) uint64 {
} }
func (self *XEth) Block(hash []byte) *types.Block { func (self *XEth) Block(hash []byte) *types.Block {
return self.blockChain.GetBlock(hash) return self.chainManager.GetBlock(hash)
} }
func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value { func (self *XEth) Storage(addr, storageAddr []byte) *ethutil.Value {
@ -82,7 +82,7 @@ func (self *XEth) Execute(addr []byte, data []byte, value, gas, price *ethutil.V
func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) { func (self *XEth) ExecuteObject(object *Object, data []byte, value, gas, price *ethutil.Value) ([]byte, error) {
var ( var (
initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address()) initiator = state.NewStateObject(self.obj.KeyManager().KeyPair().Address())
block = self.blockChain.CurrentBlock block = self.chainManager.CurrentBlock
) )
self.Vm.State = self.World().State().Copy() self.Vm.State = self.World().State().Copy()
@ -131,14 +131,14 @@ func (self *XEth) Transact(key *crypto.KeyPair, to []byte, value, gas, price *et
tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data) tx = types.NewTransactionMessage(hash, value.BigInt(), gas.BigInt(), price.BigInt(), data)
} }
state := self.blockManager.TransState() state := self.chainManager.TransState()
nonce := state.GetNonce(key.Address()) nonce := state.GetNonce(key.Address())
tx.Nonce = nonce tx.Nonce = nonce
tx.Sign(key.PrivateKey) tx.Sign(key.PrivateKey)
// Do some pre processing for our "pre" events and hooks // Do some pre processing for our "pre" events and hooks
block := self.blockChain.NewBlock(key.Address()) block := self.chainManager.NewBlock(key.Address())
coinbase := state.GetStateObject(key.Address()) coinbase := state.GetStateObject(key.Address())
coinbase.SetGasPool(block.GasLimit) coinbase.SetGasPool(block.GasLimit)
self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true) self.blockManager.ApplyTransactions(coinbase, state, block, types.Transactions{tx}, true)

View File

@ -23,7 +23,7 @@ func (self *XEth) World() *World {
} }
func (self *World) State() *state.StateDB { func (self *World) State() *state.StateDB {
return self.pipe.blockManager.CurrentState() return self.pipe.chainManager.State()
} }
func (self *World) Get(addr []byte) *Object { func (self *World) Get(addr []byte) *Object {