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

@ -84,20 +84,10 @@ func NewBlockManager(ethereum EthManager) *BlockManager {
eth: ethereum,
bc: ethereum.ChainManager(),
}
sm.transState = ethereum.ChainManager().CurrentBlock.State().Copy()
sm.miningState = ethereum.ChainManager().CurrentBlock.State().Copy()
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) {
coinbase := statedb.GetOrNewStateObject(block.Coinbase)
coinbase.SetGasPool(block.CalcGasLimit(parent))

View File

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

View File

@ -116,7 +116,7 @@ func (pool *TxPool) ValidateTransaction(tx *types.Transaction) error {
}
// 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)
// Make sure there's enough in the sender's account. Having insufficient